Subbly.js reference

Introduction

This reference documents every method available in Subbly's browser-side JavaScript library, Subbly.js SDK.

Using Subbly.js SDK script in your application

Installing from npm

npm install @subbly/sdk

Import with ES6 modules. Recommended way to use Subbly.js SDK with modern JavaScript frameworks like React.js and Vue.js.

import Subbly from '@subbly/sdk'

Subbly.init({
  apiKey: 'API_KEY'
}).then((subbly) => {
  // access Subbly SDK methods
})

Using CDN

Alternatively, use CDN to include the script on your HTML page. You need to do this only once per page.

<script src="https://cdn.jsdelivr.net/npm/@subbly/sdk"></script>
<script>
  window.Subbly.init({
    apiKey: 'API_KEY'
  }).then((subbly) => {
    // access Subbly SDK methods
  })
</script>

Configuration

apiKey REQUIRED string

The Subbly Storefront API key is required. To obtain your API key, visit Shop Settingsopen in new window in Subbly Admin.

cartId optional string

Manually provide a Cart ID to initialize the SDK with. By the default Subbly.js manages the cart ID in secure browser cookies. During initialization the SDK will check for subbly_cart_id cookie if cartId is not provided.

loadCart optional string

Optional loadCart allows to load the cart during initialization, or create a new one and save it's ID in the browser cookies.

accessToken optional string

Optional accessToken allows to authenticate the customer during initialization. The token is saved in the browser cookies and used for all subsequent requests.

Example:

Subbly.init({
  apiKey: 'API_KEY',
  cartId: 'aaea067c-6364-4157-82e9-71b6edfd84a0',
  loadCart: true,
  accessToken: 'eyJh...eyJ9'
})

Address

Get addresses

subbly.addresses.list(): Promise<CustomerAddress[]>

Use subbly.addresses.list to get a list customer's addresses.

Requires authentication.

Example:

const addresses = await subbly.addresses.list()

Returns

Promise<CustomerAddress[]>

This method returns a promise that resolves with an array of CustomerAddress.


Create an address

subbly.addresses.store(): Promise<CustomerAddress>

Use subbly.addresses.store to create a new address for the customer

Example

const address = await subbly.addresses.store(payload)

Parameters

NameType
payloadAddressStorePayload

Returns

Promise<CustomerAddress>

This method returns a primise that resolves with CustomerAddress

Auth

Check authentication

subbly.auth.checkAuthenticated(token?): Promise<boolean>

Use subbly.auth.checkAuthenticated to verify that the client is allowed to call authenticated methods. Locally stored access token will be removed if authentication check fails.

Example

const isAuthenticated = await subbly.auth.checkAuthenticated()

Parameters

NameTypeDescription
token?string{String} - Token parameter is optional. Provided token will take priority over the locally stored token.

Returns

Promise<boolean>

This method returns a promise that resolves with a boolean value that is true when the customer is authenticated.


Create an account

subbly.auth.register(payload): Promise<AuthResourceLoginResponse>

Use subbly.auth.register to create a new account. If password is not provided a generated password will be sent to the provided email. Successful registration will automatically authenticate the customer.

Example

await subbly.auth.register({
  email: '[email protected]',
  firstName: 'John',
  lastName: 'Doe'
})

Parameters

NameType
payloadAuthResourceRegisterPayload

Returns

Promise<AuthResourceLoginResponse>

This method returns a promise that resolves with AuthResourceLoginResponse


Sign in with password

subbly.auth.login(payload): Promise<AuthResourceLoginResponse>

Use subbly.auth.login to authenticate the customer using an email and a password.

Example

await subbly.auth.login({
  email: '[email protected]',
  password: 'C5wrzJtK9HHg'
})

Parameters

NameType
payloadAuthResourceLoginPayload

Returns

Promise<AuthResourceLoginResponse>

This method returns a promise that resolves with AuthResourceLoginResponse


Request OTP

subbly.auth.otp(payload): Promise<void>

Use subbly.auth.otp to request OTP for the provided email.

Example

await subbly.auth.otp({
  email: '[email protected]'
})

Parameters

NameType
payloadAuthResourceOtpPayload

Returns

Promise<void>

