Class: SubscriptionsResource
You can use subscriptions to manage the subscriptions in your project. It's similar to the carts but the difference is that the subscriptions are carts that are already checked out.
Methods
addProduct()
addProduct(subscriptionToken, input): Promise<{
orderedProduct: FirmhouseOrderedProduct;
subscription: FirmhouseSubscription;
}>;Add a new product to subscription
Parameters
subscriptionToken
string
Subscription token
input
Parameters for the added product
customPriceCents?
number | null
A custom price in cents for this ordered product, if left blank the default product price will be used
ensureNewRecord?
boolean | null
Create a new record even if the same product already exists in subscription. Without this paramater when you add a new product and if the product already exists in the subscription, the quantity of the product will be updated.
interval?
number | null
The amount of time in units between shipments of this order
intervalUnitOfMeasure?
string | null
The time measure for interval units. This argument is deprecated. Use intervalUnitOfMeasureType instead. If intervalUnitOfMeasureType passed, this field will be ignored.
intervalUnitOfMeasureType?
| OrderedProductIntervalUnitOfMeasure | null
The time measure for interval units
metadata?
unknown
Metadata that can be used by developers to store additional information on objects.
productId?
string | null
ID for the related product
quantity?
number | null
The quantity for this ordered product.
shipmentDate?
string | null
The next date on which a new order should get initiated
Example
shopifyVariantId?
string | null
Use this field to look up the associated product based on Shopify Variant ID.
sku?
string | null
Use this field to look up the associated product based on SKU.
slug?
string | null
Use this field to look up the associated product based on slug.
subscriptionId?
string | null
ID of the subscription to create this OrderedProduct for. Required if authenticated via a project access token
Returns
Promise<{ orderedProduct: FirmhouseOrderedProduct; subscription: FirmhouseSubscription; }>
Ordered product and subscription
Throws
ServerError - When the request fails
NotFoundError - When the product or subscription is not found
applyPromotion()
Applies a promotion to a subscription.
Parameters
subscriptionId
string
ID of the subscription to apply the promotion to.
promotionId
string
ID of the promotion to apply.
Returns
Promise< | FirmhouseAppliedOrderDiscountPromotion | FirmhouseBillingCyclePromotion>
Applied promotion
Throws
ServerError - When the request fails
ValidationError - When there are invalid fields
applyPromotionWithDiscountCode()
Beta
Apply a promotion using a discount code to a subscription
Parameters
subscriptionToken
string
Subscription token
code
string
Discount code to apply
Returns
Promise< | FirmhouseAppliedOrderDiscountPromotion | FirmhouseBillingCyclePromotion>
Applied promotion
Throws
ServerError - When the request fails
ValidationError - When there are invalid fields
NotFoundError - When the subscription is not found
cancel()
Cancel a subscription
Parameters
subscriptionId
string
ID of the subscription to cancel
input?
Payload for cancellation
cancellationNotes?
string | null
Why did this customer decide to cancel?
skipCancellationConfirmationEmail?
boolean | null
Skip sending the standard cancellation confirmation email to the customer.
skipContractTermsEnforcement?
boolean | null
If a customer cannot be cancelled due to active commitments, this process can be skipped.
skipTwoStepCancellation?
boolean | null
If two-step cancellation is enabled it can be skipped
Returns
Promise<FirmhouseSubscription>
Cancelled subscription
Throws
ValidationError - When the request is not in cancellable state
ServerError - When the request fails
NotFoundError - When the subscription is not found
deactivateAppliedPromotion()
Deactivates an applied promotion
Parameters
appliedPromotionId
string
ID of the applied promotion that needs to be deactivated.
Returns
Promise< | FirmhouseAppliedOrderDiscountPromotion | FirmhouseBillingCyclePromotion>
Deactivated applied promotion
Throws
ServerError - When the request fails
get()
Get a subscription by subscription token including relations
Parameters
token
string
Subscription token
includeRelations?
Relations to include
appliedPromotions?
{ includeRelations?: { discountCode?: boolean; promotion?: boolean; }; }
Include applied promotions
appliedPromotions.includeRelations?
{ discountCode?: boolean; promotion?: boolean; }
Include relations for applied promotions
appliedPromotions.includeRelations.discountCode?
boolean
Include the discountCode relation
appliedPromotions.includeRelations.promotion?
boolean
Include the promotion relation
collectionCases?
boolean
Include collectionCases relation
discountCodes?
{ includeRelations?: { autoSelectPlan?: boolean; promotion?: boolean; }; }
Parameters for including discountCodes Relation
discountCodes.includeRelations?
{ autoSelectPlan?: boolean; promotion?: boolean; }
Include relations for discountCodes
discountCodes.includeRelations.autoSelectPlan?
boolean
Include the autoSelectPlan relation
discountCodes.includeRelations.promotion?
boolean
Include the promotion relation
invoices?
{ includeRelations?: { collectionCase?: boolean; invoiceLineItems?: boolean; invoiceReminders?: boolean; originalInvoice?: boolean; payment?: boolean; }; }
Parameters for including invoices relation
invoices.includeRelations?
{ collectionCase?: boolean; invoiceLineItems?: boolean; invoiceReminders?: boolean; originalInvoice?: boolean; payment?: boolean; }
Include collectionCase relation
invoices.includeRelations.collectionCase?
boolean
Include collectionCase relation
invoices.includeRelations.invoiceLineItems?
boolean
Include invoiceLineItems relation
invoices.includeRelations.invoiceReminders?
boolean
Include invoiceReminders relation
invoices.includeRelations.originalInvoice?
boolean
Include originalInvoice relation
invoices.includeRelations.payment?
boolean
Include payment relation
orders?
{ after?: string; before?: string; first?: number; includeRelations?: { invoice?: boolean; orderLines?: boolean; payment?: boolean; }; last?: number; }
Parameters for including orders relation
orders.after?
string
Fetch orders after this cursor
orders.before?
string
Fetch orders before this cursor
orders.first?
number
Fetch first n orders
orders.includeRelations?
{ invoice?: boolean; orderLines?: boolean; payment?: boolean; }
Include relations for orders
orders.includeRelations.invoice?
boolean
Include invoice relation
orders.includeRelations.orderLines?
boolean
Include orderLines relation
orders.includeRelations.payment?
boolean
Include payment relation
orders.last?
number
Fetch last n orders
verifiedIdentity?
boolean
Include verifiedIdentity relation
Returns
Promise<FirmhouseSubscription>
Subscription
Throws
NotFoundError - When the subscription is not found
getBySelfServiceCenterLoginToken()
Get a subscription by self service center login token
Parameters
token
string
Self service center login token
Returns
Promise<FirmhouseSubscription>
Subscription
Throws
NotFoundError - When the subscription is not found
pause()
Pause a subscription
Parameters
subscriptionId
string
ID of the subscription to pause
input?
Payload for pausing
pauseUntil?
string | null
Time from which the subscription automaticaly resumes again.
Example
Returns
Promise<FirmhouseSubscription>
Paused subscription
Throws
ValidationError - When the request is not in pausable state
ServerError - When the request fails
NotFoundError - When the subscription is not found
removeProduct()
Remove a product from subscription
Parameters
subscriptionToken
string
Subscription token
orderedProductId
string
Ordered product id to destroy
Returns
Promise<{ subscription: FirmhouseSubscription; }>
Subscription
Throws
ServerError - When the request fails
NotFoundError - When the product is not found
resume()
Resume a subscription
Parameters
subscriptionId
string
ID of the subscription to resume
input?
Payload for resuming
resumeFrom?
string | null
Time to resume the subscription from. If not given the subscription will be immediately resumed.
Example
Returns
Promise<FirmhouseSubscription>
Resumed subscription
Throws
ValidationError - When the request is not in resumable state
ServerError - When the request fails
NotFoundError - When the subscription is not found
updateAppliedPromotion()
Updates a promotion applied to a subscription
Parameters
input
Paramater for updating the applied promotion
active?
boolean | null
Whether this promotion should actively be used for this subscription.
deactivateAfterAmountIncludingTaxCents?
number | null
The maximum discount amount in cents that this promotion should provide.Only applicable when using the VALUE deactivation strategy.
deactivateAfterTimes?
number | null
After how mamy times used this applied promotion should get deactivated.Only applicable when using the TIMES deactivation strategy.
id
string
ID of the applied promotion that needs to be updated.
Returns
Promise< | FirmhouseAppliedOrderDiscountPromotion | FirmhouseBillingCyclePromotion>
Applied promotion
Throws
ServerError - When the request fails
ValidationError - When there are invalid fields
NotFoundError - When the subscription is not found
updateOrderedProduct()
Update a product in the subscription
Parameters
subscriptionToken
string
Subscription token
input
Payload for fields to update
customPriceCents?
number | null
A custom price in cents for this ordered product, if left blank the default product price will be used
id?
string | null
ID of the ordered product to update
interval?
number | null
The amount of time in units between shipments of this order
intervalUnitOfMeasure?
string | null
The time measure for interval units. This argument is deprecated. Use intervalUnitOfMeasureType instead. If intervalUnitOfMeasureType passed, this field will be ignored.
intervalUnitOfMeasureType?
| OrderedProductIntervalUnitOfMeasure | null
The time measure for interval units
metadata?
unknown
Metadata that can be used by developers to store additional information on objects.
productId?
string | null
ID for the related product
quantity?
number | null
The quantity for this ordered product.
shipmentDate?
string | null
The next date on which a new order should get initiated
Example
Returns
Promise<{ orderedProduct: FirmhouseOrderedProduct; subscription: FirmhouseSubscription; }>
Updated subscription and ordered product
Throws
ServerError - When the request fails
NotFoundError - When the product is not found
ValidationError - When there are invalid fields
updatePlan()
Update the plan of a subscription
Parameters
subscriptionToken
string
Subscription token
planSlug
string
Slug of the plan to update to
Returns
Promise<FirmhouseSubscription>
Updated subscription
Throws
ServerError - When the request fails
NotFoundError - When the plan or subscription is not found
updateSubscription()
Update a subscription.
Parameters
subscriptionToken
string
Subscription token
input
Payload for updating subscription
activatedAt?
string | null
The time the subscription was activated
Example
address?
string | null
The customer's address line or street.
adyenShopperReference?
string | null
The Adyen shopper reference being used for charges.
billToAddress?
string | null
The customer's billing address address line or street.
billToCity?
string | null
The customer's billing address city or town.
billToCompanyName?
string | null
The company name of the customer's billing address.
billToCountry?
string | null
The customer's billing address country code (ISO3661).
billToDistrict?
string | null
The customer's billing address district.
billToHouseNumber?
string | null
The customer's billing address house, building, or appartment number.
billToLastName?
string | null
The customer's billing address last name.
billToName?
string | null
The customer's billing address first name.
billToPhoneNumber?
string | null
The customer's billing address phone number (international format).
billToSalutation?
string | null
The customer's billing address salutation (mr,ms,mx).
billToState?
string | null
The customer's billing address state or province (ISO3661-2).
billToZipcode?
string | null
The customer's billing address zip code or postal code.
cancellationStartedAt?
string | null
The time the subscription started the cancellation process (with two-step cancellation)
Example
cancelledAt?
string | null
The time the subscription was (fully) cancelled.
Example
chargeDayOfTheMonth?
number | null
The day of the month when the customer is charged.
city?
string | null
The customer's city or town.
companyName?
string | null
The company name of the customer.
country?
string | null
The customer's country code (ISO3661).
customerReference?
string | null
The field that can be used for your internal reference. For example, internal customer id.
dateOfBirth?
string | null
The customer's date of birth (yyyy-mm-dd).
Example
differentBillingAddress?
boolean | null
Whether billing and shipping addresses are the same. Set this flag to true to store a separate billing address.
district?
string | null
The customer's district.
email?
string | null
The customer's email address.
extraFields?
ExtraFieldInput[] | null
Extra field values for the subscription.
houseNumber?
string | null
The customer's house, building, or appartment number.
importedSubscriptionId?
string | null
Unique ID for an imported subscription.
lastName?
string | null
The customer's last name.
locale?
string | null
The customer's language/locale. Must be enabled on the project.
markedAsNonPayingAt?
string | null
Time time the subscription was marked as non-paying.
Example
marketingOptIn?
boolean | null
Whether the customer accepted optional marketing communication opt-in.
metadata?
unknown
Metadata that can be used by developers to store additional information on objects.
mollieCustomerId?
string | null
The Mollie Customer ID (cst_XXX)
name?
string | null
The customer's first name.
notes?
string | null
Notes specific for this subscription
phoneNumber?
string | null
The customer's phone number (international format).
pspPaymentProperties?
unknown
Additional payment service provider specific properties used for payment creation.
salutation?
string | null
The customer's salutation (mr,ms,mx).
signupCompletedAt?
string | null
The time when the signup was completed.
Example
skipAutoActivationOnSignup?
boolean | null
Don't automatically activate the subscription on signup.
state?
string | null
The customer's state or province (ISO3661-2).
status?
SubscriptionStatus | null
The current status of the subscription. (default: inactive)
stripeCustomerId?
string | null
The Stripe Customer ID (cus_XXX)
stripePaymentMethodId?
string | null
The Stripe Payment Method ID of the active payment method to charge. (pm_XXX)
termsAccepted?
boolean | null
Whether the customer accepted the terms and conditions.
token?
string | null
The token of the subscription to update, or creates a new one if one doesn't exist.
trialPeriodMonths?
number | null
The number of months before the customer is charged for the first time.
vatNumber?
string | null
The company VAT number.
zipcode?
string | null
The customer's zip code or postal code.
Returns
Promise<FirmhouseSubscription>
Updated subscription and validation errors
Remarks
Will return validation error messages for invalid fields.
Throws
ServerError - When the request fails
ValidationError - When there are invalid fields
NotFoundError - When the subscription is not found
Last updated
Was this helpful?