@funnelfox/billing 0.8.0-ffb-395.10 → 0.8.1
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/README.md +0 -211
- package/dist/chunk-index.cjs.js +59 -152
- package/dist/chunk-index.es.js +60 -152
- package/dist/funnelfox-billing.js +59 -336
- package/dist/funnelfox-billing.min.js +1 -1
- package/package.json +9 -5
- package/src/types.d.ts +1 -94
- package/dist/chunk-stripe-card-form.cjs.js +0 -81
- package/dist/chunk-stripe-card-form.es.js +0 -79
- package/dist/chunk-stripe-loader.cjs.js +0 -20
- package/dist/chunk-stripe-loader.es.js +0 -18
- package/dist/chunk-stripe-wallet.cjs.js +0 -112
- package/dist/chunk-stripe-wallet.es.js +0 -109
|
@@ -495,7 +495,7 @@
|
|
|
495
495
|
/**
|
|
496
496
|
* @fileoverview Constants for Funnefox SDK
|
|
497
497
|
*/
|
|
498
|
-
const SDK_VERSION = '0.
|
|
498
|
+
const SDK_VERSION = '0.8.1';
|
|
499
499
|
const DEFAULTS = {
|
|
500
500
|
BASE_URL: 'https://billing.funnelfox.com',
|
|
501
501
|
REGION: 'default',
|
|
@@ -1132,7 +1132,7 @@
|
|
|
1132
1132
|
async createClientSession(params) {
|
|
1133
1133
|
const payload = {
|
|
1134
1134
|
region: params.region || 'default',
|
|
1135
|
-
integration_type:
|
|
1135
|
+
integration_type: 'primer',
|
|
1136
1136
|
pp_ident: params.priceId,
|
|
1137
1137
|
external_id: params.externalId,
|
|
1138
1138
|
email_address: params.email,
|
|
@@ -1268,45 +1268,6 @@
|
|
|
1268
1268
|
}
|
|
1269
1269
|
}
|
|
1270
1270
|
|
|
1271
|
-
class SessionService {
|
|
1272
|
-
constructor() {
|
|
1273
|
-
this.cache = new Map();
|
|
1274
|
-
}
|
|
1275
|
-
buildCacheKey(p) {
|
|
1276
|
-
return [p.orgId, p.priceId, p.externalId, p.email, p.integration].join('-');
|
|
1277
|
-
}
|
|
1278
|
-
makeClient(orgId, baseUrl) {
|
|
1279
|
-
return new APIClient({
|
|
1280
|
-
baseUrl: baseUrl || DEFAULTS.BASE_URL,
|
|
1281
|
-
orgId,
|
|
1282
|
-
timeout: DEFAULTS.REQUEST_TIMEOUT,
|
|
1283
|
-
retryAttempts: DEFAULTS.RETRY_ATTEMPTS,
|
|
1284
|
-
});
|
|
1285
|
-
}
|
|
1286
|
-
createSession(p) {
|
|
1287
|
-
const key = this.buildCacheKey(p);
|
|
1288
|
-
const cached = this.cache.get(key);
|
|
1289
|
-
if (cached)
|
|
1290
|
-
return cached;
|
|
1291
|
-
const client = this.makeClient(p.orgId, p.baseUrl);
|
|
1292
|
-
const req = client.createClientSession({
|
|
1293
|
-
priceId: p.priceId,
|
|
1294
|
-
externalId: p.externalId,
|
|
1295
|
-
email: p.email,
|
|
1296
|
-
region: p.region || DEFAULTS.REGION,
|
|
1297
|
-
clientMetadata: p.clientMetadata,
|
|
1298
|
-
countryCode: p.countryCode,
|
|
1299
|
-
integration: p.integration,
|
|
1300
|
-
});
|
|
1301
|
-
this.cache.set(key, req);
|
|
1302
|
-
return req;
|
|
1303
|
-
}
|
|
1304
|
-
clearCache() {
|
|
1305
|
-
this.cache.clear();
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
var sessionService = new SessionService();
|
|
1309
|
-
|
|
1310
1271
|
var loaderHtml = "<div class=\"ff-sdk-loader-container\">\n <div class=\"ff-sdk-loader\"></div>\n</div>\n";
|
|
1311
1272
|
|
|
1312
1273
|
if(typeof document!=="undefined")document.head.appendChild(document.createElement("style")).textContent=".ff-sdk-loader-container {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n display: flex;\n justify-content: center;\n align-items: center;\n background-color: rgba(255, 255, 255);\n z-index: 2;\n}\n\n.ff-sdk-loader {\n width: 24px;\n height: 24px;\n border: 4px solid #e32f41;\n border-top: 4px solid transparent;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n}\n\n@keyframes spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n }";
|
|
@@ -1901,12 +1862,6 @@
|
|
|
1901
1862
|
this.cardEmailAddress = this.checkoutConfig.customer.email;
|
|
1902
1863
|
this.shouldApplySessionCardholderNameConfig =
|
|
1903
1864
|
this.checkoutConfig.card?.cardholderName?.required === undefined;
|
|
1904
|
-
this.apiClient = new APIClient({
|
|
1905
|
-
baseUrl: this.baseUrl || DEFAULTS.BASE_URL,
|
|
1906
|
-
orgId: this.orgId,
|
|
1907
|
-
timeout: DEFAULTS.REQUEST_TIMEOUT,
|
|
1908
|
-
retryAttempts: DEFAULTS.RETRY_ATTEMPTS,
|
|
1909
|
-
});
|
|
1910
1865
|
this._setupCallbackBridges();
|
|
1911
1866
|
}
|
|
1912
1867
|
_setupCallbackBridges() {
|
|
@@ -1948,35 +1903,64 @@
|
|
|
1948
1903
|
}
|
|
1949
1904
|
}
|
|
1950
1905
|
async createSession() {
|
|
1951
|
-
|
|
1906
|
+
this.apiClient = new APIClient({
|
|
1907
|
+
baseUrl: this.baseUrl || DEFAULTS.BASE_URL,
|
|
1952
1908
|
orgId: this.orgId,
|
|
1953
|
-
|
|
1909
|
+
timeout: DEFAULTS.REQUEST_TIMEOUT,
|
|
1910
|
+
retryAttempts: DEFAULTS.RETRY_ATTEMPTS,
|
|
1911
|
+
});
|
|
1912
|
+
const sessionParams = {
|
|
1954
1913
|
priceId: this.checkoutConfig.priceId,
|
|
1955
1914
|
externalId: this.checkoutConfig.customer.externalId,
|
|
1956
1915
|
email: this.checkoutConfig.customer.email,
|
|
1957
|
-
region: this.region,
|
|
1916
|
+
region: this.region || DEFAULTS.REGION,
|
|
1958
1917
|
clientMetadata: this.checkoutConfig.clientMetadata,
|
|
1959
1918
|
countryCode: this.checkoutConfig.customer.countryCode,
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
.
|
|
1979
|
-
|
|
1919
|
+
};
|
|
1920
|
+
const cacheKey = [
|
|
1921
|
+
this.orgId,
|
|
1922
|
+
this.checkoutConfig.priceId,
|
|
1923
|
+
this.checkoutConfig.customer.externalId,
|
|
1924
|
+
this.checkoutConfig.customer.email,
|
|
1925
|
+
].join('-');
|
|
1926
|
+
let sessionResponse;
|
|
1927
|
+
// Return cached response if payload hasn't changed
|
|
1928
|
+
const cachedResponse = CheckoutInstance.sessionCache.get(cacheKey);
|
|
1929
|
+
if (cachedResponse) {
|
|
1930
|
+
sessionResponse = await cachedResponse;
|
|
1931
|
+
}
|
|
1932
|
+
else {
|
|
1933
|
+
const sessionRequest = this.apiClient
|
|
1934
|
+
.createClientSession(sessionParams)
|
|
1935
|
+
.then((response) => {
|
|
1936
|
+
const cachedResponse = response;
|
|
1937
|
+
if (response.data?.stripe_public_key) {
|
|
1938
|
+
const stripePublicKey = response.data.stripe_public_key;
|
|
1939
|
+
cachedResponse.radarSessionId = loadStripe(stripePublicKey)
|
|
1940
|
+
.then(stripe => stripe
|
|
1941
|
+
? stripe
|
|
1942
|
+
.createRadarSession()
|
|
1943
|
+
.then(session => session?.radarSession?.id || '')
|
|
1944
|
+
.catch(() => '')
|
|
1945
|
+
: '')
|
|
1946
|
+
.catch(() => '');
|
|
1947
|
+
}
|
|
1948
|
+
// Initialize Airwallex device fingerprinting if enabled by backend
|
|
1949
|
+
if (response.data?.airwallex_risk_enabled) {
|
|
1950
|
+
const isLivemode = response.data?.is_livemode;
|
|
1951
|
+
const deviceId = generateUUID();
|
|
1952
|
+
cachedResponse.airwallexDeviceId = loadAirwallexDeviceFingerprint(deviceId, isLivemode)
|
|
1953
|
+
.then(() => deviceId)
|
|
1954
|
+
.catch(() => {
|
|
1955
|
+
// Silently fail - return deviceId anyway
|
|
1956
|
+
return deviceId;
|
|
1957
|
+
});
|
|
1958
|
+
}
|
|
1959
|
+
return cachedResponse;
|
|
1960
|
+
});
|
|
1961
|
+
// Cache the successful response
|
|
1962
|
+
CheckoutInstance.sessionCache.set(cacheKey, sessionRequest);
|
|
1963
|
+
sessionResponse = await sessionRequest;
|
|
1980
1964
|
}
|
|
1981
1965
|
this.cachedSessionResponse = sessionResponse;
|
|
1982
1966
|
this.isTelemetryEnabled = !!sessionResponse.data?.sdk_telemetry_enabled;
|
|
@@ -2235,7 +2219,8 @@
|
|
|
2235
2219
|
try {
|
|
2236
2220
|
this.onLoaderChangeWithRace(true);
|
|
2237
2221
|
this._setState('updating');
|
|
2238
|
-
|
|
2222
|
+
// Invalidate session cache
|
|
2223
|
+
CheckoutInstance.sessionCache.clear();
|
|
2239
2224
|
await this.apiClient.updateClientSession({
|
|
2240
2225
|
orderId: this.orderId,
|
|
2241
2226
|
clientToken: this.clientToken,
|
|
@@ -2268,7 +2253,7 @@
|
|
|
2268
2253
|
return;
|
|
2269
2254
|
try {
|
|
2270
2255
|
this.stopUnhandledTelemetry();
|
|
2271
|
-
|
|
2256
|
+
CheckoutInstance.sessionCache.clear();
|
|
2272
2257
|
await this.primerWrapper.destroy();
|
|
2273
2258
|
this._setState('destroyed');
|
|
2274
2259
|
this.orderId = null;
|
|
@@ -2479,6 +2464,7 @@
|
|
|
2479
2464
|
this.telemetryPaymentMethod = undefined;
|
|
2480
2465
|
}
|
|
2481
2466
|
}
|
|
2467
|
+
CheckoutInstance.sessionCache = new Map();
|
|
2482
2468
|
|
|
2483
2469
|
/**
|
|
2484
2470
|
* @fileoverview Public API with configuration and orchestration logic
|
|
@@ -2669,79 +2655,6 @@
|
|
|
2669
2655
|
throw error;
|
|
2670
2656
|
}
|
|
2671
2657
|
}
|
|
2672
|
-
async function createStripeCardForm(element, params) {
|
|
2673
|
-
const config = resolveConfig(params, 'createStripeCardForm');
|
|
2674
|
-
const [session, { mountStripeCardForm }] = await Promise.all([
|
|
2675
|
-
sessionService.createSession({
|
|
2676
|
-
orgId: config.orgId,
|
|
2677
|
-
baseUrl: config.baseUrl,
|
|
2678
|
-
region: config.region,
|
|
2679
|
-
priceId: params.priceId,
|
|
2680
|
-
externalId: params.externalId,
|
|
2681
|
-
email: params.email,
|
|
2682
|
-
clientMetadata: params.clientMetadata,
|
|
2683
|
-
countryCode: params.countryCode,
|
|
2684
|
-
integration: 'stripe',
|
|
2685
|
-
}),
|
|
2686
|
-
Promise.resolve().then(function () { return stripeCardForm; }),
|
|
2687
|
-
]);
|
|
2688
|
-
const apiClient = new APIClient({
|
|
2689
|
-
orgId: config.orgId,
|
|
2690
|
-
baseUrl: config.baseUrl || DEFAULTS.BASE_URL,
|
|
2691
|
-
});
|
|
2692
|
-
return mountStripeCardForm(element, session, { ...params, apiClient });
|
|
2693
|
-
}
|
|
2694
|
-
async function purchaseStripeWallet(params) {
|
|
2695
|
-
const config = resolveConfig(params, 'purchaseStripeWallet');
|
|
2696
|
-
const [session, { purchaseWallet }] = await Promise.all([
|
|
2697
|
-
sessionService.createSession({
|
|
2698
|
-
orgId: config.orgId,
|
|
2699
|
-
baseUrl: config.baseUrl,
|
|
2700
|
-
region: config.region,
|
|
2701
|
-
priceId: params.priceId,
|
|
2702
|
-
externalId: params.externalId,
|
|
2703
|
-
email: params.email,
|
|
2704
|
-
clientMetadata: params.clientMetadata,
|
|
2705
|
-
countryCode: params.countryCode,
|
|
2706
|
-
integration: 'stripe',
|
|
2707
|
-
}),
|
|
2708
|
-
Promise.resolve().then(function () { return stripeWallet; }),
|
|
2709
|
-
]);
|
|
2710
|
-
const apiClient = new APIClient({
|
|
2711
|
-
orgId: config.orgId,
|
|
2712
|
-
baseUrl: config.baseUrl || DEFAULTS.BASE_URL,
|
|
2713
|
-
});
|
|
2714
|
-
return purchaseWallet(session, { ...params, apiClient });
|
|
2715
|
-
}
|
|
2716
|
-
async function getAvailableStripeWallet(params) {
|
|
2717
|
-
const config = resolveConfig(params, 'getAvailableStripeWallet');
|
|
2718
|
-
const [session, { getAvailableWallet }] = await Promise.all([
|
|
2719
|
-
sessionService.createSession({
|
|
2720
|
-
orgId: config.orgId,
|
|
2721
|
-
baseUrl: config.baseUrl,
|
|
2722
|
-
region: config.region,
|
|
2723
|
-
priceId: params.priceId,
|
|
2724
|
-
externalId: params.externalId,
|
|
2725
|
-
email: params.email,
|
|
2726
|
-
clientMetadata: params.clientMetadata,
|
|
2727
|
-
countryCode: params.countryCode,
|
|
2728
|
-
integration: 'stripe',
|
|
2729
|
-
}),
|
|
2730
|
-
Promise.resolve().then(function () { return stripeWallet; }),
|
|
2731
|
-
]);
|
|
2732
|
-
const result = await getAvailableWallet(session);
|
|
2733
|
-
if (result === 'APPLE_PAY')
|
|
2734
|
-
return exports.PaymentMethod.APPLE_PAY;
|
|
2735
|
-
if (result === 'GOOGLE_PAY')
|
|
2736
|
-
return exports.PaymentMethod.GOOGLE_PAY;
|
|
2737
|
-
return null;
|
|
2738
|
-
}
|
|
2739
|
-
async function getAvailableStripePaymentMethods(params) {
|
|
2740
|
-
const wallet = await getAvailableStripeWallet(params);
|
|
2741
|
-
return wallet
|
|
2742
|
-
? [exports.PaymentMethod.PAYMENT_CARD, wallet]
|
|
2743
|
-
: [exports.PaymentMethod.PAYMENT_CARD];
|
|
2744
|
-
}
|
|
2745
2658
|
|
|
2746
2659
|
/**
|
|
2747
2660
|
* @fileoverview Main entry point for @funnelfox/billing
|
|
@@ -2753,16 +2666,11 @@
|
|
|
2753
2666
|
initMethod: initMethod,
|
|
2754
2667
|
silentPurchase: silentPurchase,
|
|
2755
2668
|
getAvailablePaymentMethods: getAvailablePaymentMethods,
|
|
2756
|
-
stripe: {
|
|
2757
|
-
createCardForm: createStripeCardForm,
|
|
2758
|
-
purchaseWallet: purchaseStripeWallet,
|
|
2759
|
-
getAvailableWallet: getAvailableStripeWallet,
|
|
2760
|
-
getAvailablePaymentMethods: getAvailableStripePaymentMethods,
|
|
2761
|
-
},
|
|
2762
2669
|
};
|
|
2763
2670
|
if (typeof window !== 'undefined') {
|
|
2764
2671
|
window.Billing = Billing;
|
|
2765
2672
|
}
|
|
2673
|
+
console.debug('Billing SDK inited');
|
|
2766
2674
|
|
|
2767
2675
|
var template$1 = "<div class=\"ff-skin-default\" id=\"ff-payment-method-containers\">\n <div id=\"success-screen\" style=\"display: none\">\n <div class=\"success\">\n <img alt=\"Loading\" src=\"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTAiIGhlaWdodD0iNTAiIHZpZXdCb3g9IjAgMCA1MCA1MCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTI1IDAuMTExMzI4QzIwLjA3NzQgMC4xMTEzMjggMTUuMjY1NCAxLjU3MTA0IDExLjE3MjUgNC4zMDU4NkM3LjA3OTUyIDcuMDQwNjkgMy44ODk0NSAxMC45Mjc4IDIuMDA1NjYgMTUuNDc1N0MwLjEyMTg4MyAyMC4wMjM1IC0wLjM3MSAyNS4wMjc4IDAuNTg5MzQzIDI5Ljg1NThDMS41NDk2OSAzNC42ODM4IDMuOTIwMTIgMzkuMTE4NSA3LjQwMDkgNDIuNTk5M0MxMC44ODE3IDQ2LjA4MDEgMTUuMzE2NCA0OC40NTA1IDIwLjE0NDQgNDkuNDEwOUMyNC45NzI0IDUwLjM3MTIgMjkuOTc2NyA0OS44NzgzIDM0LjUyNDYgNDcuOTk0NkMzOS4wNzI0IDQ2LjExMDggNDIuOTU5NSA0Mi45MjA3IDQ1LjY5NDQgMzguODI3N0M0OC40MjkyIDM0LjczNDggNDkuODg4OSAyOS45MjI4IDQ5Ljg4ODkgMjUuMDAwMkM0OS44ODg5IDE4LjM5OTMgNDcuMjY2NyAxMi4wNjg3IDQyLjU5OTEgNy40MDExMkMzNy45MzE1IDIuNzMzNTQgMzEuNjAwOSAwLjExMTMyOCAyNSAwLjExMTMyOFpNNDEuMjU1NiAxNi42NDY5TDIwLjgxNTYgMzcuMDcxM0w4Ljc0NDQ0IDI1LjAwMDJDOC4zMzE4OCAyNC41ODc3IDguMTAwMTEgMjQuMDI4MSA4LjEwMDExIDIzLjQ0NDdDOC4xMDAxMSAyMi44NjEyIDguMzMxODggMjIuMzAxNyA4Ljc0NDQ0IDIxLjg4OTFDOS4xNTcgMjEuNDc2NSA5LjcxNjU1IDIxLjI0NDggMTAuMyAyMS4yNDQ4QzEwLjg4MzQgMjEuMjQ0OCAxMS40NDMgMjEuNDc2NSAxMS44NTU2IDIxLjg4OTFMMjAuODQ2NyAzMC44ODAyTDM4LjE3NTYgMTMuNTY2OUMzOC4zNzk4IDEzLjM2MjYgMzguNjIyMyAxMy4yMDA2IDM4Ljg4OTIgMTMuMDlDMzkuMTU2MiAxMi45Nzk1IDM5LjQ0MjIgMTIuOTIyNiAzOS43MzExIDEyLjkyMjZDNDAuMDIgMTIuOTIyNiA0MC4zMDYxIDEyLjk3OTUgNDAuNTczIDEzLjA5QzQwLjgzOTkgMTMuMjAwNiA0MS4wODI0IDEzLjM2MjYgNDEuMjg2NyAxMy41NjY5QzQxLjQ5MDkgMTMuNzcxMiA0MS42NTMgMTQuMDEzNyA0MS43NjM1IDE0LjI4MDZDNDEuODc0MSAxNC41NDc1IDQxLjkzMSAxNC44MzM1IDQxLjkzMSAxNS4xMjI0QzQxLjkzMSAxNS40MTEzIDQxLjg3NDEgMTUuNjk3NCA0MS43NjM1IDE1Ljk2NDNDNDEuNjUzIDE2LjIzMTIgNDEuNDkwOSAxNi40NzM3IDQxLjI4NjcgMTYuNjc4TDQxLjI1NTYgMTYuNjQ2OVoiIGZpbGw9IiM4RURGQzIiLz4KPC9zdmc+Cg==\">\n <div>Payment completed successfully</div>\n </div>\n </div>\n</div>\n";
|
|
2768
2676
|
|
|
@@ -3162,191 +3070,6 @@
|
|
|
3162
3070
|
default: createDefaultSkin
|
|
3163
3071
|
});
|
|
3164
3072
|
|
|
3165
|
-
const cache = new Map();
|
|
3166
|
-
function getStripe(publicKey) {
|
|
3167
|
-
if (!cache.has(publicKey)) {
|
|
3168
|
-
cache.set(publicKey, loadStripe(publicKey));
|
|
3169
|
-
}
|
|
3170
|
-
return cache.get(publicKey);
|
|
3171
|
-
}
|
|
3172
|
-
|
|
3173
|
-
async function mountStripeCardForm(element, session, params) {
|
|
3174
|
-
const { stripe_public_key, amount, currency, order_id, is_link_enabled } = session.data;
|
|
3175
|
-
const stripe = await getStripe(stripe_public_key);
|
|
3176
|
-
if (!stripe)
|
|
3177
|
-
throw new Error('Failed to load Stripe');
|
|
3178
|
-
const stripeElements = stripe.elements({
|
|
3179
|
-
mode: 'subscription',
|
|
3180
|
-
amount,
|
|
3181
|
-
currency,
|
|
3182
|
-
paymentMethodCreation: 'manual',
|
|
3183
|
-
paymentMethodTypes: is_link_enabled ? ['card', 'link'] : ['card'],
|
|
3184
|
-
appearance: params.appearance,
|
|
3185
|
-
});
|
|
3186
|
-
const paymentElement = stripeElements.create('payment', {
|
|
3187
|
-
layout: 'tabs',
|
|
3188
|
-
wallets: {
|
|
3189
|
-
applePay: params.showWallets ? 'auto' : 'never',
|
|
3190
|
-
googlePay: params.showWallets ? 'auto' : 'never',
|
|
3191
|
-
},
|
|
3192
|
-
terms: { card: 'never' },
|
|
3193
|
-
});
|
|
3194
|
-
paymentElement.mount(element);
|
|
3195
|
-
await new Promise((resolve, reject) => {
|
|
3196
|
-
paymentElement.once('ready', () => resolve());
|
|
3197
|
-
// 'loaderror' is a valid Stripe event but not yet in the @stripe/stripe-js types
|
|
3198
|
-
paymentElement.once('loaderror', e => reject(e.error));
|
|
3199
|
-
});
|
|
3200
|
-
params.onRenderSuccess?.();
|
|
3201
|
-
return {
|
|
3202
|
-
submit: async () => {
|
|
3203
|
-
params.onLoaderChange?.(true);
|
|
3204
|
-
try {
|
|
3205
|
-
const { error: submitError } = await stripeElements.submit();
|
|
3206
|
-
if (submitError)
|
|
3207
|
-
throw submitError;
|
|
3208
|
-
const { error, paymentMethod } = await stripe.createPaymentMethod({
|
|
3209
|
-
elements: stripeElements,
|
|
3210
|
-
});
|
|
3211
|
-
if (error)
|
|
3212
|
-
throw error;
|
|
3213
|
-
const raw = await params.apiClient.createPayment({
|
|
3214
|
-
orderId: order_id,
|
|
3215
|
-
paymentMethodToken: paymentMethod.id,
|
|
3216
|
-
email: params.email,
|
|
3217
|
-
countryCode: params.countryCode,
|
|
3218
|
-
clientMetadata: params.clientMetadata,
|
|
3219
|
-
});
|
|
3220
|
-
const result = params.apiClient.processPaymentResponse(raw);
|
|
3221
|
-
if (result.type === 'action_required') {
|
|
3222
|
-
const { error: actionError } = await stripe.handleNextAction({
|
|
3223
|
-
clientSecret: result.clientToken,
|
|
3224
|
-
});
|
|
3225
|
-
if (actionError)
|
|
3226
|
-
throw actionError;
|
|
3227
|
-
}
|
|
3228
|
-
params.onPaymentSuccess?.(paymentMethod, order_id);
|
|
3229
|
-
}
|
|
3230
|
-
catch (err) {
|
|
3231
|
-
params.onPaymentFail?.(err);
|
|
3232
|
-
throw err;
|
|
3233
|
-
}
|
|
3234
|
-
finally {
|
|
3235
|
-
params.onLoaderChange?.(false);
|
|
3236
|
-
}
|
|
3237
|
-
},
|
|
3238
|
-
};
|
|
3239
|
-
}
|
|
3240
|
-
|
|
3241
|
-
var stripeCardForm = /*#__PURE__*/Object.freeze({
|
|
3242
|
-
__proto__: null,
|
|
3243
|
-
mountStripeCardForm: mountStripeCardForm
|
|
3244
|
-
});
|
|
3245
|
-
|
|
3246
|
-
function buildPaymentRequest(stripe, data, totalLabel) {
|
|
3247
|
-
const raw = data.apple_pay_recurring_payment_request;
|
|
3248
|
-
if (raw) {
|
|
3249
|
-
const parseDates = (b) => {
|
|
3250
|
-
if (b.recurringPaymentStartDate)
|
|
3251
|
-
Object.assign(b, {
|
|
3252
|
-
recurringPaymentStartDate: new Date(b.recurringPaymentStartDate),
|
|
3253
|
-
});
|
|
3254
|
-
if (b.recurringPaymentEndDate)
|
|
3255
|
-
Object.assign(b, {
|
|
3256
|
-
recurringPaymentEndDate: new Date(b.recurringPaymentEndDate),
|
|
3257
|
-
});
|
|
3258
|
-
};
|
|
3259
|
-
parseDates(raw.regularBilling);
|
|
3260
|
-
if (raw.trialBilling)
|
|
3261
|
-
parseDates(raw.trialBilling);
|
|
3262
|
-
}
|
|
3263
|
-
const applePay = raw
|
|
3264
|
-
? { recurringPaymentRequest: raw }
|
|
3265
|
-
: undefined;
|
|
3266
|
-
return stripe.paymentRequest({
|
|
3267
|
-
country: data.country,
|
|
3268
|
-
currency: data.currency,
|
|
3269
|
-
total: {
|
|
3270
|
-
label: totalLabel?.trim() || 'Total',
|
|
3271
|
-
amount: data.amount,
|
|
3272
|
-
},
|
|
3273
|
-
requestPayerName: false,
|
|
3274
|
-
requestPayerEmail: false,
|
|
3275
|
-
applePay,
|
|
3276
|
-
});
|
|
3277
|
-
}
|
|
3278
|
-
async function getAvailableWallet(session) {
|
|
3279
|
-
const { stripe_public_key } = session.data;
|
|
3280
|
-
const stripe = await getStripe(stripe_public_key);
|
|
3281
|
-
if (!stripe)
|
|
3282
|
-
throw new Error('Failed to load Stripe');
|
|
3283
|
-
const paymentRequest = buildPaymentRequest(stripe, session.data);
|
|
3284
|
-
const result = await paymentRequest.canMakePayment();
|
|
3285
|
-
if (!result)
|
|
3286
|
-
return null;
|
|
3287
|
-
if (result.applePay)
|
|
3288
|
-
return 'APPLE_PAY';
|
|
3289
|
-
if (result.googlePay)
|
|
3290
|
-
return 'GOOGLE_PAY';
|
|
3291
|
-
return null;
|
|
3292
|
-
}
|
|
3293
|
-
async function purchaseWallet(session, params) {
|
|
3294
|
-
const { stripe_public_key, order_id } = session.data;
|
|
3295
|
-
const stripe = await getStripe(stripe_public_key);
|
|
3296
|
-
if (!stripe)
|
|
3297
|
-
throw new Error('Failed to load Stripe');
|
|
3298
|
-
const paymentRequest = buildPaymentRequest(stripe, session.data, params.totalLabel);
|
|
3299
|
-
const canPay = await paymentRequest.canMakePayment();
|
|
3300
|
-
if (!canPay)
|
|
3301
|
-
throw new Error('No wallet payment method available');
|
|
3302
|
-
return new Promise((resolve, reject) => {
|
|
3303
|
-
paymentRequest.on('paymentmethod', async (event) => {
|
|
3304
|
-
params.onLoaderChange?.(true);
|
|
3305
|
-
try {
|
|
3306
|
-
const raw = await params.apiClient.createPayment({
|
|
3307
|
-
orderId: order_id,
|
|
3308
|
-
paymentMethodToken: event.paymentMethod.id,
|
|
3309
|
-
email: params.email,
|
|
3310
|
-
countryCode: params.countryCode,
|
|
3311
|
-
clientMetadata: params.clientMetadata,
|
|
3312
|
-
});
|
|
3313
|
-
const result = params.apiClient.processPaymentResponse(raw);
|
|
3314
|
-
if (result.type === 'action_required') {
|
|
3315
|
-
const { error } = await stripe.handleNextAction({
|
|
3316
|
-
clientSecret: result.clientToken,
|
|
3317
|
-
});
|
|
3318
|
-
if (error) {
|
|
3319
|
-
event.complete('fail');
|
|
3320
|
-
throw error;
|
|
3321
|
-
}
|
|
3322
|
-
}
|
|
3323
|
-
event.complete('success');
|
|
3324
|
-
params.onPaymentSuccess?.(event.paymentMethod, order_id);
|
|
3325
|
-
resolve();
|
|
3326
|
-
}
|
|
3327
|
-
catch (err) {
|
|
3328
|
-
event.complete('fail');
|
|
3329
|
-
params.onPaymentFail?.(err);
|
|
3330
|
-
reject(err);
|
|
3331
|
-
}
|
|
3332
|
-
finally {
|
|
3333
|
-
params.onLoaderChange?.(false);
|
|
3334
|
-
}
|
|
3335
|
-
});
|
|
3336
|
-
paymentRequest.on('cancel', () => {
|
|
3337
|
-
params.onPaymentCancel?.();
|
|
3338
|
-
resolve();
|
|
3339
|
-
});
|
|
3340
|
-
paymentRequest.show();
|
|
3341
|
-
});
|
|
3342
|
-
}
|
|
3343
|
-
|
|
3344
|
-
var stripeWallet = /*#__PURE__*/Object.freeze({
|
|
3345
|
-
__proto__: null,
|
|
3346
|
-
getAvailableWallet: getAvailableWallet,
|
|
3347
|
-
purchaseWallet: purchaseWallet
|
|
3348
|
-
});
|
|
3349
|
-
|
|
3350
3073
|
exports.APIError = APIError;
|
|
3351
3074
|
exports.Billing = Billing;
|
|
3352
3075
|
exports.CHECKOUT_STATES = CHECKOUT_STATES;
|