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
REQUIRED string
apiKey The Subbly Storefront API key is required. To obtain your API key, visit Shop Settings in Subbly Admin.
optional
string
cartId 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.
optional
string
loadCart Optional loadCart
allows to load the cart during initialization, or create a new one and save it's ID in the browser cookies.
optional
string
accessToken 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
Name | Type |
---|---|
payload | AddressStorePayload |
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
Name | Type | Description |
---|---|---|
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
Name | Type |
---|---|
payload | AuthResourceRegisterPayload |
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
Name | Type |
---|---|
payload | AuthResourceLoginPayload |
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
Name | Type |
---|---|
payload | AuthResourceOtpPayload |
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
Name | Type |
---|---|
payload | AuthResourceOtpLoginPayload |
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
Name | Type |
---|---|
payload | AuthResourceSocialPayload |
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
Name | Type |
---|---|
payload | AuthResourceRegisteredPayload |
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
Name | Type |
---|---|
bundleId | number |
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
Name | Type |
---|---|
bundleId | number |
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
Name | Type |
---|---|
bundleId | number |
payload | BundleQuotePayload |
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
Name | Type |
---|---|
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
Name | Type | Description |
---|---|---|
cartId? | string | not 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
Name | Type |
---|---|
payload | CartUpdatePayload |
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
Name | Type |
---|---|
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
Name | Type |
---|---|
payload | CartItemAddPayload |
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
Name | Type |
---|---|
cartItemId | string |
payload | CartResourceUpdateItemPayload |
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
Name | Type |
---|---|
cartItemId | string |
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
Name | Type |
---|---|
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
Name | Type |
---|---|
cartId | string |
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
Name | Type |
---|---|
payload | CustomerUpdatePayload |
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
Name | Type |
---|---|
cartId | string |
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
Name | Type |
---|---|
cartId | string |
funnelStepId | number |
payload | FunnelAcceptPayload |
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
Name | Type |
---|---|
cartId | string |
funnelStepId | number |
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
Name | Type |
---|---|
cartId | string |
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
Name | Type |
---|---|
cartId | string |
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
Name | Type |
---|---|
cartId | string |
funnelStepId | number |
payload | FunnelAcceptPayload |
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
Name | Type |
---|---|
cartId | string |
funnelStepId | number |
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
Name | Type |
---|---|
cartId | string |
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
Name | Type |
---|---|
cartId | string |
funnelStepId | number |
payload | FunnelPostAcceptPayload |
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
Name | Type |
---|---|
cartId | string |
funnelStepId | number |
Returns
Promise<void>
Lead
Subscribe a lead
subbly.lead.subscribe(): Promise<LeadSubscribeResponse>
Use subbly.lead.subscribe
to track a lead.
Parameters
Name | Type |
---|---|
payload | LeadSubscribePayload |
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
Name | Type | Description |
---|---|---|
paymentIntentId | string | Stripe 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.confirmCardPayment.
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
Name | Type | Description |
---|---|---|
paymentIntentId | string | Stripe payment intent ID from subbly.checkout.purchase error response |
externalPaymentId | string | payment intent ID from stripe.confirmCardPayment 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
Name | Type |
---|---|
params | PickupInfoFetchParams |
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
Name | Type |
---|---|
payload | PickupInfoStorePayload |
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
Name | Type |
---|---|
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
Name | Type |
---|---|
productId | number |
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
Name | Type |
---|---|
productId | number |
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
Name | Type |
---|---|
payload | StockSubscriptionPayload |
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
Name | Type |
---|---|
subscriptionId | number |
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
Name | Type |
---|---|
subscriptionId | number |
payload | SubscriptionUpdatePayload |
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
Name | Type |
---|---|
subscriptionId | number |
payload | SubscriptionBundlePayload |
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
Name | Type |
---|---|
subscriptionId | number |
payload | SubscriptionPreferencesPayload |
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
Name | Type |
---|---|
surveyId | number |
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
Name | Type |
---|---|
currencyCode | string |
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
Name | Type |
---|---|
payload | WalletSetupPayload |
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
Name | Type |
---|---|
payload | PaymentMethodStorePayload |
Token value is different for each gateway type
Gateway | Token |
---|---|
Stripe | Setup intent ID |
Braintree | Payment method nonce |
PayPal | Order ID |
Authorize.net | Base64 encoded data that contains encrypted payment data. |
Returns
Promise<PaymentMethod>
This method returns a promise that resolves with a PaymentMethod