Skip to content

Latest commit

 

History

History
147 lines (93 loc) · 3.91 KB

checkoutbuttoninitializer.md

File metadata and controls

147 lines (93 loc) · 3.91 KB

@bigcommerce/checkout-sdkCheckoutButtonInitializer

Class: CheckoutButtonInitializer

Hierarchy

  • CheckoutButtonInitializer

Index

Methods

Methods

deinitializeButton

deinitializeButton(options: CheckoutButtonOptions): Promise‹CheckoutButtonSelectors

De-initializes the checkout button by performing any necessary clean-ups.

await service.deinitializeButton({
    methodId: 'braintreepaypal',
});

Parameters:

Name Type Description
options CheckoutButtonOptions Options for deinitializing the checkout button.

Returns: Promise‹CheckoutButtonSelectors

A promise that resolves to the current state.


getState

getState(): CheckoutButtonSelectors

Returns a snapshot of the current state.

The method returns a new instance every time there is a change in the state. You can query the state by calling any of its getter methods.

const state = service.getState();

console.log(state.errors.getInitializeButtonError());
console.log(state.statuses.isInitializingButton());

Returns: CheckoutButtonSelectors

The current customer's checkout state


initializeButton

initializeButton(options: CheckoutButtonInitializeOptions): Promise‹CheckoutButtonSelectors

Initializes the checkout button of a payment method.

When the checkout button is initialized, it will be inserted into the DOM, ready to be interacted with by the customer.

initializer.initializeButton({
    methodId: 'braintreepaypal',
    containerId: 'checkoutButton',
    braintreepaypal: {
    },
});

Parameters:

Name Type Description
options CheckoutButtonInitializeOptions Options for initializing the checkout button.

Returns: Promise‹CheckoutButtonSelectors

A promise that resolves to the current state.


subscribe

subscribe(subscriber: function, ...filters: Array‹function›): function

Subscribes to any changes to the current state.

The method registers a callback function and executes it every time there is a change in the current state.

service.subscribe(state => {
    console.log(state.statuses.isInitializingButton());
});

The method can be configured to notify subscribers only regarding relevant changes, by providing a filter function.

const filter = state => state.errors.getInitializeButtonError();

// Only trigger the subscriber when the cart changes.
service.subscribe(state => {
    console.log(state.errors.getInitializeButtonError())
}, filter);

Parameters:

subscriber: function

The function to subscribe to state changes.

▸ (state: CheckoutButtonSelectors): void

Parameters:

Name Type
state CheckoutButtonSelectors

▪... filters: Array‹function›

One or more functions to filter out irrelevant state changes. If more than one function is provided, the subscriber will only be triggered if all conditions are met.

Returns: function

A function, if called, will unsubscribe the subscriber.

▸ (): void