@bigcommerce/checkout-sdk / CheckoutButtonInitializer
• new CheckoutButtonInitializer()
▸ deinitializeButton(options
): Promise
<CheckoutButtonSelectors
>
De-initializes the checkout button by performing any necessary clean-ups.
await service.deinitializeButton({
methodId: 'braintreepaypal',
});
Name | Type | Description |
---|---|---|
options |
CheckoutButtonOptions |
Options for deinitializing the checkout button. |
Promise
<CheckoutButtonSelectors
>
A promise that resolves to the current state.
▸ 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());
The current customer's checkout state
▸ 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: {
},
});
Name | Type | Description |
---|---|---|
options |
CheckoutButtonInitializeOptions |
Options for initializing the checkout button. |
Promise
<CheckoutButtonSelectors
>
A promise that resolves to the current state.
▸ 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);
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. |
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);
void
A function, if called, will unsubscribe the subscriber.