This method returns a promise that resolves with an empty value when OTP has been sent to the provided email.


Sign in with OTP

subbly.auth.otpLogin(payload): Promise<AuthResourceLoginResponse>

Use subbly.auth.otpLogin to authenticate the customer using email OTP.

Example

await subbly.auth.otpLogin({
  email: '[email protected]',
  token: '123456'
})

Parameters

NameType
payloadAuthResourceOtpLoginPayload

Returns

Promise<AuthResourceLoginResponse>

This method returns a promise that resolves with AuthResourceLoginResponse


Sign in with social login

subbly.auth.social(payload): Promise<AuthResourceLoginResponse>

Use subbly.auth.social to authenticate the customer using one of the supported SSO services.

Example

const { accessToken } = await subbly.auth.social({
  token: 'eyJhbGciOiJIU....dQssw5c',
  provider: 'facebook'
})

Parameters

NameType
payloadAuthResourceSocialPayload

Returns

Promise<AuthResourceLoginResponse>

This method returns a promise that resolves with AuthResourceLoginResponse


Email availability check

subbly.auth.registered(payload): Promise<AuthResourceRegisteredResponse>

Use subbly.auth.registered to check if the email is already registered in Subbly.

Example

const { registered } = await subbly.auth.registered({
  email: '[email protected]'
})

Parameters

NameType
payloadAuthResourceRegisteredPayload

Returns

Promise<AuthResourceRegisteredResponse>

This method returns a promise that resolves with AuthResourceRegisteredResponse


Get access token

subbly.auth.getAccessToken(): string | undefined

Use subbly.auth.getAccessToken to get locally stored access token of the current authenticated user.

Example

const accessToken = subbly.auth.getAccessToken()

Returns

string | undefined

Bundles

Load a bundle

subbly.subbly.bundles.load(bundleId): Promise<Bundle>

Use subbly.bundles.load to load bundle information.

Example

const bundle = await subbly.bundles.load(123, {
  expand: ['plans.variants.parent', 'plans.pricings.parent']
})

Parameters

NameType
bundleIdnumber
params?BundleResourceParams
headers?BundleRequestHeaders

Returns

Promise<Bundle>

This method returns a promise that resolves with Bundle.


Load bundle items

subbly.bundles.loadItems(bundleId, params?, headers?): Promise<BundleItemsResponse>

Use subbly.bundles.loadItems to load items for the bundle.

Example

const { data, pagination } = await subbly.bundles.loadItems(123, {
  page: 1,
  perPage: 10,
  expand: ['product.parent']
})

Parameters

NameType
bundleIdnumber
params?BundleItemsParams
headers?BundleRequestHeaders

Returns

Promise<BundleItemsResponse>

This method returns a promise that resolves with BundleItemsResponse.


Get a bundle quote

subbly.bundles.quote(bundleId, payload, params?, headers?): Promise<BundleQuote>

Use subbly.bundles.quote to get a summary of the bundle with the given items.

Example

const quote = await subbly.subscriptions.quote(123, {
  productId: 123,
  quantity: 1,
  items: [
    {
      productId: 234,
      quantity: 1
    }
  ]
})

Parameters

NameType
bundleIdnumber
payloadBundleQuotePayload
params?BundleQuoteParams
headers?BundleRequestHeaders

Returns

Promise<BundleQuote>

This method returns a promise that resolves with BundleQuote.

Cart


Create a cart

subbly.cart.create(payload?, params?): Promise<Cart>

Use subbly.cart.create to create a new cart and store the ID in storage. Replaces any previously loaded cart data.

Example

const cart = await subbly.cart.create({
  currencyCode: 'EUR'
})

Parameters

NameType
payload?CartUpdatePayload
params?CartResourceParams

Returns

Promise<Cart>

This method returns a promise that resolves with a SubblyCart


Load a cart

subbly.cart.load(cartId?, params?): Promise<Cart>

Use subbly.cart.load to Load a cart by ID. Current loaded cart ID is used unless cartId parameter is provided.

Example

const cart = await subbly.cart.load('14920f9c-f261-4879-a3a9-e1b75993eeed')

Parameters

NameTypeDescription
cartId?stringnot required if the cart is already loaded
params?CartResourceParams

