Skip to content

Commit

Permalink
Implement custom order data for primary sales sign call
Browse files Browse the repository at this point in the history
  • Loading branch information
luads committed Sep 26, 2024
1 parent c253fe9 commit 96ff372
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SaleWidgetParams, 'excludePaymentTypes' | 'excludeFiatCurrencies'>;
type OptionalWidgetParams = Pick<SaleWidgetParams, 'excludePaymentTypes' | 'excludeFiatCurrencies' | 'customOrderData'>;
type RequiredWidgetParams = Required<
Omit<SaleWidgetParams, 'walletProviderName'>
>;
Expand All @@ -63,6 +63,7 @@ export default function SaleWidget(props: SaleWidgetProps) {
excludePaymentTypes,
excludeFiatCurrencies,
preferredCurrency,
customOrderData,
hideExcludedPaymentTypes,
waitFulfillmentSettlements = true,
} = props;
Expand Down Expand Up @@ -131,6 +132,7 @@ export default function SaleWidget(props: SaleWidgetProps) {
excludePaymentTypes,
excludeFiatCurrencies,
preferredCurrency,
customOrderData,
waitFulfillmentSettlements,
hideExcludedPaymentTypes,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export class Sale extends Base<WidgetType.SALE> {
this.parameters.excludeFiatCurrencies!
}
preferredCurrency={this.parameters.preferredCurrency!}
customOrderData={this.parameters.customOrderData!}
hideExcludedPaymentTypes={
this.properties?.config?.hideExcludedPaymentTypes ?? false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type SaleContextProps = {
excludePaymentTypes: SalePaymentTypes[];
excludeFiatCurrencies?: string[];
preferredCurrency?: string;
customOrderData?: Record<string, any>;
waitFulfillmentSettlements: boolean;
hideExcludedPaymentTypes: boolean;
};
Expand Down Expand Up @@ -132,6 +133,7 @@ const SaleContext = createContext<SaleContextValues>({
signTokenIds: [],
excludePaymentTypes: [],
preferredCurrency: undefined,
customOrderData: undefined,
selectedCurrency: undefined,
waitFulfillmentSettlements: true,
hideExcludedPaymentTypes: false,
Expand Down Expand Up @@ -160,6 +162,7 @@ export function SaleContextProvider(props: {
excludePaymentTypes,
excludeFiatCurrencies,
preferredCurrency,
customOrderData,
waitFulfillmentSettlements,
hideExcludedPaymentTypes,
},
Expand Down Expand Up @@ -254,6 +257,7 @@ export function SaleContextProvider(props: {
environmentId,
environment,
waitFulfillmentSettlements,
customOrderData,
});

const sign = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type SignApiRequest = {
product_id: string;
quantity: number;
}[];
custom_data?: Record<string, any>;
};

type SignApiError = {
Expand Down Expand Up @@ -159,6 +160,7 @@ export const useSignOrder = (input: SignOrderInput) => {
environment,
environmentId,
waitFulfillmentSettlements,
customOrderData,
} = input;
const [signError, setSignError] = useState<SignOrderError | undefined>(
undefined,
Expand Down Expand Up @@ -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`;
Expand Down
1 change: 1 addition & 0 deletions packages/checkout/widgets-lib/src/widgets/sale/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type SignOrderInput = {
environment: string;
environmentId: string;
waitFulfillmentSettlements: boolean;
customOrderData?: Record<string, any>;
};

export type SignOrderError = {
Expand Down

0 comments on commit 96ff372

Please sign in to comment.