Skip to content

setPaymentData(payment: BasketPayment, paymentData: Record<string, unknown>): Promise<void>

The setPaymentData method allows you to add or update additional data related to a specific payment option within the basket's shipping configuration.

Input parameters

payment

payment is a mandatory parameter which represents the BasketPayment model specifying the payment method to which the additional data will be associated.

paymentData

paymentData is a mandatory parameter of the Record<string, unknown> type that contains key-value pairs of additional information or configurations related to the selected payment method.

Returned value

A returned value has a type of Promise<void>, indicating that the method completes without returning any data upon successful execution.

Event Bus events

This API method dispatches the following events with the Event Bus:

Example

In this example, we use the basketPaymentsApi to set a Blik code for a selected payment option. To get a selected payment option we use the getSelectedPayment method.

useStorefront(async ({ eventBus, getApi }) => {
    eventBus.on('basket.initialized', async () => {
        const basketPaymentsApi = await getApi('basketPaymentsApi');

        const selectedPayment = basketPaymentsApi.getSelectedPayment();

        const additionalPaymentData = {
            blikCode: '111111',
        };

        try {
            await basketPaymentsApi.setPaymentData(selectedPayment, additionalPaymentData);
            console.log('Payment data set successfully.');
        } catch (error) {
            console.error('Error setting payment data:', error);
        }
    });
});

Basket Payments API methods reference

Models reference