Skip to content

Latest commit

 

History

History
177 lines (113 loc) · 4.49 KB

CheckoutButtonInitializer.md

File metadata and controls

177 lines (113 loc) · 4.49 KB

@bigcommerce/checkout-sdk / CheckoutButtonInitializer

Class: CheckoutButtonInitializer

Table of contents

Constructors

Methods

Constructors

constructor

new CheckoutButtonInitializer()

Methods

deinitializeButton

deinitializeButton(options): 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): 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, ...filters): () => void

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

Name Type Description
subscriber (state: CheckoutButtonSelectors) => void The function to subscribe to state changes.
...filters (state: CheckoutButtonSelectors) => any[] 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

fn

A function, if called, will unsubscribe the subscriber.

▸ (): void

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);
Returns

void

A function, if called, will unsubscribe the subscriber.