Returns

Promise<Cart>

This method returns a promise that resolves with a SubblyCart


Update a cart

subbly.cart.update(payload, params?): Promise<Cart>

Use subbly.cart.update to update cart information.

Example

const cart = await subbly.cart.update({
  couponCode: 'COUPON_CODE'
})

Parameters

NameType
payloadCartUpdatePayload
params?CartResourceParams

Returns

Promise<Cart>

This method returns a promise that resolves with a SubblyCart


Attach a customer

subbly.cart.attachCustomer(params?): Promise<Cart>

Use subbly.cart.attachCustomer to assign the cart to the customer. Attach method requires the customer to be authenticated.

const cart = await subbly.cart.attachCustomer()

Parameters

NameType
params?CartResourceParams

Returns

Promise<Cart>

This method returns a promise that resolves with a SubblyCart


Add an item

subbly.cart.addItem(payload, params?): Promise<Cart>

Use subbly.cart.addItem to add a new item to the cart. Adding the same non subscription item multiple times will increase the quantity.

Example

const cart = await subbly.cart.addItem({
  productId: 111,
  quantity: 2
})

Parameters

NameType
payloadCartItemAddPayload
params?CartResourceParams

Returns

Promise<Cart>

This method returns a promise that resolves with a SubblyCart


Update an item

subbly.cart.updateItem(cartItemId, payload, params?): Promise<Cart>

Use subbly.cart.updateItem to change quantity or preferences of an item in the cart

Example

const cart = await subbly.cart.updateItem('7ae5a8e5-bd15-4a5b-870d-0dbb605a3a1d', {
  options: [
    {
      questionId: 111,
      answers: [
        {
          id: 222
        }
      ]
    }
  ]
})

Parameters

NameType
cartItemIdstring
payloadCartResourceUpdateItemPayload
params?CartResourceParams

Returns

Promise<Cart>

This method returns a promise that resolves with a SubblyCart


Remove an item

subbly.cart.removeItem(cartItemId, params?): Promise<Cart>

Use subbly.cart.removeItem to remove an item from the cart

Example

const cart = await subbly.cart.removeItem('c9554583-99bb-465d-b0e4-97a8cd652cef')

Parameters

NameType
cartItemIdstring
params?CartResourceParams

Returns

Promise<Cart>

This method returns a promise that resolves with a SubblyCart


Get available gifting dates

subbly.cart.getGiftingDates(): Promise<CartResourceGiftingDatesResponse>

Use subbly.cart.getGiftingDates to get available date for configuring the cart as a gift.

Example

const cart = await subbly.cart.getGiftingDates()

Returns

Promise<CartResourceGiftingDatesResponse>

This method returns a promise that resolves with a CartResourceGiftingDatesResponse object.


Get pick-up points

subbly.cart.getLocalPickups(): Promise<ShippingMethodPickup>

Use subbly.cart.getLocalPickups to get a list of available pick-up points for the cart.

const cart = await subbly.cart.getLocalPickups()

Returns

Promise<ShippingMethodPickup>

This method returns a promise that resolves with an array of ShippingMethodPickup


Get shipping methods

subbly.cart.getShippingMethods(params): Promise<ShippingMethodDelivery>

Use subbly.cart.getShippingMethods to get a list of available shipping methods for the cart.

const cart = await subbly.cart.getShippingMethods({ 
  country: 2, 
  zip: 'GL56 8EH' 
})

Parameters

NameType
params?CartShippingMethodsParams

Returns

Promise<ShippingMethodDelivery>

This method returns a promise that resolves with an array of ShippingMethodDelivery

Checkout

Purchase

subbly.checkout.purchase(cartId, paymentIntentId?): Promise<CheckoutPurchaseResponse>

Use subbly.checkout.purchase to perform purchase action of the cart. Requires authentication and a complete cart, including an attached customer, shipping and payment information.

Example

const cartId = subbly.cart.id
const checkoutResponse = await subbly.checkout.purchase(cartId)

Parameters

NameType
cartIdstring
payload?CheckoutPurchasePayload
params?PurchaseRequestParams

Returns

Promise<CheckoutPurchaseResponse>

