JavaScript SDK reference

function initializeDefaultContext ( ) : SDK

Initialize the SDK for use in a Javascript environment without DOM

initializeDefaultContext doesn't take any arguments

Returns

initializeDefaultContext returns a SDK

interface SnipcartBrowserContextOptions

Inititialization options for `initializeBrowserContext`

Properties

  • exportGlobal boolean

    When set to true, window.Snipcart gets assigned with the constructed SnipcartBrowserContext instance

function initializeBrowserContext ( apiKey? : string, doc? : HTMLDocument, options? : SnipcartBrowserContextOptions ) : Promise

Initialize the SDK for use in a Web browser

Arguments

  1. apiKey – an optional string

    Snipcart Public API Key

  2. doc – an optional HTMLDocument

    Custom document node instead of `window.document`

  3. options – an optional SnipcartBrowserContextOptions

    Initialization options

Returns

initializeBrowserContext returns a Promise

interface BrowserAPI

The browser API, responsible for all browser related operations

Methods

  • insertPaymentForm ( parentNode: HTMLElement ) : Promise

    Inserts a payment form iframe served and secured by Snipcart's payment service.

    Arguments

    1. parentNode HTMLElement

      The HTML node that the payment form iframe will be appended to. // tslint:disable-next-line:max-line-length

    Returns

    insertPaymentForm returns a Promise

interface PaymentFormAPI

Interface that exposes the actions available on a payment form instance.

Methods

  • destroy ( ) : void

    Removes the payment form iframe element from the DOM.

    destroy doesn't take any arguments and return nothing

  • authorizePayment ( ) : Promise

    Triggers the authorization of the payment using the information provided in the form.

    authorizePayment doesn't take any arguments

    Returns

    authorizePayment returns a Promise

interface PaymentFormCrossWindowInterop

Properties

Methods

  • authorizePayment ( ) : Promise

    authorizePayment doesn't take any arguments

    Returns

    authorizePayment returns a Promise

interface SDKWithinBrowser

This is a specialization of the SDK interface, providing additional browser specific members

Properties

interface EventEmitter

Subscribe Only event emitter

Methods

  • on ( eventName: string, callback: (payload: T) => void ) : void

    Arguments

    1. eventName string

    2. callback (payload: T) => void

    on doesn't return anything

interface ReadOnlyStore

ReadOnly Redux store

Methods

  • getState ( ) : S

    Get the current state

    getState doesn't take any arguments

    Returns

    getState returns a S

  • subscribe ( listener: () => void ) : Unsubscribe

    Subscribe to state changes

    Arguments

    1. listener () => void

      A callback to be invoked on every state change.

    Returns

    subscribe returns a Unsubscribe

interface SDK

This is the SDK

Properties

  • api API

    Cart API entry point

  • store ReadOnlyStore

    Returns the current store object backing Snipcart's current state

  • version string

    Returns the current Snipcart version

  • events EventEmitter

    Returns the event bus used to subscribe to events

interface Unsubscribe

Function to remove listener added by `ReadOnlyStore.subscribe()`.

Methods

  • ( ) : void

    Signature of the `Unsubscribe` type itself

    It doesn't take any arguments and return nothing

interface SDKInitilizationOptions

These are the SDK initialization options

Properties

  • apiKey – an optional string

    Snipcart's Public API Key

  • cartToken – an optional string

    The UID token of the cart to load at session start

interface API

This is the main API entrypoint to interact with Snipcart remote API. All APIs used to interact with the current cart are available through this.

Properties

interface CartAPI

The cart API

Properties

  • items ItemsAPI

    Cart items API entry point

