### JavaScript Example: Fetch Current Customer Profile Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk This example demonstrates how to use `subbly.customers.me` to asynchronously fetch the currently authenticated customer's profile. The example shows how to await the promise resolution, passing consent parameters. ```javascript const customer = await subbly.customers.me({ marketingConsent: true, tosConsent: true }) ``` -------------------------------- ### Subbly Pickup Info: Fetch All Pickup Locations Example Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Simple JavaScript example demonstrating how to fetch a list of available customer pickup information using `subbly.pickupInfo.list`. ```javascript const pickupInfos = await subbly.pickupInfo.list() ``` -------------------------------- ### Subbly Pickup Info: Create New Customer Pickup Record Example Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk JavaScript example demonstrating how to create a new customer pickup information record using `subbly.pickupInfo.store` with a sample payload. ```javascript const pickupInfo = await subbly.pickupInfo.store({ firstName: 'John', lastName: 'Doe' phone: '+447078582260' }) ``` -------------------------------- ### JavaScript Example: Fetch Pre-Purchase Funnel Offer Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk This example demonstrates how to use `subbly.funnels.prePurchaseFetch` to asynchronously retrieve a pre-purchase offer for a specific cart, extracting the `step` from the response. ```javascript const cartId = subbly.cart.id const { step } = await subbly.funnels.prePurchaseFetch(cartId) ``` -------------------------------- ### Subbly Products: Load Product with Expanded Details Example Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk JavaScript example demonstrating how to load a specific product by its ID using `subbly.products.load`, with parameters to expand related pricing and variant information. ```javascript const product = await subbly.products.load(123, { expand: [ 'pricings.parent', 'variants.parent' ] }) ``` -------------------------------- ### Subbly Products: Fetch Paginated Product List Example Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk JavaScript example demonstrating how to fetch a paginated list of products using `subbly.products.list`, including parameters for page, items per page, and expanding related data. ```javascript const { data, pagination } = await subbly.products.list({ page: 1, perPage: 10, expand: ['variants.parent', 'pricings.parent'] }) ``` -------------------------------- ### Programmatically Add Product to Cart Source: https://docs.subbly.dev/reference/subbly-sdk/docs/guide This JavaScript example illustrates how to add products to the cart dynamically using `subblyCart.configureItem` or `subblyCart.addItem` methods. It demonstrates attaching these methods to a button click event, allowing for custom product addition logic. ```javascript ``` -------------------------------- ### Get Payment Setup Token for a Gateway using subbly.wallet.setup Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk This method obtains a payment setup token for a given gateway. The token type varies by gateway (e.g., client token for Braintree, secret for Stripe, order ID for PayPal). It returns a Promise resolving to a WalletSetupResponse. ```APIDOC subbly.wallet.setup(payload): Promise payload: WalletSetupPayload Returns: Promise ``` ```JavaScript const { token } = await subbly.wallet.setup({ gatewayId: 111 }) ``` -------------------------------- ### Get Bundle Quote Example (JavaScript) Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Illustrates how to use the `subbly.subscriptions.quote` method in JavaScript to obtain a bundle quote. This example specifies product ID, quantity, and nested items. ```JavaScript const quote = await subbly.subscriptions.quote(123, { productId: 123, quantity: 1, items: [ { productId: 234, quantity: 1 } ] }) ``` -------------------------------- ### JavaScript Example: Fetch Mid-Purchase Funnel Offer Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk This example demonstrates how to use `subbly.funnels.midPurchaseFetch` to asynchronously retrieve a mid-purchase offer for a specific cart, extracting the `step` from the response. ```javascript const cartId = subbly.cart.id const { step } = await subbly.funnels.midPurchaseFetch(cartId) ``` -------------------------------- ### JavaScript Example: Accept Pre-Purchase Funnel Offer Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk This example shows how to accept a pre-purchase offer using `subbly.funnels.prePurchaseAccept`, providing the cart ID, funnel step ID, and an offers payload. ```javascript const cartId = subbly.cart.id const { step } = await subbly.funnels.prePurchaseFetch(cartId) await subbly.funnels.prePurchaseAccept(cartId, step.id, { offers: [ { productId: 111 } ] }) ``` -------------------------------- ### Install SubblyCart.js with API Key Source: https://docs.subbly.dev/reference/subbly-sdk/docs/installation This snippet demonstrates how to install SubblyCart.js by embedding script tags into an HTML page. It initializes the library with a `subblyConfig` object containing the `apiKey`, enabling access to Subbly's checkout functionality. ```html ``` -------------------------------- ### Subbly Payment Intents: Confirm Stripe Payment Flow Example Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Example JavaScript code demonstrating the full flow for confirming a Stripe payment intent. It shows how to get the payment intent token, confirm it with Stripe, and then complete the purchase using `subbly.checkout.purchase`. ```javascript // 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) ``` -------------------------------- ### Fetch Post-Purchase Offer Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Documents and provides an example for the `subbly.funnels.postPurchaseFetch` method, used to get a post-purchase funnel offer for a provided cart, available after a successful purchase. ```APIDOC subbly.funnels.postPurchaseFetch(cartId, params?): Promise cartId: string params?: FunnelsResourceParams Returns: Promise ``` ```javascript const cartId = subbly.cart.id const { step } = await subbly.funnels.postPurchaseFetch(cartId) ``` -------------------------------- ### JavaScript Example: Reject Pre-Purchase Funnel Offer Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk This example demonstrates how to reject a pre-purchase offer using `subbly.funnels.prePurchaseReject`, requiring the cart ID and funnel step ID. ```javascript const cartId = subbly.cart.id const { step } = await subbly.funnels.prePurchaseFetch(cartId) await subbly.funnels.prePurchaseReject(cartId, step.id) ``` -------------------------------- ### JavaScript Example: Accept Mid-Purchase Funnel Offer Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk This example shows how to accept a mid-purchase offer using `subbly.funnels.midPurchaseAccept`, providing the cart ID, funnel step ID, and an offers payload. ```javascript const cartId = subbly.cart.id const { step } = await subbly.funnels.prePurchaseFetch(cartId) await subbly.funnels.midPurchaseAccept(cartId, step.id, { offers: [ { productId: 111 } ] }) ``` -------------------------------- ### JavaScript Example: Refresh Pre-Purchase Funnel Progress Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk This example shows how to refresh the progress of pre-purchase funnel offers using `subbly.funnels.prePurchaseRefresh` with the cart ID. ```javascript const cartId = subbly.cart.id await subbly.funnels.prePurchaseRefresh(cartId) ``` -------------------------------- ### Install Subbly SDK via npm Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Installs the Subbly SDK package using npm, the Node.js package manager. This is the recommended way to use Subbly.js SDK with modern JavaScript frameworks. ```bash npm install @subbly/sdk ``` -------------------------------- ### Example JavaScript AuthResourceRegisterPayload Object Source: https://docs.subbly.dev/reference/subbly-sdk/reference/types Illustrates a sample JavaScript object for the `AuthResourceRegisterPayload`, used when registering a new user. This example shows the basic required fields. ```javascript const payload = { email: '[email protected]', firstName: 'John', lastName: 'Doe' } ``` -------------------------------- ### Subscribe a Lead Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Documents and provides an example for the `subbly.lead.subscribe` method, used to track a lead, including parameters and return type. ```APIDOC subbly.lead.subscribe(): Promise payload: LeadSubscribePayload Returns: Promise ``` ```javascript await subbly.lead.subscribe({ email: '[email protected]' }) ``` -------------------------------- ### JavaScript: Get Available Shipping Methods Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Example of using `subbly.cart.getShippingMethods` to fetch shipping options for the cart, filtered by country and zip code. This helps determine available delivery options. ```JavaScript const cart = await subbly.cart.getShippingMethods({ country: 2, zip: 'GL56 8EH' }) ``` -------------------------------- ### Load Cart Example (JavaScript) Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Demonstrates how to load a cart by its unique ID using `subbly.cart.load` in JavaScript. The example uses a specific cart ID string. ```JavaScript const cart = await subbly.cart.load('14920f9c-f261-4879-a3a9-e1b75993eeed') ``` -------------------------------- ### Authenticate User with Email and Password Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Example of using `subbly.auth.login` to sign in a user with their email and password, returning an authentication response. ```javascript await subbly.auth.login({ email: '[email protected]', password: 'C5wrzJtK9HHg' }) ``` -------------------------------- ### Create Cart Example (JavaScript) Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Shows how to create a new cart using `subbly.cart.create` in JavaScript, specifying an initial currency code. This method replaces any existing cart data. ```JavaScript const cart = await subbly.cart.create({ currencyCode: 'EUR' }) ``` -------------------------------- ### SubblyCart.js Widget Basic Installation Source: https://docs.subbly.dev/reference/subbly-sdk/reference/cart Includes the SubblyCart.js script and sets the API key for automatic initialization. It is recommended to place this script before the closing tag for optimal performance. ```HTML ``` -------------------------------- ### Define WalletSetupResponse Type Source: https://docs.subbly.dev/reference/subbly-sdk/reference/types Defines the response structure for a wallet setup operation, containing a token. ```APIDOC WalletSetupResponse: Object token: string ``` -------------------------------- ### Get a Payment Intent Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Documents and provides an example for the `subbly.paymentIntents.getPaymentIntent` method, used to retrieve payment intent details, including a token for 3DS verification. ```APIDOC subbly.paymentIntents.getPaymentIntent(paymentIntentId): Promise paymentIntentId: string Returns: Promise ``` ```javascript 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 } } ``` -------------------------------- ### Load Bundle Items Example (JavaScript) Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Demonstrates how to use the `subbly.bundles.loadItems` method in JavaScript to fetch bundle items, including pagination and expansion options. It returns data and pagination information. ```JavaScript const { data, pagination } = await subbly.bundles.loadItems(123, { page: 1, perPage: 10, expand: ['product.parent'] }) ``` -------------------------------- ### Register a New User Account Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Example of using `subbly.auth.register` to create a new user account with email, first name, and last name. This call will automatically log in the user upon successful registration. ```javascript await subbly.auth.register({ email: '[email protected]', firstName: 'John', lastName: 'Doe' }) ``` -------------------------------- ### Define WalletSetupIntentPayload Type Source: https://docs.subbly.dev/reference/subbly-sdk/reference/types Defines the payload structure for initiating a wallet setup intent, requiring a gateway ID and a redirect URL. ```APIDOC WalletSetupIntentPayload: Object gatewayId: ShopGateway["id"] redirectUrl: string ``` -------------------------------- ### JavaScript: Get Local Pick-up Points Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Example of using `subbly.cart.getLocalPickups` to retrieve a list of available pick-up locations for the current cart. This method does not require any parameters. ```JavaScript const cart = await subbly.cart.getLocalPickups() ``` -------------------------------- ### Configure Subbly Cart Language via subblyConfig Source: https://docs.subbly.dev/reference/subbly-sdk/docs/guide Initializes the Subbly cart widget with a specific language code by setting the `languageCode` property within the `window.subblyConfig` object. This configuration should be present before the widget loads to ensure the correct language is applied from the start. ```javascript window.subblyConfig = { apiKey: 'API_KEY', languageCode: 'es' } ``` -------------------------------- ### JavaScript: Get Available Gifting Dates Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Example of using `subbly.cart.getGiftingDates` to fetch dates suitable for configuring the cart as a gift. This method does not require any parameters. ```JavaScript const cart = await subbly.cart.getGiftingDates() ``` -------------------------------- ### Authenticate User with OTP Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Example of using `subbly.auth.otpLogin` to sign in a user using their email and a received OTP token. ```javascript await subbly.auth.otpLogin({ email: '[email protected]', token: '123456' }) ``` -------------------------------- ### Update Cart Example (JavaScript) Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Illustrates how to update a cart's information using `subbly.cart.update` in JavaScript, specifically applying a coupon code to the cart. ```JavaScript const cart = await subbly.cart.update({ couponCode: 'COUPON_CODE' }) ``` -------------------------------- ### CustomerAddress Object Definition and Example Source: https://docs.subbly.dev/reference/subbly-sdk/reference/types Defines the structure of a customer's shipping address object, including an example JavaScript representation and its detailed type declaration. ```JavaScript const address = { addressOne: '123 Main St', addressTwo: null, city: 'New York', country: 'United States', countryCode: 'US', countryId: 230, firstName: 'John', id: 111, lastName: 'Doe', phone: '+15105829395', regionId: 2472, zip: '12992' } ``` ```APIDOC CustomerAddress: Object addressOne: string addressTwo: string | null city: string country: string countryCode: string countryId: Country["id"] firstName: string id: ID lastName: string phone: string region: string regionId: CountryRegion["id"] | null zip: string ``` -------------------------------- ### Reject Post-Purchase Offer Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Documents and provides an example for the `subbly.funnels.postPurchaseReject` method, used to skip a post-purchase funnel offer. ```APIDOC subbly.funnels.postPurchaseReject(cartId, funnelStepId): Promise cartId: string funnelStepId: number Returns: Promise ``` ```javascript const cartId = subbly.cart.id const { step } = await subbly.funnels.postPurchaseReject(cartId) await subbly.funnels.postPurchaseReject(cartId, step.id) ``` -------------------------------- ### Add Product to Cart via Intercepted Links Source: https://docs.subbly.dev/reference/subbly-sdk/docs/guide This section details how SubblyCart.js can automatically handle product, bundle, and survey links on your page. It includes the JavaScript configuration to enable link interception and various HTML examples of link structures that the widget recognizes. ```javascript ``` ```html Buy ``` ```html Buy ``` ```html Buy a bundle ``` ```html Start a survey flow ``` -------------------------------- ### Load Product or Product Variant Information (JavaScript) Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk This snippet demonstrates how to load detailed information for a specific product or product variant, including expanding related data like the parent product. It uses the `subbly.products.loadVariant` method for the example, but also documents `subbly.products.load`. ```JavaScript const product = await subbly.products.loadVariant(123, { expand: ['parent'] }) ``` ```APIDOC subbly.products.load(productId, params?, headers?): Promise subbly.products.loadVariant(productId, params?, headers?): Promise Description: Use subbly.products.load to load product information. Use subbly.products.loadVariant to load information of a product variant/pricing. Parameters: productId: number params?: ProductsResourceParams headers?: ProductRequestHeaders Returns: Promise Description: This method returns a promise that resolves with Product. ``` -------------------------------- ### Define WalletSetupPayload Type Source: https://docs.subbly.dev/reference/subbly-sdk/reference/types Defines the payload structure for a wallet setup operation, requiring a gateway ID. ```APIDOC WalletSetupPayload: Object gatewayId: ShopGateway["id"] ``` -------------------------------- ### Define WalletSetupIntentResponse Type Source: https://docs.subbly.dev/reference/subbly-sdk/reference/types Defines the response structure for a wallet setup intent, including expiration timestamp, ID, redirect URL, and Subbly URL. ```APIDOC WalletSetupIntentResponse: Object expiresAt: string id: string redirectUrl: string subblyUrl: string ``` -------------------------------- ### Load Bundle Information by ID Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Example of using `subbly.bundles.load` to retrieve bundle details by its ID, with optional expansion parameters to include related data like plans and pricings. ```javascript const bundle = await subbly.bundles.load(123, { expand: ['plans.variants.parent', 'plans.pricings.parent'] }) ``` -------------------------------- ### CartSummaryItemSetupFee Type Definition Source: https://docs.subbly.dev/reference/subbly-sdk/reference/types Extends CartSummaryItemBase to define properties specific to setup fee items in the cart summary, linking to a product ID. ```APIDOC CartSummaryItemSetupFee: CartSummaryItemBase & { productId: ID } ``` -------------------------------- ### Accept Mid-Purchase Offer Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Documents and provides an example for the `subbly.funnels.midPurchaseAccept` method, used to accept a mid-purchase funnel offer, including required parameters and expected return type. ```APIDOC subbly.funnels.midPurchaseAccept(cartId, funnelStepId, payload, params?): Promise cartId: string funnelStepId: number payload: FunnelAcceptPayload params?: CartResourceParams Returns: Promise ``` ```javascript 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 }) ``` -------------------------------- ### Open Subbly Cart Gift Configuration View Source: https://docs.subbly.dev/reference/subbly-sdk/docs/guide Opens the gift configuration view within the Subbly cart widget. The `configureGift` method can be used to immediately show the view (`true`) or only when the customer opens the widget (`false`). This method should be called after the cart is initialized. ```javascript window.addEventListener('subbly-cart-initialized', () => { subblyCart.configureGift(null, true) }) ``` -------------------------------- ### Attach Customer to Cart Example (JavaScript) Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Shows how to attach an authenticated customer to the current cart using `subbly.cart.attachCustomer` in JavaScript. This operation requires prior customer authentication. ```JavaScript const cart = await subbly.cart.attachCustomer() ``` -------------------------------- ### ProductSubscription Type Definition Source: https://docs.subbly.dev/reference/subbly-sdk/reference/types Defines a subscription product, extending ProductBase with properties for pre-order end dates, pricing plans, setup fees, and type. ```APIDOC ProductSubscription: ProductBase & { preOrderEndAt: string | null; pricings: ProductPricing[]; setupFee: number; type: subscription; } ``` -------------------------------- ### Add Item to Cart Example (JavaScript) Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Demonstrates how to add a new item to the cart using `subbly.cart.addItem` in JavaScript, specifying the product ID and quantity. Adding the same non-subscription item increases its quantity. ```JavaScript const cart = await subbly.cart.addItem({ productId: 111, quantity: 2 }) ``` -------------------------------- ### Request One-Time Password (OTP) Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Example of using `subbly.auth.otp` to request an OTP for a given email address. This sends the OTP to the user's email. ```javascript await subbly.auth.otp({ email: '[email protected]' }) ``` -------------------------------- ### Reject Mid-Purchase Offer Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Documents and provides an example for the `subbly.funnels.midPurchaseReject` method, used to skip a mid-purchase funnel offer, including parameters and return type. ```APIDOC subbly.funnels.midPurchaseReject(cartId, funnelStepId): Promise cartId: string funnelStepId: number Returns: Promise ``` ```javascript const cartId = subbly.cart.id const { step } = await subbly.funnels.midPurchaseFetch(cartId) await subbly.funnels.midPurchaseReject(cartId, step.id) ``` -------------------------------- ### JavaScript: Fetch List of Countries Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Example of using `subbly.countries.list` to retrieve all available countries. This method is useful for populating country selection fields. ```JavaScript const countries = await subbly.countries.list() ``` -------------------------------- ### Retrieve Current User Access Token Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Example of using `subbly.auth.getAccessToken` to retrieve the access token for the currently authenticated user from local storage. ```javascript const accessToken = subbly.auth.getAccessToken() ``` -------------------------------- ### Authenticate User with Social Login Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Example of using `subbly.auth.social` to authenticate a user via a social provider like Facebook using an access token obtained from the social service. ```javascript const { accessToken } = await subbly.auth.social({ token: 'eyJhbGciOiJIU....dQssw5c', provider: 'facebook' }) ``` -------------------------------- ### Example JavaScript AddressStorePayload Object Source: https://docs.subbly.dev/reference/subbly-sdk/reference/types Demonstrates a sample JavaScript object representing the `AddressStorePayload` for storing shipping address information. This object includes common address fields such as street, city, country, and contact details. ```javascript const address = { addressOne: '123 Main St', addressTwo: 'Apt 4B', city: 'New York', countryId: 230, firstName: 'John', lastName: 'Doe', phone: '+15105829395', regionId: 2472, zip: '12992' } ``` -------------------------------- ### Get Customer Addresses API Reference Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk API documentation for the `subbly.addresses.list()` method, which retrieves a list of customer addresses. This method requires prior authentication. ```APIDOC Method: subbly.addresses.list() Returns: Promise Description: Use subbly.addresses.list to get a list customer's addresses. Requires authentication. Return Details: This method returns a promise that resolves with an array of CustomerAddress. ``` ```javascript const addresses = await subbly.addresses.list() ``` -------------------------------- ### JavaScript: Perform Cart Purchase Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Example of using `subbly.checkout.purchase` to finalize a transaction. It requires the cart ID and assumes prior authentication and complete cart information. ```JavaScript const cartId = subbly.cart.id const checkoutResponse = await subbly.checkout.purchase(cartId) ``` -------------------------------- ### Create a Payment Method using subbly.wallet.store Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk This method adds a new payment source for the customer. It requires authentication. The `token` parameter, obtained from a third-party widget, varies based on the gateway type (e.g., Setup intent ID for Stripe, Payment method nonce for Braintree). It returns a Promise resolving to a PaymentMethod object. ```APIDOC subbly.wallet.store(payload): Promise payload: PaymentMethodStorePayload Token value is different for each gateway type: Stripe: Setup intent ID Braintree: Payment method nonce PayPal: Order ID Authorize.net: Base64 encoded data that contains encrypted payment data. Returns: Promise ``` ```JavaScript const paymentMethod = await subbly.wallet.store({ gatewayId: 111, token: '49j06RWRUYW1kt...' }) ``` -------------------------------- ### Subbly SDK Initialization with Advanced Configuration Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Demonstrates initializing the Subbly SDK with optional parameters beyond just the API key. This includes manually providing a `cartId`, forcing a `loadCart` operation, and authenticating a customer with an `accessToken` during initialization. ```javascript Subbly.init({ apiKey: 'API_KEY', cartId: 'aaea067c-6364-4157-82e9-71b6edfd84a0', loadCart: true, accessToken: 'eyJh...eyJ9' }) ``` -------------------------------- ### Get Customer Payment Methods using subbly.wallet.list Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk This method retrieves a customer's available payment methods for a specified currency. It requires authentication and returns a Promise resolving to an array of PaymentMethod objects. ```APIDOC subbly.wallet.list(currencyCode): Promise currencyCode: string Returns: Promise ``` ```JavaScript const paymentMethods = await subbly.wallet.list('USD') ``` -------------------------------- ### Check Email Registration Status Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Example of using `subbly.auth.registered` to check if a given email address is already registered in the system, returning a boolean `registered` status. ```javascript const { registered } = await subbly.auth.registered({ email: '[email protected]' }) ``` -------------------------------- ### Apply Coupon to Subbly Cart Source: https://docs.subbly.dev/reference/subbly-sdk/docs/guide Applies a specified coupon code to the Subbly cart. This method should be called once the cart widget has been fully initialized, typically within the `subbly-cart-initialized` event listener. ```javascript window.addEventListener('subbly-cart-initialized', () => { subblyCart.applyCoupon('COUPON_CODE') }) ``` -------------------------------- ### Initialize Subbly SDK via CDN Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Includes the Subbly SDK script directly on an HTML page via CDN and initializes it with your API key. The SDK becomes available globally via `window.Subbly`. This method is suitable for direct HTML page inclusion. ```html ``` -------------------------------- ### JavaScript: Update Customer Information Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Example of using `subbly.customers.update` to modify a customer's marketing and terms of service consent. This method allows updating various customer profile fields. ```JavaScript const customer = await subbly.customers.update({ marketingConsent: true, tosConsent: true }) ``` -------------------------------- ### Get Bundle Quote API Reference Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Provides the API signature, parameters, and return type for the `subbly.bundles.quote` method, used to generate a summary quote for a bundle based on specified items. ```APIDOC subbly.bundles.quote(bundleId, payload, params?, headers?): Promise bundleId: number payload: BundleQuotePayload params?: BundleQuoteParams headers?: BundleRequestHeaders Returns: Promise ``` -------------------------------- ### Load a Subscription (JavaScript) Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk This snippet demonstrates how to fetch details for a specific subscription, with an option to expand related data like product information. It uses the `subbly.subscriptions.load` method. ```JavaScript const subscription = await subbly.subscriptions.load(123, { expand: ['product.parent'] }) ``` ```APIDOC subbly.subscriptions.load(subscriptionId, params?): Promise Description: Use subbly.subscriptions.load to load subscription information. Parameters: subscriptionId: number params?: SubscriptionsResourceParams Returns: Promise Description: This method returns a promise that resolves with Subscription. ``` -------------------------------- ### Listen for SubblyCart.js Initialization Event Source: https://docs.subbly.dev/reference/subbly-sdk/reference/cart Demonstrates how to listen for the 'subbly-cart-initialized' event, which indicates that the SubblyCart widget has finished loading and 'window.subblyCart' is now available for use. ```JavaScript window.addEventListener('subbly-cart-initialized', () => { // window.subblyCart is now available }) ``` -------------------------------- ### Initialize Subbly SDK with ES6 Modules Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Imports the Subbly SDK using ES6 modules and initializes it with your API key. The returned promise provides access to Subbly SDK methods upon resolution. This approach is recommended for modern JavaScript frameworks like React.js and Vue.js. ```javascript import Subbly from '@subbly/sdk' Subbly.init({ apiKey: 'API_KEY' }).then((subbly) => { // access Subbly SDK methods }) ``` -------------------------------- ### Load Shop Information (JavaScript) Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk This snippet shows how to retrieve general shop information using the `subbly.shop.load` method. This method requires no parameters and returns a Promise resolving to a Shop object. ```JavaScript const shop = await subbly.shop.load() ``` ```APIDOC subbly.shop.load(): Promise Description: Use subbly.shop.load to load the shop information. Parameters: None Returns: Promise Description: This method returns a promise that resolves with Shop. ``` -------------------------------- ### Subbly Customers API: Get Customer Profile Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk This method allows retrieving the current authenticated customer profile. ```APIDOC subbly.customers.me(): Promise Parameters: None Returns: Promise ``` -------------------------------- ### API Reference: Sign In with Password Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Documents the `subbly.auth.login` method for authenticating a customer using their email and password. ```APIDOC subbly.auth.login(payload): Promise payload: AuthResourceLoginPayload Returns: Promise ``` -------------------------------- ### API Reference: Get Access Token Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Documents the `subbly.auth.getAccessToken` method for retrieving the locally stored access token of the current authenticated user. ```APIDOC subbly.auth.getAccessToken(): string | undefined Returns: string | undefined ``` -------------------------------- ### Initialize SubblyCart Widget with Extended Settings Source: https://docs.subbly.dev/reference/subbly-sdk/reference/cart This JavaScript snippet demonstrates how to configure the SubblyCart widget by setting global `window.subblyConfig` properties. It includes essential settings like the API key, language code, and various cart-related UI/UX configurations such as intercepting product links, specifying cart counter and toggle elements, and customizing the cart button image. ```JavaScript window.subblyConfig = { apiKey: 'API_KEY', languageCode: 'es', settings: { interceptProductLinks: true, cartCounterEl: '#cartCounter', cartToggleEl: '#cartToggle', cartButton: true, cartButtonImage: 'https://example.com/cart-icon.png' } } ``` -------------------------------- ### JavaScript: Remove an Item from Cart Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Example of using `subbly.cart.removeItem` to remove a specific item from the cart. It demonstrates passing the cart item ID to the method. ```JavaScript const cart = await subbly.cart.removeItem('c9554583-99bb-465d-b0e4-97a8cd652cef') ``` -------------------------------- ### Subbly Products: List All Products API Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Documents the `subbly.products.list` method, used to retrieve a list of products. It supports optional parameters for pagination and expanding related data, and optional headers. ```APIDOC subbly.products.list(params?, headers?): Promise Parameters: params?: ProductsListParams headers?: ProductRequestHeaders Returns: Promise - This method returns an array ProductsListResponse. ``` -------------------------------- ### API Reference: Register Account Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Documents the `subbly.auth.register` method used to create a new user account. If a password is not provided, a generated one will be sent to the provided email. Successful registration automatically authenticates the customer. ```APIDOC subbly.auth.register(payload): Promise payload: AuthResourceRegisterPayload Returns: Promise ``` -------------------------------- ### Subbly Products: Load Parent Product Details API Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Documents the `subbly.products.load` method, used to load detailed information for a product that has variants or pricing options. It requires a `productId` and supports optional parameters for expanding related data and headers. ```APIDOC subbly.products.load(productId, params?, headers?): Promise Parameters: productId: number params?: ProductsResourceParams headers?: ProductRequestHeaders Returns: Promise - This method returns a promise that resolves with ParentProduct. ``` -------------------------------- ### Create Customer Address API Reference Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk API documentation for the `subbly.addresses.store()` method, used to create a new address for the customer. It requires a payload containing the address details. ```APIDOC Method: subbly.addresses.store() Returns: Promise Description: Use subbly.addresses.store to create a new address for the customer. Parameters: payload: AddressStorePayload Return Details: This method returns a promise that resolves with CustomerAddress. ``` ```javascript const address = await subbly.addresses.store(payload) ``` -------------------------------- ### CartGiftInfo Type Definition Source: https://docs.subbly.dev/reference/subbly-sdk/reference/types Provides information about a cart's gift details, such as message, number of orders, recipient email, and start date. ```APIDOC CartGiftInfo: Object message: string | null numberOfOrders: number | null recipientEmail?: string | null startsAt: string | null ``` -------------------------------- ### Create Cart API Reference Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Provides the API signature, parameters, and return type for the `subbly.cart.create` method, used to initialize a new shopping cart and store its ID. ```APIDOC subbly.cart.create(payload?, params?): Promise payload?: CartUpdatePayload params?: CartResourceParams Returns: Promise ``` -------------------------------- ### Accept Post-Purchase Offer Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Documents the `subbly.funnels.postPurchaseAccept` method, used to accept a post-purchase offer. Notes required `shippingAddressId` and `shippingMethodId` in the payload. ```APIDOC subbly.funnels.postPurchaseAccept(cartId, funnelStepId, payload, params?): Promise cartId: string funnelStepId: number payload: FunnelPostAcceptPayload params?: CartResourceParams Returns: Promise ``` -------------------------------- ### JavaScript: Update an Item in Cart Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Example of using `subbly.cart.updateItem` to change options for a specific item in the cart. It demonstrates how to pass the cart item ID and the new options payload. ```JavaScript const cart = await subbly.cart.updateItem('7ae5a8e5-bd15-4a5b-870d-0dbb605a3a1d', { options: [ { questionId: 111, answers: [ { id: 222 } ] } ] }) ``` -------------------------------- ### SubblyCart configureItem(payload) Method Source: https://docs.subbly.dev/reference/subbly-sdk/reference/cart The `configureItem()` method adds a product to the cart and handles scenarios where the product requires further configuration (e.g., variant selection, survey completion). It returns a Promise that resolves with a `finalized` property, indicating if the product was fully added or if a customization view was opened. ```APIDOC configureItem(configureItemPayload: object): Promise<{ finalized: boolean }> description: Adds a product to the cart and opens customization view if product is not finalized, e.i. requires customer to select a variant, pricing, or fill a survey. parameters: cartItemPayload: REQUIRED, object description: See CartItemAddPayload for complete reference. Subscription products: productId: REQUIRED, number options: optional, array description: A complete list of survey options with required properties: questionId: number answers: array description: Answer interface depends on the type of question it belongs to: id: number - required for select, multiple, quantity question types content: string - required only for survey question type text quantity: number - required only for survey question type quantity One-time products: productId: REQUIRED, number quantity: REQUIRED, number addon: optional, boolean, Default: false. Allowed only with subscription product in the cart. addonDuration: optional, 1 | null, Default: null. Allowed only with addon: true. Can be either null (forever) or 1 (once). giftCard: optional, object | null, Default: null. Allowed only for gift card products and with quantity of 1. customerEmail: required, string customerName: optional, string | null message: optional, string | null returns: A Promise that resolves with an object containing finalized property. If finalized is true, the product is added to the cart, otherwise, the product is not finalized and appropriate customization view is opened. ``` ```JavaScript subblyCart.configureItem({ productId: 555, options: [{ questionId: 777, answers: [{ id: 888, quantity: 3 }] }] }) ``` ```JavaScript subblyCart.configureItem({ productId: 555, quantity: 2, addon: true, addonDuration: 1 }) ``` ```JavaScript subblyCart.configureItem({ bundleId: 555 }) ``` ```JavaScript subblyCart.configureItem({ surveyId: 555 }) ``` -------------------------------- ### Update Subscription Details (JavaScript) Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk This snippet shows how to modify an existing subscription, for example, by updating its quantity. It uses the `subbly.subscriptions.update` method, requiring the subscription ID and a payload with the updated fields. ```JavaScript const subscription = await subbly.subscriptions.update(123, { quantity: 2 }) ``` ```APIDOC subbly.subscriptions.update(subscriptionId, payload, params?): Promise Description: Use subbly.subscriptions.update to update a subscription. Parameters: subscriptionId: number payload: SubscriptionUpdatePayload params?: SubscriptionsResourceParams Returns: Promise Description: This method returns a promise that resolves with Subscription. ``` -------------------------------- ### API Reference: Sign In with OTP Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Documents the `subbly.auth.otpLogin` method for authenticating a customer using an email and a received One-Time Password (OTP). ```APIDOC subbly.auth.otpLogin(payload): Promise payload: AuthResourceOtpLoginPayload Returns: Promise ``` -------------------------------- ### ProductVariant Object Definition Source: https://docs.subbly.dev/reference/subbly-sdk/reference/types Defines the structure for a product variant, including bundle plan ID, creation timestamp, description, name, options, parent product, price, and stock count. ```APIDOC ProductVariant: Object bundlePlanId: BundlePlan["id"] | null createdAt: string description: string | null id: ID name: string options: ProductVariantOption[] parent: ProductOneTime price: number priceScheme: ProductPriceScheme | null stockCount: number | null ``` -------------------------------- ### SubblyCart.js Widget Configuration Options Source: https://docs.subbly.dev/reference/subbly-sdk/reference/cart Details the available configuration parameters for the SubblyCart.js widget, including required and optional settings for API key, language, cart ID, and various UI behaviors. ```APIDOC window.subblyConfig: apiKey: string (REQUIRED) description: Your Subbly Storefront API key is required, as it provides identification and Cart Widget customization. example: '0736e2ec-484a-4f73-bebe-4b0263ef16c6' languageCode: string (optional) description: Sets preferred storefront translation. Primary translation is used by default. When not provided, Cart Widget will attempt to read the language from 'lang' query parameter, or 'lang' attribute from page's 'html' tag. example: 'en' cartId: string (optional) description: Manually provide a Cart ID to initialize the cart widget with. By the default SubblyCart automatically manages the cart ID in secure browser cookies. example: '97affe36-cfab-459b-8220-d7fac2e49913' settings: object (optional) description: Various settings to customize widget behavior. properties: interceptProductLinks: boolean (optional) description: Intercept and prevent default click behavior on every link that contains a URL with '/checkout/buy/{productID}' and '/checkout/add/{productID}', or has 'data-subbly-product' HTML attribute containing a product ID. cartCounterEl: string | HTMLElement (optional) description: A selector or an HTML element that will be updated with the current Cart items count. cartToggleEl: string | HTMLElement (optional) description: A selector or an HTML element that will open/close the SubblyCart widget. cartButton: boolean (optional) description: Add a floating cart button on the page. cartButtonImage: string (optional) description: URL to the image that will be used as a cart button. By default, a cart icon is used. localizationSettings: boolean (optional) description: Enable currency and language settings dropdown in the cart widget toolbar. By the default, localization settings dropdown is displayed only on the checkout part of the cart widget. sdkClient: object (optional) description: Use previously configured instance of [Subbly SDK](/subbly-js-sdk). With 'sdkClient' provided the required parameter 'apiKey' can be omitted. note: See [Initializing Subbly JS SDK](/subbly-js-sdk#initialization). ``` -------------------------------- ### ProductPricing Object Definition Source: https://docs.subbly.dev/reference/subbly-sdk/reference/types Defines the detailed pricing structure for a product, encompassing bundle plans, charge immediacy, commitment billing, frequencies, and stock management. ```APIDOC ProductPricing: Object bundlePlanId: BundlePlan["id"] | null chargeImmediately: boolean chargesLimit: number | null commitmentBillingCount: number createdAt: string cutOffAt: string | null description: string | null frequencyCount: number frequencyUnit: FrequencyUnit id: number name: string parent: ProductSubscription price: number priceScheme: ProductPriceScheme | null pricingName: string | null rebillingStartAt: string | null shipImmediately: boolean shippings: ProductShipping[] stockCount: number | null survey: Survey | null trialLength: number | null trialPrice: number | null ``` -------------------------------- ### API Reference: Load a Bundle Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Documents the `subbly.bundles.load` method used to retrieve detailed information about a specific bundle by its ID. ```APIDOC subbly.bundles.load(bundleId): Promise bundleId: number params?: BundleResourceParams headers?: BundleRequestHeaders Returns: Promise ``` -------------------------------- ### Define CartSummaryItemType Enumeration Source: https://docs.subbly.dev/reference/subbly-sdk/reference/types Enumerates the various types of items that can appear in a cart summary, including one-time, subscription, trial, gift card, setup fee, survey, shipping, and tax. ```TypeScript enum CartSummaryItemType { oneTime = 'one_time', subscription = 'subscription', trialFirst = 'trial_first', giftCard = 'gift_card', setupFee = 'setup_fee', survey = 'survey', shipping = 'shipping', tax = 'tax' } ``` -------------------------------- ### ProductsListParams Type Source: https://docs.subbly.dev/reference/subbly-sdk/reference/types Defines the parameters available for listing products. It includes options for expanding related data, pagination (page number), and items per page. ```APIDOC ProductsListParams: Object expand?: ProductsExpandableProperties[] page?: number perPage?: number ``` -------------------------------- ### ProductBase Object Definition Source: https://docs.subbly.dev/reference/subbly-sdk/reference/types Defines the base structure for product-related entities, including bundle information, shipping address collection, creation timestamp, and general product details. ```APIDOC ProductBase: Object bundle: Bundle | null bundleId: Bundle["id"] | null bundleRulesetId: BundleRuleset["id"] | null collectShippingAddress: boolean createdAt: string deliveryInfo: string | null description: string | null digital: boolean giftingEnabled: boolean id: ID images: ProductImage[] name: string slug: string ``` -------------------------------- ### ProductVariantOption Object Definition Source: https://docs.subbly.dev/reference/subbly-sdk/reference/types Defines the structure for a product variant option. The specific fields are not detailed in the provided documentation. ```APIDOC ProductVariantOption: Object ``` -------------------------------- ### CartSummaryItem Type Definition Source: https://docs.subbly.dev/reference/subbly-sdk/reference/types Represents a union type for various kinds of items that can appear in a cart summary, allowing for different item behaviors like one-time purchases, subscriptions, setup fees, or survey-related items. ```APIDOC CartSummaryItem: CartSummaryItemOneTime | CartSummaryItemSubscription | CartSummaryItemSetupFee | CartSummaryItemSurvey ``` -------------------------------- ### Apply Gift Card to Subbly Cart Source: https://docs.subbly.dev/reference/subbly-sdk/docs/guide Applies a specified gift card code to the Subbly cart. This method should be called once the cart widget has been fully initialized, typically within the `subbly-cart-initialized` event listener. ```javascript window.addEventListener('subbly-cart-initialized', () => { subblyCart.applyGiftCard('GIFT_CARD_CODE') }) ``` -------------------------------- ### Enable Built-in Floating Cart Button Source: https://docs.subbly.dev/reference/subbly-sdk/docs/guide This code snippet shows how to activate SubblyCart.js's integrated floating cart button. By setting the `cartButton` property to `true` in your configuration, the widget will display its own floating button. ```javascript ``` -------------------------------- ### API Reference: Sign In with Social Login Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Documents the `subbly.auth.social` method for authenticating a customer using one of the supported Single Sign-On (SSO) services. ```APIDOC subbly.auth.social(payload): Promise payload: AuthResourceSocialPayload Returns: Promise ``` -------------------------------- ### Set Subbly Cart Currency with setCurrency Method Source: https://docs.subbly.dev/reference/subbly-sdk/docs/guide Sets the currency for the Subbly cart widget dynamically. This method requires multi-currency to be enabled and should be invoked after the cart is initialized. The currency setting will persist across page reloads. ```javascript window.addEventListener('subbly-cart-initialized', () => { subblyCart.setCurrency('EUR') }) ``` -------------------------------- ### ProductPriceScheme Object Definition Source: https://docs.subbly.dev/reference/subbly-sdk/reference/types Defines the structure for a product's pricing scheme, including its ID, a list of price ranges, and the type of pricing scheme. ```APIDOC ProductPriceScheme: Object id: ID ranges: PriceSchemeRange[] type: "volume_price" | string ``` -------------------------------- ### Dynamically Set Subbly Cart Language with setLanguage Method Source: https://docs.subbly.dev/reference/subbly-sdk/docs/guide Changes the language of the Subbly cart widget dynamically after it has been initialized. This method should be called within the `subbly-cart-initialized` event listener to ensure the cart is ready to receive commands. ```javascript window.addEventListener('subbly-cart-initialized', () => { subblyCart.setLanguage('es') }) ``` -------------------------------- ### Subbly Pickup Info: Store New Pickup Information API Source: https://docs.subbly.dev/reference/subbly-sdk/reference/subbly-sdk Documents the `subbly.pickupInfo.store` method, used to create a new pick-up info for the customer. This method requires authentication and accepts a payload for the new pickup details. ```APIDOC subbly.pickupInfo.store(payload): Promise Parameters: payload: PickupInfoStorePayload Returns: Promise - This method returns a promise that resolves with CustomerPickupInfo ``` -------------------------------- ### Define ProductType Enumeration Source: https://docs.subbly.dev/reference/subbly-sdk/reference/types Enumerates the types of products, distinguishing between one-time purchases and subscriptions. ```TypeScript enum ProductType { oneTime = 'one_time', subscription = 'subscription' } ```