This methods returns a promise that resolves with CheckoutPurchaseResponse.


Countries

Fetch a list of countries

subbly.countries.list: Promise<Country>

Use subbly.countries.list to get a complete list of countries.

Example

const countries = await subbly.countries.list()

Returns

Promise<Country>

This method returns an array Country.

Customers

Customers are automatically created with registration.


Update a customer

subbly.customers.update(payload): Promise<SubblyCustomer>

Use subbly.customers.update to update a customer.

Example

const customer = await subbly.customers.update({
  marketingConsent: true,
  tosConsent: true
})

Parameters

NameType
payloadCustomerUpdatePayload

Returns

Promise<SubblyCustomer>

This method returns a promise that resolves with SubblyCustomer

Get customer profile

subbly.customers.me(): Promise<SubblyCustomer>

Use subbly.customers.me to get the current authenticated customer profile.

Example

const customer = await subbly.customers.me({
  marketingConsent: true,
  tosConsent: true
})

Returns

Promise<SubblyCustomer>

This method returns a promise that resolves with SubblyCustomer

Funnels

Fetch pre-purchase offer

subbly.funnels.prePurchaseFetch(cartId, params?): Promise<FunnelFetchResponse>

Use subbly.funnels.prePurchaseFetch to get a pre-purchase funnel offer for the provided cart.

Once an offer is accepted or rejected will return the next offer if available or an empty response.

Example

const cartId = subbly.cart.id
const { step } = await subbly.funnels.prePurchaseFetch(cartId)

Parameters

NameType
cartIdstring
params?FunnelsResourceParams

Returns

Promise<FunnelFetchResponse>

This method returns a promise that resolves with FunnelFetchResponse.


Accept pre-purchase offer

subbly.funnels.prePurchaseAccept(cartId, funnelStepId, payload, params?): Promise<SubblyCart>

Use subbly.funnels.prePurchaseAccept to accept a pre-purchase offer.

Example

const cartId = subbly.cart.id
const { step } = await subbly.funnels.prePurchaseFetch(cartId)
await subbly.funnels.prePurchaseAccept(cartId, step.id, {
  offers: [
    {
      productId: 111
    }
  ]
})

Parameters

NameType
cartIdstring
funnelStepIdnumber
payloadFunnelAcceptPayload
params?CartResourceParams

Returns

Promise<SubblyCart>

This method returns a promise that resolves with SubblyCart.


Reject pre-purchase offer

subbly.funnels.prePurchaseReject(cartId, funnelStepId): Promise<void>

Use subbly.funnels.prePurchaseReject to skip a pre-purchase funnel offer.

Example

const cartId = subbly.cart.id
const { step } = await subbly.funnels.prePurchaseFetch(cartId)
await subbly.funnels.prePurchaseReject(cartId, step.id)

Parameters

NameType
cartIdstring
funnelStepIdnumber

Returns

Promise<void>


Refresh pre-purchase offer progress

subbly.funnels.prePurchaseRefresh(cartId): Promise<void>

Use subbly.funnels.prePurchaseRefresh to reset previously accepted and rejected pre-purchase funnel offers

Example

const cartId = subbly.cart.id
await subbly.funnels.prePurchaseRefresh(cartId)

Parameters

NameType
cartIdstring

Returns

Promise<void>


Fetch mid-purchase offer

subbly.funnels.midPurchaseFetch(cartId, params?): Promise<FunnelFetchResponse>

Use subbly.funnels.midPurchaseFetch to get a mid-purchase funnel offer for the provided cart.

Once an offer is accepted or rejected will return the next offer if available or an empty response.

Example

const cartId = subbly.cart.id
const { step } = await subbly.funnels.midPurchaseFetch(cartId)

Parameters

NameType
cartIdstring
params?FunnelsResourceParams

Returns

Promise<FunnelFetchResponse>

This method returns a promise that resolves with FunnelFetchResponse.


Accept mid-purchase offer

subbly.funnels.midPurchaseAccept(cartId, funnelStepId, payload, params?): Promise<SubblyCart>

Use subbly.funnels.midPurchaseAccept to accept a mid-purchase offer.

Example