Methods

  • update ( payload: UpdateCartPayload ) : Promise

    Updates a cart in progress

    Arguments

    1. payload UpdateCartPayload

      Data to update

    Returns

    update returns a Promise

  • applyDiscount ( discountCode: string ) : Promise

    Arguments

    1. discountCode string

      The discount code to apply

    Returns

    applyDiscount returns a Promise

  • removeDiscount ( discountCode: string ) : Promise

    Arguments

    1. discountCode string

      The discount code to apply

    Returns

    removeDiscount returns a Promise

  • setShippingInformation ( information: ShippingInformation ) : Promise

    Provide shipping information for the current cart

    Arguments

    1. information ShippingInformation

      Billing address

    Returns

    setShippingInformation returns a Promise

  • setPaymentDetails ( details: PaymentDetails ) : Promise

    Provide selected payment method and associated details for the current cart

    Arguments

    1. details PaymentDetails

      Payment method details

    Returns

    setPaymentDetails returns a Promise

  • fetchShippingRates ( ) : Promise

    Fetch shipping rates for the cart.

    fetchShippingRates doesn't take any arguments

    Returns

    fetchShippingRates returns a Promise

  • initializePaymentSession ( paymentAuthorizedRedirectUrl: string ) : Promise

    Initializes the payment session.

    Arguments

    1. paymentAuthorizedRedirectUrl string

      When the payment authorization flow is Redirect, this is the URL to redirect once authorized.

    Returns

    initializePaymentSession returns a Promise

  • selectPaymentMethod ( paymentMethodId: string ) : Promise

    Select the payment method to be used

    Arguments

    1. paymentMethodId string

    Returns

    selectPaymentMethod returns a Promise

  • confirm ( ) : Promise

    Confirm the order and process the payment

    confirm doesn't take any arguments

    Returns

    confirm returns a Promise

interface ItemsAPI

The cart items API

Methods

  • add ( items: ) : Promise

    Adds an item or multiple items to the cart.

    Arguments

    1. items

      Items that will be added to the cart. Can be an arry of items or a single one.

    Returns

    add returns a Promise

  • remove ( item: ) : Promise

    Removes an item from the cart.

    Arguments

    1. item

      Item unique ID.

    Returns

    remove returns a Promise

  • update ( item: CartItem ) : Promise

    Update an item in the cart

    Arguments

    1. item CartItem

      Item to update with new values

    Returns

    update returns a Promise

interface CustomerAPI

The customer API

Methods

  • fetchOrder ( token: string ) : Promise

    Retrieves an order by its unique token.

    Arguments

    1. token string

      Order unique token.

    Returns

    fetchOrder returns a Promise

interface LocalizationAPI

The localization API

Methods

interface Address

Properties

interface CartItem

Properties

interface CartSummary

Properties

interface CustomField

Properties

  • name string

  • value

  • type string

  • options – an optional

interface CustomFieldOption

Properties

interface Dimensions

Properties

interface Discount

Properties

interface DiscountError

Properties

  • cartSummary CartSummary

  • result { errors: ApiErrors; message: string; }

enum DiscountTrigger : string

Members

  • Code = "Code"

enum DiscountType : string

Members

  • FixedAmount = "FixedAmount"

interface EntityState

Properties

  • committing Boolean

interface EntityWithState

Properties

interface ErrorActionPayload

Properties

interface ErrorsBagItem

Properties

  • validation string

  • message string

  • attemptedValue any

interface LazyCollection

Properties

interface LocalizationQuery

Properties

enum PaymentAuthorizationFlow : string

Members

  • Form = "Form"
  • Redirect = "Redirect"

enum PaymentConfirmationSynchronicity : string

Members

  • Synchronous = "Synchronous"
  • Asynchronous = "Asynchronous"

interface PaymentDetails

Properties

  • method string

  • details T

interface Invoice

Properties

  • targetId string

  • email string

  • amount number

  • currency string

  • billingAddress Address

  • shippingAddress – an optional Address

interface InvoiceUpdatePayload

Properties

  • amount – an optional number

  • currency – an optional string

  • email – an optional string

  • billingAddress – an optional AddressUpdatePayload

  • shippingAddress – an optional AddressUpdatePayload

interface PaymentAuthorization

Properties

enum PaymentFormLoadingState : number

Members

  • None = 0
  • Loading = 1
  • Loaded = 2

