CartsResource
You can use carts for all the necessary operations to manage a customer's cart and implement cart functionality in your application. You can handle everything related to managing items in the cart before checkout such as adding, removing items, updating quantities, accessing payment and checkout urls and more.
Methods
addProduct()
addProduct(cartToken, input): Promise<{
orderedProduct: FirmhouseOrderedProduct;
subscription: FirmhouseCart;
}>Add a product to the cart
Parameters
• cartToken: string
Cart token
• input
Parameters for the added product
customPriceCents?:
null|numberA custom price in cents for this ordered product, if left blank the default product price will be used
ensureNewRecord?:
null|booleanCreate 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?:
null|numberThe amount of time in units between shipments of this order
intervalUnitOfMeasureType?:
null|OrderedProductIntervalUnitOfMeasureThe time measure for interval units
metadata?:
unknownMetadata that can be used by developers to store additional information on objects.
productId?:
null|stringID for the related product
quantity?:
null|numberThe quantity for this ordered product.
shipmentDate?:
null|stringThe next date on which a new order should get initiated
Example
2000-01-01shopifyVariantId?:
null|stringUse this field to look up the associated product based on Shopify Variant ID.
sku?:
null|stringUse this field to look up the associated product based on SKU.
slug?:
null|stringUse this field to look up the associated product based on slug.
subscriptionId?:
null|stringID of the subscription to create this OrderedProduct for. Required if authenticated via a project access token
Returns
Promise<{ orderedProduct: FirmhouseOrderedProduct; subscription: FirmhouseCart; }>
subscription after adding the product and the ordered product
Throws
ServerError Thrown if the product could not be added to the cart
ValidationError Thrown if the input is invalid
NotFoundError Thrown if the product or cart is not found
createCartToken()
createCartToken(): Promise<string>Create a new cart and return the subscription token
Returns
Promise<string>
cart token
Throws
ServerError Thrown if no token is returned from the API
createSubscription()
createSubscription(
cartToken,
paymentPageUrl,
returnUrl): Promise<{
paymentUrl: null | string;
returnUrl: createSubscriptionFromCart.returnUrl;
subscription: FirmhouseCart;
}>Finalises a subscription and returns payment details based on a cart/draft subscription
Parameters
• cartToken: string
Cart token
• paymentPageUrl: string
The URL where the user can sign up for a new subscription
• returnUrl: string
The URL the user gets redirected to after completing payment
Returns
Promise<{ paymentUrl: null | string; returnUrl: createSubscriptionFromCart.returnUrl; subscription: FirmhouseCart; }>
Payment details and validation errors if any
paymentUrl
null | string
-
returnUrl
null | string
createSubscriptionFromCart.returnUrl
Throws
ValidationError Thrown if required fields is missing from cart
ServerError Thrown if the subscription could not be created
NotFoundError Thrown if the cart is not found
get()
get(token, includeRelations?): Promise<FirmhouseCart>Get a cart by cart token
Parameters
• token: string
Cart token
• includeRelations?
Relations to include
appliedPromotions?: Include applied promotions
includeRelations?: Include relations for applied promotions
discountCode?:
booleanInclude the discountCode relation
promotion?:
booleanInclude the promotion relation
discountCodes?: Parameters for including discountCodes Relation
includeRelations?: Include relations for discountCodes
autoSelectPlan?:
booleanInclude the autoSelectPlan relation
promotion?:
booleanInclude the promotion relation
Returns
Promise<FirmhouseCart>
Cart
Throws
NotFoundError Thrown if the cart is not found
getOrCreate()
getOrCreate(token?, includeRelations?): Promise<FirmhouseCart>Try to get a cart by token, if it exists and is a subscription in draft status, return it. Otherwise create a new cart.
Parameters
• token?: string
Cart token
• includeRelations?
appliedPromotions?: Include applied promotions
includeRelations?: Include relations for applied promotions
discountCode?:
booleanInclude the discountCode relation
promotion?:
booleanInclude the promotion relation
discountCodes?: Parameters for including discountCodes Relation
includeRelations?: Include relations for discountCodes
autoSelectPlan?:
booleanInclude the autoSelectPlan relation
promotion?:
booleanInclude the promotion relation
Returns
Promise<FirmhouseCart>
Cart if it exists, otherwise a new cart
removeProduct()
removeProduct(cartToken, orderedProductId): Promise<{
orderedProduct: FirmhouseOrderedProduct;
subscription: FirmhouseCart;
}>Remove a product from the cart
Parameters
• cartToken: string
Cart token
• orderedProductId: string
Ordered product id to remove from the cart
Returns
Promise<{ orderedProduct: FirmhouseOrderedProduct; subscription: FirmhouseCart; }>
subscription after removing the product and the removed product
Throws
ServerError Thrown if the product could not be removed from the cart
NotFoundError Thrown if the product or cart is not found
updateAddressDetails()
updateAddressDetails(cartToken, input): Promise<FirmhouseCart>Update the address details of a subscription.
Parameters
• cartToken: string
Cart token
• input
Address details, address, name, email, etc
activatedAt?:
null|stringThe time the subscription was activated
Example
2024-01-15T00:00:00+01:00address?:
null|stringThe customer's address line or street.
adyenShopperReference?:
null|stringThe Adyen shopper reference being used for charges.
billToAddress?:
null|stringThe customer's billing address address line or street.
billToCity?:
null|stringThe customer's billing address city or town.
billToCompanyName?:
null|stringThe company name of the customer's billing address.
billToCountry?:
null|stringThe customer's billing address country code (ISO3661).
billToDistrict?:
null|stringThe customer's billing address district.
billToHouseNumber?:
null|stringThe customer's billing address house, building, or appartment number.
billToLastName?:
null|stringThe customer's billing address last name.
billToName?:
null|stringThe customer's billing address first name.
billToPhoneNumber?:
null|stringThe customer's billing address phone number (international format).
billToSalutation?:
null|stringThe customer's billing address salutation (mr,ms,mx).
billToState?:
null|stringThe customer's billing address state or province (ISO3661-2).
billToZipcode?:
null|stringThe customer's billing address zip code or postal code.
cancellationStartedAt?:
null|stringThe time the subscription started the cancellation process (with two-step cancellation)
Example
2024-01-15T00:00:00+01:00cancelledAt?:
null|stringThe time the subscription was (fully) cancelled.
Example
2024-01-15T00:00:00+01:00chargeDayOfTheMonth?:
null|numberThe day of the month when the customer is charged.
city?:
null|stringThe customer's city or town.
companyName?:
null|stringThe company name of the customer.
country?:
null|stringThe customer's country code (ISO3661).
customerReference?:
null|stringThe field that can be used for your internal reference. For example, internal customer id.
dateOfBirth?:
null|stringThe customer's date of birth (yyyy-mm-dd).
Example
2000-01-01differentBillingAddress?:
null|booleanWhether billing and shipping addresses are the same. Set this flag to
trueto store a separate billing address.district?:
null|stringThe customer's district.
email?:
null|stringThe customer's email address.
extraFields?:
null|ExtraFieldInput[]Extra field values for the subscription.
houseNumber?:
null|stringThe customer's house, building, or appartment number.
importedSubscriptionId?:
null|stringUnique ID for an imported subscription.
lastName?:
null|stringThe customer's last name.
locale?:
null|stringThe customer's language/locale. Must be enabled on the project.
markedAsNonPayingAt?:
null|stringTime time the subscription was marked as non-paying.
Example
2024-01-15T00:00:00+01:00marketingOptIn?:
null|booleanWhether the customer accepted optional marketing communication opt-in.
metadata?:
unknownMetadata that can be used by developers to store additional information on objects.
mollieCustomerId?:
null|stringThe Mollie Customer ID (cst_XXX)
name?:
null|stringThe customer's first name.
notes?:
null|stringNotes specific for this subscription
phoneNumber?:
null|stringThe customer's phone number (international format).
pspPaymentProperties?:
unknownAdditional payment service provider specific properties used for payment creation.
salutation?:
null|stringThe customer's salutation (mr,ms,mx).
signupCompletedAt?:
null|stringThe time when the signup was completed.
Example
2024-01-15T00:00:00+01:00skipAutoActivationOnSignup?:
null|booleanDon't automatically activate the subscription on signup.
state?:
null|stringThe customer's state or province (ISO3661-2).
status?:
null|SubscriptionStatusThe current status of the subscription. (default: inactive)
stripeCustomerId?:
null|stringThe Stripe Customer ID (cus_XXX)
stripePaymentMethodId?:
null|stringThe Stripe Payment Method ID of the active payment method to charge. (pm_XXX)
termsAccepted?:
null|booleanWhether the customer accepted the terms and conditions.
token?:
null|stringThe token of the subscription to update, or creates a new one if one doesn't exist.
trialPeriodMonths?:
null|numberThe number of months before the customer is charged for the first time.
vatNumber?:
null|stringThe company VAT number.
zipcode?:
null|stringThe customer's zip code or postal code.
Returns
Promise<FirmhouseCart>
Updated cart and validation errors
Remarks
Will save changes to certain fields even when other fields given are invalid. Will return validation error messages for invalid fields.
Throws
ValidationError Thrown if the input is invalid
ServerError Thrown if the address details could not be updated
NotFoundError Thrown if the cart is not found
updateOrderedProduct()
updateOrderedProduct(cartToken, input): Promise<{
orderedProduct: FirmhouseOrderedProduct;
subscription: FirmhouseCart;
}>Update an ordered product
Parameters
• cartToken: string
Cart token
• input
Payload for fields to update
customPriceCents?:
null|numberA custom price in cents for this ordered product, if left blank the default product price will be used
id?:
null|stringID of this ordered product.
interval?:
null|numberThe amount of time in units between shipments of this order
intervalUnitOfMeasureType?:
null|OrderedProductIntervalUnitOfMeasureThe time measure for interval units
metadata?:
unknownMetadata that can be used by developers to store additional information on objects.
productId?:
null|stringID for the related product
quantity?:
null|numberThe quantity for this ordered product.
shipmentDate?:
null|stringThe next date on which a new order should get initiated
Example
2024-01-01
Returns
Promise<{ orderedProduct: FirmhouseOrderedProduct; subscription: FirmhouseCart; }>
Updated cart
Throws
ServerError Thrown if the ordered product could not be updated
ValidationError Thrown if the input is invalid
NotFoundError Thrown if the product or cart is not found
updateOrderedProductQuantity()
updateOrderedProductQuantity(
cartToken,
orderedProductId,
quantity): Promise<{
orderedProduct: FirmhouseOrderedProduct;
subscription: FirmhouseCart;
}>Update a product quantity in the cart
Parameters
• cartToken: string
Cart token
• orderedProductId: string
Ordered product id to update quantity
• quantity: number
New quantity
Returns
Promise<{ orderedProduct: FirmhouseOrderedProduct; subscription: FirmhouseCart; }>
Updated cart
Throws
ServerError Thrown if the product quantity could not be updated
NotFoundError Thrown if the product or cart is not found
ValidationError Thrown if the input is invalid
updatePlan()
updatePlan(cartToken, planSlug): Promise<FirmhouseCart>Updates the active plan of a subscription
Parameters
• cartToken: string
Cart token
• planSlug: string
Slug of the plan to update the subscription to
Returns
Promise<FirmhouseCart>
Updated cart
Throws
ServerError Thrown if the plan could not be changed
NotFoundError Thrown if the cart or plan is not found
Last updated
Was this helpful?