diff --git a/packages/checkout/sdk/src/widgets/definitions/parameters/sale.ts b/packages/checkout/sdk/src/widgets/definitions/parameters/sale.ts index 9a721ba740..cb54c74eed 100644 --- a/packages/checkout/sdk/src/widgets/definitions/parameters/sale.ts +++ b/packages/checkout/sdk/src/widgets/definitions/parameters/sale.ts @@ -28,6 +28,8 @@ export type SaleWidgetParams = { excludeFiatCurrencies?: string[]; /** Preferred currency, replacing the backend's base currency */ preferredCurrency?: string; + /** Custom key-value pairs to be passed to the order */ + customOrderData?: Record; }; /** diff --git a/packages/checkout/widgets-lib/src/widgets/sale/SaleWidget.tsx b/packages/checkout/widgets-lib/src/widgets/sale/SaleWidget.tsx index 6c939f4516..d65d34bcd4 100644 --- a/packages/checkout/widgets-lib/src/widgets/sale/SaleWidget.tsx +++ b/packages/checkout/widgets-lib/src/widgets/sale/SaleWidget.tsx @@ -39,7 +39,7 @@ import { EventTargetContext } from '../../context/event-target-context/EventTarg import { OrderSummary } from './views/OrderSummary'; import { CreditCardWarningDrawer } from './components/CreditCardWarningDrawer'; -type OptionalWidgetParams = Pick; +type OptionalWidgetParams = Pick; type RequiredWidgetParams = Required< Omit >; @@ -63,6 +63,7 @@ export default function SaleWidget(props: SaleWidgetProps) { excludePaymentTypes, excludeFiatCurrencies, preferredCurrency, + customOrderData, hideExcludedPaymentTypes, waitFulfillmentSettlements = true, } = props; @@ -131,6 +132,7 @@ export default function SaleWidget(props: SaleWidgetProps) { excludePaymentTypes, excludeFiatCurrencies, preferredCurrency, + customOrderData, waitFulfillmentSettlements, hideExcludedPaymentTypes, }} diff --git a/packages/checkout/widgets-lib/src/widgets/sale/SaleWidgetRoot.tsx b/packages/checkout/widgets-lib/src/widgets/sale/SaleWidgetRoot.tsx index 9a2100790f..cc9af8ff6f 100644 --- a/packages/checkout/widgets-lib/src/widgets/sale/SaleWidgetRoot.tsx +++ b/packages/checkout/widgets-lib/src/widgets/sale/SaleWidgetRoot.tsx @@ -156,6 +156,7 @@ export class Sale extends Base { this.parameters.excludeFiatCurrencies! } preferredCurrency={this.parameters.preferredCurrency!} + customOrderData={this.parameters.customOrderData!} hideExcludedPaymentTypes={ this.properties?.config?.hideExcludedPaymentTypes ?? false } diff --git a/packages/checkout/widgets-lib/src/widgets/sale/context/SaleContextProvider.tsx b/packages/checkout/widgets-lib/src/widgets/sale/context/SaleContextProvider.tsx index 128126e864..f5e75c484e 100644 --- a/packages/checkout/widgets-lib/src/widgets/sale/context/SaleContextProvider.tsx +++ b/packages/checkout/widgets-lib/src/widgets/sale/context/SaleContextProvider.tsx @@ -48,6 +48,7 @@ type SaleContextProps = { excludePaymentTypes: SalePaymentTypes[]; excludeFiatCurrencies?: string[]; preferredCurrency?: string; + customOrderData?: Record; waitFulfillmentSettlements: boolean; hideExcludedPaymentTypes: boolean; }; @@ -132,6 +133,7 @@ const SaleContext = createContext({ signTokenIds: [], excludePaymentTypes: [], preferredCurrency: undefined, + customOrderData: undefined, selectedCurrency: undefined, waitFulfillmentSettlements: true, hideExcludedPaymentTypes: false, @@ -160,6 +162,7 @@ export function SaleContextProvider(props: { excludePaymentTypes, excludeFiatCurrencies, preferredCurrency, + customOrderData, waitFulfillmentSettlements, hideExcludedPaymentTypes, }, @@ -254,6 +257,7 @@ export function SaleContextProvider(props: { environmentId, environment, waitFulfillmentSettlements, + customOrderData, }); const sign = useCallback( diff --git a/packages/checkout/widgets-lib/src/widgets/sale/hooks/useSignOrder.ts b/packages/checkout/widgets-lib/src/widgets/sale/hooks/useSignOrder.ts index 1b09dcf64c..dae04ef437 100644 --- a/packages/checkout/widgets-lib/src/widgets/sale/hooks/useSignOrder.ts +++ b/packages/checkout/widgets-lib/src/widgets/sale/hooks/useSignOrder.ts @@ -73,6 +73,7 @@ type SignApiRequest = { product_id: string; quantity: number; }[]; + custom_data?: Record; }; type SignApiError = { @@ -159,6 +160,7 @@ export const useSignOrder = (input: SignOrderInput) => { environment, environmentId, waitFulfillmentSettlements, + customOrderData, } = input; const [signError, setSignError] = useState( undefined, @@ -274,6 +276,7 @@ export const useSignOrder = (input: SignOrderInput) => { product_id: item.productId, quantity: item.qty, })), + custom_data: customOrderData, }; const baseUrl = `${PRIMARY_SALES_API_BASE_URL[environment]}/${environmentId}/order/sign`; diff --git a/packages/checkout/widgets-lib/src/widgets/sale/types.ts b/packages/checkout/widgets-lib/src/widgets/sale/types.ts index 26cb1f4529..62c2be0719 100644 --- a/packages/checkout/widgets-lib/src/widgets/sale/types.ts +++ b/packages/checkout/widgets-lib/src/widgets/sale/types.ts @@ -54,6 +54,7 @@ export type SignOrderInput = { environment: string; environmentId: string; waitFulfillmentSettlements: boolean; + customOrderData?: Record; }; export type SignOrderError = {