Class: SubscriptionService

SubscriptionService

new SubscriptionService()

Creates a new SubscriptionService. Generally you should never create a PAYMILL service on your own. Instead use the exported "subscriptions".
Source:

Classes

Creator

Methods

cancel(obj, cb) → {Promise}

This function cancels an existing subscription. The subscription will be directly terminated and no pending transactions will be charged.
Parameters:
Name Type Argument Description
obj string | Subscription a Subscription object or its id. note, if you set a Subscription object it will be updated, no new object will be created.
cb Object <optional>
a callback.
Source:
Returns:
a promise, which will be fulfilled with a Subscription or rejected with a PMError.
Type
Promise

changeAmount(obj, amount, currency, interval, cb) → {Promise}

Changes the amount of a subscription. The new amount is valid until the end of the subscription. If you want to set a temporary one-time amount use changeAmountTemporary().
Parameters:
Name Type Argument Description
obj string | Subscription a Subscription object or its id. note, if you set a Subscription object it will be updated, no new object will be created.
amount string | number the new amount.
currency string <optional>
optionally, a new currency.
interval string | Interval <optional>
optionally, a new interval.
cb Object <optional>
a callback.
Source:
Returns:
a promise, which will be fulfilled with a Subscription or rejected with a PMError.
Type
Promise

changeAmountTemporary(obj, amount, cb) → {Promise}

Changes the amount of a subscription. The new amount is valid one-time only after which the original subscription amount will be charged again. If you want to permanently change the amount use changeAmount()
Parameters:
Name Type Argument Description
obj string | Subscription a Subscription object or its id. note, if you set a Subscription object it will be updated, no new object will be created.
amount string | number the new amount.
cb Object <optional>
a callback.
Source:
Returns:
a promise, which will be fulfilled with a Subscription or rejected with a PMError.
Type
Promise

changeOfferChangeCaptureDateAndRefund(obj, offer, cb) → {Promise}

Change the offer of a subscription.
The plan will be changed immediately. The next_capture_at will change to the current date (immediately). A refund will be given if due.
If the new amount is higher than the old one, a pro-rata charge will occur. The next charge date is immediate i.e. the current date. If the new amount is less then the old one, a pro-rata refund will occur. The next charge date is immediate i.e. the current date.
IMPORTANT
Permitted up only until one day (24 hours) before the next charge date.
Parameters:
Name Type Argument Description
obj string | Subscription a Subscription object or its id. note, if you set a Subscription object it will be updated, no new object will be created.
offer string | Offer a new offer or its id.
cb Object <optional>
a callback.
Source:
Returns:
a promise, which will be fulfilled with a Subscription or rejected with a PMError.
Type
Promise

changeOfferKeepCaptureDateAndRefund(obj, offer, cb) → {Promise}

Change the offer of a subscription.
The plan will be changed immediately. The next_capture_at will change to the current date (immediately). A refund will be given if due.
If the new amount is higher than the old one, a pro-rata charge will occur. The next charge date is immediate i.e. the current date. If the new amount is less then the old one, a pro-rata refund will occur. The next charge date is immediate i.e. the current date.
IMPORTANT
Permitted up only until one day (24 hours) before the next charge date.
Parameters:
Name Type Argument Description
obj string | Subscription a Subscription object or its id. note, if you set a Subscription object it will be updated, no new object will be created.
offer string | Offer a new offer or its id.
cb Object <optional>
a callback.
Source:
Returns:
a promise, which will be fulfilled with a Subscription or rejected with a PMError.
Type
Promise

changeOfferKeepCaptureDateNoRefund(obj, offer, cb) → {Promise}

Change the offer of a subscription.
the plan will be changed immediately. The next_capture_at date will remain unchanged. No refund will be given
IMPORTANT
Permitted up only until one day (24 hours) before the next charge date.
Parameters:
Name Type Argument Description
obj string | Subscription a Subscription object or its id. note, if you set a Subscription object it will be updated, no new object will be created.
offer string | Offer a new offer or its id.
cb Object <optional>
a callback.
Source:
Returns:
a promise, which will be fulfilled with a Subscription or rejected with a PMError.
Type
Promise

createWithAll(offer, payment, client, start_at, amount, currency, interval, periodOfValidity, name, cb) → {Promise}

This function creates a Subscription between a Client and an Offer. A Client can have several Subscriptions to different Offers, but only one Subscription to the same Offer. The Clients is charged for each billing interval entered. NOTEAs the Subscription create method has a lot of options, we recommend you to use a Subscription.Creator.
Parameters:
Name Type Argument Description
offer string | Offer an offer object or its id.
payment string | Payment a payment object or its id.
client string | Client the identifier of a client or a client. If not provided the client from the payment is being used.
start_at string | number | Date Unix-Timestamp for the subscription start date, if trial_end > start_at, the trial_end will be set to start_at
amount string | number the amount of the subscription in cents
currency string ISO 4217 formatted currency code startAt
interval string | Interval define how often the client should be charged.
periodOfValidity string | Interval limits the validity of the subscription
name string name of the subscription
cb Object <optional>
a callback.
Source:
Returns:
a promise, which will be fulfilled with a Subscription or rejected with a PMError.
Type
Promise

delete(obj, cb) → {Promise}

This function removes an existing subscription. The subscription will be deleted and no pending transactions will be charged. Deleted subscriptions will not be displayed.
Parameters:
Name Type Argument Description
obj string | Subscription a Subscription object or its id. note, if you set a Subscription object it will be updated, no new object will be created.
cb Object <optional>
a callback.
Source:
Returns:
a promise, which will be fulfilled with a Subscription or rejected with a PMError.
Type
Promise

