@pelcro/react-pelcro-js 3.2.0-beta.4 → 3.2.0-beta.5
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/index.cjs.js +162 -70
- package/dist/index.esm.js +162 -70
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -6814,7 +6814,9 @@ function userMustVerifyEmail() {
|
|
|
6814
6814
|
return window.Pelcro.user.isAuthenticated() && isEmailVerificationEnabled && !isUserEmailVerified;
|
|
6815
6815
|
}
|
|
6816
6816
|
function getRenewableProducts() {
|
|
6817
|
-
|
|
6817
|
+
var _window$Pelcro$subscr, _window$Pelcro$subscr2;
|
|
6818
|
+
|
|
6819
|
+
const renewableSubs = (_window$Pelcro$subscr = (_window$Pelcro$subscr2 = window.Pelcro.subscription.list()) === null || _window$Pelcro$subscr2 === void 0 ? void 0 : _window$Pelcro$subscr2.filter(sub => sub.status === "active" && sub.cancel_at_period_end === 1)) !== null && _window$Pelcro$subscr !== void 0 ? _window$Pelcro$subscr : [];
|
|
6818
6820
|
const renewableProductsIds = [...new Set(renewableSubs.map(sub => sub.plan.product.id))];
|
|
6819
6821
|
const renewablePlansIds = [...new Set(renewableSubs.map(sub => sub.plan.id))];
|
|
6820
6822
|
const {
|
|
@@ -12839,20 +12841,21 @@ var es_12 = es.injectStripe;
|
|
|
12839
12841
|
var es_13 = es.StripeProvider;
|
|
12840
12842
|
|
|
12841
12843
|
/**
|
|
12842
|
-
* @TODO: All
|
|
12844
|
+
* @TODO: All payment related business logic should end up moving
|
|
12843
12845
|
* to this service, and out of react components.
|
|
12844
12846
|
*/
|
|
12845
12847
|
|
|
12846
12848
|
/**
|
|
12847
|
-
* Enum for
|
|
12849
|
+
* Enum for payment types
|
|
12848
12850
|
* @readonly
|
|
12849
12851
|
* @enum {string}
|
|
12850
12852
|
*/
|
|
12851
|
-
const
|
|
12853
|
+
const PAYMENT_TYPES = {
|
|
12852
12854
|
CREATE_SUBSCRIPTION: "CREATE_SUBSCRIPTION",
|
|
12853
12855
|
CREATE_GIFTED_SUBSCRIPTION: "CREATE_GIFTED_SUBSCRIPTION",
|
|
12854
12856
|
RENEW_SUBSCRIPTION: "RENEW_SUBSCRIPTION",
|
|
12855
12857
|
RENEW_GIFTED_SUBSCRIPTION: "RENEW_GIFTED_SUBSCRIPTION",
|
|
12858
|
+
PURCHASE_ECOMMERCE_ORDER: "PURCHASE_ECOMMERCE_ORDER",
|
|
12856
12859
|
PAY_INVOICE: "PAY_INVOICE"
|
|
12857
12860
|
};
|
|
12858
12861
|
|
|
@@ -12860,9 +12863,8 @@ var _isPaymentGatewayInvalid = /*#__PURE__*/new WeakMap();
|
|
|
12860
12863
|
|
|
12861
12864
|
var _generateUserError = /*#__PURE__*/new WeakMap();
|
|
12862
12865
|
|
|
12863
|
-
class
|
|
12866
|
+
class Payment {
|
|
12864
12867
|
/**
|
|
12865
|
-
* Subscription service constructor
|
|
12866
12868
|
* @param {(StripeGateway|PaypalGateway|VantivGateway)} paymentGateway
|
|
12867
12869
|
*/
|
|
12868
12870
|
constructor(paymentGateway) {
|
|
@@ -12874,7 +12876,7 @@ class Subscription {
|
|
|
12874
12876
|
|
|
12875
12877
|
if (!options.type) {
|
|
12876
12878
|
callback(_classPrivateFieldGet(this, _generateUserError).call(this), null);
|
|
12877
|
-
return console.error("No
|
|
12879
|
+
return console.error("No payment type provided");
|
|
12878
12880
|
} // delegate execution to paymentgateway
|
|
12879
12881
|
|
|
12880
12882
|
|
|
@@ -12892,21 +12894,21 @@ class Subscription {
|
|
|
12892
12894
|
writable: true,
|
|
12893
12895
|
value: () => {
|
|
12894
12896
|
return {
|
|
12895
|
-
error: new Error("An error has occured in the
|
|
12897
|
+
error: new Error("An error has occured in the payment service, please try again later")
|
|
12896
12898
|
};
|
|
12897
12899
|
}
|
|
12898
12900
|
});
|
|
12899
12901
|
|
|
12900
12902
|
if (_classPrivateFieldGet(this, _isPaymentGatewayInvalid).call(this, paymentGateway)) {
|
|
12901
12903
|
this.paymentGateway = null;
|
|
12902
|
-
console.error("Incompatible
|
|
12904
|
+
console.error("Incompatible payment gateway");
|
|
12903
12905
|
} else {
|
|
12904
12906
|
this.paymentGateway = paymentGateway;
|
|
12905
12907
|
}
|
|
12906
12908
|
}
|
|
12907
12909
|
/**
|
|
12908
|
-
* @typedef
|
|
12909
|
-
* @property {
|
|
12910
|
+
* @typedef paymentOptions
|
|
12911
|
+
* @property {PAYMENT_TYPES} type
|
|
12910
12912
|
* @property {string} token
|
|
12911
12913
|
* @property {object} plan
|
|
12912
12914
|
* @property {object} [product]
|
|
@@ -12917,6 +12919,7 @@ class Subscription {
|
|
|
12917
12919
|
* @property {string} addressId
|
|
12918
12920
|
* @property {number} invoiceId
|
|
12919
12921
|
* @property {boolean} isExistingSource
|
|
12922
|
+
* @property {Array} items
|
|
12920
12923
|
*/
|
|
12921
12924
|
|
|
12922
12925
|
/**
|
|
@@ -12927,8 +12930,8 @@ class Subscription {
|
|
|
12927
12930
|
*/
|
|
12928
12931
|
|
|
12929
12932
|
/**
|
|
12930
|
-
*
|
|
12931
|
-
* @param {
|
|
12933
|
+
* Payment execution method
|
|
12934
|
+
* @param {paymentOptions} options payment options
|
|
12932
12935
|
* @param {executeCallback} callback
|
|
12933
12936
|
* @return {void}
|
|
12934
12937
|
*/
|
|
@@ -12941,7 +12944,7 @@ const PAYMENT_GATEWAYS_ENUM = {
|
|
|
12941
12944
|
vantiv: "vantiv"
|
|
12942
12945
|
};
|
|
12943
12946
|
/**
|
|
12944
|
-
*
|
|
12947
|
+
* Payment Strategies
|
|
12945
12948
|
*/
|
|
12946
12949
|
|
|
12947
12950
|
/**
|
|
@@ -12958,6 +12961,8 @@ var _renewSubscription = /*#__PURE__*/new WeakMap();
|
|
|
12958
12961
|
|
|
12959
12962
|
var _renewGiftedSubscription = /*#__PURE__*/new WeakMap();
|
|
12960
12963
|
|
|
12964
|
+
var _purchaseEcommerceOrder = /*#__PURE__*/new WeakMap();
|
|
12965
|
+
|
|
12961
12966
|
var _payInvoice = /*#__PURE__*/new WeakMap();
|
|
12962
12967
|
|
|
12963
12968
|
class StripeGateway {
|
|
@@ -12968,7 +12973,7 @@ class StripeGateway {
|
|
|
12968
12973
|
});
|
|
12969
12974
|
|
|
12970
12975
|
_defineProperty$3(this, "execute", (options, callback) => {
|
|
12971
|
-
const types =
|
|
12976
|
+
const types = PAYMENT_TYPES;
|
|
12972
12977
|
|
|
12973
12978
|
switch (options.type) {
|
|
12974
12979
|
case types.CREATE_SUBSCRIPTION:
|
|
@@ -12983,11 +12988,14 @@ class StripeGateway {
|
|
|
12983
12988
|
case types.RENEW_GIFTED_SUBSCRIPTION:
|
|
12984
12989
|
return _classPrivateFieldGet(this, _renewGiftedSubscription).call(this, options, callback);
|
|
12985
12990
|
|
|
12991
|
+
case types.PURCHASE_ECOMMERCE_ORDER:
|
|
12992
|
+
return _classPrivateFieldGet(this, _purchaseEcommerceOrder).call(this, options, callback);
|
|
12993
|
+
|
|
12986
12994
|
case types.PAY_INVOICE:
|
|
12987
12995
|
return _classPrivateFieldGet(this, _payInvoice).call(this, options, callback);
|
|
12988
12996
|
|
|
12989
12997
|
default:
|
|
12990
|
-
console.error("Unsupported
|
|
12998
|
+
console.error("Unsupported payment method: Stripe Gateway");
|
|
12991
12999
|
}
|
|
12992
13000
|
});
|
|
12993
13001
|
|
|
@@ -13095,6 +13103,35 @@ class StripeGateway {
|
|
|
13095
13103
|
}
|
|
13096
13104
|
});
|
|
13097
13105
|
|
|
13106
|
+
_purchaseEcommerceOrder.set(this, {
|
|
13107
|
+
writable: true,
|
|
13108
|
+
value: (options, callback) => {
|
|
13109
|
+
const {
|
|
13110
|
+
token,
|
|
13111
|
+
items,
|
|
13112
|
+
couponCode,
|
|
13113
|
+
addressId,
|
|
13114
|
+
isExistingSource
|
|
13115
|
+
} = options;
|
|
13116
|
+
const params = isExistingSource ? {
|
|
13117
|
+
source_id: token
|
|
13118
|
+
} : {
|
|
13119
|
+
payment_gateway: _classPrivateFieldGet(this, _paymentGateway),
|
|
13120
|
+
gateway_token: token
|
|
13121
|
+
};
|
|
13122
|
+
window.Pelcro.ecommerce.order.create({
|
|
13123
|
+
items,
|
|
13124
|
+
coupon_code: couponCode,
|
|
13125
|
+
...params,
|
|
13126
|
+
...(addressId && {
|
|
13127
|
+
address_id: addressId
|
|
13128
|
+
})
|
|
13129
|
+
}, (err, res) => {
|
|
13130
|
+
callback(err, res);
|
|
13131
|
+
});
|
|
13132
|
+
}
|
|
13133
|
+
});
|
|
13134
|
+
|
|
13098
13135
|
_payInvoice.set(this, {
|
|
13099
13136
|
writable: true,
|
|
13100
13137
|
value: (options, callback) => {
|
|
@@ -13138,7 +13175,7 @@ class PaypalGateway {
|
|
|
13138
13175
|
});
|
|
13139
13176
|
|
|
13140
13177
|
_defineProperty$3(this, "execute", (options, callback) => {
|
|
13141
|
-
const types =
|
|
13178
|
+
const types = PAYMENT_TYPES;
|
|
13142
13179
|
|
|
13143
13180
|
switch (options.type) {
|
|
13144
13181
|
case types.CREATE_SUBSCRIPTION:
|
|
@@ -13241,6 +13278,10 @@ var _createGiftedSubscription3 = /*#__PURE__*/new WeakMap();
|
|
|
13241
13278
|
|
|
13242
13279
|
var _renewGiftedSubscription2 = /*#__PURE__*/new WeakMap();
|
|
13243
13280
|
|
|
13281
|
+
var _purchaseEcommerceOrder2 = /*#__PURE__*/new WeakMap();
|
|
13282
|
+
|
|
13283
|
+
var _payInvoice3 = /*#__PURE__*/new WeakMap();
|
|
13284
|
+
|
|
13244
13285
|
class VantivGateway {
|
|
13245
13286
|
constructor() {
|
|
13246
13287
|
_paymentGateway3.set(this, {
|
|
@@ -13249,7 +13290,7 @@ class VantivGateway {
|
|
|
13249
13290
|
});
|
|
13250
13291
|
|
|
13251
13292
|
_defineProperty$3(this, "execute", (options, callback) => {
|
|
13252
|
-
const types =
|
|
13293
|
+
const types = PAYMENT_TYPES;
|
|
13253
13294
|
|
|
13254
13295
|
switch (options.type) {
|
|
13255
13296
|
case types.CREATE_SUBSCRIPTION:
|
|
@@ -13263,12 +13304,15 @@ class VantivGateway {
|
|
|
13263
13304
|
|
|
13264
13305
|
case types.RENEW_GIFTED_SUBSCRIPTION:
|
|
13265
13306
|
return _classPrivateFieldGet(this, _renewGiftedSubscription2).call(this, options, callback);
|
|
13266
|
-
|
|
13267
|
-
|
|
13268
|
-
|
|
13307
|
+
|
|
13308
|
+
case types.PURCHASE_ECOMMERCE_ORDER:
|
|
13309
|
+
return _classPrivateFieldGet(this, _purchaseEcommerceOrder2).call(this, options, callback);
|
|
13310
|
+
|
|
13311
|
+
case types.PAY_INVOICE:
|
|
13312
|
+
return _classPrivateFieldGet(this, _payInvoice3).call(this, options, callback);
|
|
13269
13313
|
|
|
13270
13314
|
default:
|
|
13271
|
-
console.error("Unsupported
|
|
13315
|
+
console.error("Unsupported payment method: vantiv Gateway");
|
|
13272
13316
|
}
|
|
13273
13317
|
});
|
|
13274
13318
|
|
|
@@ -13401,6 +13445,56 @@ class VantivGateway {
|
|
|
13401
13445
|
});
|
|
13402
13446
|
}
|
|
13403
13447
|
});
|
|
13448
|
+
|
|
13449
|
+
_purchaseEcommerceOrder2.set(this, {
|
|
13450
|
+
writable: true,
|
|
13451
|
+
value: (options, callback) => {
|
|
13452
|
+
const {
|
|
13453
|
+
token,
|
|
13454
|
+
items,
|
|
13455
|
+
couponCode,
|
|
13456
|
+
addressId,
|
|
13457
|
+
isExistingSource
|
|
13458
|
+
} = options;
|
|
13459
|
+
const params = isExistingSource ? {
|
|
13460
|
+
source_id: token
|
|
13461
|
+
} : {
|
|
13462
|
+
payment_gateway: _classPrivateFieldGet(this, _paymentGateway3),
|
|
13463
|
+
gateway_token: token
|
|
13464
|
+
};
|
|
13465
|
+
window.Pelcro.ecommerce.order.create({
|
|
13466
|
+
items,
|
|
13467
|
+
coupon_code: couponCode,
|
|
13468
|
+
...params,
|
|
13469
|
+
...(addressId && {
|
|
13470
|
+
address_id: addressId
|
|
13471
|
+
})
|
|
13472
|
+
}, (err, res) => {
|
|
13473
|
+
callback(err, res);
|
|
13474
|
+
});
|
|
13475
|
+
}
|
|
13476
|
+
});
|
|
13477
|
+
|
|
13478
|
+
_payInvoice3.set(this, {
|
|
13479
|
+
writable: true,
|
|
13480
|
+
value: (options, callback) => {
|
|
13481
|
+
const {
|
|
13482
|
+
token,
|
|
13483
|
+
invoiceId
|
|
13484
|
+
} = options;
|
|
13485
|
+
const params = options.isExistingSource ? {
|
|
13486
|
+
source_id: token,
|
|
13487
|
+
invoice_id: invoiceId
|
|
13488
|
+
} : {
|
|
13489
|
+
payment_gateway: _classPrivateFieldGet(this, _paymentGateway3),
|
|
13490
|
+
gateway_token: token,
|
|
13491
|
+
invoice_id: invoiceId
|
|
13492
|
+
};
|
|
13493
|
+
window.Pelcro.invoice.pay(params, (err, res) => {
|
|
13494
|
+
callback(err, res);
|
|
13495
|
+
});
|
|
13496
|
+
}
|
|
13497
|
+
});
|
|
13404
13498
|
}
|
|
13405
13499
|
|
|
13406
13500
|
}
|
|
@@ -13493,22 +13587,22 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
13493
13587
|
updateTotalAmountWithTax();
|
|
13494
13588
|
}, []);
|
|
13495
13589
|
|
|
13496
|
-
|
|
13497
|
-
if (
|
|
13498
|
-
|
|
13499
|
-
|
|
13500
|
-
}
|
|
13501
|
-
|
|
13502
|
-
const orderId = `pelcro-${new Date().getTime()}`; // calls handleVantivPayment
|
|
13590
|
+
const submitVantivPayment = () => {
|
|
13591
|
+
if (selectedPaymentMethodId) {
|
|
13592
|
+
return handleVantivPayment(null);
|
|
13593
|
+
}
|
|
13503
13594
|
|
|
13504
|
-
|
|
13505
|
-
|
|
13506
|
-
orderId: orderId
|
|
13507
|
-
});
|
|
13508
|
-
} else {
|
|
13509
|
-
handleVantivPayment(null);
|
|
13595
|
+
if (!vantivInstanceRef.current) {
|
|
13596
|
+
return console.error("Vantiv sdk script wasn't loaded, you need to load vantiv sdk before rendering the vantiv payment flow");
|
|
13510
13597
|
}
|
|
13511
|
-
|
|
13598
|
+
|
|
13599
|
+
const orderId = `pelcro-${new Date().getTime()}`; // calls handleVantivPayment
|
|
13600
|
+
|
|
13601
|
+
vantivInstanceRef.current.getPaypageRegistrationId({
|
|
13602
|
+
id: orderId,
|
|
13603
|
+
orderId: orderId
|
|
13604
|
+
});
|
|
13605
|
+
};
|
|
13512
13606
|
|
|
13513
13607
|
function handleVantivPayment(paymentRequest) {
|
|
13514
13608
|
if (paymentRequest) {
|
|
@@ -13521,19 +13615,18 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
13521
13615
|
}
|
|
13522
13616
|
}
|
|
13523
13617
|
|
|
13524
|
-
const
|
|
13618
|
+
const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
|
|
13525
13619
|
|
|
13526
13620
|
if (type === "createPayment") {
|
|
13527
13621
|
handleVantivSubscription();
|
|
13528
|
-
}
|
|
13529
|
-
|
|
13530
|
-
|
|
13531
|
-
|
|
13532
|
-
|
|
13533
|
-
// }
|
|
13534
|
-
|
|
13622
|
+
} else if (type === "orderCreate") {
|
|
13623
|
+
purchase(new VantivGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest, state, dispatch);
|
|
13624
|
+
} else if (type === "invoicePayment") {
|
|
13625
|
+
payInvoice(new VantivGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest, dispatch);
|
|
13626
|
+
}
|
|
13535
13627
|
|
|
13536
13628
|
function handleVantivSubscription() {
|
|
13629
|
+
const payment = new Payment(new VantivGateway());
|
|
13537
13630
|
const createSubscription = !isGift && !subscriptionIdToRenew;
|
|
13538
13631
|
const renewSubscription = !isGift && subscriptionIdToRenew;
|
|
13539
13632
|
const giftSubscriprition = isGift && !subscriptionIdToRenew;
|
|
@@ -13541,11 +13634,10 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
13541
13634
|
const {
|
|
13542
13635
|
couponCode
|
|
13543
13636
|
} = state;
|
|
13544
|
-
const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
|
|
13545
13637
|
|
|
13546
13638
|
if (renewGift) {
|
|
13547
|
-
return
|
|
13548
|
-
type:
|
|
13639
|
+
return payment.execute({
|
|
13640
|
+
type: PAYMENT_TYPES.RENEW_GIFTED_SUBSCRIPTION,
|
|
13549
13641
|
token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
|
|
13550
13642
|
plan,
|
|
13551
13643
|
couponCode,
|
|
@@ -13561,8 +13653,8 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
13561
13653
|
onSuccess(res);
|
|
13562
13654
|
});
|
|
13563
13655
|
} else if (giftSubscriprition) {
|
|
13564
|
-
return
|
|
13565
|
-
type:
|
|
13656
|
+
return payment.execute({
|
|
13657
|
+
type: PAYMENT_TYPES.CREATE_GIFTED_SUBSCRIPTION,
|
|
13566
13658
|
token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
|
|
13567
13659
|
quantity: plan.quantity,
|
|
13568
13660
|
plan,
|
|
@@ -13579,8 +13671,8 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
13579
13671
|
onSuccess(res);
|
|
13580
13672
|
});
|
|
13581
13673
|
} else if (renewSubscription) {
|
|
13582
|
-
return
|
|
13583
|
-
type:
|
|
13674
|
+
return payment.execute({
|
|
13675
|
+
type: PAYMENT_TYPES.RENEW_SUBSCRIPTION,
|
|
13584
13676
|
token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
|
|
13585
13677
|
quantity: plan.quantity,
|
|
13586
13678
|
plan,
|
|
@@ -13597,8 +13689,8 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
13597
13689
|
onSuccess(res);
|
|
13598
13690
|
});
|
|
13599
13691
|
} else if (createSubscription) {
|
|
13600
|
-
return
|
|
13601
|
-
type:
|
|
13692
|
+
return payment.execute({
|
|
13693
|
+
type: PAYMENT_TYPES.CREATE_SUBSCRIPTION,
|
|
13602
13694
|
token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
|
|
13603
13695
|
quantity: plan.quantity,
|
|
13604
13696
|
plan,
|
|
@@ -14068,7 +14160,7 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
14068
14160
|
|
|
14069
14161
|
|
|
14070
14162
|
const handlePaypalSubscription = (state, paypalNonce) => {
|
|
14071
|
-
const
|
|
14163
|
+
const payment = new Payment(new PaypalGateway());
|
|
14072
14164
|
const {
|
|
14073
14165
|
couponCode
|
|
14074
14166
|
} = state;
|
|
@@ -14077,8 +14169,8 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
14077
14169
|
*/
|
|
14078
14170
|
|
|
14079
14171
|
if (giftRecipient) {
|
|
14080
|
-
return
|
|
14081
|
-
type:
|
|
14172
|
+
return payment.execute({
|
|
14173
|
+
type: PAYMENT_TYPES.CREATE_GIFTED_SUBSCRIPTION,
|
|
14082
14174
|
token: paypalNonce,
|
|
14083
14175
|
quantity: plan.quantity,
|
|
14084
14176
|
plan,
|
|
@@ -14111,8 +14203,8 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
14111
14203
|
});
|
|
14112
14204
|
}
|
|
14113
14205
|
|
|
14114
|
-
return
|
|
14115
|
-
type:
|
|
14206
|
+
return payment.execute({
|
|
14207
|
+
type: PAYMENT_TYPES.CREATE_SUBSCRIPTION,
|
|
14116
14208
|
token: paypalNonce,
|
|
14117
14209
|
quantity: plan.quantity,
|
|
14118
14210
|
plan,
|
|
@@ -14144,7 +14236,7 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
14144
14236
|
});
|
|
14145
14237
|
};
|
|
14146
14238
|
|
|
14147
|
-
const purchase = (
|
|
14239
|
+
const purchase = (gatewayService, gatewayToken, state, dispatch) => {
|
|
14148
14240
|
const isQuickPurchase = !Array.isArray(order);
|
|
14149
14241
|
const mappedOrderItems = isQuickPurchase ? [{
|
|
14150
14242
|
sku_id: order.id,
|
|
@@ -14156,14 +14248,14 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
14156
14248
|
const {
|
|
14157
14249
|
couponCode
|
|
14158
14250
|
} = state;
|
|
14159
|
-
|
|
14160
|
-
|
|
14161
|
-
|
|
14251
|
+
const payment = new Payment(gatewayService);
|
|
14252
|
+
payment.execute({
|
|
14253
|
+
type: PAYMENT_TYPES.PURCHASE_ECOMMERCE_ORDER,
|
|
14254
|
+
token: gatewayToken,
|
|
14255
|
+
isExistingSource: Boolean(selectedPaymentMethodId),
|
|
14162
14256
|
items: mappedOrderItems,
|
|
14163
|
-
|
|
14164
|
-
|
|
14165
|
-
address_id: selectedAddressId
|
|
14166
|
-
})
|
|
14257
|
+
addressId: selectedAddressId,
|
|
14258
|
+
couponCode
|
|
14167
14259
|
}, (err, res) => {
|
|
14168
14260
|
dispatch({
|
|
14169
14261
|
type: DISABLE_SUBMIT,
|
|
@@ -14201,9 +14293,9 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
14201
14293
|
};
|
|
14202
14294
|
|
|
14203
14295
|
const payInvoice = (gatewayService, gatewayToken, dispatch) => {
|
|
14204
|
-
const
|
|
14205
|
-
return
|
|
14206
|
-
type:
|
|
14296
|
+
const payment = new Payment(gatewayService);
|
|
14297
|
+
return payment.execute({
|
|
14298
|
+
type: PAYMENT_TYPES.PAY_INVOICE,
|
|
14207
14299
|
token: gatewayToken,
|
|
14208
14300
|
isExistingSource: Boolean(selectedPaymentMethodId),
|
|
14209
14301
|
invoiceId: invoice.id
|
|
@@ -14441,7 +14533,7 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
14441
14533
|
if (stripeSource && type === "createPayment") {
|
|
14442
14534
|
subscribe(stripeSource, state, dispatch);
|
|
14443
14535
|
} else if (stripeSource && type === "orderCreate") {
|
|
14444
|
-
purchase(stripeSource, state, dispatch);
|
|
14536
|
+
purchase(new StripeGateway(), stripeSource.id, state, dispatch);
|
|
14445
14537
|
} else if (stripeSource && type === "invoicePayment") {
|
|
14446
14538
|
payInvoice(new StripeGateway(), stripeSource.id, dispatch);
|
|
14447
14539
|
}
|
package/dist/index.esm.js
CHANGED
|
@@ -6784,7 +6784,9 @@ function userMustVerifyEmail() {
|
|
|
6784
6784
|
return window.Pelcro.user.isAuthenticated() && isEmailVerificationEnabled && !isUserEmailVerified;
|
|
6785
6785
|
}
|
|
6786
6786
|
function getRenewableProducts() {
|
|
6787
|
-
|
|
6787
|
+
var _window$Pelcro$subscr, _window$Pelcro$subscr2;
|
|
6788
|
+
|
|
6789
|
+
const renewableSubs = (_window$Pelcro$subscr = (_window$Pelcro$subscr2 = window.Pelcro.subscription.list()) === null || _window$Pelcro$subscr2 === void 0 ? void 0 : _window$Pelcro$subscr2.filter(sub => sub.status === "active" && sub.cancel_at_period_end === 1)) !== null && _window$Pelcro$subscr !== void 0 ? _window$Pelcro$subscr : [];
|
|
6788
6790
|
const renewableProductsIds = [...new Set(renewableSubs.map(sub => sub.plan.product.id))];
|
|
6789
6791
|
const renewablePlansIds = [...new Set(renewableSubs.map(sub => sub.plan.id))];
|
|
6790
6792
|
const {
|
|
@@ -12809,20 +12811,21 @@ var es_12 = es.injectStripe;
|
|
|
12809
12811
|
var es_13 = es.StripeProvider;
|
|
12810
12812
|
|
|
12811
12813
|
/**
|
|
12812
|
-
* @TODO: All
|
|
12814
|
+
* @TODO: All payment related business logic should end up moving
|
|
12813
12815
|
* to this service, and out of react components.
|
|
12814
12816
|
*/
|
|
12815
12817
|
|
|
12816
12818
|
/**
|
|
12817
|
-
* Enum for
|
|
12819
|
+
* Enum for payment types
|
|
12818
12820
|
* @readonly
|
|
12819
12821
|
* @enum {string}
|
|
12820
12822
|
*/
|
|
12821
|
-
const
|
|
12823
|
+
const PAYMENT_TYPES = {
|
|
12822
12824
|
CREATE_SUBSCRIPTION: "CREATE_SUBSCRIPTION",
|
|
12823
12825
|
CREATE_GIFTED_SUBSCRIPTION: "CREATE_GIFTED_SUBSCRIPTION",
|
|
12824
12826
|
RENEW_SUBSCRIPTION: "RENEW_SUBSCRIPTION",
|
|
12825
12827
|
RENEW_GIFTED_SUBSCRIPTION: "RENEW_GIFTED_SUBSCRIPTION",
|
|
12828
|
+
PURCHASE_ECOMMERCE_ORDER: "PURCHASE_ECOMMERCE_ORDER",
|
|
12826
12829
|
PAY_INVOICE: "PAY_INVOICE"
|
|
12827
12830
|
};
|
|
12828
12831
|
|
|
@@ -12830,9 +12833,8 @@ var _isPaymentGatewayInvalid = /*#__PURE__*/new WeakMap();
|
|
|
12830
12833
|
|
|
12831
12834
|
var _generateUserError = /*#__PURE__*/new WeakMap();
|
|
12832
12835
|
|
|
12833
|
-
class
|
|
12836
|
+
class Payment {
|
|
12834
12837
|
/**
|
|
12835
|
-
* Subscription service constructor
|
|
12836
12838
|
* @param {(StripeGateway|PaypalGateway|VantivGateway)} paymentGateway
|
|
12837
12839
|
*/
|
|
12838
12840
|
constructor(paymentGateway) {
|
|
@@ -12844,7 +12846,7 @@ class Subscription {
|
|
|
12844
12846
|
|
|
12845
12847
|
if (!options.type) {
|
|
12846
12848
|
callback(_classPrivateFieldGet(this, _generateUserError).call(this), null);
|
|
12847
|
-
return console.error("No
|
|
12849
|
+
return console.error("No payment type provided");
|
|
12848
12850
|
} // delegate execution to paymentgateway
|
|
12849
12851
|
|
|
12850
12852
|
|
|
@@ -12862,21 +12864,21 @@ class Subscription {
|
|
|
12862
12864
|
writable: true,
|
|
12863
12865
|
value: () => {
|
|
12864
12866
|
return {
|
|
12865
|
-
error: new Error("An error has occured in the
|
|
12867
|
+
error: new Error("An error has occured in the payment service, please try again later")
|
|
12866
12868
|
};
|
|
12867
12869
|
}
|
|
12868
12870
|
});
|
|
12869
12871
|
|
|
12870
12872
|
if (_classPrivateFieldGet(this, _isPaymentGatewayInvalid).call(this, paymentGateway)) {
|
|
12871
12873
|
this.paymentGateway = null;
|
|
12872
|
-
console.error("Incompatible
|
|
12874
|
+
console.error("Incompatible payment gateway");
|
|
12873
12875
|
} else {
|
|
12874
12876
|
this.paymentGateway = paymentGateway;
|
|
12875
12877
|
}
|
|
12876
12878
|
}
|
|
12877
12879
|
/**
|
|
12878
|
-
* @typedef
|
|
12879
|
-
* @property {
|
|
12880
|
+
* @typedef paymentOptions
|
|
12881
|
+
* @property {PAYMENT_TYPES} type
|
|
12880
12882
|
* @property {string} token
|
|
12881
12883
|
* @property {object} plan
|
|
12882
12884
|
* @property {object} [product]
|
|
@@ -12887,6 +12889,7 @@ class Subscription {
|
|
|
12887
12889
|
* @property {string} addressId
|
|
12888
12890
|
* @property {number} invoiceId
|
|
12889
12891
|
* @property {boolean} isExistingSource
|
|
12892
|
+
* @property {Array} items
|
|
12890
12893
|
*/
|
|
12891
12894
|
|
|
12892
12895
|
/**
|
|
@@ -12897,8 +12900,8 @@ class Subscription {
|
|
|
12897
12900
|
*/
|
|
12898
12901
|
|
|
12899
12902
|
/**
|
|
12900
|
-
*
|
|
12901
|
-
* @param {
|
|
12903
|
+
* Payment execution method
|
|
12904
|
+
* @param {paymentOptions} options payment options
|
|
12902
12905
|
* @param {executeCallback} callback
|
|
12903
12906
|
* @return {void}
|
|
12904
12907
|
*/
|
|
@@ -12911,7 +12914,7 @@ const PAYMENT_GATEWAYS_ENUM = {
|
|
|
12911
12914
|
vantiv: "vantiv"
|
|
12912
12915
|
};
|
|
12913
12916
|
/**
|
|
12914
|
-
*
|
|
12917
|
+
* Payment Strategies
|
|
12915
12918
|
*/
|
|
12916
12919
|
|
|
12917
12920
|
/**
|
|
@@ -12928,6 +12931,8 @@ var _renewSubscription = /*#__PURE__*/new WeakMap();
|
|
|
12928
12931
|
|
|
12929
12932
|
var _renewGiftedSubscription = /*#__PURE__*/new WeakMap();
|
|
12930
12933
|
|
|
12934
|
+
var _purchaseEcommerceOrder = /*#__PURE__*/new WeakMap();
|
|
12935
|
+
|
|
12931
12936
|
var _payInvoice = /*#__PURE__*/new WeakMap();
|
|
12932
12937
|
|
|
12933
12938
|
class StripeGateway {
|
|
@@ -12938,7 +12943,7 @@ class StripeGateway {
|
|
|
12938
12943
|
});
|
|
12939
12944
|
|
|
12940
12945
|
_defineProperty$3(this, "execute", (options, callback) => {
|
|
12941
|
-
const types =
|
|
12946
|
+
const types = PAYMENT_TYPES;
|
|
12942
12947
|
|
|
12943
12948
|
switch (options.type) {
|
|
12944
12949
|
case types.CREATE_SUBSCRIPTION:
|
|
@@ -12953,11 +12958,14 @@ class StripeGateway {
|
|
|
12953
12958
|
case types.RENEW_GIFTED_SUBSCRIPTION:
|
|
12954
12959
|
return _classPrivateFieldGet(this, _renewGiftedSubscription).call(this, options, callback);
|
|
12955
12960
|
|
|
12961
|
+
case types.PURCHASE_ECOMMERCE_ORDER:
|
|
12962
|
+
return _classPrivateFieldGet(this, _purchaseEcommerceOrder).call(this, options, callback);
|
|
12963
|
+
|
|
12956
12964
|
case types.PAY_INVOICE:
|
|
12957
12965
|
return _classPrivateFieldGet(this, _payInvoice).call(this, options, callback);
|
|
12958
12966
|
|
|
12959
12967
|
default:
|
|
12960
|
-
console.error("Unsupported
|
|
12968
|
+
console.error("Unsupported payment method: Stripe Gateway");
|
|
12961
12969
|
}
|
|
12962
12970
|
});
|
|
12963
12971
|
|
|
@@ -13065,6 +13073,35 @@ class StripeGateway {
|
|
|
13065
13073
|
}
|
|
13066
13074
|
});
|
|
13067
13075
|
|
|
13076
|
+
_purchaseEcommerceOrder.set(this, {
|
|
13077
|
+
writable: true,
|
|
13078
|
+
value: (options, callback) => {
|
|
13079
|
+
const {
|
|
13080
|
+
token,
|
|
13081
|
+
items,
|
|
13082
|
+
couponCode,
|
|
13083
|
+
addressId,
|
|
13084
|
+
isExistingSource
|
|
13085
|
+
} = options;
|
|
13086
|
+
const params = isExistingSource ? {
|
|
13087
|
+
source_id: token
|
|
13088
|
+
} : {
|
|
13089
|
+
payment_gateway: _classPrivateFieldGet(this, _paymentGateway),
|
|
13090
|
+
gateway_token: token
|
|
13091
|
+
};
|
|
13092
|
+
window.Pelcro.ecommerce.order.create({
|
|
13093
|
+
items,
|
|
13094
|
+
coupon_code: couponCode,
|
|
13095
|
+
...params,
|
|
13096
|
+
...(addressId && {
|
|
13097
|
+
address_id: addressId
|
|
13098
|
+
})
|
|
13099
|
+
}, (err, res) => {
|
|
13100
|
+
callback(err, res);
|
|
13101
|
+
});
|
|
13102
|
+
}
|
|
13103
|
+
});
|
|
13104
|
+
|
|
13068
13105
|
_payInvoice.set(this, {
|
|
13069
13106
|
writable: true,
|
|
13070
13107
|
value: (options, callback) => {
|
|
@@ -13108,7 +13145,7 @@ class PaypalGateway {
|
|
|
13108
13145
|
});
|
|
13109
13146
|
|
|
13110
13147
|
_defineProperty$3(this, "execute", (options, callback) => {
|
|
13111
|
-
const types =
|
|
13148
|
+
const types = PAYMENT_TYPES;
|
|
13112
13149
|
|
|
13113
13150
|
switch (options.type) {
|
|
13114
13151
|
case types.CREATE_SUBSCRIPTION:
|
|
@@ -13211,6 +13248,10 @@ var _createGiftedSubscription3 = /*#__PURE__*/new WeakMap();
|
|
|
13211
13248
|
|
|
13212
13249
|
var _renewGiftedSubscription2 = /*#__PURE__*/new WeakMap();
|
|
13213
13250
|
|
|
13251
|
+
var _purchaseEcommerceOrder2 = /*#__PURE__*/new WeakMap();
|
|
13252
|
+
|
|
13253
|
+
var _payInvoice3 = /*#__PURE__*/new WeakMap();
|
|
13254
|
+
|
|
13214
13255
|
class VantivGateway {
|
|
13215
13256
|
constructor() {
|
|
13216
13257
|
_paymentGateway3.set(this, {
|
|
@@ -13219,7 +13260,7 @@ class VantivGateway {
|
|
|
13219
13260
|
});
|
|
13220
13261
|
|
|
13221
13262
|
_defineProperty$3(this, "execute", (options, callback) => {
|
|
13222
|
-
const types =
|
|
13263
|
+
const types = PAYMENT_TYPES;
|
|
13223
13264
|
|
|
13224
13265
|
switch (options.type) {
|
|
13225
13266
|
case types.CREATE_SUBSCRIPTION:
|
|
@@ -13233,12 +13274,15 @@ class VantivGateway {
|
|
|
13233
13274
|
|
|
13234
13275
|
case types.RENEW_GIFTED_SUBSCRIPTION:
|
|
13235
13276
|
return _classPrivateFieldGet(this, _renewGiftedSubscription2).call(this, options, callback);
|
|
13236
|
-
|
|
13237
|
-
|
|
13238
|
-
|
|
13277
|
+
|
|
13278
|
+
case types.PURCHASE_ECOMMERCE_ORDER:
|
|
13279
|
+
return _classPrivateFieldGet(this, _purchaseEcommerceOrder2).call(this, options, callback);
|
|
13280
|
+
|
|
13281
|
+
case types.PAY_INVOICE:
|
|
13282
|
+
return _classPrivateFieldGet(this, _payInvoice3).call(this, options, callback);
|
|
13239
13283
|
|
|
13240
13284
|
default:
|
|
13241
|
-
console.error("Unsupported
|
|
13285
|
+
console.error("Unsupported payment method: vantiv Gateway");
|
|
13242
13286
|
}
|
|
13243
13287
|
});
|
|
13244
13288
|
|
|
@@ -13371,6 +13415,56 @@ class VantivGateway {
|
|
|
13371
13415
|
});
|
|
13372
13416
|
}
|
|
13373
13417
|
});
|
|
13418
|
+
|
|
13419
|
+
_purchaseEcommerceOrder2.set(this, {
|
|
13420
|
+
writable: true,
|
|
13421
|
+
value: (options, callback) => {
|
|
13422
|
+
const {
|
|
13423
|
+
token,
|
|
13424
|
+
items,
|
|
13425
|
+
couponCode,
|
|
13426
|
+
addressId,
|
|
13427
|
+
isExistingSource
|
|
13428
|
+
} = options;
|
|
13429
|
+
const params = isExistingSource ? {
|
|
13430
|
+
source_id: token
|
|
13431
|
+
} : {
|
|
13432
|
+
payment_gateway: _classPrivateFieldGet(this, _paymentGateway3),
|
|
13433
|
+
gateway_token: token
|
|
13434
|
+
};
|
|
13435
|
+
window.Pelcro.ecommerce.order.create({
|
|
13436
|
+
items,
|
|
13437
|
+
coupon_code: couponCode,
|
|
13438
|
+
...params,
|
|
13439
|
+
...(addressId && {
|
|
13440
|
+
address_id: addressId
|
|
13441
|
+
})
|
|
13442
|
+
}, (err, res) => {
|
|
13443
|
+
callback(err, res);
|
|
13444
|
+
});
|
|
13445
|
+
}
|
|
13446
|
+
});
|
|
13447
|
+
|
|
13448
|
+
_payInvoice3.set(this, {
|
|
13449
|
+
writable: true,
|
|
13450
|
+
value: (options, callback) => {
|
|
13451
|
+
const {
|
|
13452
|
+
token,
|
|
13453
|
+
invoiceId
|
|
13454
|
+
} = options;
|
|
13455
|
+
const params = options.isExistingSource ? {
|
|
13456
|
+
source_id: token,
|
|
13457
|
+
invoice_id: invoiceId
|
|
13458
|
+
} : {
|
|
13459
|
+
payment_gateway: _classPrivateFieldGet(this, _paymentGateway3),
|
|
13460
|
+
gateway_token: token,
|
|
13461
|
+
invoice_id: invoiceId
|
|
13462
|
+
};
|
|
13463
|
+
window.Pelcro.invoice.pay(params, (err, res) => {
|
|
13464
|
+
callback(err, res);
|
|
13465
|
+
});
|
|
13466
|
+
}
|
|
13467
|
+
});
|
|
13374
13468
|
}
|
|
13375
13469
|
|
|
13376
13470
|
}
|
|
@@ -13463,22 +13557,22 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
13463
13557
|
updateTotalAmountWithTax();
|
|
13464
13558
|
}, []);
|
|
13465
13559
|
|
|
13466
|
-
|
|
13467
|
-
if (
|
|
13468
|
-
|
|
13469
|
-
|
|
13470
|
-
}
|
|
13471
|
-
|
|
13472
|
-
const orderId = `pelcro-${new Date().getTime()}`; // calls handleVantivPayment
|
|
13560
|
+
const submitVantivPayment = () => {
|
|
13561
|
+
if (selectedPaymentMethodId) {
|
|
13562
|
+
return handleVantivPayment(null);
|
|
13563
|
+
}
|
|
13473
13564
|
|
|
13474
|
-
|
|
13475
|
-
|
|
13476
|
-
orderId: orderId
|
|
13477
|
-
});
|
|
13478
|
-
} else {
|
|
13479
|
-
handleVantivPayment(null);
|
|
13565
|
+
if (!vantivInstanceRef.current) {
|
|
13566
|
+
return console.error("Vantiv sdk script wasn't loaded, you need to load vantiv sdk before rendering the vantiv payment flow");
|
|
13480
13567
|
}
|
|
13481
|
-
|
|
13568
|
+
|
|
13569
|
+
const orderId = `pelcro-${new Date().getTime()}`; // calls handleVantivPayment
|
|
13570
|
+
|
|
13571
|
+
vantivInstanceRef.current.getPaypageRegistrationId({
|
|
13572
|
+
id: orderId,
|
|
13573
|
+
orderId: orderId
|
|
13574
|
+
});
|
|
13575
|
+
};
|
|
13482
13576
|
|
|
13483
13577
|
function handleVantivPayment(paymentRequest) {
|
|
13484
13578
|
if (paymentRequest) {
|
|
@@ -13491,19 +13585,18 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
13491
13585
|
}
|
|
13492
13586
|
}
|
|
13493
13587
|
|
|
13494
|
-
const
|
|
13588
|
+
const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
|
|
13495
13589
|
|
|
13496
13590
|
if (type === "createPayment") {
|
|
13497
13591
|
handleVantivSubscription();
|
|
13498
|
-
}
|
|
13499
|
-
|
|
13500
|
-
|
|
13501
|
-
|
|
13502
|
-
|
|
13503
|
-
// }
|
|
13504
|
-
|
|
13592
|
+
} else if (type === "orderCreate") {
|
|
13593
|
+
purchase(new VantivGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest, state, dispatch);
|
|
13594
|
+
} else if (type === "invoicePayment") {
|
|
13595
|
+
payInvoice(new VantivGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest, dispatch);
|
|
13596
|
+
}
|
|
13505
13597
|
|
|
13506
13598
|
function handleVantivSubscription() {
|
|
13599
|
+
const payment = new Payment(new VantivGateway());
|
|
13507
13600
|
const createSubscription = !isGift && !subscriptionIdToRenew;
|
|
13508
13601
|
const renewSubscription = !isGift && subscriptionIdToRenew;
|
|
13509
13602
|
const giftSubscriprition = isGift && !subscriptionIdToRenew;
|
|
@@ -13511,11 +13604,10 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
13511
13604
|
const {
|
|
13512
13605
|
couponCode
|
|
13513
13606
|
} = state;
|
|
13514
|
-
const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
|
|
13515
13607
|
|
|
13516
13608
|
if (renewGift) {
|
|
13517
|
-
return
|
|
13518
|
-
type:
|
|
13609
|
+
return payment.execute({
|
|
13610
|
+
type: PAYMENT_TYPES.RENEW_GIFTED_SUBSCRIPTION,
|
|
13519
13611
|
token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
|
|
13520
13612
|
plan,
|
|
13521
13613
|
couponCode,
|
|
@@ -13531,8 +13623,8 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
13531
13623
|
onSuccess(res);
|
|
13532
13624
|
});
|
|
13533
13625
|
} else if (giftSubscriprition) {
|
|
13534
|
-
return
|
|
13535
|
-
type:
|
|
13626
|
+
return payment.execute({
|
|
13627
|
+
type: PAYMENT_TYPES.CREATE_GIFTED_SUBSCRIPTION,
|
|
13536
13628
|
token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
|
|
13537
13629
|
quantity: plan.quantity,
|
|
13538
13630
|
plan,
|
|
@@ -13549,8 +13641,8 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
13549
13641
|
onSuccess(res);
|
|
13550
13642
|
});
|
|
13551
13643
|
} else if (renewSubscription) {
|
|
13552
|
-
return
|
|
13553
|
-
type:
|
|
13644
|
+
return payment.execute({
|
|
13645
|
+
type: PAYMENT_TYPES.RENEW_SUBSCRIPTION,
|
|
13554
13646
|
token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
|
|
13555
13647
|
quantity: plan.quantity,
|
|
13556
13648
|
plan,
|
|
@@ -13567,8 +13659,8 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
13567
13659
|
onSuccess(res);
|
|
13568
13660
|
});
|
|
13569
13661
|
} else if (createSubscription) {
|
|
13570
|
-
return
|
|
13571
|
-
type:
|
|
13662
|
+
return payment.execute({
|
|
13663
|
+
type: PAYMENT_TYPES.CREATE_SUBSCRIPTION,
|
|
13572
13664
|
token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
|
|
13573
13665
|
quantity: plan.quantity,
|
|
13574
13666
|
plan,
|
|
@@ -14038,7 +14130,7 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
14038
14130
|
|
|
14039
14131
|
|
|
14040
14132
|
const handlePaypalSubscription = (state, paypalNonce) => {
|
|
14041
|
-
const
|
|
14133
|
+
const payment = new Payment(new PaypalGateway());
|
|
14042
14134
|
const {
|
|
14043
14135
|
couponCode
|
|
14044
14136
|
} = state;
|
|
@@ -14047,8 +14139,8 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
14047
14139
|
*/
|
|
14048
14140
|
|
|
14049
14141
|
if (giftRecipient) {
|
|
14050
|
-
return
|
|
14051
|
-
type:
|
|
14142
|
+
return payment.execute({
|
|
14143
|
+
type: PAYMENT_TYPES.CREATE_GIFTED_SUBSCRIPTION,
|
|
14052
14144
|
token: paypalNonce,
|
|
14053
14145
|
quantity: plan.quantity,
|
|
14054
14146
|
plan,
|
|
@@ -14081,8 +14173,8 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
14081
14173
|
});
|
|
14082
14174
|
}
|
|
14083
14175
|
|
|
14084
|
-
return
|
|
14085
|
-
type:
|
|
14176
|
+
return payment.execute({
|
|
14177
|
+
type: PAYMENT_TYPES.CREATE_SUBSCRIPTION,
|
|
14086
14178
|
token: paypalNonce,
|
|
14087
14179
|
quantity: plan.quantity,
|
|
14088
14180
|
plan,
|
|
@@ -14114,7 +14206,7 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
14114
14206
|
});
|
|
14115
14207
|
};
|
|
14116
14208
|
|
|
14117
|
-
const purchase = (
|
|
14209
|
+
const purchase = (gatewayService, gatewayToken, state, dispatch) => {
|
|
14118
14210
|
const isQuickPurchase = !Array.isArray(order);
|
|
14119
14211
|
const mappedOrderItems = isQuickPurchase ? [{
|
|
14120
14212
|
sku_id: order.id,
|
|
@@ -14126,14 +14218,14 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
14126
14218
|
const {
|
|
14127
14219
|
couponCode
|
|
14128
14220
|
} = state;
|
|
14129
|
-
|
|
14130
|
-
|
|
14131
|
-
|
|
14221
|
+
const payment = new Payment(gatewayService);
|
|
14222
|
+
payment.execute({
|
|
14223
|
+
type: PAYMENT_TYPES.PURCHASE_ECOMMERCE_ORDER,
|
|
14224
|
+
token: gatewayToken,
|
|
14225
|
+
isExistingSource: Boolean(selectedPaymentMethodId),
|
|
14132
14226
|
items: mappedOrderItems,
|
|
14133
|
-
|
|
14134
|
-
|
|
14135
|
-
address_id: selectedAddressId
|
|
14136
|
-
})
|
|
14227
|
+
addressId: selectedAddressId,
|
|
14228
|
+
couponCode
|
|
14137
14229
|
}, (err, res) => {
|
|
14138
14230
|
dispatch({
|
|
14139
14231
|
type: DISABLE_SUBMIT,
|
|
@@ -14171,9 +14263,9 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
14171
14263
|
};
|
|
14172
14264
|
|
|
14173
14265
|
const payInvoice = (gatewayService, gatewayToken, dispatch) => {
|
|
14174
|
-
const
|
|
14175
|
-
return
|
|
14176
|
-
type:
|
|
14266
|
+
const payment = new Payment(gatewayService);
|
|
14267
|
+
return payment.execute({
|
|
14268
|
+
type: PAYMENT_TYPES.PAY_INVOICE,
|
|
14177
14269
|
token: gatewayToken,
|
|
14178
14270
|
isExistingSource: Boolean(selectedPaymentMethodId),
|
|
14179
14271
|
invoiceId: invoice.id
|
|
@@ -14411,7 +14503,7 @@ const PaymentMethodContainerWithoutStripe = ({
|
|
|
14411
14503
|
if (stripeSource && type === "createPayment") {
|
|
14412
14504
|
subscribe(stripeSource, state, dispatch);
|
|
14413
14505
|
} else if (stripeSource && type === "orderCreate") {
|
|
14414
|
-
purchase(stripeSource, state, dispatch);
|
|
14506
|
+
purchase(new StripeGateway(), stripeSource.id, state, dispatch);
|
|
14415
14507
|
} else if (stripeSource && type === "invoicePayment") {
|
|
14416
14508
|
payInvoice(new StripeGateway(), stripeSource.id, dispatch);
|
|
14417
14509
|
}
|