@payment-kit-js/vanilla 0.5.16 → 0.5.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{bnpl-shared-DGs1YzS9.mjs → bnpl-shared-CL900HFN.mjs} +2 -2
- package/dist/{bnpl-shared-DGs1YzS9.mjs.map → bnpl-shared-CL900HFN.mjs.map} +1 -1
- package/dist/{bnpl-shared-BQwCBD45.d.mts → bnpl-shared-D-Kd58Qz.d.mts} +2 -2
- package/dist/{bnpl-shared-BQwCBD45.d.mts.map → bnpl-shared-D-Kd58Qz.d.mts.map} +1 -1
- package/dist/cdn/paymentkit.js +194 -59
- package/dist/cdn/paymentkit.js.map +3 -3
- package/dist/cdn/paymentkit.min.js +24 -24
- package/dist/cdn/paymentkit.min.js.map +3 -3
- package/dist/connect-card-CZhzK_Tp.d.mts.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +11 -4
- package/dist/index.mjs.map +1 -1
- package/dist/{next-action-handlers-CLOt1wzO.mjs → next-action-handlers-BZ5gynXe.mjs} +18 -18
- package/dist/next-action-handlers-BZ5gynXe.mjs.map +1 -0
- package/dist/payment-methods/affirm.d.mts +2 -2
- package/dist/payment-methods/affirm.mjs +2 -2
- package/dist/payment-methods/afterpay.d.mts +2 -2
- package/dist/payment-methods/afterpay.mjs +2 -2
- package/dist/payment-methods/apple-pay.d.mts +16 -7
- package/dist/payment-methods/apple-pay.d.mts.map +1 -1
- package/dist/payment-methods/apple-pay.mjs +12 -14
- package/dist/payment-methods/apple-pay.mjs.map +1 -1
- package/dist/payment-methods/bnpl-shared.d.mts +2 -2
- package/dist/payment-methods/bnpl-shared.mjs +2 -2
- package/dist/payment-methods/card.d.mts +1 -1
- package/dist/payment-methods/card.d.mts.map +1 -1
- package/dist/payment-methods/card.mjs +8 -4
- package/dist/payment-methods/card.mjs.map +1 -1
- package/dist/payment-methods/google-pay.d.mts +25 -3
- package/dist/payment-methods/google-pay.d.mts.map +1 -1
- package/dist/payment-methods/google-pay.mjs +131 -10
- package/dist/payment-methods/google-pay.mjs.map +1 -1
- package/dist/payment-methods/klarna.d.mts +2 -2
- package/dist/payment-methods/klarna.mjs +2 -2
- package/dist/payment-methods/next-action-handlers.mjs +1 -1
- package/dist/payment-methods/paypal.d.mts +1 -1
- package/dist/payment-methods/paypal.mjs +1 -1
- package/dist/{types-B3mjYfOm.d.mts → types-Cjcc3xak.d.mts} +6 -9
- package/dist/types-Cjcc3xak.d.mts.map +1 -0
- package/dist/{utils-Dc6zwOe1.mjs → utils-DIqrx4XF.mjs} +10 -7
- package/dist/utils-DIqrx4XF.mjs.map +1 -0
- package/package.json +2 -2
- package/dist/next-action-handlers-CLOt1wzO.mjs.map +0 -1
- package/dist/types-B3mjYfOm.d.mts.map +0 -1
- package/dist/utils-Dc6zwOe1.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as definePaymentMethod, n as collectFraudMetadata, o as getOrCreateCheckoutRequestId } from "./utils-
|
|
1
|
+
import { i as definePaymentMethod, n as collectFraudMetadata, o as getOrCreateCheckoutRequestId } from "./utils-DIqrx4XF.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/payment-methods/bnpl-shared.ts
|
|
4
4
|
const createSubmitPayment = (states, config) => {
|
|
@@ -104,4 +104,4 @@ function createBnplPaymentMethod(config) {
|
|
|
104
104
|
|
|
105
105
|
//#endregion
|
|
106
106
|
export { createBnplPaymentMethod as t };
|
|
107
|
-
//# sourceMappingURL=bnpl-shared-
|
|
107
|
+
//# sourceMappingURL=bnpl-shared-CL900HFN.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bnpl-shared-DGs1YzS9.mjs","names":["submitPayment: TInternalFuncs[\"submitPayment\"]","requestBody: BnplStartRequest","localStates: BnplStates"],"sources":["../src/payment-methods/bnpl-shared.ts"],"sourcesContent":["/**\n * Shared BNPL (Buy Now Pay Later) payment method factory.\n * Used by Klarna, Afterpay, and Affirm payment methods.\n */\n\nimport type { PaymentKitErrors, PaymentKitStates, TInternalFuncs } from \"../types\";\nimport { collectFraudMetadata, definePaymentMethod, getOrCreateCheckoutRequestId } from \"../utils\";\n\nexport type BnplCustomerInfo = {\n first_name: string;\n last_name: string;\n email?: string;\n};\n\nexport type BnplStartRequest = {\n processor_id: string;\n customer_info: BnplCustomerInfo;\n fraud_metadata: {\n ipAddress?: string;\n browserInfo?: { [key: string]: unknown };\n processorFraudInfo?: { [key: string]: unknown };\n };\n setup_future_usage?: boolean;\n};\n\nexport type BnplStartResponse = {\n approval_url: string;\n popup_token: string;\n checkout_attempt_id: string;\n};\n\nexport type BnplStatusResponse = {\n completed: boolean;\n status: \"success\" | \"failed\" | \"cancelled\";\n result?: unknown;\n error?: string;\n};\n\nexport type BnplCheckoutResponse = {\n id: string;\n checkoutAttemptId: string;\n checkoutSessionId: string;\n state: string;\n customerId?: string;\n paymentMethodId?: string;\n processorUsed?: string;\n subscriptionId?: string;\n invoiceId?: string;\n invoiceNumber?: number;\n};\n\nexport type BnplSubmitOptions = {\n processorId: string;\n customerInfo: BnplCustomerInfo;\n setupFutureUsage?: boolean;\n};\n\ntype BnplStates = PaymentKitStates & {\n popup?: Window | null;\n pollInterval?: ReturnType<typeof setInterval>;\n};\n\nexport type BnplProviderConfig = {\n name: string;\n endpointPath: string;\n supportsSetupFutureUsage?: boolean;\n};\n\nconst createSubmitPayment = (states: BnplStates, config: BnplProviderConfig) => {\n const { name, endpointPath, supportsSetupFutureUsage } = config;\n const capitalizedName = name.charAt(0).toUpperCase() + name.slice(1);\n\n const submitPayment: TInternalFuncs[\"submitPayment\"] = async (_fields, options) => {\n const { apiBaseUrl, secureToken, environment } = states;\n const bnplOptions = options as BnplSubmitOptions;\n\n if (!bnplOptions?.processorId) {\n return { errors: { processor_id: \"Processor ID is required\" } as PaymentKitErrors };\n }\n\n if (!bnplOptions?.customerInfo?.first_name || !bnplOptions?.customerInfo?.last_name) {\n return {\n errors: {\n customer_name: \"Customer first and last name are required\",\n } as PaymentKitErrors,\n };\n }\n\n try {\n const checkoutRequestId = getOrCreateCheckoutRequestId(environment);\n\n const requestBody: BnplStartRequest = {\n processor_id: bnplOptions.processorId,\n customer_info: bnplOptions.customerInfo,\n fraud_metadata: collectFraudMetadata(),\n };\n\n if (supportsSetupFutureUsage && bnplOptions.setupFutureUsage !== undefined) {\n requestBody.setup_future_usage = bnplOptions.setupFutureUsage;\n }\n\n const startResponse = await fetch(`${apiBaseUrl}/api/checkout/${secureToken}/stripe/${endpointPath}/start`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-request-id\": checkoutRequestId,\n },\n body: JSON.stringify(requestBody),\n });\n\n if (!startResponse.ok) {\n let errorMessage = `Failed to start ${capitalizedName} checkout (${startResponse.status})`;\n try {\n const errorData = await startResponse.json();\n errorMessage = errorData.detail || errorMessage;\n } catch {\n errorMessage = startResponse.statusText || errorMessage;\n }\n return {\n errors: {\n [name]: errorMessage,\n } as PaymentKitErrors,\n };\n }\n\n const { approval_url, popup_token, checkout_attempt_id } = (await startResponse.json()) as BnplStartResponse;\n\n const popup = window.open(approval_url, capitalizedName, \"width=600,height=700\");\n\n if (!popup) {\n return {\n errors: {\n [name]: `Failed to open ${capitalizedName} popup. Please allow popups for this site.`,\n } as PaymentKitErrors,\n };\n }\n\n states.popup = popup;\n\n return new Promise((resolve) => {\n let popupClosedGracePolls = 0;\n const MAX_GRACE_POLLS = 5;\n\n const pollInterval = setInterval(async () => {\n try {\n const statusResponse = await fetch(\n `${apiBaseUrl}/api/checkout/${secureToken}/popup/status?popup_token=${popup_token}`,\n );\n\n if (!statusResponse.ok) {\n clearInterval(pollInterval);\n popup.close();\n resolve({\n errors: {\n [name]: `Failed to check ${capitalizedName} status`,\n } as PaymentKitErrors,\n });\n return;\n }\n\n const statusResult = (await statusResponse.json()) as BnplStatusResponse;\n\n if (statusResult.completed) {\n clearInterval(pollInterval);\n popup.close();\n\n if (statusResult.status === \"success\") {\n // Result is returned directly from popup status endpoint\n const result = statusResult.result || {\n id: checkout_attempt_id,\n checkoutAttemptId: checkout_attempt_id,\n checkoutSessionId: secureToken,\n state: \"checkout_succeeded\",\n };\n\n resolve({ data: result });\n } else {\n resolve({\n errors: {\n [name]: statusResult.error || `${capitalizedName} checkout ${statusResult.status}`,\n } as PaymentKitErrors,\n });\n }\n return;\n }\n\n if (popup.closed) {\n popupClosedGracePolls++;\n if (popupClosedGracePolls >= MAX_GRACE_POLLS) {\n clearInterval(pollInterval);\n resolve({\n errors: {\n [name]: `${capitalizedName} popup closed by user`,\n } as PaymentKitErrors,\n });\n }\n return;\n }\n } catch (error) {\n clearInterval(pollInterval);\n popup.close();\n resolve({\n errors: {\n [name]: `Polling error: ${error}`,\n } as PaymentKitErrors,\n });\n }\n }, 2000);\n\n states.pollInterval = pollInterval;\n });\n } catch (error) {\n return {\n errors: {\n [name]: `${capitalizedName} checkout error: ${error}`,\n } as PaymentKitErrors,\n };\n }\n };\n\n return submitPayment;\n};\n\nexport function createBnplPaymentMethod(config: BnplProviderConfig) {\n return definePaymentMethod((paymentKitStates) => {\n const localStates: BnplStates = { ...paymentKitStates };\n\n return {\n name: config.name,\n externalFuncs: {},\n internalFuncs: {\n submitPayment: createSubmitPayment(localStates, config),\n cleanup: () => {\n if (localStates.pollInterval) {\n clearInterval(localStates.pollInterval);\n }\n if (localStates.popup && !localStates.popup.closed) {\n localStates.popup.close();\n }\n },\n },\n };\n });\n}\n"],"mappings":";;;AAoEA,MAAM,uBAAuB,QAAoB,WAA+B;CAC9E,MAAM,EAAE,MAAM,cAAc,6BAA6B;CACzD,MAAM,kBAAkB,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;CAEpE,MAAMA,gBAAiD,OAAO,SAAS,YAAY;EACjF,MAAM,EAAE,YAAY,aAAa,gBAAgB;EACjD,MAAM,cAAc;AAEpB,MAAI,CAAC,aAAa,YAChB,QAAO,EAAE,QAAQ,EAAE,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BAAgB,UAC5C,EACF,CAAC;AACF;;MAGF,MAAM,eAAgB,MAAM,eAAe,MAAM;AAEjD,UAAI,aAAa,WAAW;AAC1B,qBAAc,aAAa;AAC3B,aAAM,OAAO;AAEb,WAAI,aAAa,WAAW,UAS1B,SAAQ,EAAE,MAPK,aAAa,UAAU;QACpC,IAAI;QACJ,mBAAmB;QACnB,mBAAmB;QACnB,OAAO;QACR,EAEuB,CAAC;WAEzB,SAAQ,EACN,QAAQ,GACL,OAAO,aAAa,SAAS,GAAG,gBAAgB,YAAY,aAAa,UAC3E,EACF,CAAC;AAEJ;;AAGF,UAAI,MAAM,QAAQ;AAChB;AACA,WAAI,yBAAyB,iBAAiB;AAC5C,sBAAc,aAAa;AAC3B,gBAAQ,EACN,QAAQ,GACL,OAAO,GAAG,gBAAgB,wBAC5B,EACF,CAAC;;AAEJ;;cAEK,OAAO;AACd,oBAAc,aAAa;AAC3B,YAAM,OAAO;AACb,cAAQ,EACN,QAAQ,GACL,OAAO,kBAAkB,SAC3B,EACF,CAAC;;OAEH,IAAK;AAER,WAAO,eAAe;KACtB;WACK,OAAO;AACd,UAAO,EACL,QAAQ,GACL,OAAO,GAAG,gBAAgB,mBAAmB,SAC/C,EACF;;;AAIL,QAAO;;AAGT,SAAgB,wBAAwB,QAA4B;AAClE,QAAO,qBAAqB,qBAAqB;EAC/C,MAAMC,cAA0B,EAAE,GAAG,kBAAkB;AAEvD,SAAO;GACL,MAAM,OAAO;GACb,eAAe,EAAE;GACjB,eAAe;IACb,eAAe,oBAAoB,aAAa,OAAO;IACvD,eAAe;AACb,SAAI,YAAY,aACd,eAAc,YAAY,aAAa;AAEzC,SAAI,YAAY,SAAS,CAAC,YAAY,MAAM,OAC1C,aAAY,MAAM,OAAO;;IAG9B;GACF;GACD"}
|
|
1
|
+
{"version":3,"file":"bnpl-shared-CL900HFN.mjs","names":["submitPayment: TInternalFuncs[\"submitPayment\"]","requestBody: BnplStartRequest","localStates: BnplStates"],"sources":["../src/payment-methods/bnpl-shared.ts"],"sourcesContent":["/**\n * Shared BNPL (Buy Now Pay Later) payment method factory.\n * Used by Klarna, Afterpay, and Affirm payment methods.\n */\n\nimport type { PaymentKitErrors, PaymentKitStates, TInternalFuncs } from \"../types\";\nimport { collectFraudMetadata, definePaymentMethod, getOrCreateCheckoutRequestId } from \"../utils\";\n\nexport type BnplCustomerInfo = {\n first_name: string;\n last_name: string;\n email?: string;\n};\n\nexport type BnplStartRequest = {\n processor_id: string;\n customer_info: BnplCustomerInfo;\n fraud_metadata: {\n ipAddress?: string;\n browserInfo?: { [key: string]: unknown };\n processorFraudInfo?: { [key: string]: unknown };\n };\n setup_future_usage?: boolean;\n};\n\nexport type BnplStartResponse = {\n approval_url: string;\n popup_token: string;\n checkout_attempt_id: string;\n};\n\nexport type BnplStatusResponse = {\n completed: boolean;\n status: \"success\" | \"failed\" | \"cancelled\";\n result?: unknown;\n error?: string;\n};\n\nexport type BnplCheckoutResponse = {\n id: string;\n checkoutAttemptId: string;\n checkoutSessionId: string;\n state: string;\n customerId?: string;\n paymentMethodId?: string;\n processorUsed?: string;\n subscriptionId?: string;\n invoiceId?: string;\n invoiceNumber?: number;\n};\n\nexport type BnplSubmitOptions = {\n processorId: string;\n customerInfo: BnplCustomerInfo;\n setupFutureUsage?: boolean;\n};\n\ntype BnplStates = PaymentKitStates & {\n popup?: Window | null;\n pollInterval?: ReturnType<typeof setInterval>;\n};\n\nexport type BnplProviderConfig = {\n name: string;\n endpointPath: string;\n supportsSetupFutureUsage?: boolean;\n};\n\nconst createSubmitPayment = (states: BnplStates, config: BnplProviderConfig) => {\n const { name, endpointPath, supportsSetupFutureUsage } = config;\n const capitalizedName = name.charAt(0).toUpperCase() + name.slice(1);\n\n const submitPayment: TInternalFuncs[\"submitPayment\"] = async (_fields, options) => {\n const { apiBaseUrl, secureToken, environment } = states;\n const bnplOptions = options as BnplSubmitOptions;\n\n if (!bnplOptions?.processorId) {\n return { errors: { processor_id: \"Processor ID is required\" } as PaymentKitErrors };\n }\n\n if (!bnplOptions?.customerInfo?.first_name || !bnplOptions?.customerInfo?.last_name) {\n return {\n errors: {\n customer_name: \"Customer first and last name are required\",\n } as PaymentKitErrors,\n };\n }\n\n try {\n const checkoutRequestId = getOrCreateCheckoutRequestId(environment);\n\n const requestBody: BnplStartRequest = {\n processor_id: bnplOptions.processorId,\n customer_info: bnplOptions.customerInfo,\n fraud_metadata: collectFraudMetadata(),\n };\n\n if (supportsSetupFutureUsage && bnplOptions.setupFutureUsage !== undefined) {\n requestBody.setup_future_usage = bnplOptions.setupFutureUsage;\n }\n\n const startResponse = await fetch(`${apiBaseUrl}/api/checkout/${secureToken}/stripe/${endpointPath}/start`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-request-id\": checkoutRequestId,\n },\n body: JSON.stringify(requestBody),\n });\n\n if (!startResponse.ok) {\n let errorMessage = `Failed to start ${capitalizedName} checkout (${startResponse.status})`;\n try {\n const errorData = await startResponse.json();\n errorMessage = errorData.detail || errorMessage;\n } catch {\n errorMessage = startResponse.statusText || errorMessage;\n }\n return {\n errors: {\n [name]: errorMessage,\n } as PaymentKitErrors,\n };\n }\n\n const { approval_url, popup_token, checkout_attempt_id } = (await startResponse.json()) as BnplStartResponse;\n\n const popup = window.open(approval_url, capitalizedName, \"width=600,height=700\");\n\n if (!popup) {\n return {\n errors: {\n [name]: `Failed to open ${capitalizedName} popup. Please allow popups for this site.`,\n } as PaymentKitErrors,\n };\n }\n\n states.popup = popup;\n\n return new Promise((resolve) => {\n let popupClosedGracePolls = 0;\n const MAX_GRACE_POLLS = 5;\n\n const pollInterval = setInterval(async () => {\n try {\n const statusResponse = await fetch(\n `${apiBaseUrl}/api/checkout/${secureToken}/popup/status?popup_token=${popup_token}`,\n );\n\n if (!statusResponse.ok) {\n clearInterval(pollInterval);\n popup.close();\n resolve({\n errors: {\n [name]: `Failed to check ${capitalizedName} status`,\n } as PaymentKitErrors,\n });\n return;\n }\n\n const statusResult = (await statusResponse.json()) as BnplStatusResponse;\n\n if (statusResult.completed) {\n clearInterval(pollInterval);\n popup.close();\n\n if (statusResult.status === \"success\") {\n // Result is returned directly from popup status endpoint\n const result = statusResult.result || {\n id: checkout_attempt_id,\n checkoutAttemptId: checkout_attempt_id,\n checkoutSessionId: secureToken,\n state: \"checkout_succeeded\",\n };\n\n resolve({ data: result });\n } else {\n resolve({\n errors: {\n [name]: statusResult.error || `${capitalizedName} checkout ${statusResult.status}`,\n } as PaymentKitErrors,\n });\n }\n return;\n }\n\n if (popup.closed) {\n popupClosedGracePolls++;\n if (popupClosedGracePolls >= MAX_GRACE_POLLS) {\n clearInterval(pollInterval);\n resolve({\n errors: {\n [name]: `${capitalizedName} popup closed by user`,\n } as PaymentKitErrors,\n });\n }\n return;\n }\n } catch (error) {\n clearInterval(pollInterval);\n popup.close();\n resolve({\n errors: {\n [name]: `Polling error: ${error}`,\n } as PaymentKitErrors,\n });\n }\n }, 2000);\n\n states.pollInterval = pollInterval;\n });\n } catch (error) {\n return {\n errors: {\n [name]: `${capitalizedName} checkout error: ${error}`,\n } as PaymentKitErrors,\n };\n }\n };\n\n return submitPayment;\n};\n\nexport function createBnplPaymentMethod(config: BnplProviderConfig) {\n return definePaymentMethod((paymentKitStates) => {\n const localStates: BnplStates = { ...paymentKitStates };\n\n return {\n name: config.name,\n externalFuncs: {},\n internalFuncs: {\n submitPayment: createSubmitPayment(localStates, config),\n cleanup: () => {\n if (localStates.pollInterval) {\n clearInterval(localStates.pollInterval);\n }\n if (localStates.popup && !localStates.popup.closed) {\n localStates.popup.close();\n }\n },\n },\n };\n });\n}\n"],"mappings":";;;AAoEA,MAAM,uBAAuB,QAAoB,WAA+B;CAC9E,MAAM,EAAE,MAAM,cAAc,6BAA6B;CACzD,MAAM,kBAAkB,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;CAEpE,MAAMA,gBAAiD,OAAO,SAAS,YAAY;EACjF,MAAM,EAAE,YAAY,aAAa,gBAAgB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
import { i as PaymentMethod } from "./types-Cjcc3xak.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/payment-methods/bnpl-shared.d.ts
|
|
4
4
|
|
|
@@ -61,4 +61,4 @@ type BnplProviderConfig = {
|
|
|
61
61
|
declare function createBnplPaymentMethod(config: BnplProviderConfig): PaymentMethod<{}, string>;
|
|
62
62
|
//#endregion
|
|
63
63
|
export { BnplStartResponse as a, createBnplPaymentMethod as c, BnplStartRequest as i, BnplCustomerInfo as n, BnplStatusResponse as o, BnplProviderConfig as r, BnplSubmitOptions as s, BnplCheckoutResponse as t };
|
|
64
|
-
//# sourceMappingURL=bnpl-shared-
|
|
64
|
+
//# sourceMappingURL=bnpl-shared-D-Kd58Qz.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bnpl-shared-
|
|
1
|
+
{"version":3,"file":"bnpl-shared-D-Kd58Qz.d.mts","names":[],"sources":["../src/payment-methods/bnpl-shared.ts"],"sourcesContent":[],"mappings":";;;;;;;AAQA;AAMY,KANA,gBAAA,GAMgB;EAWhB,UAAA,EAAA,MAAA;EAMA,SAAA,EAAA,MAAA;EAOA,KAAA,CAAA,EAAA,MAAA;AAaZ,CAAA;AAWY,KAhDA,gBAAA,GAgDkB;EAiKd,YAAA,EAAA,MAAA;iBA/MC;;;;;;;;;;;;KASL,iBAAA;;;;;KAMA,kBAAA;;;;;;KAOA,oBAAA;;;;;;;;;;;;KAaA,iBAAA;;gBAEI;;;KASJ,kBAAA;;;;;iBAiKI,uBAAA,SAAgC,qBAAkB"}
|
package/dist/cdn/paymentkit.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* PaymentKit.js v0.5.
|
|
2
|
+
* PaymentKit.js v0.5.18
|
|
3
3
|
* https://paymentkit.com
|
|
4
4
|
*
|
|
5
5
|
* @license MIT
|
|
@@ -42,7 +42,7 @@ var PaymentKit = (() => {
|
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
// package.json
|
|
45
|
-
var version = "0.5.
|
|
45
|
+
var version = "0.5.18";
|
|
46
46
|
|
|
47
47
|
// src/analytics/mock-adapter.ts
|
|
48
48
|
var MockAnalyticsAdapter = class {
|
|
@@ -6049,6 +6049,10 @@ var PaymentKit = (() => {
|
|
|
6049
6049
|
apiBaseUrl: "http://localhost:9000"
|
|
6050
6050
|
},
|
|
6051
6051
|
sandbox: {
|
|
6052
|
+
baseUrl: "https://app.paymentkit.com/customer",
|
|
6053
|
+
apiBaseUrl: "https://app.paymentkit.com"
|
|
6054
|
+
},
|
|
6055
|
+
staging: {
|
|
6052
6056
|
baseUrl: "https://staging.paymentkit.com/customer",
|
|
6053
6057
|
apiBaseUrl: "https://staging.paymentkit.com"
|
|
6054
6058
|
},
|
|
@@ -6082,10 +6086,10 @@ var PaymentKit = (() => {
|
|
|
6082
6086
|
if (environment === "tunnel") {
|
|
6083
6087
|
return getTunnelUrls();
|
|
6084
6088
|
}
|
|
6085
|
-
const
|
|
6086
|
-
const urls = STATIC_ENVIRONMENT_URLS[env];
|
|
6089
|
+
const urls = STATIC_ENVIRONMENT_URLS[environment];
|
|
6087
6090
|
if (!urls) {
|
|
6088
|
-
|
|
6091
|
+
console.warn(`[PaymentKit] Invalid environment "${environment}", falling back to local`);
|
|
6092
|
+
return STATIC_ENVIRONMENT_URLS.local;
|
|
6089
6093
|
}
|
|
6090
6094
|
return urls;
|
|
6091
6095
|
}
|
|
@@ -6107,22 +6111,22 @@ var PaymentKit = (() => {
|
|
|
6107
6111
|
var ENV_TO_SLUG = {
|
|
6108
6112
|
local: "dev",
|
|
6109
6113
|
tunnel: "dev",
|
|
6110
|
-
sandbox: "
|
|
6114
|
+
sandbox: "prod",
|
|
6115
|
+
staging: "stg",
|
|
6111
6116
|
production: "prod"
|
|
6112
6117
|
};
|
|
6113
|
-
var WINDOW_KEY = "__paymentKitRequestId__";
|
|
6114
6118
|
function generateCheckoutRequestId(environment) {
|
|
6115
|
-
const envSlug = ENV_TO_SLUG[environment]
|
|
6119
|
+
const envSlug = ENV_TO_SLUG[environment] ?? "dev";
|
|
6116
6120
|
const randomPart = nanoid(12);
|
|
6117
6121
|
return `pk_${envSlug}_${randomPart}`;
|
|
6118
6122
|
}
|
|
6119
6123
|
function getOrCreateCheckoutRequestId(environment) {
|
|
6120
|
-
if (typeof window !== "undefined" && window
|
|
6121
|
-
return window
|
|
6124
|
+
if (typeof window !== "undefined" && window.__paymentKitRequestId__) {
|
|
6125
|
+
return window.__paymentKitRequestId__;
|
|
6122
6126
|
}
|
|
6123
6127
|
const requestId = generateCheckoutRequestId(environment);
|
|
6124
6128
|
if (typeof window !== "undefined") {
|
|
6125
|
-
window
|
|
6129
|
+
window.__paymentKitRequestId__ = requestId;
|
|
6126
6130
|
}
|
|
6127
6131
|
return requestId;
|
|
6128
6132
|
}
|
|
@@ -6423,7 +6427,7 @@ var PaymentKit = (() => {
|
|
|
6423
6427
|
}, {});
|
|
6424
6428
|
return { isSuccess: false, errors };
|
|
6425
6429
|
}
|
|
6426
|
-
return { isSuccess: true };
|
|
6430
|
+
return { isSuccess: true, errors: {} };
|
|
6427
6431
|
};
|
|
6428
6432
|
|
|
6429
6433
|
// src/utils/index.ts
|
|
@@ -6475,7 +6479,7 @@ var PaymentKit = (() => {
|
|
|
6475
6479
|
return { unmount, connection };
|
|
6476
6480
|
};
|
|
6477
6481
|
var PaymentKit = ({
|
|
6478
|
-
environment,
|
|
6482
|
+
environment = "production",
|
|
6479
6483
|
secureToken,
|
|
6480
6484
|
paymentMethods,
|
|
6481
6485
|
cardTokenizationMode,
|
|
@@ -7023,21 +7027,21 @@ var PaymentKit = (() => {
|
|
|
7023
7027
|
closeButton.setAttribute("aria-label", "Cancel verification");
|
|
7024
7028
|
closeButton.setAttribute("type", "button");
|
|
7025
7029
|
closeButton.style.cssText = `
|
|
7026
|
-
position: absolute;
|
|
7027
|
-
top:
|
|
7028
|
-
right:
|
|
7029
|
-
width: 32px;
|
|
7030
|
-
height: 32px;
|
|
7031
|
-
border: none;
|
|
7032
|
-
background: white;
|
|
7033
|
-
border-radius: 8px;
|
|
7034
|
-
cursor: pointer;
|
|
7035
|
-
display: flex;
|
|
7036
|
-
align-items: center;
|
|
7037
|
-
justify-content: center;
|
|
7038
|
-
z-index: 10;
|
|
7039
|
-
transition: background 0.15s ease;
|
|
7040
|
-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
|
|
7030
|
+
position: absolute !important;
|
|
7031
|
+
top: 8px !important;
|
|
7032
|
+
right: 8px !important;
|
|
7033
|
+
width: 32px !important;
|
|
7034
|
+
height: 32px !important;
|
|
7035
|
+
border: none !important;
|
|
7036
|
+
background: white !important;
|
|
7037
|
+
border-radius: 8px !important;
|
|
7038
|
+
cursor: pointer !important;
|
|
7039
|
+
display: flex !important;
|
|
7040
|
+
align-items: center !important;
|
|
7041
|
+
justify-content: center !important;
|
|
7042
|
+
z-index: 10 !important;
|
|
7043
|
+
transition: background 0.15s ease !important;
|
|
7044
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
|
|
7041
7045
|
`;
|
|
7042
7046
|
closeButton.innerHTML = `
|
|
7043
7047
|
<svg width="12" height="12" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
@@ -7045,10 +7049,10 @@ var PaymentKit = (() => {
|
|
|
7045
7049
|
</svg>
|
|
7046
7050
|
`;
|
|
7047
7051
|
closeButton.onmouseenter = () => {
|
|
7048
|
-
closeButton.style.background
|
|
7052
|
+
closeButton.style.setProperty("background", "#f5f5f5", "important");
|
|
7049
7053
|
};
|
|
7050
7054
|
closeButton.onmouseleave = () => {
|
|
7051
|
-
closeButton.style.background
|
|
7055
|
+
closeButton.style.setProperty("background", "white", "important");
|
|
7052
7056
|
};
|
|
7053
7057
|
const iframe = document.createElement("iframe");
|
|
7054
7058
|
iframe.src = url;
|
|
@@ -7527,17 +7531,14 @@ var PaymentKit = (() => {
|
|
|
7527
7531
|
function getMockScenarioStr(mockScenario) {
|
|
7528
7532
|
return mockScenario && mockScenario !== "none" /* None */ ? mockScenario : void 0;
|
|
7529
7533
|
}
|
|
7530
|
-
async function callStripeStartEndpoint(apiBaseUrl, secureToken, options,
|
|
7534
|
+
async function callStripeStartEndpoint(apiBaseUrl, secureToken, options, checkoutRequestId) {
|
|
7531
7535
|
return apiCall(
|
|
7532
7536
|
`${apiBaseUrl}/api/checkout/${secureToken}/apple-pay/start`,
|
|
7533
7537
|
{
|
|
7534
7538
|
method: "POST",
|
|
7535
7539
|
headers: { "Content-Type": "application/json" },
|
|
7536
7540
|
body: JSON.stringify({
|
|
7537
|
-
processor_id: options.processorId
|
|
7538
|
-
customer_info: options.customerInfo,
|
|
7539
|
-
fraud_metadata: collectFraudMetadata(),
|
|
7540
|
-
mock_scenario: mockScenarioStr
|
|
7541
|
+
processor_id: options.processorId
|
|
7541
7542
|
})
|
|
7542
7543
|
},
|
|
7543
7544
|
checkoutRequestId
|
|
@@ -7550,13 +7551,16 @@ var PaymentKit = (() => {
|
|
|
7550
7551
|
}
|
|
7551
7552
|
return { adapter };
|
|
7552
7553
|
}
|
|
7553
|
-
async function callStripeConfirmEndpoint(apiBaseUrl, secureToken, paymentMethodId, mockScenarioStr, checkoutRequestId, payerEmail) {
|
|
7554
|
+
async function callStripeConfirmEndpoint(apiBaseUrl, secureToken, options, paymentMethodId, mockScenarioStr, checkoutRequestId, payerEmail) {
|
|
7554
7555
|
const result = await apiCall(
|
|
7555
7556
|
`${apiBaseUrl}/api/checkout/${secureToken}/apple-pay/confirm`,
|
|
7556
7557
|
{
|
|
7557
7558
|
method: "POST",
|
|
7558
7559
|
headers: { "Content-Type": "application/json" },
|
|
7559
7560
|
body: JSON.stringify({
|
|
7561
|
+
processor_id: options.processorId,
|
|
7562
|
+
customer_info: options.customerInfo,
|
|
7563
|
+
fraud_metadata: collectFraudMetadata(),
|
|
7560
7564
|
payment_method_id: paymentMethodId,
|
|
7561
7565
|
payer_email: payerEmail,
|
|
7562
7566
|
mock_scenario: mockScenarioStr
|
|
@@ -7643,13 +7647,7 @@ var PaymentKit = (() => {
|
|
|
7643
7647
|
console.log("[ApplePay] Airwallex prepared state:", preparedAirwallexState);
|
|
7644
7648
|
return { success: true, applePay: true };
|
|
7645
7649
|
}
|
|
7646
|
-
const startResult = await callStripeStartEndpoint(
|
|
7647
|
-
apiBaseUrl,
|
|
7648
|
-
secureToken,
|
|
7649
|
-
options,
|
|
7650
|
-
mockScenarioStr,
|
|
7651
|
-
checkoutRequestId
|
|
7652
|
-
);
|
|
7650
|
+
const startResult = await callStripeStartEndpoint(apiBaseUrl, secureToken, options, checkoutRequestId);
|
|
7653
7651
|
if (startResult.error || !startResult.data) {
|
|
7654
7652
|
return { success: false, error: startResult.error || "Failed to start Apple Pay" };
|
|
7655
7653
|
}
|
|
@@ -7952,6 +7950,7 @@ var PaymentKit = (() => {
|
|
|
7952
7950
|
const confirmResult2 = await callStripeConfirmEndpoint(
|
|
7953
7951
|
apiBaseUrl,
|
|
7954
7952
|
secureToken,
|
|
7953
|
+
applePayOptions,
|
|
7955
7954
|
paymentMethodId2,
|
|
7956
7955
|
mockScenarioStr,
|
|
7957
7956
|
preparedStripeState.checkoutRequestId,
|
|
@@ -7981,13 +7980,7 @@ var PaymentKit = (() => {
|
|
|
7981
7980
|
preparedAirwallexState = null;
|
|
7982
7981
|
}
|
|
7983
7982
|
}
|
|
7984
|
-
const startResult = await callStripeStartEndpoint(
|
|
7985
|
-
apiBaseUrl,
|
|
7986
|
-
secureToken,
|
|
7987
|
-
applePayOptions,
|
|
7988
|
-
mockScenarioStr,
|
|
7989
|
-
checkoutRequestId
|
|
7990
|
-
);
|
|
7983
|
+
const startResult = await callStripeStartEndpoint(apiBaseUrl, secureToken, applePayOptions, checkoutRequestId);
|
|
7991
7984
|
if (startResult.error || !startResult.data) {
|
|
7992
7985
|
return { errors: { apple_pay: startResult.error || "Failed to start Apple Pay" } };
|
|
7993
7986
|
}
|
|
@@ -8023,6 +8016,7 @@ var PaymentKit = (() => {
|
|
|
8023
8016
|
const confirmResult = await callStripeConfirmEndpoint(
|
|
8024
8017
|
apiBaseUrl,
|
|
8025
8018
|
secureToken,
|
|
8019
|
+
applePayOptions,
|
|
8026
8020
|
paymentMethodId,
|
|
8027
8021
|
mockScenarioStr,
|
|
8028
8022
|
checkoutRequestId,
|
|
@@ -8530,7 +8524,7 @@ var PaymentKit = (() => {
|
|
|
8530
8524
|
const requestOptions = withRequestId(checkoutRequestId);
|
|
8531
8525
|
const tunnelX = await TunnelXManager.createFromPenpalConnection(states.tunnelXConnection);
|
|
8532
8526
|
const skipCustomerValidation = options?.skipCustomerValidation === true;
|
|
8533
|
-
const validateFormResult = skipCustomerValidation ? { isSuccess: true } : await validateFormFields(fields);
|
|
8527
|
+
const validateFormResult = skipCustomerValidation ? { isSuccess: true, errors: {} } : await validateFormFields(fields);
|
|
8534
8528
|
if (!isVgsMode) {
|
|
8535
8529
|
const validateCardResult = await validateCardFields(states);
|
|
8536
8530
|
if (!(validateCardResult.isSuccess && validateFormResult.isSuccess)) {
|
|
@@ -8805,6 +8799,12 @@ var PaymentKit = (() => {
|
|
|
8805
8799
|
return { errors, isSuccess: false };
|
|
8806
8800
|
}
|
|
8807
8801
|
const { pan_alias, cvc_alias, exp_month, exp_year } = cardResult.data.attributes;
|
|
8802
|
+
if (!cvc_alias) {
|
|
8803
|
+
console.warn(
|
|
8804
|
+
`${logPrefix} VGS createCard response missing cvc_alias (303 dedup):`,
|
|
8805
|
+
JSON.stringify(cardResult.data.attributes)
|
|
8806
|
+
);
|
|
8807
|
+
}
|
|
8808
8808
|
const fullYear = exp_year < 100 ? 2e3 + exp_year : exp_year;
|
|
8809
8809
|
const formattedExp = `${String(exp_month).padStart(2, "0")}/${fullYear}`;
|
|
8810
8810
|
const cmpCardId = cardResult.data.id;
|
|
@@ -8815,7 +8815,7 @@ var PaymentKit = (() => {
|
|
|
8815
8815
|
updateCardSetupIntentReq: {
|
|
8816
8816
|
cardPan: pan_alias,
|
|
8817
8817
|
cardExp: formattedExp,
|
|
8818
|
-
cardCvc: cvc_alias,
|
|
8818
|
+
...cvc_alias ? { cardCvc: cvc_alias } : {},
|
|
8819
8819
|
cmpCardId,
|
|
8820
8820
|
fraudMetadata: collectFraudMetadata()
|
|
8821
8821
|
}
|
|
@@ -9217,12 +9217,41 @@ var PaymentKit = (() => {
|
|
|
9217
9217
|
}
|
|
9218
9218
|
return { data: await response.json() };
|
|
9219
9219
|
}
|
|
9220
|
-
function validateOptions2(options) {
|
|
9221
|
-
if (!options?.processorId) {
|
|
9220
|
+
function validateOptions2(options, autoPrepareConfig) {
|
|
9221
|
+
if (!options?.processorId && !autoPrepareConfig?.processorId) {
|
|
9222
9222
|
return { processor_id: "Processor ID is required" };
|
|
9223
9223
|
}
|
|
9224
9224
|
return null;
|
|
9225
9225
|
}
|
|
9226
|
+
async function checkGooglePayAvailability() {
|
|
9227
|
+
if (!window.google?.payments?.api?.PaymentsClient) {
|
|
9228
|
+
console.log("[GooglePay] Google Pay API not loaded");
|
|
9229
|
+
return false;
|
|
9230
|
+
}
|
|
9231
|
+
try {
|
|
9232
|
+
const client = new window.google.payments.api.PaymentsClient({
|
|
9233
|
+
environment: "TEST"
|
|
9234
|
+
});
|
|
9235
|
+
const request = {
|
|
9236
|
+
apiVersion: 2,
|
|
9237
|
+
apiVersionMinor: 0,
|
|
9238
|
+
allowedPaymentMethods: [
|
|
9239
|
+
{
|
|
9240
|
+
type: "CARD",
|
|
9241
|
+
parameters: {
|
|
9242
|
+
allowedAuthMethods: ["PAN_ONLY", "CRYPTOGRAM_3DS"],
|
|
9243
|
+
allowedCardNetworks: ["VISA", "MASTERCARD", "AMEX", "DISCOVER", "JCB"]
|
|
9244
|
+
}
|
|
9245
|
+
}
|
|
9246
|
+
]
|
|
9247
|
+
};
|
|
9248
|
+
const response = await client.isReadyToPay(request);
|
|
9249
|
+
return response.result;
|
|
9250
|
+
} catch (error) {
|
|
9251
|
+
console.error("[GooglePay] availability check error:", error);
|
|
9252
|
+
return false;
|
|
9253
|
+
}
|
|
9254
|
+
}
|
|
9226
9255
|
function getMockScenarioStr2(mockScenario) {
|
|
9227
9256
|
return mockScenario && mockScenario !== "none" /* None */ ? mockScenario : void 0;
|
|
9228
9257
|
}
|
|
@@ -9456,14 +9485,19 @@ var PaymentKit = (() => {
|
|
|
9456
9485
|
}
|
|
9457
9486
|
return toGooglePayResult(response, secureToken);
|
|
9458
9487
|
}
|
|
9459
|
-
var defSubmitPayment3 = (states) => {
|
|
9488
|
+
var defSubmitPayment3 = (states, getAutoPrepareConfig) => {
|
|
9460
9489
|
const submitPayment = async (_fields, options) => {
|
|
9461
9490
|
const { apiBaseUrl, secureToken, environment } = states;
|
|
9462
9491
|
const gpayOptions = options;
|
|
9463
|
-
const
|
|
9492
|
+
const autoPrepareConfig = getAutoPrepareConfig();
|
|
9493
|
+
const validationError = validateOptions2(gpayOptions, autoPrepareConfig);
|
|
9464
9494
|
if (validationError) {
|
|
9465
9495
|
return { errors: validationError };
|
|
9466
9496
|
}
|
|
9497
|
+
const effectiveOptions = {
|
|
9498
|
+
...gpayOptions,
|
|
9499
|
+
processorId: gpayOptions.processorId || autoPrepareConfig?.processorId || ""
|
|
9500
|
+
};
|
|
9467
9501
|
try {
|
|
9468
9502
|
const mockScenarioStr = getMockScenarioStr2(gpayOptions.mockScenario);
|
|
9469
9503
|
const checkoutRequestId = getOrCreateCheckoutRequestId(environment);
|
|
@@ -9471,7 +9505,7 @@ var PaymentKit = (() => {
|
|
|
9471
9505
|
const startResult = await callStartEndpoint(
|
|
9472
9506
|
apiBaseUrl,
|
|
9473
9507
|
secureToken,
|
|
9474
|
-
|
|
9508
|
+
effectiveOptions,
|
|
9475
9509
|
mockScenarioStr,
|
|
9476
9510
|
checkoutRequestId
|
|
9477
9511
|
);
|
|
@@ -9517,12 +9551,113 @@ var PaymentKit = (() => {
|
|
|
9517
9551
|
return submitPayment;
|
|
9518
9552
|
};
|
|
9519
9553
|
var GooglePayPaymentMethod = definePaymentMethod((paymentKitStates) => {
|
|
9554
|
+
const { apiBaseUrl, secureToken, environment } = paymentKitStates;
|
|
9555
|
+
let autoPrepareConfig = null;
|
|
9556
|
+
let onGooglePayReadyCallbacks = [];
|
|
9557
|
+
let isGooglePayReadyState = false;
|
|
9558
|
+
let autoPrepareInProgress = false;
|
|
9559
|
+
let cleanupGeneration = 0;
|
|
9560
|
+
let pendingAutoPrepareArgs = null;
|
|
9561
|
+
let pendingPrepareResolvers = [];
|
|
9562
|
+
function instanceSetGooglePayReady(ready) {
|
|
9563
|
+
isGooglePayReadyState = ready;
|
|
9564
|
+
for (const cb of onGooglePayReadyCallbacks) cb(ready);
|
|
9565
|
+
}
|
|
9566
|
+
function instanceClearPreparedGooglePay() {
|
|
9567
|
+
instanceSetGooglePayReady(false);
|
|
9568
|
+
}
|
|
9569
|
+
async function instanceAutoPrepare(apBase, sToken, env) {
|
|
9570
|
+
if (autoPrepareInProgress) {
|
|
9571
|
+
pendingAutoPrepareArgs = { apiBaseUrl: apBase, secureToken: sToken, environment: env };
|
|
9572
|
+
return new Promise((resolve) => pendingPrepareResolvers.push(resolve));
|
|
9573
|
+
}
|
|
9574
|
+
autoPrepareInProgress = true;
|
|
9575
|
+
const capturedGeneration = cleanupGeneration;
|
|
9576
|
+
instanceSetGooglePayReady(false);
|
|
9577
|
+
try {
|
|
9578
|
+
const result = await apiCall2(`${apBase}/api/checkout-sessions/token/${sToken}`, {
|
|
9579
|
+
method: "GET"
|
|
9580
|
+
});
|
|
9581
|
+
if (cleanupGeneration !== capturedGeneration) return;
|
|
9582
|
+
if (result.error || !result.data) {
|
|
9583
|
+
console.warn("[GooglePay] Auto-prepare: failed to fetch session config:", result.error);
|
|
9584
|
+
return;
|
|
9585
|
+
}
|
|
9586
|
+
const processorId = result.data.express_checkout_processor_id;
|
|
9587
|
+
if (!processorId) {
|
|
9588
|
+
console.log("[GooglePay] Auto-prepare: no express checkout processor configured");
|
|
9589
|
+
return;
|
|
9590
|
+
}
|
|
9591
|
+
const processorTypeRaw = result.data.express_checkout_processor_type;
|
|
9592
|
+
const processorType = processorTypeRaw === "airwallex" || processorTypeRaw === "stripe" ? processorTypeRaw : void 0;
|
|
9593
|
+
autoPrepareConfig = { processorId, processorType };
|
|
9594
|
+
const isAvailable = await checkGooglePayAvailability();
|
|
9595
|
+
if (cleanupGeneration !== capturedGeneration) return;
|
|
9596
|
+
instanceSetGooglePayReady(isAvailable);
|
|
9597
|
+
} catch (err) {
|
|
9598
|
+
if (cleanupGeneration === capturedGeneration) {
|
|
9599
|
+
console.error("[GooglePay] Auto-prepare failed:", err);
|
|
9600
|
+
}
|
|
9601
|
+
} finally {
|
|
9602
|
+
autoPrepareInProgress = false;
|
|
9603
|
+
const stale = cleanupGeneration !== capturedGeneration;
|
|
9604
|
+
const pending = pendingAutoPrepareArgs;
|
|
9605
|
+
const resolvers = pendingPrepareResolvers.splice(0);
|
|
9606
|
+
if (!stale && pending) {
|
|
9607
|
+
pendingAutoPrepareArgs = null;
|
|
9608
|
+
instanceAutoPrepare(pending.apiBaseUrl, pending.secureToken, pending.environment).then(() => {
|
|
9609
|
+
for (const r2 of resolvers) r2();
|
|
9610
|
+
});
|
|
9611
|
+
} else {
|
|
9612
|
+
pendingAutoPrepareArgs = null;
|
|
9613
|
+
for (const r2 of resolvers) r2();
|
|
9614
|
+
}
|
|
9615
|
+
}
|
|
9616
|
+
}
|
|
9617
|
+
instanceAutoPrepare(apiBaseUrl, secureToken, environment).catch(
|
|
9618
|
+
(err) => console.error("[GooglePay] Unhandled init error:", err)
|
|
9619
|
+
);
|
|
9520
9620
|
return {
|
|
9521
9621
|
name: "google_pay",
|
|
9522
|
-
externalFuncs: {
|
|
9622
|
+
externalFuncs: {
|
|
9623
|
+
/**
|
|
9624
|
+
* Register a callback to be notified when Google Pay becomes ready (or stops being ready).
|
|
9625
|
+
* Fires immediately with the current state, then on every state change.
|
|
9626
|
+
* Multiple registrations are all notified — none are silently overwritten.
|
|
9627
|
+
*
|
|
9628
|
+
* @example
|
|
9629
|
+
* paymentKit.google_pay.onGooglePayReady((isReady) => {
|
|
9630
|
+
* googlePayButton.disabled = !isReady;
|
|
9631
|
+
* });
|
|
9632
|
+
*/
|
|
9633
|
+
onGooglePayReady: (callback) => {
|
|
9634
|
+
onGooglePayReadyCallbacks.push(callback);
|
|
9635
|
+
callback(isGooglePayReadyState);
|
|
9636
|
+
},
|
|
9637
|
+
/**
|
|
9638
|
+
* Notify the SDK that the payment amount has changed (e.g. coupon applied).
|
|
9639
|
+
* The SDK will disable Google Pay, re-prepare with the new amount, then re-enable.
|
|
9640
|
+
* The returned promise resolves when re-prepare is fully complete.
|
|
9641
|
+
*
|
|
9642
|
+
* @example
|
|
9643
|
+
* await paymentKit.google_pay.notifyAmountChanged();
|
|
9644
|
+
*/
|
|
9645
|
+
notifyAmountChanged: () => {
|
|
9646
|
+
instanceClearPreparedGooglePay();
|
|
9647
|
+
autoPrepareConfig = null;
|
|
9648
|
+
return instanceAutoPrepare(apiBaseUrl, secureToken, environment);
|
|
9649
|
+
}
|
|
9650
|
+
},
|
|
9523
9651
|
internalFuncs: {
|
|
9524
|
-
submitPayment: defSubmitPayment3(paymentKitStates),
|
|
9652
|
+
submitPayment: defSubmitPayment3(paymentKitStates, () => autoPrepareConfig),
|
|
9525
9653
|
cleanup: () => {
|
|
9654
|
+
cleanupGeneration++;
|
|
9655
|
+
onGooglePayReadyCallbacks = [];
|
|
9656
|
+
isGooglePayReadyState = false;
|
|
9657
|
+
autoPrepareConfig = null;
|
|
9658
|
+
pendingAutoPrepareArgs = null;
|
|
9659
|
+
pendingPrepareResolvers = [];
|
|
9660
|
+
autoPrepareInProgress = false;
|
|
9526
9661
|
}
|
|
9527
9662
|
}
|
|
9528
9663
|
};
|