@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
package/src/types.d.ts
CHANGED
|
@@ -284,42 +284,7 @@ export interface CreateClientSessionOptions {
|
|
|
284
284
|
apiConfig?: APIConfig;
|
|
285
285
|
clientMetadata?: MetadataType;
|
|
286
286
|
countryCode?: string;
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
export type StripeClientSessionResponse = Omit<
|
|
291
|
-
CreateClientSessionResponse,
|
|
292
|
-
'data'
|
|
293
|
-
> & {
|
|
294
|
-
data: CreateClientSessionResponse['data'] & {
|
|
295
|
-
stripe_public_key: string;
|
|
296
|
-
amount: number;
|
|
297
|
-
currency: string;
|
|
298
|
-
country: string;
|
|
299
|
-
is_link_enabled?: boolean;
|
|
300
|
-
apple_pay_recurring_payment_request?: {
|
|
301
|
-
paymentDescription: string;
|
|
302
|
-
managementURL: string;
|
|
303
|
-
billingAgreement?: string;
|
|
304
|
-
regularBilling: {
|
|
305
|
-
label: string;
|
|
306
|
-
amount: number;
|
|
307
|
-
recurringPaymentIntervalUnit: string;
|
|
308
|
-
recurringPaymentIntervalCount: number;
|
|
309
|
-
recurringPaymentStartDate?: string;
|
|
310
|
-
recurringPaymentEndDate?: string;
|
|
311
|
-
};
|
|
312
|
-
trialBilling?: {
|
|
313
|
-
label: string;
|
|
314
|
-
amount: number;
|
|
315
|
-
recurringPaymentIntervalUnit: string;
|
|
316
|
-
recurringPaymentIntervalCount: number;
|
|
317
|
-
recurringPaymentStartDate?: string;
|
|
318
|
-
recurringPaymentEndDate?: string;
|
|
319
|
-
};
|
|
320
|
-
} | null;
|
|
321
|
-
};
|
|
322
|
-
};
|
|
287
|
+
}
|
|
323
288
|
|
|
324
289
|
export interface ClientSessionData {
|
|
325
290
|
clientToken: string;
|
|
@@ -383,51 +348,6 @@ export declare function getAvailablePaymentMethods(params: {
|
|
|
383
348
|
orgId: string;
|
|
384
349
|
baseUrl: string;
|
|
385
350
|
}): Promise<PaymentMethod[]>;
|
|
386
|
-
|
|
387
|
-
export interface StripeCardFormOptions
|
|
388
|
-
extends
|
|
389
|
-
CreateClientSessionOptions,
|
|
390
|
-
Omit<InitMethodCallbacks, 'onPaymentSuccess'> {
|
|
391
|
-
onPaymentSuccess?: (
|
|
392
|
-
paymentMethod: import('@stripe/stripe-js').PaymentMethod,
|
|
393
|
-
orderId: string
|
|
394
|
-
) => void;
|
|
395
|
-
appearance?: import('@stripe/stripe-js').Appearance;
|
|
396
|
-
showWallets?: boolean;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
export interface StripeWalletOptions
|
|
400
|
-
extends
|
|
401
|
-
CreateClientSessionOptions,
|
|
402
|
-
Omit<InitMethodCallbacks, 'onPaymentSuccess'> {
|
|
403
|
-
onPaymentSuccess?: (
|
|
404
|
-
paymentMethod: import('@stripe/stripe-js').PaymentMethod,
|
|
405
|
-
orderId: string
|
|
406
|
-
) => void;
|
|
407
|
-
totalLabel?: string;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
export interface StripeCardForm {
|
|
411
|
-
submit: () => Promise<void>;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
export declare function createStripeCardForm(
|
|
415
|
-
element: HTMLElement,
|
|
416
|
-
params: StripeCardFormOptions
|
|
417
|
-
): Promise<StripeCardForm>;
|
|
418
|
-
|
|
419
|
-
export declare function purchaseStripeWallet(
|
|
420
|
-
params: StripeWalletOptions
|
|
421
|
-
): Promise<void>;
|
|
422
|
-
|
|
423
|
-
export declare function getAvailableStripeWallet(
|
|
424
|
-
params: CreateClientSessionOptions
|
|
425
|
-
): Promise<PaymentMethod.APPLE_PAY | PaymentMethod.GOOGLE_PAY | null>;
|
|
426
|
-
|
|
427
|
-
export declare function getAvailableStripePaymentMethods(
|
|
428
|
-
params: CreateClientSessionOptions
|
|
429
|
-
): Promise<PaymentMethod[]>;
|
|
430
|
-
|
|
431
351
|
// Billing namespace
|
|
432
352
|
export declare const Billing: {
|
|
433
353
|
configure: typeof configure;
|
|
@@ -436,12 +356,6 @@ export declare const Billing: {
|
|
|
436
356
|
initMethod: typeof initMethod;
|
|
437
357
|
silentPurchase: typeof silentPurchase;
|
|
438
358
|
getAvailablePaymentMethods: typeof getAvailablePaymentMethods;
|
|
439
|
-
stripe: {
|
|
440
|
-
createCardForm: typeof createStripeCardForm;
|
|
441
|
-
purchaseWallet: typeof purchaseStripeWallet;
|
|
442
|
-
getAvailableWallet: typeof getAvailableStripeWallet;
|
|
443
|
-
getAvailablePaymentMethods: typeof getAvailableStripePaymentMethods;
|
|
444
|
-
};
|
|
445
359
|
};
|
|
446
360
|
|
|
447
361
|
// Constants
|
|
@@ -496,13 +410,6 @@ export interface CreateClientSessionResponse {
|
|
|
496
410
|
client_token: string;
|
|
497
411
|
order_id: string;
|
|
498
412
|
stripe_public_key?: string;
|
|
499
|
-
stripe_intent?: {
|
|
500
|
-
intent_client_secret: string;
|
|
501
|
-
customer_session_client_secret: string;
|
|
502
|
-
amount?: number;
|
|
503
|
-
currency?: string;
|
|
504
|
-
country?: string;
|
|
505
|
-
};
|
|
506
413
|
collect_apple_pay_email?: boolean;
|
|
507
414
|
show_email_field?: boolean;
|
|
508
415
|
show_cardholder_name_field?: boolean; //true
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @funnelfox/billing v0.1.0
|
|
3
|
-
* JavaScript SDK for Funnelfox billing with Primer integration
|
|
4
|
-
*
|
|
5
|
-
* @author Funnelfox
|
|
6
|
-
* @license MIT
|
|
7
|
-
*/
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
var stripeLoader = require('./chunk-stripe-loader.cjs.js');
|
|
11
|
-
require('./chunk-index.cjs.js');
|
|
12
|
-
|
|
13
|
-
async function mountStripeCardForm(element, session, params) {
|
|
14
|
-
const { stripe_public_key, amount, currency, order_id, is_link_enabled } = session.data;
|
|
15
|
-
const stripe = await stripeLoader.getStripe(stripe_public_key);
|
|
16
|
-
if (!stripe)
|
|
17
|
-
throw new Error('Failed to load Stripe');
|
|
18
|
-
const stripeElements = stripe.elements({
|
|
19
|
-
mode: 'subscription',
|
|
20
|
-
amount,
|
|
21
|
-
currency,
|
|
22
|
-
paymentMethodCreation: 'manual',
|
|
23
|
-
paymentMethodTypes: is_link_enabled ? ['card', 'link'] : ['card'],
|
|
24
|
-
appearance: params.appearance,
|
|
25
|
-
});
|
|
26
|
-
const paymentElement = stripeElements.create('payment', {
|
|
27
|
-
layout: 'tabs',
|
|
28
|
-
wallets: {
|
|
29
|
-
applePay: params.showWallets ? 'auto' : 'never',
|
|
30
|
-
googlePay: params.showWallets ? 'auto' : 'never',
|
|
31
|
-
},
|
|
32
|
-
terms: { card: 'never' },
|
|
33
|
-
});
|
|
34
|
-
paymentElement.mount(element);
|
|
35
|
-
await new Promise((resolve, reject) => {
|
|
36
|
-
paymentElement.once('ready', () => resolve());
|
|
37
|
-
// 'loaderror' is a valid Stripe event but not yet in the @stripe/stripe-js types
|
|
38
|
-
paymentElement.once('loaderror', e => reject(e.error));
|
|
39
|
-
});
|
|
40
|
-
params.onRenderSuccess?.();
|
|
41
|
-
return {
|
|
42
|
-
submit: async () => {
|
|
43
|
-
params.onLoaderChange?.(true);
|
|
44
|
-
try {
|
|
45
|
-
const { error: submitError } = await stripeElements.submit();
|
|
46
|
-
if (submitError)
|
|
47
|
-
throw submitError;
|
|
48
|
-
const { error, paymentMethod } = await stripe.createPaymentMethod({
|
|
49
|
-
elements: stripeElements,
|
|
50
|
-
});
|
|
51
|
-
if (error)
|
|
52
|
-
throw error;
|
|
53
|
-
const raw = await params.apiClient.createPayment({
|
|
54
|
-
orderId: order_id,
|
|
55
|
-
paymentMethodToken: paymentMethod.id,
|
|
56
|
-
email: params.email,
|
|
57
|
-
countryCode: params.countryCode,
|
|
58
|
-
clientMetadata: params.clientMetadata,
|
|
59
|
-
});
|
|
60
|
-
const result = params.apiClient.processPaymentResponse(raw);
|
|
61
|
-
if (result.type === 'action_required') {
|
|
62
|
-
const { error: actionError } = await stripe.handleNextAction({
|
|
63
|
-
clientSecret: result.clientToken,
|
|
64
|
-
});
|
|
65
|
-
if (actionError)
|
|
66
|
-
throw actionError;
|
|
67
|
-
}
|
|
68
|
-
params.onPaymentSuccess?.(paymentMethod, order_id);
|
|
69
|
-
}
|
|
70
|
-
catch (err) {
|
|
71
|
-
params.onPaymentFail?.(err);
|
|
72
|
-
throw err;
|
|
73
|
-
}
|
|
74
|
-
finally {
|
|
75
|
-
params.onLoaderChange?.(false);
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
exports.mountStripeCardForm = mountStripeCardForm;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @funnelfox/billing v0.1.0
|
|
3
|
-
* JavaScript SDK for Funnelfox billing with Primer integration
|
|
4
|
-
*
|
|
5
|
-
* @author Funnelfox
|
|
6
|
-
* @license MIT
|
|
7
|
-
*/
|
|
8
|
-
import { g as getStripe } from './chunk-stripe-loader.es.js';
|
|
9
|
-
import './chunk-index.es.js';
|
|
10
|
-
|
|
11
|
-
async function mountStripeCardForm(element, session, params) {
|
|
12
|
-
const { stripe_public_key, amount, currency, order_id, is_link_enabled } = session.data;
|
|
13
|
-
const stripe = await getStripe(stripe_public_key);
|
|
14
|
-
if (!stripe)
|
|
15
|
-
throw new Error('Failed to load Stripe');
|
|
16
|
-
const stripeElements = stripe.elements({
|
|
17
|
-
mode: 'subscription',
|
|
18
|
-
amount,
|
|
19
|
-
currency,
|
|
20
|
-
paymentMethodCreation: 'manual',
|
|
21
|
-
paymentMethodTypes: is_link_enabled ? ['card', 'link'] : ['card'],
|
|
22
|
-
appearance: params.appearance,
|
|
23
|
-
});
|
|
24
|
-
const paymentElement = stripeElements.create('payment', {
|
|
25
|
-
layout: 'tabs',
|
|
26
|
-
wallets: {
|
|
27
|
-
applePay: params.showWallets ? 'auto' : 'never',
|
|
28
|
-
googlePay: params.showWallets ? 'auto' : 'never',
|
|
29
|
-
},
|
|
30
|
-
terms: { card: 'never' },
|
|
31
|
-
});
|
|
32
|
-
paymentElement.mount(element);
|
|
33
|
-
await new Promise((resolve, reject) => {
|
|
34
|
-
paymentElement.once('ready', () => resolve());
|
|
35
|
-
// 'loaderror' is a valid Stripe event but not yet in the @stripe/stripe-js types
|
|
36
|
-
paymentElement.once('loaderror', e => reject(e.error));
|
|
37
|
-
});
|
|
38
|
-
params.onRenderSuccess?.();
|
|
39
|
-
return {
|
|
40
|
-
submit: async () => {
|
|
41
|
-
params.onLoaderChange?.(true);
|
|
42
|
-
try {
|
|
43
|
-
const { error: submitError } = await stripeElements.submit();
|
|
44
|
-
if (submitError)
|
|
45
|
-
throw submitError;
|
|
46
|
-
const { error, paymentMethod } = await stripe.createPaymentMethod({
|
|
47
|
-
elements: stripeElements,
|
|
48
|
-
});
|
|
49
|
-
if (error)
|
|
50
|
-
throw error;
|
|
51
|
-
const raw = await params.apiClient.createPayment({
|
|
52
|
-
orderId: order_id,
|
|
53
|
-
paymentMethodToken: paymentMethod.id,
|
|
54
|
-
email: params.email,
|
|
55
|
-
countryCode: params.countryCode,
|
|
56
|
-
clientMetadata: params.clientMetadata,
|
|
57
|
-
});
|
|
58
|
-
const result = params.apiClient.processPaymentResponse(raw);
|
|
59
|
-
if (result.type === 'action_required') {
|
|
60
|
-
const { error: actionError } = await stripe.handleNextAction({
|
|
61
|
-
clientSecret: result.clientToken,
|
|
62
|
-
});
|
|
63
|
-
if (actionError)
|
|
64
|
-
throw actionError;
|
|
65
|
-
}
|
|
66
|
-
params.onPaymentSuccess?.(paymentMethod, order_id);
|
|
67
|
-
}
|
|
68
|
-
catch (err) {
|
|
69
|
-
params.onPaymentFail?.(err);
|
|
70
|
-
throw err;
|
|
71
|
-
}
|
|
72
|
-
finally {
|
|
73
|
-
params.onLoaderChange?.(false);
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export { mountStripeCardForm };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @funnelfox/billing v0.1.0
|
|
3
|
-
* JavaScript SDK for Funnelfox billing with Primer integration
|
|
4
|
-
*
|
|
5
|
-
* @author Funnelfox
|
|
6
|
-
* @license MIT
|
|
7
|
-
*/
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
var index = require('./chunk-index.cjs.js');
|
|
11
|
-
|
|
12
|
-
const cache = new Map();
|
|
13
|
-
function getStripe(publicKey) {
|
|
14
|
-
if (!cache.has(publicKey)) {
|
|
15
|
-
cache.set(publicKey, index.loadStripe(publicKey));
|
|
16
|
-
}
|
|
17
|
-
return cache.get(publicKey);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
exports.getStripe = getStripe;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @funnelfox/billing v0.1.0
|
|
3
|
-
* JavaScript SDK for Funnelfox billing with Primer integration
|
|
4
|
-
*
|
|
5
|
-
* @author Funnelfox
|
|
6
|
-
* @license MIT
|
|
7
|
-
*/
|
|
8
|
-
import { l as loadStripe } from './chunk-index.es.js';
|
|
9
|
-
|
|
10
|
-
const cache = new Map();
|
|
11
|
-
function getStripe(publicKey) {
|
|
12
|
-
if (!cache.has(publicKey)) {
|
|
13
|
-
cache.set(publicKey, loadStripe(publicKey));
|
|
14
|
-
}
|
|
15
|
-
return cache.get(publicKey);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { getStripe as g };
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @funnelfox/billing v0.1.0
|
|
3
|
-
* JavaScript SDK for Funnelfox billing with Primer integration
|
|
4
|
-
*
|
|
5
|
-
* @author Funnelfox
|
|
6
|
-
* @license MIT
|
|
7
|
-
*/
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
var stripeLoader = require('./chunk-stripe-loader.cjs.js');
|
|
11
|
-
require('./chunk-index.cjs.js');
|
|
12
|
-
|
|
13
|
-
function buildPaymentRequest(stripe, data, totalLabel) {
|
|
14
|
-
const raw = data.apple_pay_recurring_payment_request;
|
|
15
|
-
if (raw) {
|
|
16
|
-
const parseDates = (b) => {
|
|
17
|
-
if (b.recurringPaymentStartDate)
|
|
18
|
-
Object.assign(b, {
|
|
19
|
-
recurringPaymentStartDate: new Date(b.recurringPaymentStartDate),
|
|
20
|
-
});
|
|
21
|
-
if (b.recurringPaymentEndDate)
|
|
22
|
-
Object.assign(b, {
|
|
23
|
-
recurringPaymentEndDate: new Date(b.recurringPaymentEndDate),
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
parseDates(raw.regularBilling);
|
|
27
|
-
if (raw.trialBilling)
|
|
28
|
-
parseDates(raw.trialBilling);
|
|
29
|
-
}
|
|
30
|
-
const applePay = raw
|
|
31
|
-
? { recurringPaymentRequest: raw }
|
|
32
|
-
: undefined;
|
|
33
|
-
return stripe.paymentRequest({
|
|
34
|
-
country: data.country,
|
|
35
|
-
currency: data.currency,
|
|
36
|
-
total: {
|
|
37
|
-
label: totalLabel?.trim() || 'Total',
|
|
38
|
-
amount: data.amount,
|
|
39
|
-
},
|
|
40
|
-
requestPayerName: false,
|
|
41
|
-
requestPayerEmail: false,
|
|
42
|
-
applePay,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
async function getAvailableWallet(session) {
|
|
46
|
-
const { stripe_public_key } = session.data;
|
|
47
|
-
const stripe = await stripeLoader.getStripe(stripe_public_key);
|
|
48
|
-
if (!stripe)
|
|
49
|
-
throw new Error('Failed to load Stripe');
|
|
50
|
-
const paymentRequest = buildPaymentRequest(stripe, session.data);
|
|
51
|
-
const result = await paymentRequest.canMakePayment();
|
|
52
|
-
if (!result)
|
|
53
|
-
return null;
|
|
54
|
-
if (result.applePay)
|
|
55
|
-
return 'APPLE_PAY';
|
|
56
|
-
if (result.googlePay)
|
|
57
|
-
return 'GOOGLE_PAY';
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
async function purchaseWallet(session, params) {
|
|
61
|
-
const { stripe_public_key, order_id } = session.data;
|
|
62
|
-
const stripe = await stripeLoader.getStripe(stripe_public_key);
|
|
63
|
-
if (!stripe)
|
|
64
|
-
throw new Error('Failed to load Stripe');
|
|
65
|
-
const paymentRequest = buildPaymentRequest(stripe, session.data, params.totalLabel);
|
|
66
|
-
const canPay = await paymentRequest.canMakePayment();
|
|
67
|
-
if (!canPay)
|
|
68
|
-
throw new Error('No wallet payment method available');
|
|
69
|
-
return new Promise((resolve, reject) => {
|
|
70
|
-
paymentRequest.on('paymentmethod', async (event) => {
|
|
71
|
-
params.onLoaderChange?.(true);
|
|
72
|
-
try {
|
|
73
|
-
const raw = await params.apiClient.createPayment({
|
|
74
|
-
orderId: order_id,
|
|
75
|
-
paymentMethodToken: event.paymentMethod.id,
|
|
76
|
-
email: params.email,
|
|
77
|
-
countryCode: params.countryCode,
|
|
78
|
-
clientMetadata: params.clientMetadata,
|
|
79
|
-
});
|
|
80
|
-
const result = params.apiClient.processPaymentResponse(raw);
|
|
81
|
-
if (result.type === 'action_required') {
|
|
82
|
-
const { error } = await stripe.handleNextAction({
|
|
83
|
-
clientSecret: result.clientToken,
|
|
84
|
-
});
|
|
85
|
-
if (error) {
|
|
86
|
-
event.complete('fail');
|
|
87
|
-
throw error;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
event.complete('success');
|
|
91
|
-
params.onPaymentSuccess?.(event.paymentMethod, order_id);
|
|
92
|
-
resolve();
|
|
93
|
-
}
|
|
94
|
-
catch (err) {
|
|
95
|
-
event.complete('fail');
|
|
96
|
-
params.onPaymentFail?.(err);
|
|
97
|
-
reject(err);
|
|
98
|
-
}
|
|
99
|
-
finally {
|
|
100
|
-
params.onLoaderChange?.(false);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
paymentRequest.on('cancel', () => {
|
|
104
|
-
params.onPaymentCancel?.();
|
|
105
|
-
resolve();
|
|
106
|
-
});
|
|
107
|
-
paymentRequest.show();
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
exports.getAvailableWallet = getAvailableWallet;
|
|
112
|
-
exports.purchaseWallet = purchaseWallet;
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @funnelfox/billing v0.1.0
|
|
3
|
-
* JavaScript SDK for Funnelfox billing with Primer integration
|
|
4
|
-
*
|
|
5
|
-
* @author Funnelfox
|
|
6
|
-
* @license MIT
|
|
7
|
-
*/
|
|
8
|
-
import { g as getStripe } from './chunk-stripe-loader.es.js';
|
|
9
|
-
import './chunk-index.es.js';
|
|
10
|
-
|
|
11
|
-
function buildPaymentRequest(stripe, data, totalLabel) {
|
|
12
|
-
const raw = data.apple_pay_recurring_payment_request;
|
|
13
|
-
if (raw) {
|
|
14
|
-
const parseDates = (b) => {
|
|
15
|
-
if (b.recurringPaymentStartDate)
|
|
16
|
-
Object.assign(b, {
|
|
17
|
-
recurringPaymentStartDate: new Date(b.recurringPaymentStartDate),
|
|
18
|
-
});
|
|
19
|
-
if (b.recurringPaymentEndDate)
|
|
20
|
-
Object.assign(b, {
|
|
21
|
-
recurringPaymentEndDate: new Date(b.recurringPaymentEndDate),
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
parseDates(raw.regularBilling);
|
|
25
|
-
if (raw.trialBilling)
|
|
26
|
-
parseDates(raw.trialBilling);
|
|
27
|
-
}
|
|
28
|
-
const applePay = raw
|
|
29
|
-
? { recurringPaymentRequest: raw }
|
|
30
|
-
: undefined;
|
|
31
|
-
return stripe.paymentRequest({
|
|
32
|
-
country: data.country,
|
|
33
|
-
currency: data.currency,
|
|
34
|
-
total: {
|
|
35
|
-
label: totalLabel?.trim() || 'Total',
|
|
36
|
-
amount: data.amount,
|
|
37
|
-
},
|
|
38
|
-
requestPayerName: false,
|
|
39
|
-
requestPayerEmail: false,
|
|
40
|
-
applePay,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
async function getAvailableWallet(session) {
|
|
44
|
-
const { stripe_public_key } = session.data;
|
|
45
|
-
const stripe = await getStripe(stripe_public_key);
|
|
46
|
-
if (!stripe)
|
|
47
|
-
throw new Error('Failed to load Stripe');
|
|
48
|
-
const paymentRequest = buildPaymentRequest(stripe, session.data);
|
|
49
|
-
const result = await paymentRequest.canMakePayment();
|
|
50
|
-
if (!result)
|
|
51
|
-
return null;
|
|
52
|
-
if (result.applePay)
|
|
53
|
-
return 'APPLE_PAY';
|
|
54
|
-
if (result.googlePay)
|
|
55
|
-
return 'GOOGLE_PAY';
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
async function purchaseWallet(session, params) {
|
|
59
|
-
const { stripe_public_key, order_id } = session.data;
|
|
60
|
-
const stripe = await getStripe(stripe_public_key);
|
|
61
|
-
if (!stripe)
|
|
62
|
-
throw new Error('Failed to load Stripe');
|
|
63
|
-
const paymentRequest = buildPaymentRequest(stripe, session.data, params.totalLabel);
|
|
64
|
-
const canPay = await paymentRequest.canMakePayment();
|
|
65
|
-
if (!canPay)
|
|
66
|
-
throw new Error('No wallet payment method available');
|
|
67
|
-
return new Promise((resolve, reject) => {
|
|
68
|
-
paymentRequest.on('paymentmethod', async (event) => {
|
|
69
|
-
params.onLoaderChange?.(true);
|
|
70
|
-
try {
|
|
71
|
-
const raw = await params.apiClient.createPayment({
|
|
72
|
-
orderId: order_id,
|
|
73
|
-
paymentMethodToken: event.paymentMethod.id,
|
|
74
|
-
email: params.email,
|
|
75
|
-
countryCode: params.countryCode,
|
|
76
|
-
clientMetadata: params.clientMetadata,
|
|
77
|
-
});
|
|
78
|
-
const result = params.apiClient.processPaymentResponse(raw);
|
|
79
|
-
if (result.type === 'action_required') {
|
|
80
|
-
const { error } = await stripe.handleNextAction({
|
|
81
|
-
clientSecret: result.clientToken,
|
|
82
|
-
});
|
|
83
|
-
if (error) {
|
|
84
|
-
event.complete('fail');
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
event.complete('success');
|
|
89
|
-
params.onPaymentSuccess?.(event.paymentMethod, order_id);
|
|
90
|
-
resolve();
|
|
91
|
-
}
|
|
92
|
-
catch (err) {
|
|
93
|
-
event.complete('fail');
|
|
94
|
-
params.onPaymentFail?.(err);
|
|
95
|
-
reject(err);
|
|
96
|
-
}
|
|
97
|
-
finally {
|
|
98
|
-
params.onLoaderChange?.(false);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
paymentRequest.on('cancel', () => {
|
|
102
|
-
params.onPaymentCancel?.();
|
|
103
|
-
resolve();
|
|
104
|
-
});
|
|
105
|
-
paymentRequest.show();
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export { getAvailableWallet, purchaseWallet };
|