const cartId = subbly.cart.id
const { step } = await subbly.funnels.prePurchaseFetch(cartId)
await subbly.funnels.midPurchaseAccept(cartId, step.id, {
  offers: [
    {
      productId: 111
    }
  ]
})

Parameters

NameType
cartIdstring
funnelStepIdnumber
payloadFunnelAcceptPayload
params?CartResourceParams

Returns

Promise<SubblyCart>

This method returns a promise that resolves with SubblyCart.


Reject mid-purchase offer

subbly.funnels.midPurchaseReject(cartId, funnelStepId): Promise<void>

Use subbly.funnels.midPurchaseReject to skip a mid-purchase funnel offer.

Example

const cartId = subbly.cart.id
const { step } = await subbly.funnels.midPurchaseFetch(cartId)
await subbly.funnels.midPurchaseReject(cartId, step.id)

Parameters

NameType
cartIdstring
funnelStepIdnumber

Returns

Promise<void>


Fetch post-purchase offer

subbly.funnels.postPurchaseFetch(cartId, params?): Promise<FunnelFetchResponse>

Use subbly.funnels.postPurchaseFetch to get a post-purchase funnel offer for the provided cart.

Available only after a successful cart purchase.

Once an offer is accepted or rejected will return the next offer if available or an empty response.

Example

const cartId = subbly.cart.id
const { step } = await subbly.funnels.postPurchaseFetch(cartId)

