### 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