@pelcro/react-pelcro-js 3.2.0-beta.4 → 3.2.0-beta.7

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 CHANGED
@@ -6814,7 +6814,9 @@ function userMustVerifyEmail() {
6814
6814
  return window.Pelcro.user.isAuthenticated() && isEmailVerificationEnabled && !isUserEmailVerified;
6815
6815
  }
6816
6816
  function getRenewableProducts() {
6817
- const renewableSubs = window.Pelcro.subscription.list().filter(sub => sub.status === "active" && sub.cancel_at_period_end === 1);
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 {
@@ -8869,7 +8871,7 @@ const loadPaymentSDKs = () => {
8869
8871
  } // Load Vantiv SDKs
8870
8872
 
8871
8873
 
8872
- const supportsVantiv = Boolean(window.Pelcro.site.read().vantiv_pay_page_id);
8874
+ const supportsVantiv = Boolean(window.Pelcro.site.read().vantiv_gateway_settings);
8873
8875
 
8874
8876
  if (supportsVantiv) {
8875
8877
  if (!window.jQuery) {
@@ -8877,7 +8879,10 @@ const loadPaymentSDKs = () => {
8877
8879
  }
8878
8880
 
8879
8881
  if (!window.EprotectIframeClient) {
8880
- window.Pelcro.helpers.loadSDK("https://request.eprotect.vantivprelive.com/eProtect/js/eProtect-iframe-client.min.js", "vantiv-eprotect-sdk");
8882
+ const PRELIVE_URL = "https://request.eprotect.vantivprelive.com/eProtect/js/eProtect-iframe-client.min.js";
8883
+ const PRODUCTION_URL = "https://request.eprotect.vantivcnp.com/eProtect/js/eProtect-iframe-client4.min.js";
8884
+ const scriptUrlToUse = window.Pelcro.site.read().vantiv_gateway_settings.environment === "production" ? PRODUCTION_URL : PRELIVE_URL;
8885
+ window.Pelcro.helpers.loadSDK(scriptUrlToUse, "vantiv-eprotect-sdk");
8881
8886
  }
8882
8887
  }
8883
8888
  };
@@ -12839,20 +12844,21 @@ var es_12 = es.injectStripe;
12839
12844
  var es_13 = es.StripeProvider;
12840
12845
 
12841
12846
  /**
12842
- * @TODO: All subscription related business logic should end up moving
12847
+ * @TODO: All payment related business logic should end up moving
12843
12848
  * to this service, and out of react components.
12844
12849
  */
12845
12850
 
12846
12851
  /**
12847
- * Enum for subscription types
12852
+ * Enum for payment types
12848
12853
  * @readonly
12849
12854
  * @enum {string}
12850
12855
  */
12851
- const SUBSCRIPTION_TYPES = {
12856
+ const PAYMENT_TYPES = {
12852
12857
  CREATE_SUBSCRIPTION: "CREATE_SUBSCRIPTION",
12853
12858
  CREATE_GIFTED_SUBSCRIPTION: "CREATE_GIFTED_SUBSCRIPTION",
12854
12859
  RENEW_SUBSCRIPTION: "RENEW_SUBSCRIPTION",
12855
12860
  RENEW_GIFTED_SUBSCRIPTION: "RENEW_GIFTED_SUBSCRIPTION",
12861
+ PURCHASE_ECOMMERCE_ORDER: "PURCHASE_ECOMMERCE_ORDER",
12856
12862
  PAY_INVOICE: "PAY_INVOICE"
12857
12863
  };
12858
12864
 
@@ -12860,9 +12866,8 @@ var _isPaymentGatewayInvalid = /*#__PURE__*/new WeakMap();
12860
12866
 
12861
12867
  var _generateUserError = /*#__PURE__*/new WeakMap();
12862
12868
 
12863
- class Subscription {
12869
+ class Payment {
12864
12870
  /**
12865
- * Subscription service constructor
12866
12871
  * @param {(StripeGateway|PaypalGateway|VantivGateway)} paymentGateway
12867
12872
  */
12868
12873
  constructor(paymentGateway) {
@@ -12874,7 +12879,7 @@ class Subscription {
12874
12879
 
12875
12880
  if (!options.type) {
12876
12881
  callback(_classPrivateFieldGet(this, _generateUserError).call(this), null);
12877
- return console.error("No subscription type provided");
12882
+ return console.error("No payment type provided");
12878
12883
  } // delegate execution to paymentgateway
12879
12884
 
12880
12885
 
@@ -12892,21 +12897,21 @@ class Subscription {
12892
12897
  writable: true,
12893
12898
  value: () => {
12894
12899
  return {
12895
- error: new Error("An error has occured in the subscription service, please try again later")
12900
+ error: new Error("An error has occured in the payment service, please try again later")
12896
12901
  };
12897
12902
  }
12898
12903
  });
12899
12904
 
12900
12905
  if (_classPrivateFieldGet(this, _isPaymentGatewayInvalid).call(this, paymentGateway)) {
12901
12906
  this.paymentGateway = null;
12902
- console.error("Incompatible subscription gateway");
12907
+ console.error("Incompatible payment gateway");
12903
12908
  } else {
12904
12909
  this.paymentGateway = paymentGateway;
12905
12910
  }
12906
12911
  }
12907
12912
  /**
12908
- * @typedef subscriptionOptions
12909
- * @property {SUBSCRIPTION_TYPES} type
12913
+ * @typedef paymentOptions
12914
+ * @property {PAYMENT_TYPES} type
12910
12915
  * @property {string} token
12911
12916
  * @property {object} plan
12912
12917
  * @property {object} [product]
@@ -12917,6 +12922,7 @@ class Subscription {
12917
12922
  * @property {string} addressId
12918
12923
  * @property {number} invoiceId
12919
12924
  * @property {boolean} isExistingSource
12925
+ * @property {Array} items
12920
12926
  */
12921
12927
 
12922
12928
  /**
@@ -12927,8 +12933,8 @@ class Subscription {
12927
12933
  */
12928
12934
 
12929
12935
  /**
12930
- * Subscription execution method
12931
- * @param {subscriptionOptions} options subscription options
12936
+ * Payment execution method
12937
+ * @param {paymentOptions} options payment options
12932
12938
  * @param {executeCallback} callback
12933
12939
  * @return {void}
12934
12940
  */
@@ -12941,7 +12947,7 @@ const PAYMENT_GATEWAYS_ENUM = {
12941
12947
  vantiv: "vantiv"
12942
12948
  };
12943
12949
  /**
12944
- * Subscription Strategies
12950
+ * Payment Strategies
12945
12951
  */
12946
12952
 
12947
12953
  /**
@@ -12958,6 +12964,8 @@ var _renewSubscription = /*#__PURE__*/new WeakMap();
12958
12964
 
12959
12965
  var _renewGiftedSubscription = /*#__PURE__*/new WeakMap();
12960
12966
 
12967
+ var _purchaseEcommerceOrder = /*#__PURE__*/new WeakMap();
12968
+
12961
12969
  var _payInvoice = /*#__PURE__*/new WeakMap();
12962
12970
 
12963
12971
  class StripeGateway {
@@ -12968,7 +12976,7 @@ class StripeGateway {
12968
12976
  });
12969
12977
 
12970
12978
  _defineProperty$3(this, "execute", (options, callback) => {
12971
- const types = SUBSCRIPTION_TYPES;
12979
+ const types = PAYMENT_TYPES;
12972
12980
 
12973
12981
  switch (options.type) {
12974
12982
  case types.CREATE_SUBSCRIPTION:
@@ -12983,11 +12991,14 @@ class StripeGateway {
12983
12991
  case types.RENEW_GIFTED_SUBSCRIPTION:
12984
12992
  return _classPrivateFieldGet(this, _renewGiftedSubscription).call(this, options, callback);
12985
12993
 
12994
+ case types.PURCHASE_ECOMMERCE_ORDER:
12995
+ return _classPrivateFieldGet(this, _purchaseEcommerceOrder).call(this, options, callback);
12996
+
12986
12997
  case types.PAY_INVOICE:
12987
12998
  return _classPrivateFieldGet(this, _payInvoice).call(this, options, callback);
12988
12999
 
12989
13000
  default:
12990
- console.error("Unsupported subscriptiion method: Stripe Gateway");
13001
+ console.error("Unsupported payment method: Stripe Gateway");
12991
13002
  }
12992
13003
  });
12993
13004
 
@@ -13009,6 +13020,7 @@ class StripeGateway {
13009
13020
  auth_token: window.Pelcro.user.read().auth_token,
13010
13021
  plan_id: plan.id,
13011
13022
  coupon_code: couponCode,
13023
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13012
13024
  address_id: product.address_required ? addressId : null
13013
13025
  }, (err, res) => {
13014
13026
  callback(err, res);
@@ -13035,6 +13047,7 @@ class StripeGateway {
13035
13047
  auth_token: window.Pelcro.user.read().auth_token,
13036
13048
  plan_id: plan.id,
13037
13049
  coupon_code: couponCode,
13050
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13038
13051
  gift_recipient_email: giftRecipient.email,
13039
13052
  gift_recipient_first_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.firstName,
13040
13053
  gift_recipient_last_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.lastName,
@@ -13062,6 +13075,7 @@ class StripeGateway {
13062
13075
  stripe_token: token,
13063
13076
  auth_token: window.Pelcro.user.read().auth_token,
13064
13077
  plan_id: plan.id,
13078
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13065
13079
  coupon_code: couponCode,
13066
13080
  subscription_id: subscriptionIdToRenew,
13067
13081
  address_id: product.address_required ? addressId : null
@@ -13095,6 +13109,36 @@ class StripeGateway {
13095
13109
  }
13096
13110
  });
13097
13111
 
13112
+ _purchaseEcommerceOrder.set(this, {
13113
+ writable: true,
13114
+ value: (options, callback) => {
13115
+ const {
13116
+ token,
13117
+ items,
13118
+ couponCode,
13119
+ addressId,
13120
+ isExistingSource
13121
+ } = options;
13122
+ const params = isExistingSource ? {
13123
+ source_id: token
13124
+ } : {
13125
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway),
13126
+ gateway_token: token
13127
+ };
13128
+ window.Pelcro.ecommerce.order.create({
13129
+ items,
13130
+ coupon_code: couponCode,
13131
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13132
+ ...params,
13133
+ ...(addressId && {
13134
+ address_id: addressId
13135
+ })
13136
+ }, (err, res) => {
13137
+ callback(err, res);
13138
+ });
13139
+ }
13140
+ });
13141
+
13098
13142
  _payInvoice.set(this, {
13099
13143
  writable: true,
13100
13144
  value: (options, callback) => {
@@ -13138,7 +13182,7 @@ class PaypalGateway {
13138
13182
  });
13139
13183
 
13140
13184
  _defineProperty$3(this, "execute", (options, callback) => {
13141
- const types = SUBSCRIPTION_TYPES;
13185
+ const types = PAYMENT_TYPES;
13142
13186
 
13143
13187
  switch (options.type) {
13144
13188
  case types.CREATE_SUBSCRIPTION:
@@ -13172,6 +13216,7 @@ class PaypalGateway {
13172
13216
  payment_gateway: _classPrivateFieldGet(this, _paymentGateway2),
13173
13217
  auth_token: window.Pelcro.user.read().auth_token,
13174
13218
  plan_id: plan.id,
13219
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13175
13220
  coupon_code: couponCode,
13176
13221
  address_id: product.address_required ? addressId : null
13177
13222
  }, (err, res) => {
@@ -13199,6 +13244,7 @@ class PaypalGateway {
13199
13244
  auth_token: window.Pelcro.user.read().auth_token,
13200
13245
  plan_id: plan.id,
13201
13246
  coupon_code: couponCode,
13247
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13202
13248
  gift_recipient_email: giftRecipient.email,
13203
13249
  gift_recipient_first_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.firstName,
13204
13250
  gift_recipient_last_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.lastName,
@@ -13241,6 +13287,10 @@ var _createGiftedSubscription3 = /*#__PURE__*/new WeakMap();
13241
13287
 
13242
13288
  var _renewGiftedSubscription2 = /*#__PURE__*/new WeakMap();
13243
13289
 
13290
+ var _purchaseEcommerceOrder2 = /*#__PURE__*/new WeakMap();
13291
+
13292
+ var _payInvoice3 = /*#__PURE__*/new WeakMap();
13293
+
13244
13294
  class VantivGateway {
13245
13295
  constructor() {
13246
13296
  _paymentGateway3.set(this, {
@@ -13249,7 +13299,7 @@ class VantivGateway {
13249
13299
  });
13250
13300
 
13251
13301
  _defineProperty$3(this, "execute", (options, callback) => {
13252
- const types = SUBSCRIPTION_TYPES;
13302
+ const types = PAYMENT_TYPES;
13253
13303
 
13254
13304
  switch (options.type) {
13255
13305
  case types.CREATE_SUBSCRIPTION:
@@ -13263,12 +13313,15 @@ class VantivGateway {
13263
13313
 
13264
13314
  case types.RENEW_GIFTED_SUBSCRIPTION:
13265
13315
  return _classPrivateFieldGet(this, _renewGiftedSubscription2).call(this, options, callback);
13266
- // TODO: implement paying invoices as well
13267
- // case types.PAY_INVOICE:
13268
- // return this.#payInvoice(options, callback);
13316
+
13317
+ case types.PURCHASE_ECOMMERCE_ORDER:
13318
+ return _classPrivateFieldGet(this, _purchaseEcommerceOrder2).call(this, options, callback);
13319
+
13320
+ case types.PAY_INVOICE:
13321
+ return _classPrivateFieldGet(this, _payInvoice3).call(this, options, callback);
13269
13322
 
13270
13323
  default:
13271
- console.error("Unsupported subscriptiion method: vantiv Gateway");
13324
+ console.error("Unsupported payment method: vantiv Gateway");
13272
13325
  }
13273
13326
  });
13274
13327
 
@@ -13294,6 +13347,7 @@ class VantivGateway {
13294
13347
  quantity,
13295
13348
  auth_token: window.Pelcro.user.read().auth_token,
13296
13349
  plan_id: plan.id,
13350
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13297
13351
  coupon_code: couponCode,
13298
13352
  address_id: product.address_required ? addressId : null,
13299
13353
  ...params
@@ -13325,6 +13379,7 @@ class VantivGateway {
13325
13379
  auth_token: window.Pelcro.user.read().auth_token,
13326
13380
  plan_id: plan.id,
13327
13381
  coupon_code: couponCode,
13382
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13328
13383
  subscription_id: subscriptionIdToRenew,
13329
13384
  address_id: product.address_required ? addressId : null,
13330
13385
  ...params
@@ -13358,6 +13413,7 @@ class VantivGateway {
13358
13413
  auth_token: window.Pelcro.user.read().auth_token,
13359
13414
  plan_id: plan.id,
13360
13415
  coupon_code: couponCode,
13416
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13361
13417
  gift_recipient_email: giftRecipient.email,
13362
13418
  gift_recipient_first_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.firstName,
13363
13419
  gift_recipient_last_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.lastName,
@@ -13401,6 +13457,57 @@ class VantivGateway {
13401
13457
  });
13402
13458
  }
13403
13459
  });
13460
+
13461
+ _purchaseEcommerceOrder2.set(this, {
13462
+ writable: true,
13463
+ value: (options, callback) => {
13464
+ const {
13465
+ token,
13466
+ items,
13467
+ couponCode,
13468
+ addressId,
13469
+ isExistingSource
13470
+ } = options;
13471
+ const params = isExistingSource ? {
13472
+ source_id: token
13473
+ } : {
13474
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway3),
13475
+ gateway_token: token
13476
+ };
13477
+ window.Pelcro.ecommerce.order.create({
13478
+ items,
13479
+ coupon_code: couponCode,
13480
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13481
+ ...params,
13482
+ ...(addressId && {
13483
+ address_id: addressId
13484
+ })
13485
+ }, (err, res) => {
13486
+ callback(err, res);
13487
+ });
13488
+ }
13489
+ });
13490
+
13491
+ _payInvoice3.set(this, {
13492
+ writable: true,
13493
+ value: (options, callback) => {
13494
+ const {
13495
+ token,
13496
+ invoiceId
13497
+ } = options;
13498
+ const params = options.isExistingSource ? {
13499
+ source_id: token,
13500
+ invoice_id: invoiceId
13501
+ } : {
13502
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway3),
13503
+ gateway_token: token,
13504
+ invoice_id: invoiceId
13505
+ };
13506
+ window.Pelcro.invoice.pay(params, (err, res) => {
13507
+ callback(err, res);
13508
+ });
13509
+ }
13510
+ });
13404
13511
  }
13405
13512
 
13406
13513
  }
@@ -13493,22 +13600,22 @@ const PaymentMethodContainerWithoutStripe = ({
13493
13600
  updateTotalAmountWithTax();
13494
13601
  }, []);
13495
13602
 
13496
- function submitVantivPayment() {
13497
- if (!selectedPaymentMethodId) {
13498
- if (!vantivInstanceRef.current) {
13499
- return console.error("Vantiv sdk script wasn't loaded, you need to load vantiv sdk before rendering the vantiv payment flow");
13500
- }
13501
-
13502
- const orderId = `pelcro-${new Date().getTime()}`; // calls handleVantivPayment
13603
+ const submitVantivPayment = () => {
13604
+ if (selectedPaymentMethodId) {
13605
+ return handleVantivPayment(null);
13606
+ }
13503
13607
 
13504
- vantivInstanceRef.current.getPaypageRegistrationId({
13505
- id: orderId,
13506
- orderId: orderId
13507
- });
13508
- } else {
13509
- handleVantivPayment(null);
13608
+ if (!vantivInstanceRef.current) {
13609
+ return console.error("Vantiv sdk script wasn't loaded, you need to load vantiv sdk before rendering the vantiv payment flow");
13510
13610
  }
13511
- }
13611
+
13612
+ const orderId = `pelcro-${new Date().getTime()}`; // calls handleVantivPayment
13613
+
13614
+ vantivInstanceRef.current.getPaypageRegistrationId({
13615
+ id: orderId,
13616
+ orderId: orderId
13617
+ });
13618
+ };
13512
13619
 
13513
13620
  function handleVantivPayment(paymentRequest) {
13514
13621
  if (paymentRequest) {
@@ -13521,19 +13628,18 @@ const PaymentMethodContainerWithoutStripe = ({
13521
13628
  }
13522
13629
  }
13523
13630
 
13524
- const subscription = new Subscription(new VantivGateway());
13631
+ const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
13525
13632
 
13526
13633
  if (type === "createPayment") {
13527
13634
  handleVantivSubscription();
13528
- } // TODO: handle other types of payments
13529
- // } else if (type === "orderCreate") {
13530
- // purchase(stripeSource, state, dispatch);
13531
- // } else if (type === "invoicePayment") {
13532
- // payInvoice(new StripeGateway(), stripeSource.id, dispatch);
13533
- // }
13534
-
13635
+ } else if (type === "orderCreate") {
13636
+ purchase(new VantivGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest, state, dispatch);
13637
+ } else if (type === "invoicePayment") {
13638
+ payInvoice(new VantivGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest, dispatch);
13639
+ }
13535
13640
 
13536
13641
  function handleVantivSubscription() {
13642
+ const payment = new Payment(new VantivGateway());
13537
13643
  const createSubscription = !isGift && !subscriptionIdToRenew;
13538
13644
  const renewSubscription = !isGift && subscriptionIdToRenew;
13539
13645
  const giftSubscriprition = isGift && !subscriptionIdToRenew;
@@ -13541,11 +13647,10 @@ const PaymentMethodContainerWithoutStripe = ({
13541
13647
  const {
13542
13648
  couponCode
13543
13649
  } = state;
13544
- const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
13545
13650
 
13546
13651
  if (renewGift) {
13547
- return subscription.execute({
13548
- type: SUBSCRIPTION_TYPES.RENEW_GIFTED_SUBSCRIPTION,
13652
+ return payment.execute({
13653
+ type: PAYMENT_TYPES.RENEW_GIFTED_SUBSCRIPTION,
13549
13654
  token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
13550
13655
  plan,
13551
13656
  couponCode,
@@ -13561,8 +13666,8 @@ const PaymentMethodContainerWithoutStripe = ({
13561
13666
  onSuccess(res);
13562
13667
  });
13563
13668
  } else if (giftSubscriprition) {
13564
- return subscription.execute({
13565
- type: SUBSCRIPTION_TYPES.CREATE_GIFTED_SUBSCRIPTION,
13669
+ return payment.execute({
13670
+ type: PAYMENT_TYPES.CREATE_GIFTED_SUBSCRIPTION,
13566
13671
  token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
13567
13672
  quantity: plan.quantity,
13568
13673
  plan,
@@ -13579,8 +13684,8 @@ const PaymentMethodContainerWithoutStripe = ({
13579
13684
  onSuccess(res);
13580
13685
  });
13581
13686
  } else if (renewSubscription) {
13582
- return subscription.execute({
13583
- type: SUBSCRIPTION_TYPES.RENEW_SUBSCRIPTION,
13687
+ return payment.execute({
13688
+ type: PAYMENT_TYPES.RENEW_SUBSCRIPTION,
13584
13689
  token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
13585
13690
  quantity: plan.quantity,
13586
13691
  plan,
@@ -13597,8 +13702,8 @@ const PaymentMethodContainerWithoutStripe = ({
13597
13702
  onSuccess(res);
13598
13703
  });
13599
13704
  } else if (createSubscription) {
13600
- return subscription.execute({
13601
- type: SUBSCRIPTION_TYPES.CREATE_SUBSCRIPTION,
13705
+ return payment.execute({
13706
+ type: PAYMENT_TYPES.CREATE_SUBSCRIPTION,
13602
13707
  token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
13603
13708
  quantity: plan.quantity,
13604
13709
  plan,
@@ -13622,12 +13727,13 @@ const PaymentMethodContainerWithoutStripe = ({
13622
13727
  const cardProcessor = getSiteCardProcessor();
13623
13728
 
13624
13729
  if (cardProcessor === "vantiv" && !selectedPaymentMethodId) {
13625
- var _window$Pelcro$site$r;
13730
+ var _window$Pelcro$site$r, _window$Pelcro$site$r2;
13626
13731
 
13627
- const payPageId = (_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.vantiv_pay_page_id;
13732
+ const payPageId = (_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.vantiv_gateway_settings.pay_page_id;
13733
+ const reportGroup = (_window$Pelcro$site$r2 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r2 === void 0 ? void 0 : _window$Pelcro$site$r2.vantiv_gateway_settings.report_group;
13628
13734
  vantivInstanceRef.current = new window.EprotectIframeClient({
13629
13735
  paypageId: payPageId,
13630
- reportGroup: payPageId,
13736
+ reportGroup: reportGroup,
13631
13737
  style: "pelcro",
13632
13738
  height: "245",
13633
13739
  timeout: 50000,
@@ -13716,9 +13822,9 @@ const PaymentMethodContainerWithoutStripe = ({
13716
13822
 
13717
13823
 
13718
13824
  const updateTotalAmountWithTax = () => {
13719
- var _window$Pelcro$site$r2;
13825
+ var _window$Pelcro$site$r3;
13720
13826
 
13721
- const taxesEnabled = (_window$Pelcro$site$r2 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r2 === void 0 ? void 0 : _window$Pelcro$site$r2.taxes_enabled;
13827
+ const taxesEnabled = (_window$Pelcro$site$r3 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r3 === void 0 ? void 0 : _window$Pelcro$site$r3.taxes_enabled;
13722
13828
 
13723
13829
  if (taxesEnabled && type === "createPayment") {
13724
13830
  dispatch({
@@ -13875,6 +13981,7 @@ const PaymentMethodContainerWithoutStripe = ({
13875
13981
  window.Pelcro.order.create({
13876
13982
  auth_token: window.Pelcro.user.read().auth_token,
13877
13983
  plan_id: plan.id,
13984
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13878
13985
  coupon_code: couponCode,
13879
13986
  address_id: selectedAddressId
13880
13987
  }, handleCouponResponse);
@@ -13956,6 +14063,7 @@ const PaymentMethodContainerWithoutStripe = ({
13956
14063
  stripe_token: !stripeSource.isExistingSource ? stripeSource.id : undefined,
13957
14064
  auth_token: window.Pelcro.user.read().auth_token,
13958
14065
  plan_id: plan.id,
14066
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13959
14067
  quantity: plan.quantity,
13960
14068
  coupon_code: couponCode,
13961
14069
  gift_recipient_email: giftRecipient ? giftRecipient.email : null,
@@ -14027,6 +14135,7 @@ const PaymentMethodContainerWithoutStripe = ({
14027
14135
  stripe_token: !stripeSource.isExistingSource ? stripeSource.id : undefined,
14028
14136
  auth_token: window.Pelcro.user.read().auth_token,
14029
14137
  plan_id: plan.id,
14138
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
14030
14139
  coupon_code: couponCode,
14031
14140
  subscription_id: subscriptionIdToRenew,
14032
14141
  address_id: product.address_required ? selectedAddressId : null
@@ -14068,7 +14177,7 @@ const PaymentMethodContainerWithoutStripe = ({
14068
14177
 
14069
14178
 
14070
14179
  const handlePaypalSubscription = (state, paypalNonce) => {
14071
- const subscription = new Subscription(new PaypalGateway());
14180
+ const payment = new Payment(new PaypalGateway());
14072
14181
  const {
14073
14182
  couponCode
14074
14183
  } = state;
@@ -14077,8 +14186,8 @@ const PaymentMethodContainerWithoutStripe = ({
14077
14186
  */
14078
14187
 
14079
14188
  if (giftRecipient) {
14080
- return subscription.execute({
14081
- type: SUBSCRIPTION_TYPES.CREATE_GIFTED_SUBSCRIPTION,
14189
+ return payment.execute({
14190
+ type: PAYMENT_TYPES.CREATE_GIFTED_SUBSCRIPTION,
14082
14191
  token: paypalNonce,
14083
14192
  quantity: plan.quantity,
14084
14193
  plan,
@@ -14111,8 +14220,8 @@ const PaymentMethodContainerWithoutStripe = ({
14111
14220
  });
14112
14221
  }
14113
14222
 
14114
- return subscription.execute({
14115
- type: SUBSCRIPTION_TYPES.CREATE_SUBSCRIPTION,
14223
+ return payment.execute({
14224
+ type: PAYMENT_TYPES.CREATE_SUBSCRIPTION,
14116
14225
  token: paypalNonce,
14117
14226
  quantity: plan.quantity,
14118
14227
  plan,
@@ -14144,7 +14253,7 @@ const PaymentMethodContainerWithoutStripe = ({
14144
14253
  });
14145
14254
  };
14146
14255
 
14147
- const purchase = (stripeSource, state, dispatch) => {
14256
+ const purchase = (gatewayService, gatewayToken, state, dispatch) => {
14148
14257
  const isQuickPurchase = !Array.isArray(order);
14149
14258
  const mappedOrderItems = isQuickPurchase ? [{
14150
14259
  sku_id: order.id,
@@ -14156,14 +14265,14 @@ const PaymentMethodContainerWithoutStripe = ({
14156
14265
  const {
14157
14266
  couponCode
14158
14267
  } = state;
14159
- window.Pelcro.ecommerce.order.create({
14160
- source_id: stripeSource.isExistingSource ? stripeSource.id : undefined,
14161
- stripe_token: !stripeSource.isExistingSource ? stripeSource.id : undefined,
14268
+ const payment = new Payment(gatewayService);
14269
+ payment.execute({
14270
+ type: PAYMENT_TYPES.PURCHASE_ECOMMERCE_ORDER,
14271
+ token: gatewayToken,
14272
+ isExistingSource: Boolean(selectedPaymentMethodId),
14162
14273
  items: mappedOrderItems,
14163
- coupon_code: couponCode,
14164
- ...(selectedAddressId && {
14165
- address_id: selectedAddressId
14166
- })
14274
+ addressId: selectedAddressId,
14275
+ couponCode
14167
14276
  }, (err, res) => {
14168
14277
  dispatch({
14169
14278
  type: DISABLE_SUBMIT,
@@ -14201,9 +14310,9 @@ const PaymentMethodContainerWithoutStripe = ({
14201
14310
  };
14202
14311
 
14203
14312
  const payInvoice = (gatewayService, gatewayToken, dispatch) => {
14204
- const subscription = new Subscription(gatewayService);
14205
- return subscription.execute({
14206
- type: SUBSCRIPTION_TYPES.PAY_INVOICE,
14313
+ const payment = new Payment(gatewayService);
14314
+ return payment.execute({
14315
+ type: PAYMENT_TYPES.PAY_INVOICE,
14207
14316
  token: gatewayToken,
14208
14317
  isExistingSource: Boolean(selectedPaymentMethodId),
14209
14318
  invoiceId: invoice.id
@@ -14363,13 +14472,13 @@ const PaymentMethodContainerWithoutStripe = ({
14363
14472
 
14364
14473
 
14365
14474
  const resolveTaxCalculation = () => {
14366
- var _window$Pelcro$site$r3;
14475
+ var _window$Pelcro$site$r4;
14367
14476
 
14368
14477
  if (type === "invoicePayment") {
14369
14478
  return new Promise(resolve => resolve());
14370
14479
  }
14371
14480
 
14372
- const taxesEnabled = (_window$Pelcro$site$r3 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r3 === void 0 ? void 0 : _window$Pelcro$site$r3.taxes_enabled;
14481
+ const taxesEnabled = (_window$Pelcro$site$r4 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r4 === void 0 ? void 0 : _window$Pelcro$site$r4.taxes_enabled;
14373
14482
  return new Promise((resolve, reject) => {
14374
14483
  // resolve early if taxes isn't enabled
14375
14484
  if (!taxesEnabled) {
@@ -14379,6 +14488,7 @@ const PaymentMethodContainerWithoutStripe = ({
14379
14488
  window.Pelcro.order.create({
14380
14489
  auth_token: window.Pelcro.user.read().auth_token,
14381
14490
  plan_id: plan.id,
14491
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
14382
14492
  coupon_code: state === null || state === void 0 ? void 0 : state.couponCode,
14383
14493
  address_id: selectedAddressId
14384
14494
  }, (error, res) => {
@@ -14441,7 +14551,7 @@ const PaymentMethodContainerWithoutStripe = ({
14441
14551
  if (stripeSource && type === "createPayment") {
14442
14552
  subscribe(stripeSource, state, dispatch);
14443
14553
  } else if (stripeSource && type === "orderCreate") {
14444
- purchase(stripeSource, state, dispatch);
14554
+ purchase(new StripeGateway(), stripeSource.id, state, dispatch);
14445
14555
  } else if (stripeSource && type === "invoicePayment") {
14446
14556
  payInvoice(new StripeGateway(), stripeSource.id, dispatch);
14447
14557
  }
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
- const renewableSubs = window.Pelcro.subscription.list().filter(sub => sub.status === "active" && sub.cancel_at_period_end === 1);
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 {
@@ -8839,7 +8841,7 @@ const loadPaymentSDKs = () => {
8839
8841
  } // Load Vantiv SDKs
8840
8842
 
8841
8843
 
8842
- const supportsVantiv = Boolean(window.Pelcro.site.read().vantiv_pay_page_id);
8844
+ const supportsVantiv = Boolean(window.Pelcro.site.read().vantiv_gateway_settings);
8843
8845
 
8844
8846
  if (supportsVantiv) {
8845
8847
  if (!window.jQuery) {
@@ -8847,7 +8849,10 @@ const loadPaymentSDKs = () => {
8847
8849
  }
8848
8850
 
8849
8851
  if (!window.EprotectIframeClient) {
8850
- window.Pelcro.helpers.loadSDK("https://request.eprotect.vantivprelive.com/eProtect/js/eProtect-iframe-client.min.js", "vantiv-eprotect-sdk");
8852
+ const PRELIVE_URL = "https://request.eprotect.vantivprelive.com/eProtect/js/eProtect-iframe-client.min.js";
8853
+ const PRODUCTION_URL = "https://request.eprotect.vantivcnp.com/eProtect/js/eProtect-iframe-client4.min.js";
8854
+ const scriptUrlToUse = window.Pelcro.site.read().vantiv_gateway_settings.environment === "production" ? PRODUCTION_URL : PRELIVE_URL;
8855
+ window.Pelcro.helpers.loadSDK(scriptUrlToUse, "vantiv-eprotect-sdk");
8851
8856
  }
8852
8857
  }
8853
8858
  };
@@ -12809,20 +12814,21 @@ var es_12 = es.injectStripe;
12809
12814
  var es_13 = es.StripeProvider;
12810
12815
 
12811
12816
  /**
12812
- * @TODO: All subscription related business logic should end up moving
12817
+ * @TODO: All payment related business logic should end up moving
12813
12818
  * to this service, and out of react components.
12814
12819
  */
12815
12820
 
12816
12821
  /**
12817
- * Enum for subscription types
12822
+ * Enum for payment types
12818
12823
  * @readonly
12819
12824
  * @enum {string}
12820
12825
  */
12821
- const SUBSCRIPTION_TYPES = {
12826
+ const PAYMENT_TYPES = {
12822
12827
  CREATE_SUBSCRIPTION: "CREATE_SUBSCRIPTION",
12823
12828
  CREATE_GIFTED_SUBSCRIPTION: "CREATE_GIFTED_SUBSCRIPTION",
12824
12829
  RENEW_SUBSCRIPTION: "RENEW_SUBSCRIPTION",
12825
12830
  RENEW_GIFTED_SUBSCRIPTION: "RENEW_GIFTED_SUBSCRIPTION",
12831
+ PURCHASE_ECOMMERCE_ORDER: "PURCHASE_ECOMMERCE_ORDER",
12826
12832
  PAY_INVOICE: "PAY_INVOICE"
12827
12833
  };
12828
12834
 
@@ -12830,9 +12836,8 @@ var _isPaymentGatewayInvalid = /*#__PURE__*/new WeakMap();
12830
12836
 
12831
12837
  var _generateUserError = /*#__PURE__*/new WeakMap();
12832
12838
 
12833
- class Subscription {
12839
+ class Payment {
12834
12840
  /**
12835
- * Subscription service constructor
12836
12841
  * @param {(StripeGateway|PaypalGateway|VantivGateway)} paymentGateway
12837
12842
  */
12838
12843
  constructor(paymentGateway) {
@@ -12844,7 +12849,7 @@ class Subscription {
12844
12849
 
12845
12850
  if (!options.type) {
12846
12851
  callback(_classPrivateFieldGet(this, _generateUserError).call(this), null);
12847
- return console.error("No subscription type provided");
12852
+ return console.error("No payment type provided");
12848
12853
  } // delegate execution to paymentgateway
12849
12854
 
12850
12855
 
@@ -12862,21 +12867,21 @@ class Subscription {
12862
12867
  writable: true,
12863
12868
  value: () => {
12864
12869
  return {
12865
- error: new Error("An error has occured in the subscription service, please try again later")
12870
+ error: new Error("An error has occured in the payment service, please try again later")
12866
12871
  };
12867
12872
  }
12868
12873
  });
12869
12874
 
12870
12875
  if (_classPrivateFieldGet(this, _isPaymentGatewayInvalid).call(this, paymentGateway)) {
12871
12876
  this.paymentGateway = null;
12872
- console.error("Incompatible subscription gateway");
12877
+ console.error("Incompatible payment gateway");
12873
12878
  } else {
12874
12879
  this.paymentGateway = paymentGateway;
12875
12880
  }
12876
12881
  }
12877
12882
  /**
12878
- * @typedef subscriptionOptions
12879
- * @property {SUBSCRIPTION_TYPES} type
12883
+ * @typedef paymentOptions
12884
+ * @property {PAYMENT_TYPES} type
12880
12885
  * @property {string} token
12881
12886
  * @property {object} plan
12882
12887
  * @property {object} [product]
@@ -12887,6 +12892,7 @@ class Subscription {
12887
12892
  * @property {string} addressId
12888
12893
  * @property {number} invoiceId
12889
12894
  * @property {boolean} isExistingSource
12895
+ * @property {Array} items
12890
12896
  */
12891
12897
 
12892
12898
  /**
@@ -12897,8 +12903,8 @@ class Subscription {
12897
12903
  */
12898
12904
 
12899
12905
  /**
12900
- * Subscription execution method
12901
- * @param {subscriptionOptions} options subscription options
12906
+ * Payment execution method
12907
+ * @param {paymentOptions} options payment options
12902
12908
  * @param {executeCallback} callback
12903
12909
  * @return {void}
12904
12910
  */
@@ -12911,7 +12917,7 @@ const PAYMENT_GATEWAYS_ENUM = {
12911
12917
  vantiv: "vantiv"
12912
12918
  };
12913
12919
  /**
12914
- * Subscription Strategies
12920
+ * Payment Strategies
12915
12921
  */
12916
12922
 
12917
12923
  /**
@@ -12928,6 +12934,8 @@ var _renewSubscription = /*#__PURE__*/new WeakMap();
12928
12934
 
12929
12935
  var _renewGiftedSubscription = /*#__PURE__*/new WeakMap();
12930
12936
 
12937
+ var _purchaseEcommerceOrder = /*#__PURE__*/new WeakMap();
12938
+
12931
12939
  var _payInvoice = /*#__PURE__*/new WeakMap();
12932
12940
 
12933
12941
  class StripeGateway {
@@ -12938,7 +12946,7 @@ class StripeGateway {
12938
12946
  });
12939
12947
 
12940
12948
  _defineProperty$3(this, "execute", (options, callback) => {
12941
- const types = SUBSCRIPTION_TYPES;
12949
+ const types = PAYMENT_TYPES;
12942
12950
 
12943
12951
  switch (options.type) {
12944
12952
  case types.CREATE_SUBSCRIPTION:
@@ -12953,11 +12961,14 @@ class StripeGateway {
12953
12961
  case types.RENEW_GIFTED_SUBSCRIPTION:
12954
12962
  return _classPrivateFieldGet(this, _renewGiftedSubscription).call(this, options, callback);
12955
12963
 
12964
+ case types.PURCHASE_ECOMMERCE_ORDER:
12965
+ return _classPrivateFieldGet(this, _purchaseEcommerceOrder).call(this, options, callback);
12966
+
12956
12967
  case types.PAY_INVOICE:
12957
12968
  return _classPrivateFieldGet(this, _payInvoice).call(this, options, callback);
12958
12969
 
12959
12970
  default:
12960
- console.error("Unsupported subscriptiion method: Stripe Gateway");
12971
+ console.error("Unsupported payment method: Stripe Gateway");
12961
12972
  }
12962
12973
  });
12963
12974
 
@@ -12979,6 +12990,7 @@ class StripeGateway {
12979
12990
  auth_token: window.Pelcro.user.read().auth_token,
12980
12991
  plan_id: plan.id,
12981
12992
  coupon_code: couponCode,
12993
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
12982
12994
  address_id: product.address_required ? addressId : null
12983
12995
  }, (err, res) => {
12984
12996
  callback(err, res);
@@ -13005,6 +13017,7 @@ class StripeGateway {
13005
13017
  auth_token: window.Pelcro.user.read().auth_token,
13006
13018
  plan_id: plan.id,
13007
13019
  coupon_code: couponCode,
13020
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13008
13021
  gift_recipient_email: giftRecipient.email,
13009
13022
  gift_recipient_first_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.firstName,
13010
13023
  gift_recipient_last_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.lastName,
@@ -13032,6 +13045,7 @@ class StripeGateway {
13032
13045
  stripe_token: token,
13033
13046
  auth_token: window.Pelcro.user.read().auth_token,
13034
13047
  plan_id: plan.id,
13048
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13035
13049
  coupon_code: couponCode,
13036
13050
  subscription_id: subscriptionIdToRenew,
13037
13051
  address_id: product.address_required ? addressId : null
@@ -13065,6 +13079,36 @@ class StripeGateway {
13065
13079
  }
13066
13080
  });
13067
13081
 
13082
+ _purchaseEcommerceOrder.set(this, {
13083
+ writable: true,
13084
+ value: (options, callback) => {
13085
+ const {
13086
+ token,
13087
+ items,
13088
+ couponCode,
13089
+ addressId,
13090
+ isExistingSource
13091
+ } = options;
13092
+ const params = isExistingSource ? {
13093
+ source_id: token
13094
+ } : {
13095
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway),
13096
+ gateway_token: token
13097
+ };
13098
+ window.Pelcro.ecommerce.order.create({
13099
+ items,
13100
+ coupon_code: couponCode,
13101
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13102
+ ...params,
13103
+ ...(addressId && {
13104
+ address_id: addressId
13105
+ })
13106
+ }, (err, res) => {
13107
+ callback(err, res);
13108
+ });
13109
+ }
13110
+ });
13111
+
13068
13112
  _payInvoice.set(this, {
13069
13113
  writable: true,
13070
13114
  value: (options, callback) => {
@@ -13108,7 +13152,7 @@ class PaypalGateway {
13108
13152
  });
13109
13153
 
13110
13154
  _defineProperty$3(this, "execute", (options, callback) => {
13111
- const types = SUBSCRIPTION_TYPES;
13155
+ const types = PAYMENT_TYPES;
13112
13156
 
13113
13157
  switch (options.type) {
13114
13158
  case types.CREATE_SUBSCRIPTION:
@@ -13142,6 +13186,7 @@ class PaypalGateway {
13142
13186
  payment_gateway: _classPrivateFieldGet(this, _paymentGateway2),
13143
13187
  auth_token: window.Pelcro.user.read().auth_token,
13144
13188
  plan_id: plan.id,
13189
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13145
13190
  coupon_code: couponCode,
13146
13191
  address_id: product.address_required ? addressId : null
13147
13192
  }, (err, res) => {
@@ -13169,6 +13214,7 @@ class PaypalGateway {
13169
13214
  auth_token: window.Pelcro.user.read().auth_token,
13170
13215
  plan_id: plan.id,
13171
13216
  coupon_code: couponCode,
13217
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13172
13218
  gift_recipient_email: giftRecipient.email,
13173
13219
  gift_recipient_first_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.firstName,
13174
13220
  gift_recipient_last_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.lastName,
@@ -13211,6 +13257,10 @@ var _createGiftedSubscription3 = /*#__PURE__*/new WeakMap();
13211
13257
 
13212
13258
  var _renewGiftedSubscription2 = /*#__PURE__*/new WeakMap();
13213
13259
 
13260
+ var _purchaseEcommerceOrder2 = /*#__PURE__*/new WeakMap();
13261
+
13262
+ var _payInvoice3 = /*#__PURE__*/new WeakMap();
13263
+
13214
13264
  class VantivGateway {
13215
13265
  constructor() {
13216
13266
  _paymentGateway3.set(this, {
@@ -13219,7 +13269,7 @@ class VantivGateway {
13219
13269
  });
13220
13270
 
13221
13271
  _defineProperty$3(this, "execute", (options, callback) => {
13222
- const types = SUBSCRIPTION_TYPES;
13272
+ const types = PAYMENT_TYPES;
13223
13273
 
13224
13274
  switch (options.type) {
13225
13275
  case types.CREATE_SUBSCRIPTION:
@@ -13233,12 +13283,15 @@ class VantivGateway {
13233
13283
 
13234
13284
  case types.RENEW_GIFTED_SUBSCRIPTION:
13235
13285
  return _classPrivateFieldGet(this, _renewGiftedSubscription2).call(this, options, callback);
13236
- // TODO: implement paying invoices as well
13237
- // case types.PAY_INVOICE:
13238
- // return this.#payInvoice(options, callback);
13286
+
13287
+ case types.PURCHASE_ECOMMERCE_ORDER:
13288
+ return _classPrivateFieldGet(this, _purchaseEcommerceOrder2).call(this, options, callback);
13289
+
13290
+ case types.PAY_INVOICE:
13291
+ return _classPrivateFieldGet(this, _payInvoice3).call(this, options, callback);
13239
13292
 
13240
13293
  default:
13241
- console.error("Unsupported subscriptiion method: vantiv Gateway");
13294
+ console.error("Unsupported payment method: vantiv Gateway");
13242
13295
  }
13243
13296
  });
13244
13297
 
@@ -13264,6 +13317,7 @@ class VantivGateway {
13264
13317
  quantity,
13265
13318
  auth_token: window.Pelcro.user.read().auth_token,
13266
13319
  plan_id: plan.id,
13320
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13267
13321
  coupon_code: couponCode,
13268
13322
  address_id: product.address_required ? addressId : null,
13269
13323
  ...params
@@ -13295,6 +13349,7 @@ class VantivGateway {
13295
13349
  auth_token: window.Pelcro.user.read().auth_token,
13296
13350
  plan_id: plan.id,
13297
13351
  coupon_code: couponCode,
13352
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13298
13353
  subscription_id: subscriptionIdToRenew,
13299
13354
  address_id: product.address_required ? addressId : null,
13300
13355
  ...params
@@ -13328,6 +13383,7 @@ class VantivGateway {
13328
13383
  auth_token: window.Pelcro.user.read().auth_token,
13329
13384
  plan_id: plan.id,
13330
13385
  coupon_code: couponCode,
13386
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13331
13387
  gift_recipient_email: giftRecipient.email,
13332
13388
  gift_recipient_first_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.firstName,
13333
13389
  gift_recipient_last_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.lastName,
@@ -13371,6 +13427,57 @@ class VantivGateway {
13371
13427
  });
13372
13428
  }
13373
13429
  });
13430
+
13431
+ _purchaseEcommerceOrder2.set(this, {
13432
+ writable: true,
13433
+ value: (options, callback) => {
13434
+ const {
13435
+ token,
13436
+ items,
13437
+ couponCode,
13438
+ addressId,
13439
+ isExistingSource
13440
+ } = options;
13441
+ const params = isExistingSource ? {
13442
+ source_id: token
13443
+ } : {
13444
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway3),
13445
+ gateway_token: token
13446
+ };
13447
+ window.Pelcro.ecommerce.order.create({
13448
+ items,
13449
+ coupon_code: couponCode,
13450
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13451
+ ...params,
13452
+ ...(addressId && {
13453
+ address_id: addressId
13454
+ })
13455
+ }, (err, res) => {
13456
+ callback(err, res);
13457
+ });
13458
+ }
13459
+ });
13460
+
13461
+ _payInvoice3.set(this, {
13462
+ writable: true,
13463
+ value: (options, callback) => {
13464
+ const {
13465
+ token,
13466
+ invoiceId
13467
+ } = options;
13468
+ const params = options.isExistingSource ? {
13469
+ source_id: token,
13470
+ invoice_id: invoiceId
13471
+ } : {
13472
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway3),
13473
+ gateway_token: token,
13474
+ invoice_id: invoiceId
13475
+ };
13476
+ window.Pelcro.invoice.pay(params, (err, res) => {
13477
+ callback(err, res);
13478
+ });
13479
+ }
13480
+ });
13374
13481
  }
13375
13482
 
13376
13483
  }
@@ -13463,22 +13570,22 @@ const PaymentMethodContainerWithoutStripe = ({
13463
13570
  updateTotalAmountWithTax();
13464
13571
  }, []);
13465
13572
 
13466
- function submitVantivPayment() {
13467
- if (!selectedPaymentMethodId) {
13468
- if (!vantivInstanceRef.current) {
13469
- return console.error("Vantiv sdk script wasn't loaded, you need to load vantiv sdk before rendering the vantiv payment flow");
13470
- }
13471
-
13472
- const orderId = `pelcro-${new Date().getTime()}`; // calls handleVantivPayment
13573
+ const submitVantivPayment = () => {
13574
+ if (selectedPaymentMethodId) {
13575
+ return handleVantivPayment(null);
13576
+ }
13473
13577
 
13474
- vantivInstanceRef.current.getPaypageRegistrationId({
13475
- id: orderId,
13476
- orderId: orderId
13477
- });
13478
- } else {
13479
- handleVantivPayment(null);
13578
+ if (!vantivInstanceRef.current) {
13579
+ return console.error("Vantiv sdk script wasn't loaded, you need to load vantiv sdk before rendering the vantiv payment flow");
13480
13580
  }
13481
- }
13581
+
13582
+ const orderId = `pelcro-${new Date().getTime()}`; // calls handleVantivPayment
13583
+
13584
+ vantivInstanceRef.current.getPaypageRegistrationId({
13585
+ id: orderId,
13586
+ orderId: orderId
13587
+ });
13588
+ };
13482
13589
 
13483
13590
  function handleVantivPayment(paymentRequest) {
13484
13591
  if (paymentRequest) {
@@ -13491,19 +13598,18 @@ const PaymentMethodContainerWithoutStripe = ({
13491
13598
  }
13492
13599
  }
13493
13600
 
13494
- const subscription = new Subscription(new VantivGateway());
13601
+ const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
13495
13602
 
13496
13603
  if (type === "createPayment") {
13497
13604
  handleVantivSubscription();
13498
- } // TODO: handle other types of payments
13499
- // } else if (type === "orderCreate") {
13500
- // purchase(stripeSource, state, dispatch);
13501
- // } else if (type === "invoicePayment") {
13502
- // payInvoice(new StripeGateway(), stripeSource.id, dispatch);
13503
- // }
13504
-
13605
+ } else if (type === "orderCreate") {
13606
+ purchase(new VantivGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest, state, dispatch);
13607
+ } else if (type === "invoicePayment") {
13608
+ payInvoice(new VantivGateway(), isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest, dispatch);
13609
+ }
13505
13610
 
13506
13611
  function handleVantivSubscription() {
13612
+ const payment = new Payment(new VantivGateway());
13507
13613
  const createSubscription = !isGift && !subscriptionIdToRenew;
13508
13614
  const renewSubscription = !isGift && subscriptionIdToRenew;
13509
13615
  const giftSubscriprition = isGift && !subscriptionIdToRenew;
@@ -13511,11 +13617,10 @@ const PaymentMethodContainerWithoutStripe = ({
13511
13617
  const {
13512
13618
  couponCode
13513
13619
  } = state;
13514
- const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
13515
13620
 
13516
13621
  if (renewGift) {
13517
- return subscription.execute({
13518
- type: SUBSCRIPTION_TYPES.RENEW_GIFTED_SUBSCRIPTION,
13622
+ return payment.execute({
13623
+ type: PAYMENT_TYPES.RENEW_GIFTED_SUBSCRIPTION,
13519
13624
  token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
13520
13625
  plan,
13521
13626
  couponCode,
@@ -13531,8 +13636,8 @@ const PaymentMethodContainerWithoutStripe = ({
13531
13636
  onSuccess(res);
13532
13637
  });
13533
13638
  } else if (giftSubscriprition) {
13534
- return subscription.execute({
13535
- type: SUBSCRIPTION_TYPES.CREATE_GIFTED_SUBSCRIPTION,
13639
+ return payment.execute({
13640
+ type: PAYMENT_TYPES.CREATE_GIFTED_SUBSCRIPTION,
13536
13641
  token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
13537
13642
  quantity: plan.quantity,
13538
13643
  plan,
@@ -13549,8 +13654,8 @@ const PaymentMethodContainerWithoutStripe = ({
13549
13654
  onSuccess(res);
13550
13655
  });
13551
13656
  } else if (renewSubscription) {
13552
- return subscription.execute({
13553
- type: SUBSCRIPTION_TYPES.RENEW_SUBSCRIPTION,
13657
+ return payment.execute({
13658
+ type: PAYMENT_TYPES.RENEW_SUBSCRIPTION,
13554
13659
  token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
13555
13660
  quantity: plan.quantity,
13556
13661
  plan,
@@ -13567,8 +13672,8 @@ const PaymentMethodContainerWithoutStripe = ({
13567
13672
  onSuccess(res);
13568
13673
  });
13569
13674
  } else if (createSubscription) {
13570
- return subscription.execute({
13571
- type: SUBSCRIPTION_TYPES.CREATE_SUBSCRIPTION,
13675
+ return payment.execute({
13676
+ type: PAYMENT_TYPES.CREATE_SUBSCRIPTION,
13572
13677
  token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
13573
13678
  quantity: plan.quantity,
13574
13679
  plan,
@@ -13592,12 +13697,13 @@ const PaymentMethodContainerWithoutStripe = ({
13592
13697
  const cardProcessor = getSiteCardProcessor();
13593
13698
 
13594
13699
  if (cardProcessor === "vantiv" && !selectedPaymentMethodId) {
13595
- var _window$Pelcro$site$r;
13700
+ var _window$Pelcro$site$r, _window$Pelcro$site$r2;
13596
13701
 
13597
- const payPageId = (_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.vantiv_pay_page_id;
13702
+ const payPageId = (_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.vantiv_gateway_settings.pay_page_id;
13703
+ const reportGroup = (_window$Pelcro$site$r2 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r2 === void 0 ? void 0 : _window$Pelcro$site$r2.vantiv_gateway_settings.report_group;
13598
13704
  vantivInstanceRef.current = new window.EprotectIframeClient({
13599
13705
  paypageId: payPageId,
13600
- reportGroup: payPageId,
13706
+ reportGroup: reportGroup,
13601
13707
  style: "pelcro",
13602
13708
  height: "245",
13603
13709
  timeout: 50000,
@@ -13686,9 +13792,9 @@ const PaymentMethodContainerWithoutStripe = ({
13686
13792
 
13687
13793
 
13688
13794
  const updateTotalAmountWithTax = () => {
13689
- var _window$Pelcro$site$r2;
13795
+ var _window$Pelcro$site$r3;
13690
13796
 
13691
- const taxesEnabled = (_window$Pelcro$site$r2 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r2 === void 0 ? void 0 : _window$Pelcro$site$r2.taxes_enabled;
13797
+ const taxesEnabled = (_window$Pelcro$site$r3 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r3 === void 0 ? void 0 : _window$Pelcro$site$r3.taxes_enabled;
13692
13798
 
13693
13799
  if (taxesEnabled && type === "createPayment") {
13694
13800
  dispatch({
@@ -13845,6 +13951,7 @@ const PaymentMethodContainerWithoutStripe = ({
13845
13951
  window.Pelcro.order.create({
13846
13952
  auth_token: window.Pelcro.user.read().auth_token,
13847
13953
  plan_id: plan.id,
13954
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13848
13955
  coupon_code: couponCode,
13849
13956
  address_id: selectedAddressId
13850
13957
  }, handleCouponResponse);
@@ -13926,6 +14033,7 @@ const PaymentMethodContainerWithoutStripe = ({
13926
14033
  stripe_token: !stripeSource.isExistingSource ? stripeSource.id : undefined,
13927
14034
  auth_token: window.Pelcro.user.read().auth_token,
13928
14035
  plan_id: plan.id,
14036
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
13929
14037
  quantity: plan.quantity,
13930
14038
  coupon_code: couponCode,
13931
14039
  gift_recipient_email: giftRecipient ? giftRecipient.email : null,
@@ -13997,6 +14105,7 @@ const PaymentMethodContainerWithoutStripe = ({
13997
14105
  stripe_token: !stripeSource.isExistingSource ? stripeSource.id : undefined,
13998
14106
  auth_token: window.Pelcro.user.read().auth_token,
13999
14107
  plan_id: plan.id,
14108
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
14000
14109
  coupon_code: couponCode,
14001
14110
  subscription_id: subscriptionIdToRenew,
14002
14111
  address_id: product.address_required ? selectedAddressId : null
@@ -14038,7 +14147,7 @@ const PaymentMethodContainerWithoutStripe = ({
14038
14147
 
14039
14148
 
14040
14149
  const handlePaypalSubscription = (state, paypalNonce) => {
14041
- const subscription = new Subscription(new PaypalGateway());
14150
+ const payment = new Payment(new PaypalGateway());
14042
14151
  const {
14043
14152
  couponCode
14044
14153
  } = state;
@@ -14047,8 +14156,8 @@ const PaymentMethodContainerWithoutStripe = ({
14047
14156
  */
14048
14157
 
14049
14158
  if (giftRecipient) {
14050
- return subscription.execute({
14051
- type: SUBSCRIPTION_TYPES.CREATE_GIFTED_SUBSCRIPTION,
14159
+ return payment.execute({
14160
+ type: PAYMENT_TYPES.CREATE_GIFTED_SUBSCRIPTION,
14052
14161
  token: paypalNonce,
14053
14162
  quantity: plan.quantity,
14054
14163
  plan,
@@ -14081,8 +14190,8 @@ const PaymentMethodContainerWithoutStripe = ({
14081
14190
  });
14082
14191
  }
14083
14192
 
14084
- return subscription.execute({
14085
- type: SUBSCRIPTION_TYPES.CREATE_SUBSCRIPTION,
14193
+ return payment.execute({
14194
+ type: PAYMENT_TYPES.CREATE_SUBSCRIPTION,
14086
14195
  token: paypalNonce,
14087
14196
  quantity: plan.quantity,
14088
14197
  plan,
@@ -14114,7 +14223,7 @@ const PaymentMethodContainerWithoutStripe = ({
14114
14223
  });
14115
14224
  };
14116
14225
 
14117
- const purchase = (stripeSource, state, dispatch) => {
14226
+ const purchase = (gatewayService, gatewayToken, state, dispatch) => {
14118
14227
  const isQuickPurchase = !Array.isArray(order);
14119
14228
  const mappedOrderItems = isQuickPurchase ? [{
14120
14229
  sku_id: order.id,
@@ -14126,14 +14235,14 @@ const PaymentMethodContainerWithoutStripe = ({
14126
14235
  const {
14127
14236
  couponCode
14128
14237
  } = state;
14129
- window.Pelcro.ecommerce.order.create({
14130
- source_id: stripeSource.isExistingSource ? stripeSource.id : undefined,
14131
- stripe_token: !stripeSource.isExistingSource ? stripeSource.id : undefined,
14238
+ const payment = new Payment(gatewayService);
14239
+ payment.execute({
14240
+ type: PAYMENT_TYPES.PURCHASE_ECOMMERCE_ORDER,
14241
+ token: gatewayToken,
14242
+ isExistingSource: Boolean(selectedPaymentMethodId),
14132
14243
  items: mappedOrderItems,
14133
- coupon_code: couponCode,
14134
- ...(selectedAddressId && {
14135
- address_id: selectedAddressId
14136
- })
14244
+ addressId: selectedAddressId,
14245
+ couponCode
14137
14246
  }, (err, res) => {
14138
14247
  dispatch({
14139
14248
  type: DISABLE_SUBMIT,
@@ -14171,9 +14280,9 @@ const PaymentMethodContainerWithoutStripe = ({
14171
14280
  };
14172
14281
 
14173
14282
  const payInvoice = (gatewayService, gatewayToken, dispatch) => {
14174
- const subscription = new Subscription(gatewayService);
14175
- return subscription.execute({
14176
- type: SUBSCRIPTION_TYPES.PAY_INVOICE,
14283
+ const payment = new Payment(gatewayService);
14284
+ return payment.execute({
14285
+ type: PAYMENT_TYPES.PAY_INVOICE,
14177
14286
  token: gatewayToken,
14178
14287
  isExistingSource: Boolean(selectedPaymentMethodId),
14179
14288
  invoiceId: invoice.id
@@ -14333,13 +14442,13 @@ const PaymentMethodContainerWithoutStripe = ({
14333
14442
 
14334
14443
 
14335
14444
  const resolveTaxCalculation = () => {
14336
- var _window$Pelcro$site$r3;
14445
+ var _window$Pelcro$site$r4;
14337
14446
 
14338
14447
  if (type === "invoicePayment") {
14339
14448
  return new Promise(resolve => resolve());
14340
14449
  }
14341
14450
 
14342
- const taxesEnabled = (_window$Pelcro$site$r3 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r3 === void 0 ? void 0 : _window$Pelcro$site$r3.taxes_enabled;
14451
+ const taxesEnabled = (_window$Pelcro$site$r4 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r4 === void 0 ? void 0 : _window$Pelcro$site$r4.taxes_enabled;
14343
14452
  return new Promise((resolve, reject) => {
14344
14453
  // resolve early if taxes isn't enabled
14345
14454
  if (!taxesEnabled) {
@@ -14349,6 +14458,7 @@ const PaymentMethodContainerWithoutStripe = ({
14349
14458
  window.Pelcro.order.create({
14350
14459
  auth_token: window.Pelcro.user.read().auth_token,
14351
14460
  plan_id: plan.id,
14461
+ campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
14352
14462
  coupon_code: state === null || state === void 0 ? void 0 : state.couponCode,
14353
14463
  address_id: selectedAddressId
14354
14464
  }, (error, res) => {
@@ -14411,7 +14521,7 @@ const PaymentMethodContainerWithoutStripe = ({
14411
14521
  if (stripeSource && type === "createPayment") {
14412
14522
  subscribe(stripeSource, state, dispatch);
14413
14523
  } else if (stripeSource && type === "orderCreate") {
14414
- purchase(stripeSource, state, dispatch);
14524
+ purchase(new StripeGateway(), stripeSource.id, state, dispatch);
14415
14525
  } else if (stripeSource && type === "invoicePayment") {
14416
14526
  payInvoice(new StripeGateway(), stripeSource.id, dispatch);
14417
14527
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pelcro/react-pelcro-js",
3
3
  "description": "Pelcro's React UI Elements",
4
- "version": "3.2.0-beta.4",
4
+ "version": "3.2.0-beta.7",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",