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 (storefront) => {
    let basketPaymentsApi = storefront.getApiSync('basketPaymentsApi');

    if (!basketPaymentsApi) {
        const featureSystemApi = this.getApiSync('FeatureSystemApi');
        await featureSystemApi.registerDynamic('basket');

        basketPaymentsApi = storefront.getApiSync('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