@payment-kit-js/vanilla 0.5.12 → 0.5.14
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/{airwallex-apple-pay-adapter-BCYt7Jzc.d.mts → airwallex-apple-pay-adapter-Bb0CreWN.d.mts} +1 -1
- package/dist/{airwallex-apple-pay-adapter-BCYt7Jzc.d.mts.map → airwallex-apple-pay-adapter-Bb0CreWN.d.mts.map} +1 -1
- package/dist/{airwallex-apple-pay-adapter-BFsoDoSf.mjs → airwallex-apple-pay-adapter-CHAnLP_x.mjs} +1 -1
- package/dist/{airwallex-apple-pay-adapter-BFsoDoSf.mjs.map → airwallex-apple-pay-adapter-CHAnLP_x.mjs.map} +1 -1
- package/dist/{airwallex-google-pay-adapter-B5xmg7b8.mjs → airwallex-google-pay-adapter-C8JTp01q.mjs} +1 -1
- package/dist/{airwallex-google-pay-adapter-B5xmg7b8.mjs.map → airwallex-google-pay-adapter-C8JTp01q.mjs.map} +1 -1
- package/dist/{airwallex-google-pay-adapter-DvEB6t5i.d.mts → airwallex-google-pay-adapter-adaDktQM.d.mts} +1 -1
- package/dist/{airwallex-google-pay-adapter-DvEB6t5i.d.mts.map → airwallex-google-pay-adapter-adaDktQM.d.mts.map} +1 -1
- package/dist/bnpl-shared-B-en2sPr.d.mts +64 -0
- package/dist/bnpl-shared-B-en2sPr.d.mts.map +1 -0
- package/dist/bnpl-shared-CEAXTL3Q.mjs +107 -0
- package/dist/bnpl-shared-CEAXTL3Q.mjs.map +1 -0
- package/dist/cdn/paymentkit.js +355 -15
- package/dist/cdn/paymentkit.js.map +4 -4
- package/dist/cdn/paymentkit.min.js +9 -9
- package/dist/cdn/paymentkit.min.js.map +4 -4
- package/dist/{connect-card-Cxy51W6t.d.mts → connect-card-Cra_F1cC.d.mts} +1 -1
- package/dist/{connect-card-Cxy51W6t.d.mts.map → connect-card-Cra_F1cC.d.mts.map} +1 -1
- package/dist/{connect-card-CMZkeppE.mjs → connect-card-D3Je4V7p.mjs} +1 -1
- package/dist/{connect-card-CMZkeppE.mjs.map → connect-card-D3Je4V7p.mjs.map} +1 -1
- package/dist/{connect-tunnel-x-lv6Wtdme.d.mts → connect-tunnel-x-Wh-JG1O5.d.mts} +1 -1
- package/dist/{connect-tunnel-x-lv6Wtdme.d.mts.map → connect-tunnel-x-Wh-JG1O5.d.mts.map} +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/{next-action-handlers-CTx8tRt0.mjs → next-action-handlers-BZs04hYb.mjs} +1 -1
- package/dist/{next-action-handlers-CTx8tRt0.mjs.map → next-action-handlers-BZs04hYb.mjs.map} +1 -1
- package/dist/payment-methods/affirm.d.mts +13 -0
- package/dist/payment-methods/affirm.d.mts.map +1 -0
- package/dist/payment-methods/affirm.mjs +14 -0
- package/dist/payment-methods/affirm.mjs.map +1 -0
- package/dist/payment-methods/afterpay.d.mts +13 -0
- package/dist/payment-methods/afterpay.d.mts.map +1 -0
- package/dist/payment-methods/afterpay.mjs +14 -0
- package/dist/payment-methods/afterpay.mjs.map +1 -0
- package/dist/payment-methods/airwallex-apple-pay-adapter.d.mts +1 -1
- package/dist/payment-methods/airwallex-apple-pay-adapter.mjs +1 -1
- package/dist/payment-methods/airwallex-google-pay-adapter.d.mts +1 -1
- package/dist/payment-methods/airwallex-google-pay-adapter.mjs +1 -1
- package/dist/payment-methods/apple-pay.d.mts +36 -7
- package/dist/payment-methods/apple-pay.d.mts.map +1 -1
- package/dist/payment-methods/apple-pay.mjs +162 -11
- package/dist/payment-methods/apple-pay.mjs.map +1 -1
- package/dist/payment-methods/bnpl-shared.d.mts +5 -0
- package/dist/payment-methods/bnpl-shared.mjs +4 -0
- package/dist/payment-methods/card.d.mts +3 -3
- package/dist/payment-methods/card.mjs +3 -3
- package/dist/payment-methods/google-pay.d.mts +5 -5
- package/dist/payment-methods/google-pay.mjs +3 -3
- package/dist/payment-methods/klarna.d.mts +13 -0
- package/dist/payment-methods/klarna.d.mts.map +1 -0
- package/dist/payment-methods/klarna.mjs +14 -0
- package/dist/payment-methods/klarna.mjs.map +1 -0
- package/dist/payment-methods/next-action-handlers.mjs +1 -1
- package/dist/payment-methods/paypal.d.mts +9 -3
- package/dist/payment-methods/paypal.d.mts.map +1 -1
- package/dist/payment-methods/paypal.mjs.map +1 -1
- package/dist/payment-methods/stripe-apple-pay-adapter.d.mts +1 -1
- package/dist/payment-methods/stripe-apple-pay-adapter.mjs +1 -1
- package/dist/payment-methods/stripe-google-pay-adapter.d.mts +1 -1
- package/dist/payment-methods/stripe-google-pay-adapter.mjs +1 -1
- package/dist/payment-methods/vgs-collect-loader.mjs +1 -1
- package/dist/penpal/connect-card.d.mts +1 -1
- package/dist/penpal/connect-card.mjs +1 -1
- package/dist/penpal/connect-tunnel-x.d.mts +1 -1
- package/dist/{stripe-apple-pay-adapter-Cd9LVNnp.mjs → stripe-apple-pay-adapter-BLRjqgDf.mjs} +1 -1
- package/dist/{stripe-apple-pay-adapter-Cd9LVNnp.mjs.map → stripe-apple-pay-adapter-BLRjqgDf.mjs.map} +1 -1
- package/dist/{stripe-apple-pay-adapter-DhpGclW9.d.mts → stripe-apple-pay-adapter-DcuGlQqQ.d.mts} +1 -1
- package/dist/{stripe-apple-pay-adapter-DhpGclW9.d.mts.map → stripe-apple-pay-adapter-DcuGlQqQ.d.mts.map} +1 -1
- package/dist/{stripe-google-pay-adapter-Bdox4xBq.d.mts → stripe-google-pay-adapter-BlQ2jVpE.d.mts} +1 -1
- package/dist/{stripe-google-pay-adapter-Bdox4xBq.d.mts.map → stripe-google-pay-adapter-BlQ2jVpE.d.mts.map} +1 -1
- package/dist/{stripe-google-pay-adapter-3cx0KNjK.mjs → stripe-google-pay-adapter-CIkgjhw8.mjs} +1 -1
- package/dist/{stripe-google-pay-adapter-3cx0KNjK.mjs.map → stripe-google-pay-adapter-CIkgjhw8.mjs.map} +1 -1
- package/dist/{types-D88-nhWu.d.mts → types-CQ8xbgoh.d.mts} +3 -3
- package/dist/{types-D88-nhWu.d.mts.map → types-CQ8xbgoh.d.mts.map} +1 -1
- package/dist/{vgs-collect-loader-BZj36d8r.mjs → vgs-collect-loader-l5_Pnmhz.mjs} +1 -1
- package/dist/{vgs-collect-loader-BZj36d8r.mjs.map → vgs-collect-loader-l5_Pnmhz.mjs.map} +1 -1
- package/package.json +6 -2
package/dist/cdn/paymentkit.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* PaymentKit.js v0.5.
|
|
2
|
+
* PaymentKit.js v0.5.14
|
|
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.14";
|
|
46
46
|
|
|
47
47
|
// src/analytics/mock-adapter.ts
|
|
48
48
|
var MockAnalyticsAdapter = class {
|
|
@@ -6598,6 +6598,175 @@ var PaymentKit = (() => {
|
|
|
6598
6598
|
};
|
|
6599
6599
|
var index_default = PaymentKit;
|
|
6600
6600
|
|
|
6601
|
+
// src/payment-methods/bnpl-shared.ts
|
|
6602
|
+
var createSubmitPayment = (states, config) => {
|
|
6603
|
+
const { name, endpointPath, supportsSetupFutureUsage } = config;
|
|
6604
|
+
const capitalizedName = name.charAt(0).toUpperCase() + name.slice(1);
|
|
6605
|
+
const submitPayment = async (_fields, options) => {
|
|
6606
|
+
const { apiBaseUrl, secureToken, environment } = states;
|
|
6607
|
+
const bnplOptions = options;
|
|
6608
|
+
if (!bnplOptions?.processorId) {
|
|
6609
|
+
return { errors: { processor_id: "Processor ID is required" } };
|
|
6610
|
+
}
|
|
6611
|
+
if (!bnplOptions?.customerInfo?.first_name || !bnplOptions?.customerInfo?.last_name) {
|
|
6612
|
+
return {
|
|
6613
|
+
errors: {
|
|
6614
|
+
customer_name: "Customer first and last name are required"
|
|
6615
|
+
}
|
|
6616
|
+
};
|
|
6617
|
+
}
|
|
6618
|
+
try {
|
|
6619
|
+
const checkoutRequestId = getOrCreateCheckoutRequestId(environment);
|
|
6620
|
+
const requestBody = {
|
|
6621
|
+
processor_id: bnplOptions.processorId,
|
|
6622
|
+
customer_info: bnplOptions.customerInfo,
|
|
6623
|
+
fraud_metadata: collectFraudMetadata()
|
|
6624
|
+
};
|
|
6625
|
+
if (supportsSetupFutureUsage && bnplOptions.setupFutureUsage !== void 0) {
|
|
6626
|
+
requestBody.setup_future_usage = bnplOptions.setupFutureUsage;
|
|
6627
|
+
}
|
|
6628
|
+
const startResponse = await fetch(`${apiBaseUrl}/api/checkout/${secureToken}/stripe/${endpointPath}/start`, {
|
|
6629
|
+
method: "POST",
|
|
6630
|
+
headers: {
|
|
6631
|
+
"Content-Type": "application/json",
|
|
6632
|
+
"x-request-id": checkoutRequestId
|
|
6633
|
+
},
|
|
6634
|
+
body: JSON.stringify(requestBody)
|
|
6635
|
+
});
|
|
6636
|
+
if (!startResponse.ok) {
|
|
6637
|
+
let errorMessage = `Failed to start ${capitalizedName} checkout (${startResponse.status})`;
|
|
6638
|
+
try {
|
|
6639
|
+
const errorData = await startResponse.json();
|
|
6640
|
+
errorMessage = errorData.detail || errorMessage;
|
|
6641
|
+
} catch {
|
|
6642
|
+
errorMessage = startResponse.statusText || errorMessage;
|
|
6643
|
+
}
|
|
6644
|
+
return {
|
|
6645
|
+
errors: {
|
|
6646
|
+
[name]: errorMessage
|
|
6647
|
+
}
|
|
6648
|
+
};
|
|
6649
|
+
}
|
|
6650
|
+
const { approval_url, popup_token, checkout_attempt_id } = await startResponse.json();
|
|
6651
|
+
const popup = window.open(approval_url, capitalizedName, "width=600,height=700");
|
|
6652
|
+
if (!popup) {
|
|
6653
|
+
return {
|
|
6654
|
+
errors: {
|
|
6655
|
+
[name]: `Failed to open ${capitalizedName} popup. Please allow popups for this site.`
|
|
6656
|
+
}
|
|
6657
|
+
};
|
|
6658
|
+
}
|
|
6659
|
+
states.popup = popup;
|
|
6660
|
+
return new Promise((resolve) => {
|
|
6661
|
+
let popupClosedGracePolls = 0;
|
|
6662
|
+
const MAX_GRACE_POLLS = 5;
|
|
6663
|
+
const pollInterval = setInterval(async () => {
|
|
6664
|
+
try {
|
|
6665
|
+
const statusResponse = await fetch(
|
|
6666
|
+
`${apiBaseUrl}/api/checkout/${secureToken}/popup/status?popup_token=${popup_token}`
|
|
6667
|
+
);
|
|
6668
|
+
if (!statusResponse.ok) {
|
|
6669
|
+
clearInterval(pollInterval);
|
|
6670
|
+
popup.close();
|
|
6671
|
+
resolve({
|
|
6672
|
+
errors: {
|
|
6673
|
+
[name]: `Failed to check ${capitalizedName} status`
|
|
6674
|
+
}
|
|
6675
|
+
});
|
|
6676
|
+
return;
|
|
6677
|
+
}
|
|
6678
|
+
const statusResult = await statusResponse.json();
|
|
6679
|
+
if (statusResult.completed) {
|
|
6680
|
+
clearInterval(pollInterval);
|
|
6681
|
+
popup.close();
|
|
6682
|
+
if (statusResult.status === "success") {
|
|
6683
|
+
const result = statusResult.result || {
|
|
6684
|
+
id: checkout_attempt_id,
|
|
6685
|
+
checkoutAttemptId: checkout_attempt_id,
|
|
6686
|
+
checkoutSessionId: secureToken,
|
|
6687
|
+
state: "checkout_succeeded"
|
|
6688
|
+
};
|
|
6689
|
+
resolve({ data: result });
|
|
6690
|
+
} else {
|
|
6691
|
+
resolve({
|
|
6692
|
+
errors: {
|
|
6693
|
+
[name]: statusResult.error || `${capitalizedName} checkout ${statusResult.status}`
|
|
6694
|
+
}
|
|
6695
|
+
});
|
|
6696
|
+
}
|
|
6697
|
+
return;
|
|
6698
|
+
}
|
|
6699
|
+
if (popup.closed) {
|
|
6700
|
+
popupClosedGracePolls++;
|
|
6701
|
+
if (popupClosedGracePolls >= MAX_GRACE_POLLS) {
|
|
6702
|
+
clearInterval(pollInterval);
|
|
6703
|
+
resolve({
|
|
6704
|
+
errors: {
|
|
6705
|
+
[name]: `${capitalizedName} popup closed by user`
|
|
6706
|
+
}
|
|
6707
|
+
});
|
|
6708
|
+
}
|
|
6709
|
+
return;
|
|
6710
|
+
}
|
|
6711
|
+
} catch (error) {
|
|
6712
|
+
clearInterval(pollInterval);
|
|
6713
|
+
popup.close();
|
|
6714
|
+
resolve({
|
|
6715
|
+
errors: {
|
|
6716
|
+
[name]: `Polling error: ${error}`
|
|
6717
|
+
}
|
|
6718
|
+
});
|
|
6719
|
+
}
|
|
6720
|
+
}, 2e3);
|
|
6721
|
+
states.pollInterval = pollInterval;
|
|
6722
|
+
});
|
|
6723
|
+
} catch (error) {
|
|
6724
|
+
return {
|
|
6725
|
+
errors: {
|
|
6726
|
+
[name]: `${capitalizedName} checkout error: ${error}`
|
|
6727
|
+
}
|
|
6728
|
+
};
|
|
6729
|
+
}
|
|
6730
|
+
};
|
|
6731
|
+
return submitPayment;
|
|
6732
|
+
};
|
|
6733
|
+
function createBnplPaymentMethod(config) {
|
|
6734
|
+
return definePaymentMethod((paymentKitStates) => {
|
|
6735
|
+
const localStates = { ...paymentKitStates };
|
|
6736
|
+
return {
|
|
6737
|
+
name: config.name,
|
|
6738
|
+
externalFuncs: {},
|
|
6739
|
+
internalFuncs: {
|
|
6740
|
+
submitPayment: createSubmitPayment(localStates, config),
|
|
6741
|
+
cleanup: () => {
|
|
6742
|
+
if (localStates.pollInterval) {
|
|
6743
|
+
clearInterval(localStates.pollInterval);
|
|
6744
|
+
}
|
|
6745
|
+
if (localStates.popup && !localStates.popup.closed) {
|
|
6746
|
+
localStates.popup.close();
|
|
6747
|
+
}
|
|
6748
|
+
}
|
|
6749
|
+
}
|
|
6750
|
+
};
|
|
6751
|
+
});
|
|
6752
|
+
}
|
|
6753
|
+
|
|
6754
|
+
// src/payment-methods/affirm.ts
|
|
6755
|
+
var AffirmPaymentMethod = createBnplPaymentMethod({
|
|
6756
|
+
name: "affirm",
|
|
6757
|
+
endpointPath: "affirm",
|
|
6758
|
+
supportsSetupFutureUsage: false
|
|
6759
|
+
});
|
|
6760
|
+
var affirm_default = AffirmPaymentMethod;
|
|
6761
|
+
|
|
6762
|
+
// src/payment-methods/afterpay.ts
|
|
6763
|
+
var AfterpayPaymentMethod = createBnplPaymentMethod({
|
|
6764
|
+
name: "afterpay",
|
|
6765
|
+
endpointPath: "afterpay",
|
|
6766
|
+
supportsSetupFutureUsage: false
|
|
6767
|
+
});
|
|
6768
|
+
var afterpay_default = AfterpayPaymentMethod;
|
|
6769
|
+
|
|
6601
6770
|
// src/payment-methods/airwallex-apple-pay-adapter.ts
|
|
6602
6771
|
var AirwallexApplePayAdapter = class {
|
|
6603
6772
|
constructor(mockScenario) {
|
|
@@ -7300,6 +7469,28 @@ var PaymentKit = (() => {
|
|
|
7300
7469
|
// src/payment-methods/apple-pay.ts
|
|
7301
7470
|
var preparedStripeState = null;
|
|
7302
7471
|
var preparedAirwallexState = null;
|
|
7472
|
+
var applePayScriptLoadPromise = null;
|
|
7473
|
+
async function loadApplePayScript() {
|
|
7474
|
+
if (typeof window === "undefined") return;
|
|
7475
|
+
if (window.ApplePaySession) return;
|
|
7476
|
+
if (document.getElementById("__pk_apple_pay_sdk")) {
|
|
7477
|
+
return applePayScriptLoadPromise ?? Promise.resolve();
|
|
7478
|
+
}
|
|
7479
|
+
applePayScriptLoadPromise = new Promise((resolve, reject) => {
|
|
7480
|
+
const script = document.createElement("script");
|
|
7481
|
+
script.id = "__pk_apple_pay_sdk";
|
|
7482
|
+
script.src = "https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js";
|
|
7483
|
+
script.crossOrigin = "anonymous";
|
|
7484
|
+
script.onload = () => resolve();
|
|
7485
|
+
script.onerror = () => {
|
|
7486
|
+
applePayScriptLoadPromise = null;
|
|
7487
|
+
document.getElementById("__pk_apple_pay_sdk")?.remove();
|
|
7488
|
+
reject(new Error("Failed to load Apple Pay SDK"));
|
|
7489
|
+
};
|
|
7490
|
+
document.head.appendChild(script);
|
|
7491
|
+
});
|
|
7492
|
+
return applePayScriptLoadPromise;
|
|
7493
|
+
}
|
|
7303
7494
|
async function apiCall(url, options, checkoutRequestId) {
|
|
7304
7495
|
const headers = new Headers(options.headers);
|
|
7305
7496
|
if (checkoutRequestId) {
|
|
@@ -7409,7 +7600,25 @@ var PaymentKit = (() => {
|
|
|
7409
7600
|
const checkoutRequestId = getOrCreateCheckoutRequestId(environment);
|
|
7410
7601
|
console.log(`[ApplePay] Using checkout_request_id: ${checkoutRequestId}`);
|
|
7411
7602
|
if (options.processorType === "airwallex") {
|
|
7412
|
-
console.log("[ApplePay] Airwallex processor - fetching session info for amount");
|
|
7603
|
+
console.log("[ApplePay] Airwallex processor - loading Apple Pay SDK, fetching session info for amount");
|
|
7604
|
+
if (!mockScenarioStr) {
|
|
7605
|
+
try {
|
|
7606
|
+
await loadApplePayScript();
|
|
7607
|
+
} catch (err) {
|
|
7608
|
+
console.error("[ApplePay] Failed to load Apple Pay SDK:", err);
|
|
7609
|
+
return { success: false, error: "Failed to load Apple Pay" };
|
|
7610
|
+
}
|
|
7611
|
+
let canMake = false;
|
|
7612
|
+
try {
|
|
7613
|
+
canMake = !!window.ApplePaySession?.canMakePayments();
|
|
7614
|
+
} catch {
|
|
7615
|
+
canMake = false;
|
|
7616
|
+
}
|
|
7617
|
+
if (!canMake) {
|
|
7618
|
+
console.log("[ApplePay] Apple Pay not available on this device/browser");
|
|
7619
|
+
return { success: false, error: "Apple Pay not available on this device" };
|
|
7620
|
+
}
|
|
7621
|
+
}
|
|
7413
7622
|
const sessionInfoResult = await callAirwallexSessionInfoEndpoint(apiBaseUrl, secureToken, checkoutRequestId);
|
|
7414
7623
|
if (sessionInfoResult.error || !sessionInfoResult.data) {
|
|
7415
7624
|
console.error("[ApplePay] Failed to fetch session info:", sessionInfoResult.error);
|
|
@@ -7418,7 +7627,7 @@ var PaymentKit = (() => {
|
|
|
7418
7627
|
console.log("[ApplePay] Got session info:", sessionInfoResult.data);
|
|
7419
7628
|
const resolvedAmount = sessionInfoResult.data.amount;
|
|
7420
7629
|
const resolvedCurrency = sessionInfoResult.data.currency;
|
|
7421
|
-
const resolvedCountry =
|
|
7630
|
+
const resolvedCountry = sessionInfoResult.data.country || options.country;
|
|
7422
7631
|
preparedAirwallexState = {
|
|
7423
7632
|
country: resolvedCountry,
|
|
7424
7633
|
currency: resolvedCurrency,
|
|
@@ -7597,6 +7806,14 @@ var PaymentKit = (() => {
|
|
|
7597
7806
|
if (!options.country) {
|
|
7598
7807
|
return { errors: { apple_pay: "Country is required for Airwallex Apple Pay" } };
|
|
7599
7808
|
}
|
|
7809
|
+
if (!options.amount) {
|
|
7810
|
+
const sessionInfoResult = await callAirwallexSessionInfoEndpoint(apiBaseUrl, secureToken, checkoutRequestId);
|
|
7811
|
+
if (sessionInfoResult.data) {
|
|
7812
|
+
options.amount = sessionInfoResult.data.amount;
|
|
7813
|
+
options.currency = options.currency || sessionInfoResult.data.currency;
|
|
7814
|
+
options.country = options.country || sessionInfoResult.data.country;
|
|
7815
|
+
}
|
|
7816
|
+
}
|
|
7600
7817
|
const adapter = new AirwallexApplePayAdapter(airwallexMockScenario);
|
|
7601
7818
|
const config = {
|
|
7602
7819
|
amount: options.amount || 0,
|
|
@@ -7605,7 +7822,7 @@ var PaymentKit = (() => {
|
|
|
7605
7822
|
merchantName: options.merchantName || "Total"
|
|
7606
7823
|
};
|
|
7607
7824
|
if (!adapter.initialize(config)) {
|
|
7608
|
-
return { errors: { apple_pay: "Apple Pay not available on this device
|
|
7825
|
+
return { errors: { apple_pay: "Apple Pay not available on this device" } };
|
|
7609
7826
|
}
|
|
7610
7827
|
const canPay = await adapter.canMakePayment();
|
|
7611
7828
|
if (!canPay) {
|
|
@@ -7690,10 +7907,17 @@ var PaymentKit = (() => {
|
|
|
7690
7907
|
complete(response.charge_status === "success" ? "success" : "fail");
|
|
7691
7908
|
return toApplePayResult(response, secureToken);
|
|
7692
7909
|
}
|
|
7693
|
-
var defSubmitPayment = (states) => {
|
|
7910
|
+
var defSubmitPayment = (states, getAutoPrepareConfig, onClearPrepared) => {
|
|
7694
7911
|
const submitPayment = async (_fields, options) => {
|
|
7695
7912
|
const { apiBaseUrl, secureToken, environment } = states;
|
|
7696
7913
|
const applePayOptions = options;
|
|
7914
|
+
const autoPrepareConfig = getAutoPrepareConfig();
|
|
7915
|
+
if (!applePayOptions.processorId && autoPrepareConfig?.processorId) {
|
|
7916
|
+
applePayOptions.processorId = autoPrepareConfig.processorId;
|
|
7917
|
+
}
|
|
7918
|
+
if (!applePayOptions.processorType && autoPrepareConfig?.processorType) {
|
|
7919
|
+
applePayOptions.processorType = autoPrepareConfig.processorType;
|
|
7920
|
+
}
|
|
7697
7921
|
const validationError = validateOptions(applePayOptions);
|
|
7698
7922
|
if (validationError) {
|
|
7699
7923
|
return { errors: validationError };
|
|
@@ -7802,26 +8026,131 @@ var PaymentKit = (() => {
|
|
|
7802
8026
|
return confirmResult;
|
|
7803
8027
|
}
|
|
7804
8028
|
} catch (error) {
|
|
7805
|
-
|
|
8029
|
+
onClearPrepared();
|
|
7806
8030
|
return { errors: { apple_pay: `Apple Pay error: ${error}` } };
|
|
7807
8031
|
}
|
|
7808
8032
|
};
|
|
7809
8033
|
return submitPayment;
|
|
7810
8034
|
};
|
|
7811
8035
|
var ApplePayPaymentMethod = definePaymentMethod((paymentKitStates) => {
|
|
8036
|
+
const { apiBaseUrl, secureToken, environment } = paymentKitStates;
|
|
8037
|
+
let autoPrepareConfig = null;
|
|
8038
|
+
let onApplePayReadyCallbacks = [];
|
|
8039
|
+
let isApplePayReadyState = false;
|
|
8040
|
+
let autoPrepareInProgress = false;
|
|
8041
|
+
let cleanupGeneration = 0;
|
|
8042
|
+
let pendingAutoPrepareArgs = null;
|
|
8043
|
+
let pendingPrepareResolvers = [];
|
|
8044
|
+
function instanceSetApplePayReady(ready) {
|
|
8045
|
+
isApplePayReadyState = ready;
|
|
8046
|
+
for (const cb of onApplePayReadyCallbacks) cb(ready);
|
|
8047
|
+
}
|
|
8048
|
+
function instanceClearPreparedApplePay() {
|
|
8049
|
+
clearPreparedApplePay();
|
|
8050
|
+
instanceSetApplePayReady(false);
|
|
8051
|
+
}
|
|
8052
|
+
async function instanceAutoPrepare(apBase, sToken, env) {
|
|
8053
|
+
if (autoPrepareInProgress) {
|
|
8054
|
+
pendingAutoPrepareArgs = { apiBaseUrl: apBase, secureToken: sToken, environment: env };
|
|
8055
|
+
return new Promise((resolve) => pendingPrepareResolvers.push(resolve));
|
|
8056
|
+
}
|
|
8057
|
+
autoPrepareInProgress = true;
|
|
8058
|
+
const capturedGeneration = cleanupGeneration;
|
|
8059
|
+
instanceSetApplePayReady(false);
|
|
8060
|
+
try {
|
|
8061
|
+
const result = await apiCall(`${apBase}/api/checkout-sessions/token/${sToken}`, {
|
|
8062
|
+
method: "GET"
|
|
8063
|
+
});
|
|
8064
|
+
if (cleanupGeneration !== capturedGeneration) return;
|
|
8065
|
+
if (result.error || !result.data) {
|
|
8066
|
+
console.warn("[ApplePay] Auto-prepare: failed to fetch session config:", result.error);
|
|
8067
|
+
return;
|
|
8068
|
+
}
|
|
8069
|
+
const processorId = result.data.express_checkout_processor_id;
|
|
8070
|
+
if (!processorId) {
|
|
8071
|
+
console.log("[ApplePay] Auto-prepare: no express checkout processor configured");
|
|
8072
|
+
return;
|
|
8073
|
+
}
|
|
8074
|
+
const processorTypeRaw = result.data.express_checkout_processor_type;
|
|
8075
|
+
const processorType = processorTypeRaw === "airwallex" || processorTypeRaw === "stripe" ? processorTypeRaw : void 0;
|
|
8076
|
+
autoPrepareConfig = { processorId, processorType };
|
|
8077
|
+
const prepareResult = await prepareApplePay(
|
|
8078
|
+
apBase,
|
|
8079
|
+
sToken,
|
|
8080
|
+
{ processorId, processorType, customerInfo: { first_name: "", last_name: "" } },
|
|
8081
|
+
env
|
|
8082
|
+
);
|
|
8083
|
+
if (cleanupGeneration !== capturedGeneration) return;
|
|
8084
|
+
instanceSetApplePayReady(prepareResult.success && prepareResult.applePay === true);
|
|
8085
|
+
} catch (err) {
|
|
8086
|
+
if (cleanupGeneration === capturedGeneration) {
|
|
8087
|
+
console.error("[ApplePay] Auto-prepare failed:", err);
|
|
8088
|
+
}
|
|
8089
|
+
} finally {
|
|
8090
|
+
autoPrepareInProgress = false;
|
|
8091
|
+
const stale = cleanupGeneration !== capturedGeneration;
|
|
8092
|
+
const pending = pendingAutoPrepareArgs;
|
|
8093
|
+
const resolvers = pendingPrepareResolvers.splice(0);
|
|
8094
|
+
if (!stale && pending) {
|
|
8095
|
+
pendingAutoPrepareArgs = null;
|
|
8096
|
+
instanceAutoPrepare(pending.apiBaseUrl, pending.secureToken, pending.environment).then(() => {
|
|
8097
|
+
for (const r2 of resolvers) r2();
|
|
8098
|
+
});
|
|
8099
|
+
} else {
|
|
8100
|
+
pendingAutoPrepareArgs = null;
|
|
8101
|
+
for (const r2 of resolvers) r2();
|
|
8102
|
+
}
|
|
8103
|
+
}
|
|
8104
|
+
}
|
|
8105
|
+
instanceAutoPrepare(apiBaseUrl, secureToken, environment).catch(
|
|
8106
|
+
(err) => console.error("[ApplePay] Unhandled init error:", err)
|
|
8107
|
+
);
|
|
7812
8108
|
return {
|
|
7813
8109
|
name: "apple_pay",
|
|
7814
8110
|
externalFuncs: {
|
|
7815
|
-
|
|
7816
|
-
|
|
7817
|
-
|
|
7818
|
-
|
|
7819
|
-
|
|
7820
|
-
|
|
8111
|
+
/**
|
|
8112
|
+
* @deprecated The SDK now prepares automatically on init. Use `onApplePayReady` to observe
|
|
8113
|
+
* readiness and `notifyAmountChanged` to trigger re-prepare after amount changes.
|
|
8114
|
+
*/
|
|
8115
|
+
prepareApplePay: (options) => prepareApplePay(apiBaseUrl, secureToken, options, environment),
|
|
8116
|
+
/**
|
|
8117
|
+
* Register a callback to be notified when Apple Pay becomes ready (or stops being ready).
|
|
8118
|
+
* Fires immediately with the current state, then on every state change.
|
|
8119
|
+
* Multiple registrations are all notified — none are silently overwritten.
|
|
8120
|
+
*
|
|
8121
|
+
* @example
|
|
8122
|
+
* paymentKit.apple_pay.onApplePayReady((isReady) => {
|
|
8123
|
+
* applePayButton.disabled = !isReady;
|
|
8124
|
+
* });
|
|
8125
|
+
*/
|
|
8126
|
+
onApplePayReady: (callback) => {
|
|
8127
|
+
onApplePayReadyCallbacks.push(callback);
|
|
8128
|
+
callback(isApplePayReadyState);
|
|
8129
|
+
},
|
|
8130
|
+
/**
|
|
8131
|
+
* Notify the SDK that the payment amount has changed (e.g. coupon applied).
|
|
8132
|
+
* The SDK will disable Apple Pay, re-prepare with the new amount, then re-enable.
|
|
8133
|
+
* The returned promise resolves when re-prepare is fully complete.
|
|
8134
|
+
*
|
|
8135
|
+
* @example
|
|
8136
|
+
* await paymentKit.apple_pay.notifyAmountChanged();
|
|
8137
|
+
*/
|
|
8138
|
+
notifyAmountChanged: () => {
|
|
8139
|
+
instanceClearPreparedApplePay();
|
|
8140
|
+
autoPrepareConfig = null;
|
|
8141
|
+
return instanceAutoPrepare(apiBaseUrl, secureToken, environment);
|
|
8142
|
+
}
|
|
7821
8143
|
},
|
|
7822
8144
|
internalFuncs: {
|
|
7823
|
-
submitPayment: defSubmitPayment(paymentKitStates),
|
|
8145
|
+
submitPayment: defSubmitPayment(paymentKitStates, () => autoPrepareConfig, instanceClearPreparedApplePay),
|
|
7824
8146
|
cleanup: () => {
|
|
8147
|
+
cleanupGeneration++;
|
|
8148
|
+
onApplePayReadyCallbacks = [];
|
|
8149
|
+
isApplePayReadyState = false;
|
|
8150
|
+
autoPrepareConfig = null;
|
|
8151
|
+
pendingAutoPrepareArgs = null;
|
|
8152
|
+
pendingPrepareResolvers = [];
|
|
8153
|
+
autoPrepareInProgress = false;
|
|
7825
8154
|
clearPreparedApplePay();
|
|
7826
8155
|
}
|
|
7827
8156
|
}
|
|
@@ -9135,6 +9464,14 @@ var PaymentKit = (() => {
|
|
|
9135
9464
|
});
|
|
9136
9465
|
var google_pay_default = GooglePayPaymentMethod;
|
|
9137
9466
|
|
|
9467
|
+
// src/payment-methods/klarna.ts
|
|
9468
|
+
var KlarnaPaymentMethod = createBnplPaymentMethod({
|
|
9469
|
+
name: "klarna",
|
|
9470
|
+
endpointPath: "klarna",
|
|
9471
|
+
supportsSetupFutureUsage: true
|
|
9472
|
+
});
|
|
9473
|
+
var klarna_default = KlarnaPaymentMethod;
|
|
9474
|
+
|
|
9138
9475
|
// src/payment-methods/paypal.ts
|
|
9139
9476
|
var defSubmitPayment4 = (states) => {
|
|
9140
9477
|
const submitPayment = async (_fields, options) => {
|
|
@@ -9285,7 +9622,10 @@ var PaymentKit = (() => {
|
|
|
9285
9622
|
applePay: apple_pay_default,
|
|
9286
9623
|
card: card_default,
|
|
9287
9624
|
googlePay: google_pay_default,
|
|
9288
|
-
paypal: paypal_default
|
|
9625
|
+
paypal: paypal_default,
|
|
9626
|
+
klarna: klarna_default,
|
|
9627
|
+
afterpay: afterpay_default,
|
|
9628
|
+
affirm: affirm_default
|
|
9289
9629
|
};
|
|
9290
9630
|
return __toCommonJS(cdn_exports);
|
|
9291
9631
|
})();
|