detail(obj, cb) → {Promise}

Get a Subscription.
Parameters:
Name Type Argument Description
obj string | Subscription a Subscription object or its id. note, if you set a Subscription object it will be updated, no new object will be created.
cb Object <optional>
a callback.
Source:
Returns:
a promise, which will be fulfilled with a Subscription or rejected with a PMError.
Type
Promise

endTrial(obj, cb) → {Promise}

Stop the trial period of a subscription and charge immediately.
Parameters:
Name Type Argument Description
obj string | Subscription a Subscription object or its id. note, if you set a Subscription object it will be updated, no new object will be created.
cb Object <optional>
a callback.
Source:
Returns:
a promise, which will be fulfilled with a Subscription or rejected with a PMError.
Type
Promise

endTrialAt(obj, date, cb) → {Promise}

Stop the trial period of a subscription on a specific date.
Parameters:
Name Type Argument Description
obj string | Subscription a Subscription object or its id. note, if you set a Subscription object it will be updated, no new object will be created.
date string | number | Date the date, on which the subscription should end.
cb Object <optional>
a callback.
Source:
Returns:
a promise, which will be fulfilled with a Subscription or rejected with a PMError.
Type
Promise

fromOffer(offer, payment) → {SubscriptionService.Creator}

Create a subscription with payment and offer. Chain further values by calling with..() functions and finish by calling create().
Parameters:
Name Type Description
offer string | Offer an offer object or its id.
payment string | Payment a payment object or its id.
Source:
Returns:
a creator. when configured please call create()
Type
SubscriptionService.Creator

limitValidity(obj, newValidity, cb) → {Promise}

Change the period of validity for a subscription.
Parameters:
Name Type Argument Description
obj string | Subscription a Subscription object or its id. note, if you set a Subscription object it will be updated, no new object will be created.
newValidity string | Interval the new validity.
cb Object <optional>
a callback.
Source:
Returns:
a promise, which will be fulfilled with a Subscription or rejected with a PMError.
Type
Promise

list(count, offset, filter, order, cb) → {Promise}

List Subscriptions.
Parameters:
Name Type Argument Description
count string | number <optional>
limit of objects to be listed. use for pagination.
offset string | number <optional>
offset. use for pagination.
filter Subscription.Filter | null <optional>
a list filter or null.
order Subscription.Order | null <optional>
a list order or null.
cb Object <optional>
a callback.
Source:
Returns:
a promise, which will be fulfilled with a PayMillObjectList or rejected with a PMError.
Type
Promise

pause(obj, cb) → {Promise}

Temporary pauses a subscription.
NOTE
Pausing is permitted until one day (24 hours) before the next charge date.
Parameters:
Name Type Argument Description
obj string | Subscription a Subscription object or its id. note, if you set a Subscription object it will be updated, no new object will be created.
cb Object <optional>
a callback.
Source:
Returns:
a promise, which will be fulfilled with a Subscription or rejected with a PMError.
Type
Promise

remove(obj, cb) → {Promise}

Remove a Subscription. f you set the attribute cancel_at_period_end parameter to the value true, the subscription will remain active until the end of the period. The subscription will not be renewed again. If the value is set to false it is directly terminated but pending transactions will still be charged.
Parameters:
Name Type Argument Description
obj Subscription a Subscription object or its id.
cb Object <optional>
a callback.
Source:
Returns:
a promise, which will be fulfilled with a Subscription or rejected with a PMError.
Type
Promise

unlimitValidity(obj, cb) → {Promise}

Change the validity of a subscription to unlimited
Parameters:
Name Type Argument Description
obj string | Subscription a Subscription object or its id. note, if you set a Subscription object it will be updated, no new object will be created.
cb Object <optional>
a callback.
Source:
Returns:
a promise, which will be fulfilled with a Subscription or rejected with a PMError.
Type
Promise

unpause(obj, cb) → {Promise}

Unpauses a subscription. Next charge will occur according to the defined interval.
NOTE
if the nextCaptureAt is the date of reactivation: a charge will happen
if the next_capture_at is in the past: it will be set to: reactivationdate + interval

IMPORTANT
An inactive subscription can reactivated within 13 month from the date of pausing. After this period, the subscription will expire and cannot be re-activated.
Parameters:
Name Type Argument Description
obj string | Subscription a Subscription object or its id. note, if you set a Subscription object it will be updated, no new object will be created.
cb Object <optional>
a callback.
Source:
Returns:
a promise, which will be fulfilled with a Subscription or rejected with a PMError.
Type
Promise

update(obj, cb) → {Promise}

Updates a subscription.Following fields will be updated:

  • interval (note, that nextCaptureAt will not change.)
  • currency
  • name
  • payment

      To update further properties of a subscription use following methods:

      • cancel() to cancel.
      • changeAmount() to change the amount.
      • changeOfferChangeCaptureDateAndRefund() to change the offer.
      • changeOfferKeepCaptureDateAndRefund() to change the offer.
      • changeOfferKeepCaptureDateNoRefund() to change the offer.
      • endTrial() to end the trial
      • limitValidity() to change the validity.
      • pause() to pause
      • unlimitValidity() to change the validity.
      • unpause() to unpause.

Parameters:
Name Type Argument Description
obj Subscription a Subscription object.
cb Object <optional>
a callback.
Source:
Returns:
a promise, which will be fulfilled with a Subscription or rejected with a PMError.
Type
Promise