`

Parameters

NameType
cartIdstring
params?FunnelsResourceParams

Returns

Promise<FunnelFetchResponse>

This method returns a promise that resolves with FunnelFetchResponse.


Accept post-purchase offer

subbly.funnels.postPurchaseAccept(cartId, funnelStepId, payload, params?): Promise<CheckoutPurchaseResponse>

Use subbly.funnels.postPurchaseAccept to accept a mid-purchase offer.

shippingAddressId, shippingMethodId in the payload are required when where not provided in the checkout.

Example

const cartId = subbly.cart.id
const { step } = await subbly.funnels.prePurchaseFetch(cartId)
await subbly.funnels.midPurchaseAccept(cartId, step.id, {
  offers: [
    {
      productId: 111
    }
  ],
  shippingAddressId: 222,
  shippingMethodId: 333
})

Parameters

NameType
cartIdstring
funnelStepIdnumber
payloadFunnelPostAcceptPayload
params?CartResourceParams

Returns

Promise<CheckoutPurchaseResponse>

This method returns a promise that resolves with CheckoutPurchaseResponse.


Reject post-purchase offer

subbly.funnels.postPurchaseReject(cartId, funnelStepId): Promise<void>

Use subbly.funnels.postPurchaseReject to skip a post-purchase funnel offer.

Example

const cartId = subbly.cart.id
const { step } = await subbly.funnels.postPurchaseReject(cartId)
await subbly.funnels.postPurchaseReject(cartId, step.id)

Parameters

NameType
cartIdstring
funnelStepIdnumber

Returns

Promise<void>

Lead

Subscribe a lead

subbly.lead.subscribe(): Promise<LeadSubscribeResponse>

Use subbly.lead.subscribe to track a lead.

Parameters

NameType
payloadLeadSubscribePayload

Returns

Promise<LeadSubscribeResponse>

This method returns a promise that resolves with a LeadSubscribeResponse

Example

await subbly.lead.subscribe({
  email: '[email protected]'
})

Payment Intents

Get a payment intent

subbly.paymentIntents.getPaymentIntent(paymentIntentId): Promise<PaymentIntentResponse>

Use subbly.paymentIntents.getPaymentIntent to get payment intent details which includes a token to perform 3DS verification using stripe.confirmCardPayment.

Example

try {
  await subbly.checkout.purchase(cartId)
} catch (err) {
  if (err.code === 'payment_requires_action') {
    const { token } = await subbly.paymentIntents.getPaymentIntent(err.paymentIntentId)
    // perform Stripe 3DS verification and repeat the purchase
  }
}

Parameters

NameTypeDescription
paymentIntentIdstringStripe payment intent ID from subbly.checkout.purchase error response with a code "payment_requires_action"

Returns

Promise<PaymentIntentResponse>

This method returns a promise that resolves with a PaymentIntentResponse


Confirm payment intent verification

subbly.paymentIntents.confirm(paymentIntentId, externalPaymentId): Promise<PaymentIntentResponse>

Use subbly.paymentIntents.confirm to confirm that purchase payment intent has been verified with stripe.confirmCardPaymentopen in new window.

After a successful confirmation repeat subbly.checkout.purchase to complete the purchase.

Example

// in subbly.checkout.purchase error handler
const { token } = await subbly.paymentIntents.getPaymentIntent(paymentIntentId)
const { paymentIntent } = await stripe.confirmCardPayment(token)
await subbly.paymentIntents.confirm(paymentIntentId, paymentIntent.id)
await subbly.checkout.purchase(paymentIntentId)

Parameters

NameTypeDescription
paymentIntentIdstringStripe payment intent ID from subbly.checkout.purchase error response
externalPaymentIdstringpayment intent ID from stripe.confirmCardPaymentopen in new window response.

Returns

Promise<PaymentIntentResponse>

This method returns a promise that resolves with a PaymentIntentResponse

Pick-up info

Fetch pick-up infos

subbly.pickupInfo.list(params): Promise<CustomerPickupInfo>

Use subbly.pickupInfo.list to get a list of available customer's pick-up infos. Requires authentication.

Filter pick-up infos by a country by providing shippingMethodId parameter.

Example

const pickupInfos = await subbly.pickupInfo.list()

Parameters

NameType
paramsPickupInfoFetchParams

Returns

Promise<CustomerPickupInfo>

This method returns a promise that resolves with an array of CustomerPickupInfo


Create a pick-up info

subbly.pickupInfo.store(payload): Promise<CustomerPickupInfo>

Use subbly.pickupInfo.store to create a new pick-up info for the customer. Requires authentication.

Example

const pickupInfo = await subbly.pickupInfo.store({
  firstName: 'John',
  lastName: 'Doe'
  phone: '+447078582260'
})

Parameters

NameType
payloadPickupInfoStorePayload

Returns

Promise<CustomerPickupInfo>

This method returns a promise that resolves with CustomerPickupInfo

Products

Get a products list

subbly.products.list(params?, headers?): Promise<ProductsListResponse>

Use subbly.products.list to get a list of products.

Example

const { data, pagination } = await subbly.products.list({
  page: 1,
  perPage: 10,
  expand: ['variants.parent', 'pricings.parent']
})

Parameters

NameType
params?ProductsListParams
headers?ProductRequestHeaders

Returns

Promise<ProductsListResponse>

This method returns an array ProductsListResponse.


Load a parent product

subbly.products.load(productId, params?, headers?): Promise<ParentProduct>

Use subbly.products.load to load information of a product that has variants or pricing options.

Example

const product = await subbly.products.load(123, {
  expand: [
    'pricings.parent',
    'variants.parent'
  ]
})

Parameters

NameType
productIdnumber
params?ProductsResourceParams
headers?ProductRequestHeaders

Returns

Promise<ParentProduct>

This method returns a promise that resolves with ParentProduct.


Load a product

subbly.products.load(productId, params?, headers?): Promise<Product>

Use subbly.products.loadVariant to load information of a product variant/pricing.

Example

const product = await subbly.products.loadVariant(123, {
  expand: ['parent']
})

Parameters

NameType
productIdnumber
params?ProductsResourceParams
headers?ProductRequestHeaders

Returns

Promise<Product>

This method returns a promise that resolves with Product.

Shop

Load the shop

subbly.shop.load(): Promise<Shop>

Use subbly.shop.load to load the shop information.

Example

const shop = await subbly.shop.load()

Returns

Promise<Shop>

This method returns a promise that resolves with Shop

Stock

Subscribe to stock availability

subbly.stock.subscribe(payload): Promise<StockSubscriptionResponse>

Use subbly.stock.subscribe to receive an email notification when a product or survey answer is back in stock.

Example

await subbly.stock.subscribe({
  email: '[email protected]',
  productId: 111,
  quantity: 3
})

Parameters

NameType
payloadStockSubscriptionPayload

Returns

Promise<StockSubscriptionResponse>

This method returns a promise that resolves with StockSubscriptionResponse

Subscriptions

Load a subscription

subbly.subscriptions.load(subscriptionId, params?): Promise<Subscription>

Use subbly.subscriptions.load to load subscription information.

Example

const subscription = await subbly.subscriptions.load(123, {
  expand: ['product.parent']
})

Parameters

NameType
subscriptionIdnumber
params?SubscriptionsResourceParams

Returns

Promise<Subscription>

This method returns a promise that resolves with Subscription.


Update a subscription

subbly.subscriptions.update(subscriptionId, payload, params?): Promise<Subscription>

Use subbly.subscriptions.update to update a subscription.

Example

const subscription = await subbly.subscriptions.update(123, {
  quantity: 2
})

Parameters

NameType
subscriptionIdnumber
payloadSubscriptionUpdatePayload
params?SubscriptionsResourceParams

Returns

Promise<Subscription>

This method returns a promise that resolves with Subscription.


Update subscription bundle preferences

subbly.subscriptions.updateBundle(subscriptionId, payload): Promise<Subscription>

Use subbly.subscriptions.updateBundle to update subscription bundle preferences.

Example

const subscription = await subbly.subscriptions.updateBundle(123, {
  productId: 234,
  quantity: 1,
  bundle: {
    items: [
      {
        productId: 345,
        quantity: 1
      }
    ]
  }
})

Parameters

NameType
subscriptionIdnumber
payloadSubscriptionBundlePayload

Returns

Promise<Subscription>

This method returns a promise that resolves with Subscription.


Update subscription survey preferences

subbly.subscriptions.updatePreferences(subscriptionId, payload): Promise<Subscription>

Use subbly.subscriptions.updatePreferences to update subscription survey preferences.

Example

await subbly.subscriptions.updatePreferences(123, {
  preferences: [
    {
      questionId: 1,
      answers: [
        {
          id: 2,
          quantity: 3
        }
      ]
    }
  ]
})

Parameters

NameType
subscriptionIdnumber
payloadSubscriptionPreferencesPayload

Returns

Promise<Subscription>

This method returns a promise that resolves with Subscription.

Surveys

load

subbly.surveys.load(surveyId): Promise<Survey>

Use subbly.surveys.load to load a survey.

Parameters

NameType
surveyIdnumber
params?SurveyResourceParams
headers?SurveyRequestHeaders

Returns

Promise<Survey>

This method returns a promise that resolves with Survey.

Example

const survey = await subbly.surveys.load(123)

Wallet

Get payment methods

subbly.wallet.list(currencyCode): Promise<PaymentMethod>

Use subbly.wallet.list to get customer's available payment methods for a provided currency. Requires authentication.

Example

const paymentMethods = await subbly.wallet.list('USD')

Parameters

NameType
currencyCodestring

Returns

Promise<PaymentMethod>

This method returns a promise that resolves with an array of PaymentMethod


Get setup token for a gateway

subbly.wallet.setup(payload): Promise<WalletSetupResponse>

Use subbly.wallet.setup to get a payment setup token for the provided gateway.

Setup token depends on the gateway type:

  • client token for Braintree to initialize the SDK
  • a secret for Stripe to complete stripe.confirmCardSetup
  • order ID for PayPal to pass to createOrder in paypal.Buttons

Example

const { token } = await subbly.wallet.setup({
  gatewayId: 111
})

Parameters

NameType
payloadWalletSetupPayload

Returns

Promise<WalletSetupResponse>

This method returns a promise that resolves with a WalletSetupResponse


Create a payment method

subbly.wallet.store(payload): Promise<PaymentMethod>

Use subbly.wallet.store to add a payment source for the customer. Requires authentication.

The token is obtained from a third party widget depending on the gateway.

Example

const paymentMethod = await subbly.wallet.store({
  gatewayId: 111,
  token: '49j06RWRUYW1kt...'
})

Parameters

NameType
payloadPaymentMethodStorePayload

Token value is different for each gateway type

GatewayToken
StripeSetup intent ID
BraintreePayment method nonce
PayPalOrder ID
Authorize.netBase64 encoded data that contains encrypted payment data.

Returns

Promise<PaymentMethod>

This method returns a promise that resolves with a PaymentMethod