@funnelfox/billing 0.4.4 → 0.4.6
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 +36 -0
- package/dist/chunk-index.cjs.js +35 -7
- package/dist/chunk-index.es.js +35 -7
- package/dist/funnelfox-billing.cjs.js +35 -15
- package/dist/funnelfox-billing.esm.js +24 -4
- package/dist/funnelfox-billing.js +68 -22
- package/dist/funnelfox-billing.min.js +1 -1
- package/package.json +2 -2
- package/src/types.d.ts +2 -0
|
@@ -206,18 +206,18 @@ function withTimeout(promise, timeoutMs, message = 'Operation timed out') {
|
|
|
206
206
|
return Promise.race([promise, timeoutPromise]);
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
|
|
209
|
+
exports.PaymentMethod = void 0;
|
|
210
210
|
(function (PaymentMethod) {
|
|
211
211
|
PaymentMethod["GOOGLE_PAY"] = "GOOGLE_PAY";
|
|
212
212
|
PaymentMethod["APPLE_PAY"] = "APPLE_PAY";
|
|
213
213
|
PaymentMethod["PAYPAL"] = "PAYPAL";
|
|
214
214
|
PaymentMethod["PAYMENT_CARD"] = "PAYMENT_CARD";
|
|
215
|
-
})(PaymentMethod || (PaymentMethod = {}));
|
|
215
|
+
})(exports.PaymentMethod || (exports.PaymentMethod = {}));
|
|
216
216
|
|
|
217
217
|
/**
|
|
218
218
|
* @fileoverview Constants for Funnefox SDK
|
|
219
219
|
*/
|
|
220
|
-
const SDK_VERSION = '0.4.
|
|
220
|
+
const SDK_VERSION = '0.4.6';
|
|
221
221
|
const DEFAULTS = {
|
|
222
222
|
BASE_URL: 'https://billing.funnelfox.com',
|
|
223
223
|
REGION: 'default',
|
|
@@ -247,6 +247,7 @@ const EVENTS = {
|
|
|
247
247
|
START_PURCHASE: 'start-purchase',
|
|
248
248
|
PURCHASE_FAILURE: 'purchase-failure',
|
|
249
249
|
PURCHASE_COMPLETED: 'purchase-completed',
|
|
250
|
+
METHODS_AVAILABLE: 'methods-available',
|
|
250
251
|
};
|
|
251
252
|
const API_ENDPOINTS = {
|
|
252
253
|
CREATE_CLIENT_SESSION: '/v1/checkout/create_client_session',
|
|
@@ -264,12 +265,12 @@ const ERROR_CODES = {
|
|
|
264
265
|
NETWORK_ERROR: 'NETWORK_ERROR',
|
|
265
266
|
};
|
|
266
267
|
const ALLOWED_BUTTON_PAYMENT_METHODS = [
|
|
267
|
-
PaymentMethod.GOOGLE_PAY,
|
|
268
|
-
PaymentMethod.APPLE_PAY,
|
|
269
|
-
PaymentMethod.PAYPAL,
|
|
268
|
+
exports.PaymentMethod.GOOGLE_PAY,
|
|
269
|
+
exports.PaymentMethod.APPLE_PAY,
|
|
270
|
+
exports.PaymentMethod.PAYPAL,
|
|
270
271
|
];
|
|
271
272
|
const ALLOWED_CARD_PAYMENT_METHODS = [
|
|
272
|
-
PaymentMethod.PAYMENT_CARD,
|
|
273
|
+
exports.PaymentMethod.PAYMENT_CARD,
|
|
273
274
|
];
|
|
274
275
|
const ALLOWED_PAYMENT_METHODS = [
|
|
275
276
|
...ALLOWED_BUTTON_PAYMENT_METHODS,
|
|
@@ -458,7 +459,7 @@ class PrimerWrapper {
|
|
|
458
459
|
}
|
|
459
460
|
}
|
|
460
461
|
async renderCheckout(clientToken, options) {
|
|
461
|
-
const { cardSelectors, paymentButtonSelectors, container, onTokenizeSuccess, onResumeSuccess, onSubmit, onInputChange, onMethodRender, ...restPrimerOptions } = options;
|
|
462
|
+
const { cardSelectors, paymentButtonSelectors, container, onTokenizeSuccess, onResumeSuccess, onSubmit, onInputChange, onMethodRender, onMethodsAvailable, ...restPrimerOptions } = options;
|
|
462
463
|
await this.createHeadlessCheckout(clientToken, {
|
|
463
464
|
...restPrimerOptions,
|
|
464
465
|
onTokenizeSuccess: this.wrapTokenizeHandler(onTokenizeSuccess),
|
|
@@ -467,18 +468,19 @@ class PrimerWrapper {
|
|
|
467
468
|
let isApplePayAvailable = false;
|
|
468
469
|
this.availableMethods = ALLOWED_PAYMENT_METHODS.filter(method => {
|
|
469
470
|
return items.some((item) => {
|
|
470
|
-
if (item.type === PaymentMethod.APPLE_PAY) {
|
|
471
|
+
if (item.type === exports.PaymentMethod.APPLE_PAY) {
|
|
471
472
|
isApplePayAvailable = true;
|
|
472
473
|
}
|
|
473
474
|
return item.type === method;
|
|
474
475
|
});
|
|
475
476
|
});
|
|
476
477
|
if (isApplePayAvailable) {
|
|
477
|
-
this.availableMethods = this.availableMethods.filter(method => method !== PaymentMethod.GOOGLE_PAY);
|
|
478
|
+
this.availableMethods = this.availableMethods.filter(method => method !== exports.PaymentMethod.GOOGLE_PAY);
|
|
478
479
|
}
|
|
479
480
|
if (this.availableMethods.length === 0) {
|
|
480
481
|
throw new PrimerError('No allowed payment methods found');
|
|
481
482
|
}
|
|
483
|
+
onMethodsAvailable(this.availableMethods);
|
|
482
484
|
},
|
|
483
485
|
});
|
|
484
486
|
const methodOptions = {
|
|
@@ -488,14 +490,14 @@ class PrimerWrapper {
|
|
|
488
490
|
onInputChange,
|
|
489
491
|
};
|
|
490
492
|
for (const method of this.availableMethods) {
|
|
491
|
-
if (method === PaymentMethod.PAYMENT_CARD) {
|
|
493
|
+
if (method === exports.PaymentMethod.PAYMENT_CARD) {
|
|
492
494
|
await this.renderCardCheckout(methodOptions);
|
|
493
|
-
onMethodRender(PaymentMethod.PAYMENT_CARD);
|
|
495
|
+
onMethodRender(exports.PaymentMethod.PAYMENT_CARD);
|
|
494
496
|
}
|
|
495
497
|
else {
|
|
496
|
-
const container = method === PaymentMethod.PAYPAL
|
|
498
|
+
const container = method === exports.PaymentMethod.PAYPAL
|
|
497
499
|
? paymentButtonSelectors.paypal
|
|
498
|
-
: method === PaymentMethod.GOOGLE_PAY
|
|
500
|
+
: method === exports.PaymentMethod.GOOGLE_PAY
|
|
499
501
|
? paymentButtonSelectors.googlePay
|
|
500
502
|
: paymentButtonSelectors.applePay;
|
|
501
503
|
await this.renderButton(method, { container });
|
|
@@ -791,6 +793,12 @@ class CheckoutInstance extends EventEmitter {
|
|
|
791
793
|
constructor(config) {
|
|
792
794
|
super();
|
|
793
795
|
this.counter = 0;
|
|
796
|
+
this.paymentMethodOrder = [
|
|
797
|
+
exports.PaymentMethod.APPLE_PAY,
|
|
798
|
+
exports.PaymentMethod.GOOGLE_PAY,
|
|
799
|
+
exports.PaymentMethod.PAYPAL,
|
|
800
|
+
exports.PaymentMethod.PAYMENT_CARD,
|
|
801
|
+
];
|
|
794
802
|
this.handleInputChange = (inputName, error) => {
|
|
795
803
|
this.emit(EVENTS.INPUT_ERROR, { name: inputName, error });
|
|
796
804
|
};
|
|
@@ -844,6 +852,9 @@ class CheckoutInstance extends EventEmitter {
|
|
|
844
852
|
this._setState('ready');
|
|
845
853
|
}
|
|
846
854
|
};
|
|
855
|
+
this.handleMethodsAvailable = (methods) => {
|
|
856
|
+
this.emit(EVENTS.METHODS_AVAILABLE, methods);
|
|
857
|
+
};
|
|
847
858
|
this.onLoaderChangeWithRace = (state) => {
|
|
848
859
|
const isLoading = !!(state ? ++this.counter : --this.counter);
|
|
849
860
|
this.emit(EVENTS.LOADER_CHANGE, isLoading);
|
|
@@ -932,6 +943,7 @@ class CheckoutInstance extends EventEmitter {
|
|
|
932
943
|
onSubmit: this.handleSubmit,
|
|
933
944
|
onInputChange: this.handleInputChange,
|
|
934
945
|
onMethodRender: this.handleMethodRender,
|
|
946
|
+
onMethodsAvailable: this.handleMethodsAvailable,
|
|
935
947
|
onResumeError: error => {
|
|
936
948
|
if (error.stack?.includes('PROCESSOR_3DS') &&
|
|
937
949
|
error.code === 'RESUME_ERROR' &&
|
|
@@ -955,9 +967,16 @@ class CheckoutInstance extends EventEmitter {
|
|
|
955
967
|
};
|
|
956
968
|
if (!this.checkoutConfig.cardSelectors ||
|
|
957
969
|
!this.checkoutConfig.paymentButtonSelectors) {
|
|
970
|
+
if (this.checkoutConfig.paymentMethodOrder) {
|
|
971
|
+
this.paymentMethodOrder = this.checkoutConfig.paymentMethodOrder;
|
|
972
|
+
}
|
|
958
973
|
const defaultSkinCheckoutOptions = await this.getDefaultSkinCheckoutOptions();
|
|
959
974
|
Object.assign(checkoutOptions, defaultSkinCheckoutOptions);
|
|
960
975
|
}
|
|
976
|
+
if (this.checkoutConfig.paymentMethodOrder) {
|
|
977
|
+
// eslint-disable-next-line no-console
|
|
978
|
+
console.warn('paymentMethodOrder is using only for default skin and will be ignored if you are using custom checkout');
|
|
979
|
+
}
|
|
961
980
|
await this.primerWrapper.renderCheckout(this.clientToken, checkoutOptions);
|
|
962
981
|
}
|
|
963
982
|
async _processPaymentResult(result, primerHandler) {
|
|
@@ -1065,7 +1084,7 @@ class CheckoutInstance extends EventEmitter {
|
|
|
1065
1084
|
async getDefaultSkinCheckoutOptions() {
|
|
1066
1085
|
const skinFactory = (await Promise.resolve().then(function () { return require('./chunk-index.cjs.js'); }))
|
|
1067
1086
|
.default;
|
|
1068
|
-
const skin = await skinFactory(this.primerWrapper, this.checkoutConfig.container);
|
|
1087
|
+
const skin = await skinFactory(this.primerWrapper, this.checkoutConfig.container, this.paymentMethodOrder);
|
|
1069
1088
|
this.on(EVENTS.INPUT_ERROR, skin.onInputError);
|
|
1070
1089
|
this.on(EVENTS.STATUS_CHANGE, skin.onStatusChange);
|
|
1071
1090
|
this.on(EVENTS.ERROR, (error) => skin.onError(error));
|
|
@@ -1076,6 +1095,7 @@ class CheckoutInstance extends EventEmitter {
|
|
|
1076
1095
|
this.on(EVENTS.START_PURCHASE, skin.onStartPurchase);
|
|
1077
1096
|
this.on(EVENTS.PURCHASE_FAILURE, skin.onPurchaseFailure);
|
|
1078
1097
|
this.on(EVENTS.PURCHASE_COMPLETED, skin.onPurchaseCompleted);
|
|
1098
|
+
this.on(EVENTS.METHODS_AVAILABLE, skin.onMethodsAvailable);
|
|
1079
1099
|
return skin.getCheckoutOptions();
|
|
1080
1100
|
}
|
|
1081
1101
|
showInitializingLoader() {
|
|
@@ -213,7 +213,7 @@ var PaymentMethod;
|
|
|
213
213
|
/**
|
|
214
214
|
* @fileoverview Constants for Funnefox SDK
|
|
215
215
|
*/
|
|
216
|
-
const SDK_VERSION = '0.4.
|
|
216
|
+
const SDK_VERSION = '0.4.6';
|
|
217
217
|
const DEFAULTS = {
|
|
218
218
|
BASE_URL: 'https://billing.funnelfox.com',
|
|
219
219
|
REGION: 'default',
|
|
@@ -243,6 +243,7 @@ const EVENTS = {
|
|
|
243
243
|
START_PURCHASE: 'start-purchase',
|
|
244
244
|
PURCHASE_FAILURE: 'purchase-failure',
|
|
245
245
|
PURCHASE_COMPLETED: 'purchase-completed',
|
|
246
|
+
METHODS_AVAILABLE: 'methods-available',
|
|
246
247
|
};
|
|
247
248
|
const API_ENDPOINTS = {
|
|
248
249
|
CREATE_CLIENT_SESSION: '/v1/checkout/create_client_session',
|
|
@@ -454,7 +455,7 @@ class PrimerWrapper {
|
|
|
454
455
|
}
|
|
455
456
|
}
|
|
456
457
|
async renderCheckout(clientToken, options) {
|
|
457
|
-
const { cardSelectors, paymentButtonSelectors, container, onTokenizeSuccess, onResumeSuccess, onSubmit, onInputChange, onMethodRender, ...restPrimerOptions } = options;
|
|
458
|
+
const { cardSelectors, paymentButtonSelectors, container, onTokenizeSuccess, onResumeSuccess, onSubmit, onInputChange, onMethodRender, onMethodsAvailable, ...restPrimerOptions } = options;
|
|
458
459
|
await this.createHeadlessCheckout(clientToken, {
|
|
459
460
|
...restPrimerOptions,
|
|
460
461
|
onTokenizeSuccess: this.wrapTokenizeHandler(onTokenizeSuccess),
|
|
@@ -475,6 +476,7 @@ class PrimerWrapper {
|
|
|
475
476
|
if (this.availableMethods.length === 0) {
|
|
476
477
|
throw new PrimerError('No allowed payment methods found');
|
|
477
478
|
}
|
|
479
|
+
onMethodsAvailable(this.availableMethods);
|
|
478
480
|
},
|
|
479
481
|
});
|
|
480
482
|
const methodOptions = {
|
|
@@ -787,6 +789,12 @@ class CheckoutInstance extends EventEmitter {
|
|
|
787
789
|
constructor(config) {
|
|
788
790
|
super();
|
|
789
791
|
this.counter = 0;
|
|
792
|
+
this.paymentMethodOrder = [
|
|
793
|
+
PaymentMethod.APPLE_PAY,
|
|
794
|
+
PaymentMethod.GOOGLE_PAY,
|
|
795
|
+
PaymentMethod.PAYPAL,
|
|
796
|
+
PaymentMethod.PAYMENT_CARD,
|
|
797
|
+
];
|
|
790
798
|
this.handleInputChange = (inputName, error) => {
|
|
791
799
|
this.emit(EVENTS.INPUT_ERROR, { name: inputName, error });
|
|
792
800
|
};
|
|
@@ -840,6 +848,9 @@ class CheckoutInstance extends EventEmitter {
|
|
|
840
848
|
this._setState('ready');
|
|
841
849
|
}
|
|
842
850
|
};
|
|
851
|
+
this.handleMethodsAvailable = (methods) => {
|
|
852
|
+
this.emit(EVENTS.METHODS_AVAILABLE, methods);
|
|
853
|
+
};
|
|
843
854
|
this.onLoaderChangeWithRace = (state) => {
|
|
844
855
|
const isLoading = !!(state ? ++this.counter : --this.counter);
|
|
845
856
|
this.emit(EVENTS.LOADER_CHANGE, isLoading);
|
|
@@ -928,6 +939,7 @@ class CheckoutInstance extends EventEmitter {
|
|
|
928
939
|
onSubmit: this.handleSubmit,
|
|
929
940
|
onInputChange: this.handleInputChange,
|
|
930
941
|
onMethodRender: this.handleMethodRender,
|
|
942
|
+
onMethodsAvailable: this.handleMethodsAvailable,
|
|
931
943
|
onResumeError: error => {
|
|
932
944
|
if (error.stack?.includes('PROCESSOR_3DS') &&
|
|
933
945
|
error.code === 'RESUME_ERROR' &&
|
|
@@ -951,9 +963,16 @@ class CheckoutInstance extends EventEmitter {
|
|
|
951
963
|
};
|
|
952
964
|
if (!this.checkoutConfig.cardSelectors ||
|
|
953
965
|
!this.checkoutConfig.paymentButtonSelectors) {
|
|
966
|
+
if (this.checkoutConfig.paymentMethodOrder) {
|
|
967
|
+
this.paymentMethodOrder = this.checkoutConfig.paymentMethodOrder;
|
|
968
|
+
}
|
|
954
969
|
const defaultSkinCheckoutOptions = await this.getDefaultSkinCheckoutOptions();
|
|
955
970
|
Object.assign(checkoutOptions, defaultSkinCheckoutOptions);
|
|
956
971
|
}
|
|
972
|
+
if (this.checkoutConfig.paymentMethodOrder) {
|
|
973
|
+
// eslint-disable-next-line no-console
|
|
974
|
+
console.warn('paymentMethodOrder is using only for default skin and will be ignored if you are using custom checkout');
|
|
975
|
+
}
|
|
957
976
|
await this.primerWrapper.renderCheckout(this.clientToken, checkoutOptions);
|
|
958
977
|
}
|
|
959
978
|
async _processPaymentResult(result, primerHandler) {
|
|
@@ -1061,7 +1080,7 @@ class CheckoutInstance extends EventEmitter {
|
|
|
1061
1080
|
async getDefaultSkinCheckoutOptions() {
|
|
1062
1081
|
const skinFactory = (await import('./chunk-index.es.js'))
|
|
1063
1082
|
.default;
|
|
1064
|
-
const skin = await skinFactory(this.primerWrapper, this.checkoutConfig.container);
|
|
1083
|
+
const skin = await skinFactory(this.primerWrapper, this.checkoutConfig.container, this.paymentMethodOrder);
|
|
1065
1084
|
this.on(EVENTS.INPUT_ERROR, skin.onInputError);
|
|
1066
1085
|
this.on(EVENTS.STATUS_CHANGE, skin.onStatusChange);
|
|
1067
1086
|
this.on(EVENTS.ERROR, (error) => skin.onError(error));
|
|
@@ -1072,6 +1091,7 @@ class CheckoutInstance extends EventEmitter {
|
|
|
1072
1091
|
this.on(EVENTS.START_PURCHASE, skin.onStartPurchase);
|
|
1073
1092
|
this.on(EVENTS.PURCHASE_FAILURE, skin.onPurchaseFailure);
|
|
1074
1093
|
this.on(EVENTS.PURCHASE_COMPLETED, skin.onPurchaseCompleted);
|
|
1094
|
+
this.on(EVENTS.METHODS_AVAILABLE, skin.onMethodsAvailable);
|
|
1075
1095
|
return skin.getCheckoutOptions();
|
|
1076
1096
|
}
|
|
1077
1097
|
showInitializingLoader() {
|
|
@@ -1154,4 +1174,4 @@ if (typeof window !== 'undefined') {
|
|
|
1154
1174
|
window.Billing = Billing;
|
|
1155
1175
|
}
|
|
1156
1176
|
|
|
1157
|
-
export { APIError, Billing, CHECKOUT_STATES, CheckoutError, ConfigurationError, DEFAULTS, ERROR_CODES, EVENTS, FunnefoxSDKError, NetworkError, PrimerError, SDK_VERSION, ValidationError, configure, createCheckout, createClientSession, Billing as default };
|
|
1177
|
+
export { APIError, Billing, CHECKOUT_STATES, CheckoutError, ConfigurationError, DEFAULTS, ERROR_CODES, EVENTS, FunnefoxSDKError, NetworkError, PaymentMethod, PrimerError, SDK_VERSION, ValidationError, configure, createCheckout, createClientSession, Billing as default };
|