diff --git a/package-lock.json b/package-lock.json index 367783b..11510fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "paypal-commercetools-client", - "version": "0.0.46", + "version": "0.0.47", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "paypal-commercetools-client", - "version": "0.0.46", + "version": "0.0.47", "license": "MIT", "dependencies": { "@heroicons/react": "^1.0.6", diff --git a/package.json b/package.json index 5723f25..644bd52 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "paypal-commercetools-client", - "version": "0.0.46", + "version": "0.0.47", "private": false, "type": "module", "license": "MIT", diff --git a/src/app/usePayment.tsx b/src/app/usePayment.tsx index b449b1f..5a15cb5 100644 --- a/src/app/usePayment.tsx +++ b/src/app/usePayment.tsx @@ -16,6 +16,7 @@ import { ClientTokenResponse, CustomOnApproveData, OnApproveResponse, + CreateOrderData, } from "../types"; import { createPayment, createOrder, onApprove } from "../services"; @@ -42,7 +43,7 @@ type PaymentContextT = { requestHeader: RequestHeader; handleCreatePayment: () => void; clientToken: string; - handleCreateOrder: () => Promise; + handleCreateOrder: (orderData?: CreateOrderData) => Promise; handleOnApprove: (data: CustomOnApproveData) => Promise; }; @@ -52,7 +53,7 @@ const PaymentContext = createContext({ requestHeader: {}, handleCreatePayment: () => {}, clientToken: "", - handleCreateOrder: () => Promise.resolve(""), + handleCreateOrder: (orderData?: CreateOrderData) => Promise.resolve(""), handleOnApprove: () => Promise.resolve(), }); @@ -101,14 +102,15 @@ export const PaymentProvider: FC< setResultMessage("Test success successful"); }; - const handleCreateOrder = async () => { + const handleCreateOrder = async (orderData?: CreateOrderData) => { if (!createOrderUrl) return ""; const createOrderResult = await createOrder( requestHeader, createOrderUrl, paymentInfo.id, - paymentInfo.version + paymentInfo.version, + orderData ); if (createOrderResult) { diff --git a/src/services/createOrder.ts b/src/services/createOrder.ts index 8be0b9e..777aca1 100644 --- a/src/services/createOrder.ts +++ b/src/services/createOrder.ts @@ -4,18 +4,21 @@ import { RequestHeader, CreateOrderRequest, CreateOrderResponse, + CreateOrderData, } from "../types"; export const createOrder = async ( requestHeader: RequestHeader, url: string, paymentId: string, - paymentVersion: number + paymentVersion: number, + orderData?: CreateOrderData ) => { try { const data: CreateOrderRequest = { paymentId, paymentVersion, + orderData, }; return await makeRequest( diff --git a/src/types/index.ts b/src/types/index.ts index 76122e8..9c9e4e0 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -3,10 +3,16 @@ import { ReactPayPalScriptOptions, PayPalMessagesComponentProps, } from "@paypal/react-paypal-js"; +import { FUNDING_SOURCE } from "@paypal/paypal-js/types/components/funding-eligibility"; export type CreateOrderRequest = { paymentId: string; paymentVersion: number; + orderData?: CreateOrderData; +}; + +export type CreateOrderData = { + paymentSource: FUNDING_SOURCE; }; export type CreateOrderResponse = {