interface PaymentSession

Properties

enum PaymentSessionStates : string

Members

  • RequiresPaymentMethod = "RequiresPaymentMethod"
  • Authorizing = "Authorizing"
  • RequiresAuthorization = "RequiresAuthorization"
  • Authorized = "Authorized"
  • Completed = "Completed"

enum PaymentSessionStates : string

Members

  • RequiresPaymentMethod = "RequiresPaymentMethod"
  • Authorizing = "Authorizing"
  • RequiresAuthorization = "RequiresAuthorization"
  • Authorized = "Authorized"
  • Completed = "Completed"

interface ProductDefinition

Properties

  • id string

  • name string

  • price

  • url string

  • description – an optional string

  • image – an optional string

  • categories – an optional

  • quantity – an optional number

  • minQuantity – an optional number

  • maxQuantity – an optional number

  • quantityStep – an optional number

  • dimensions – an optional Dimensions

  • customFields – an optional

  • stackable – an optional StackingOptions

  • hasTaxesIncluded – an optional boolean

function productDefinitionToCartItem ( definition: ProductDefinition, updatedItem? : CartItem ) : CartItem

Create a new or updated CartItem from provided ProductDefinition

Arguments

  1. definition ProductDefinition

    product definition from JS API or html

  2. updatedItem – an optional CartItem

    serve as default data when updating an existing item

Returns

productDefinitionToCartItem returns a CartItem

class SDKError

constructor ( data? : T, code? : string ) : SDKError

Arguments

  1. data – an optional T

  2. code – an optional string

Properties

interface ShippingInformation

Properties

interface ShippingRate

Properties

interface Tax

Properties

interface UpdateCartPayload

Properties

  • billingAddress – an optional Address

  • shippingAddress – an optional Address

  • shipToBillingAddress – an optional boolean

  • email – an optional string

  • customFields – an optional

interface CartCreatedResponse

Properties

interface CartResponse

Properties

interface ShippingInformationResponse

Properties

interface CartConfirmResponse

Properties

interface CartMutationResponse

Properties

interface CartMutationSummary

Properties

interface ErrorResponse

Properties

  • message string

  • reason – an optional string

  • content – an optional any

  • errors { [property: string]: string[]; }

interface CartState

Properties

function createInitialCartState ( ) : CartState

createInitialCartState doesn't take any arguments

Returns

createInitialCartState returns a CartState

function mapCartResponseToCartState ( cart: CartResponse, latestState? : CartState ) : CartState

Arguments

  1. cart CartResponse

  2. latestState – an optional CartState

Returns

mapCartResponseToCartState returns a CartState

interface CustomerState

Properties

function createInitialCustomerState ( ) : CustomerState

createInitialCustomerState doesn't take any arguments

Returns

createInitialCustomerState returns a CustomerState

interface LocalizationState

Properties

  • suggestedAddressesQueries

interface SuggestedAddressesQuery

Properties

function createInitialLocalizationState ( ) : LocalizationState

createInitialLocalizationState doesn't take any arguments

Returns

createInitialLocalizationState returns a LocalizationState

interface SessionState

Properties

  • id string

  • settings { countries: []; currency: string; shippingEnabled: boolean; }

  • loading boolean

function createInitialSessionState ( ) : SessionState

createInitialSessionState doesn't take any arguments

Returns

createInitialSessionState returns a SessionState

interface SnipcartState

Properties

interface StatusObject

Properties

  • status T

enum CartStatus : number

Members

  • Uninitialized = 0
  • Creating = 1
  • Ready = 2
  • Completed = 3

enum PaymentStatus : number

Members

  • Unset = 0
  • Saving = 1
  • Saved = 2
  • Processing = 3
  • WaitingForUser = 4
  • Paid = 5
  • Refunded = 6

enum SavingStatus : number

Members

  • Unset = 0
  • Saving = 1
  • Saved = 2

enum StackingOptions : string

Members

  • Always = "always"
  • Auto = "auto"
  • Never = "never"