@pelcro/react-pelcro-js 3.2.0-beta.2 → 3.2.0-beta.3

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
@@ -13139,6 +13139,12 @@ var _paymentGateway3 = /*#__PURE__*/new WeakMap();
13139
13139
 
13140
13140
  var _createSubscription3 = /*#__PURE__*/new WeakMap();
13141
13141
 
13142
+ var _renewSubscription2 = /*#__PURE__*/new WeakMap();
13143
+
13144
+ var _createGiftedSubscription3 = /*#__PURE__*/new WeakMap();
13145
+
13146
+ var _renewGiftedSubscription2 = /*#__PURE__*/new WeakMap();
13147
+
13142
13148
  class VantivGateway {
13143
13149
  constructor() {
13144
13150
  _paymentGateway3.set(this, {
@@ -13153,6 +13159,18 @@ class VantivGateway {
13153
13159
  case types.CREATE_SUBSCRIPTION:
13154
13160
  return _classPrivateFieldGet(this, _createSubscription3).call(this, options, callback);
13155
13161
 
13162
+ case types.RENEW_SUBSCRIPTION:
13163
+ return _classPrivateFieldGet(this, _renewSubscription2).call(this, options, callback);
13164
+
13165
+ case types.CREATE_GIFTED_SUBSCRIPTION:
13166
+ return _classPrivateFieldGet(this, _createGiftedSubscription3).call(this, options, callback);
13167
+
13168
+ case types.RENEW_GIFTED_SUBSCRIPTION:
13169
+ return _classPrivateFieldGet(this, _renewGiftedSubscription2).call(this, options, callback);
13170
+ // TODO: implement paying invoices as well
13171
+ // case types.PAY_INVOICE:
13172
+ // return this.#payInvoice(options, callback);
13173
+
13156
13174
  default:
13157
13175
  console.error("Unsupported subscriptiion method: vantiv Gateway");
13158
13176
  }
@@ -13167,16 +13185,121 @@ class VantivGateway {
13167
13185
  couponCode,
13168
13186
  product,
13169
13187
  quantity = 1,
13170
- addressId
13188
+ addressId,
13189
+ isExistingSource
13171
13190
  } = options;
13191
+ const params = isExistingSource ? {
13192
+ source_id: token
13193
+ } : {
13194
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway3),
13195
+ gateway_token: token
13196
+ };
13172
13197
  window.Pelcro.subscription.create({
13173
13198
  quantity,
13174
- gateway_token: token,
13199
+ auth_token: window.Pelcro.user.read().auth_token,
13200
+ plan_id: plan.id,
13201
+ coupon_code: couponCode,
13202
+ address_id: product.address_required ? addressId : null,
13203
+ ...params
13204
+ }, (err, res) => {
13205
+ callback(err, res);
13206
+ });
13207
+ }
13208
+ });
13209
+
13210
+ _renewSubscription2.set(this, {
13211
+ writable: true,
13212
+ value: (options, callback) => {
13213
+ const {
13214
+ subscriptionIdToRenew,
13215
+ token,
13216
+ plan,
13217
+ couponCode,
13218
+ product,
13219
+ addressId,
13220
+ isExistingSource
13221
+ } = options;
13222
+ const params = isExistingSource ? {
13223
+ source_id: token
13224
+ } : {
13175
13225
  payment_gateway: _classPrivateFieldGet(this, _paymentGateway3),
13226
+ gateway_token: token
13227
+ };
13228
+ window.Pelcro.subscription.renew({
13176
13229
  auth_token: window.Pelcro.user.read().auth_token,
13177
13230
  plan_id: plan.id,
13178
13231
  coupon_code: couponCode,
13179
- address_id: product.address_required ? addressId : null
13232
+ subscription_id: subscriptionIdToRenew,
13233
+ address_id: product.address_required ? addressId : null,
13234
+ ...params
13235
+ }, (err, res) => {
13236
+ callback(err, res);
13237
+ });
13238
+ }
13239
+ });
13240
+
13241
+ _createGiftedSubscription3.set(this, {
13242
+ writable: true,
13243
+ value: (options, callback) => {
13244
+ const {
13245
+ token,
13246
+ plan,
13247
+ couponCode,
13248
+ product,
13249
+ giftRecipient,
13250
+ quantity = 1,
13251
+ addressId,
13252
+ isExistingSource
13253
+ } = options;
13254
+ const params = isExistingSource ? {
13255
+ source_id: token
13256
+ } : {
13257
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway3),
13258
+ gateway_token: token
13259
+ };
13260
+ window.Pelcro.subscription.create({
13261
+ quantity,
13262
+ auth_token: window.Pelcro.user.read().auth_token,
13263
+ plan_id: plan.id,
13264
+ coupon_code: couponCode,
13265
+ gift_recipient_email: giftRecipient.email,
13266
+ gift_recipient_first_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.firstName,
13267
+ gift_recipient_last_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.lastName,
13268
+ gift_start_date: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.startDate,
13269
+ gift_message: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.giftMessage,
13270
+ address_id: product.address_required ? addressId : null,
13271
+ ...params
13272
+ }, (err, res) => {
13273
+ callback(err, res);
13274
+ });
13275
+ }
13276
+ });
13277
+
13278
+ _renewGiftedSubscription2.set(this, {
13279
+ writable: true,
13280
+ value: (options, callback) => {
13281
+ const {
13282
+ subscriptionIdToRenew,
13283
+ token,
13284
+ product,
13285
+ plan,
13286
+ couponCode,
13287
+ addressId,
13288
+ isExistingSource
13289
+ } = options;
13290
+ const params = isExistingSource ? {
13291
+ source_id: token
13292
+ } : {
13293
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway3),
13294
+ gateway_token: token
13295
+ };
13296
+ window.Pelcro.subscription.renewGift({
13297
+ auth_token: window.Pelcro.user.read().auth_token,
13298
+ plan_id: plan.id,
13299
+ coupon_code: couponCode,
13300
+ subscription_id: subscriptionIdToRenew,
13301
+ address_id: product.address_required ? addressId : null,
13302
+ ...params
13180
13303
  }, (err, res) => {
13181
13304
  callback(err, res);
13182
13305
  });
@@ -13241,7 +13364,7 @@ const PaymentMethodContainerWithoutStripe = ({
13241
13364
  onFailure = () => {},
13242
13365
  ...props
13243
13366
  }) => {
13244
- var _props$product, _props$plan, _props$subscriptionId, _props$selectedAddres, _props$giftRecipient, _props$isRenewingGift, _props$invoice;
13367
+ var _props$product, _props$plan, _props$subscriptionId, _props$selectedAddres, _props$giftRecipient, _props$isGift, _props$isRenewingGift, _props$invoice;
13245
13368
 
13246
13369
  const {
13247
13370
  t
@@ -13257,6 +13380,7 @@ const PaymentMethodContainerWithoutStripe = ({
13257
13380
  const subscriptionIdToRenew = (_props$subscriptionId = props.subscriptionIdToRenew) !== null && _props$subscriptionId !== void 0 ? _props$subscriptionId : pelcroStore.subscriptionIdToRenew;
13258
13381
  const selectedAddressId = (_props$selectedAddres = props.selectedAddressId) !== null && _props$selectedAddres !== void 0 ? _props$selectedAddres : pelcroStore.selectedAddressId;
13259
13382
  const giftRecipient = (_props$giftRecipient = props.giftRecipient) !== null && _props$giftRecipient !== void 0 ? _props$giftRecipient : pelcroStore.giftRecipient;
13383
+ const isGift = (_props$isGift = props.isGift) !== null && _props$isGift !== void 0 ? _props$isGift : pelcroStore.isGift;
13260
13384
  const isRenewingGift = (_props$isRenewingGift = props.isRenewingGift) !== null && _props$isRenewingGift !== void 0 ? _props$isRenewingGift : pelcroStore.isRenewingGift;
13261
13385
  const invoice = (_props$invoice = props.invoice) !== null && _props$invoice !== void 0 ? _props$invoice : pelcroStore.invoice;
13262
13386
  React.useEffect(() => {
@@ -13274,53 +13398,134 @@ const PaymentMethodContainerWithoutStripe = ({
13274
13398
  }, []);
13275
13399
 
13276
13400
  function submitVantivPayment() {
13277
- if (!vantivInstanceRef.current) {
13278
- return console.error("Vantiv sdk script wasn't loaded, you need to load vantiv sdk before rendering the vantiv payment flow");
13279
- }
13401
+ if (!selectedPaymentMethodId) {
13402
+ if (!vantivInstanceRef.current) {
13403
+ return console.error("Vantiv sdk script wasn't loaded, you need to load vantiv sdk before rendering the vantiv payment flow");
13404
+ }
13280
13405
 
13281
- const orderId = `pelcro-${new Date().getTime()}`; // calls handleVantivPayment
13406
+ const orderId = `pelcro-${new Date().getTime()}`; // calls handleVantivPayment
13282
13407
 
13283
- vantivInstanceRef.current.getPaypageRegistrationId({
13284
- id: orderId,
13285
- orderId: orderId
13286
- });
13408
+ vantivInstanceRef.current.getPaypageRegistrationId({
13409
+ id: orderId,
13410
+ orderId: orderId
13411
+ });
13412
+ } else {
13413
+ handleVantivPayment(null);
13414
+ }
13287
13415
  }
13288
13416
 
13289
13417
  function handleVantivPayment(paymentRequest) {
13290
- const SUCCESS_STATUS = "870";
13418
+ if (paymentRequest) {
13419
+ const SUCCESS_STATUS = "870";
13291
13420
 
13292
- if (paymentRequest.response !== SUCCESS_STATUS) {
13293
- return handlePaymentError({
13294
- error: new Error(paymentRequest.message)
13295
- });
13421
+ if (paymentRequest.response !== SUCCESS_STATUS) {
13422
+ return handlePaymentError({
13423
+ error: new Error(paymentRequest.message)
13424
+ });
13425
+ }
13296
13426
  }
13297
13427
 
13298
13428
  const subscription = new Subscription(new VantivGateway());
13299
- const {
13300
- couponCode
13301
- } = state;
13302
- return subscription.execute({
13303
- type: SUBSCRIPTION_TYPES.CREATE_SUBSCRIPTION,
13304
- token: paymentRequest,
13305
- quantity: plan.quantity,
13306
- plan,
13307
- couponCode,
13308
- product,
13309
- addressId: selectedAddressId
13310
- }, (err, res) => {
13311
- if (err) {
13312
- return handlePaymentError(err);
13313
- }
13314
13429
 
13315
- onSuccess(res);
13316
- });
13430
+ if (type === "createPayment") {
13431
+ handleVantivSubscription();
13432
+ } // TODO: handle other types of payments
13433
+ // } else if (type === "orderCreate") {
13434
+ // purchase(stripeSource, state, dispatch);
13435
+ // } else if (type === "invoicePayment") {
13436
+ // payInvoice(new StripeGateway(), stripeSource.id, dispatch);
13437
+ // }
13438
+
13439
+
13440
+ function handleVantivSubscription() {
13441
+ const createSubscription = !isGift && !subscriptionIdToRenew;
13442
+ const renewSubscription = !isGift && subscriptionIdToRenew;
13443
+ const giftSubscriprition = isGift && !subscriptionIdToRenew;
13444
+ const renewGift = isRenewingGift;
13445
+ const {
13446
+ couponCode
13447
+ } = state;
13448
+ const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
13449
+
13450
+ if (renewGift) {
13451
+ return subscription.execute({
13452
+ type: SUBSCRIPTION_TYPES.RENEW_GIFTED_SUBSCRIPTION,
13453
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
13454
+ plan,
13455
+ couponCode,
13456
+ product,
13457
+ isExistingSource: isUsingExistingPaymentMethod,
13458
+ subscriptionIdToRenew,
13459
+ addressId: selectedAddressId
13460
+ }, (err, res) => {
13461
+ if (err) {
13462
+ return handlePaymentError(err);
13463
+ }
13464
+
13465
+ onSuccess(res);
13466
+ });
13467
+ } else if (giftSubscriprition) {
13468
+ return subscription.execute({
13469
+ type: SUBSCRIPTION_TYPES.CREATE_GIFTED_SUBSCRIPTION,
13470
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
13471
+ quantity: plan.quantity,
13472
+ plan,
13473
+ couponCode,
13474
+ product,
13475
+ isExistingSource: isUsingExistingPaymentMethod,
13476
+ giftRecipient,
13477
+ addressId: selectedAddressId
13478
+ }, (err, res) => {
13479
+ if (err) {
13480
+ return handlePaymentError(err);
13481
+ }
13482
+
13483
+ onSuccess(res);
13484
+ });
13485
+ } else if (renewSubscription) {
13486
+ return subscription.execute({
13487
+ type: SUBSCRIPTION_TYPES.RENEW_SUBSCRIPTION,
13488
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
13489
+ quantity: plan.quantity,
13490
+ plan,
13491
+ couponCode,
13492
+ product,
13493
+ isExistingSource: isUsingExistingPaymentMethod,
13494
+ subscriptionIdToRenew,
13495
+ addressId: selectedAddressId
13496
+ }, (err, res) => {
13497
+ if (err) {
13498
+ return handlePaymentError(err);
13499
+ }
13500
+
13501
+ onSuccess(res);
13502
+ });
13503
+ } else if (createSubscription) {
13504
+ return subscription.execute({
13505
+ type: SUBSCRIPTION_TYPES.CREATE_SUBSCRIPTION,
13506
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
13507
+ quantity: plan.quantity,
13508
+ plan,
13509
+ couponCode,
13510
+ product,
13511
+ isExistingSource: isUsingExistingPaymentMethod,
13512
+ addressId: selectedAddressId
13513
+ }, (err, res) => {
13514
+ if (err) {
13515
+ return handlePaymentError(err);
13516
+ }
13517
+
13518
+ onSuccess(res);
13519
+ });
13520
+ }
13521
+ }
13317
13522
  }
13318
13523
 
13319
13524
  const vantivInstanceRef = React__default['default'].useRef(null);
13320
13525
  React.useEffect(() => {
13321
13526
  const cardProcessor = getSiteCardProcessor();
13322
13527
 
13323
- if (cardProcessor === "vantiv") {
13528
+ if (cardProcessor === "vantiv" && !selectedPaymentMethodId) {
13324
13529
  var _window$Pelcro$site$r;
13325
13530
 
13326
13531
  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;
@@ -13343,7 +13548,7 @@ const PaymentMethodContainerWithoutStripe = ({
13343
13548
  }
13344
13549
  });
13345
13550
  }
13346
- }, []);
13551
+ }, [selectedPaymentMethodId]);
13347
13552
 
13348
13553
  const initPaymentRequest = (state, dispatch) => {
13349
13554
  try {
@@ -14262,6 +14467,10 @@ const PaymentMethodContainerWithoutStripe = ({
14262
14467
  disableSubmit: true,
14263
14468
  isLoading: true
14264
14469
  }, (state, dispatch) => {
14470
+ if (getSiteCardProcessor() === "vantiv") {
14471
+ return submitVantivPayment();
14472
+ }
14473
+
14265
14474
  if (selectedPaymentMethodId) {
14266
14475
  // pay with selected method (source) if exists already
14267
14476
  return handlePayment({
@@ -14274,10 +14483,6 @@ const PaymentMethodContainerWithoutStripe = ({
14274
14483
  return updatePaymentSource(state, dispatch);
14275
14484
  }
14276
14485
 
14277
- if (getSiteCardProcessor() === "vantiv") {
14278
- return submitVantivPayment();
14279
- }
14280
-
14281
14486
  submitPayment(state);
14282
14487
  });
14283
14488
 
package/dist/index.esm.js CHANGED
@@ -13109,6 +13109,12 @@ var _paymentGateway3 = /*#__PURE__*/new WeakMap();
13109
13109
 
13110
13110
  var _createSubscription3 = /*#__PURE__*/new WeakMap();
13111
13111
 
13112
+ var _renewSubscription2 = /*#__PURE__*/new WeakMap();
13113
+
13114
+ var _createGiftedSubscription3 = /*#__PURE__*/new WeakMap();
13115
+
13116
+ var _renewGiftedSubscription2 = /*#__PURE__*/new WeakMap();
13117
+
13112
13118
  class VantivGateway {
13113
13119
  constructor() {
13114
13120
  _paymentGateway3.set(this, {
@@ -13123,6 +13129,18 @@ class VantivGateway {
13123
13129
  case types.CREATE_SUBSCRIPTION:
13124
13130
  return _classPrivateFieldGet(this, _createSubscription3).call(this, options, callback);
13125
13131
 
13132
+ case types.RENEW_SUBSCRIPTION:
13133
+ return _classPrivateFieldGet(this, _renewSubscription2).call(this, options, callback);
13134
+
13135
+ case types.CREATE_GIFTED_SUBSCRIPTION:
13136
+ return _classPrivateFieldGet(this, _createGiftedSubscription3).call(this, options, callback);
13137
+
13138
+ case types.RENEW_GIFTED_SUBSCRIPTION:
13139
+ return _classPrivateFieldGet(this, _renewGiftedSubscription2).call(this, options, callback);
13140
+ // TODO: implement paying invoices as well
13141
+ // case types.PAY_INVOICE:
13142
+ // return this.#payInvoice(options, callback);
13143
+
13126
13144
  default:
13127
13145
  console.error("Unsupported subscriptiion method: vantiv Gateway");
13128
13146
  }
@@ -13137,16 +13155,121 @@ class VantivGateway {
13137
13155
  couponCode,
13138
13156
  product,
13139
13157
  quantity = 1,
13140
- addressId
13158
+ addressId,
13159
+ isExistingSource
13141
13160
  } = options;
13161
+ const params = isExistingSource ? {
13162
+ source_id: token
13163
+ } : {
13164
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway3),
13165
+ gateway_token: token
13166
+ };
13142
13167
  window.Pelcro.subscription.create({
13143
13168
  quantity,
13144
- gateway_token: token,
13169
+ auth_token: window.Pelcro.user.read().auth_token,
13170
+ plan_id: plan.id,
13171
+ coupon_code: couponCode,
13172
+ address_id: product.address_required ? addressId : null,
13173
+ ...params
13174
+ }, (err, res) => {
13175
+ callback(err, res);
13176
+ });
13177
+ }
13178
+ });
13179
+
13180
+ _renewSubscription2.set(this, {
13181
+ writable: true,
13182
+ value: (options, callback) => {
13183
+ const {
13184
+ subscriptionIdToRenew,
13185
+ token,
13186
+ plan,
13187
+ couponCode,
13188
+ product,
13189
+ addressId,
13190
+ isExistingSource
13191
+ } = options;
13192
+ const params = isExistingSource ? {
13193
+ source_id: token
13194
+ } : {
13145
13195
  payment_gateway: _classPrivateFieldGet(this, _paymentGateway3),
13196
+ gateway_token: token
13197
+ };
13198
+ window.Pelcro.subscription.renew({
13146
13199
  auth_token: window.Pelcro.user.read().auth_token,
13147
13200
  plan_id: plan.id,
13148
13201
  coupon_code: couponCode,
13149
- address_id: product.address_required ? addressId : null
13202
+ subscription_id: subscriptionIdToRenew,
13203
+ address_id: product.address_required ? addressId : null,
13204
+ ...params
13205
+ }, (err, res) => {
13206
+ callback(err, res);
13207
+ });
13208
+ }
13209
+ });
13210
+
13211
+ _createGiftedSubscription3.set(this, {
13212
+ writable: true,
13213
+ value: (options, callback) => {
13214
+ const {
13215
+ token,
13216
+ plan,
13217
+ couponCode,
13218
+ product,
13219
+ giftRecipient,
13220
+ quantity = 1,
13221
+ addressId,
13222
+ isExistingSource
13223
+ } = options;
13224
+ const params = isExistingSource ? {
13225
+ source_id: token
13226
+ } : {
13227
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway3),
13228
+ gateway_token: token
13229
+ };
13230
+ window.Pelcro.subscription.create({
13231
+ quantity,
13232
+ auth_token: window.Pelcro.user.read().auth_token,
13233
+ plan_id: plan.id,
13234
+ coupon_code: couponCode,
13235
+ gift_recipient_email: giftRecipient.email,
13236
+ gift_recipient_first_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.firstName,
13237
+ gift_recipient_last_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.lastName,
13238
+ gift_start_date: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.startDate,
13239
+ gift_message: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.giftMessage,
13240
+ address_id: product.address_required ? addressId : null,
13241
+ ...params
13242
+ }, (err, res) => {
13243
+ callback(err, res);
13244
+ });
13245
+ }
13246
+ });
13247
+
13248
+ _renewGiftedSubscription2.set(this, {
13249
+ writable: true,
13250
+ value: (options, callback) => {
13251
+ const {
13252
+ subscriptionIdToRenew,
13253
+ token,
13254
+ product,
13255
+ plan,
13256
+ couponCode,
13257
+ addressId,
13258
+ isExistingSource
13259
+ } = options;
13260
+ const params = isExistingSource ? {
13261
+ source_id: token
13262
+ } : {
13263
+ payment_gateway: _classPrivateFieldGet(this, _paymentGateway3),
13264
+ gateway_token: token
13265
+ };
13266
+ window.Pelcro.subscription.renewGift({
13267
+ auth_token: window.Pelcro.user.read().auth_token,
13268
+ plan_id: plan.id,
13269
+ coupon_code: couponCode,
13270
+ subscription_id: subscriptionIdToRenew,
13271
+ address_id: product.address_required ? addressId : null,
13272
+ ...params
13150
13273
  }, (err, res) => {
13151
13274
  callback(err, res);
13152
13275
  });
@@ -13211,7 +13334,7 @@ const PaymentMethodContainerWithoutStripe = ({
13211
13334
  onFailure = () => {},
13212
13335
  ...props
13213
13336
  }) => {
13214
- var _props$product, _props$plan, _props$subscriptionId, _props$selectedAddres, _props$giftRecipient, _props$isRenewingGift, _props$invoice;
13337
+ var _props$product, _props$plan, _props$subscriptionId, _props$selectedAddres, _props$giftRecipient, _props$isGift, _props$isRenewingGift, _props$invoice;
13215
13338
 
13216
13339
  const {
13217
13340
  t
@@ -13227,6 +13350,7 @@ const PaymentMethodContainerWithoutStripe = ({
13227
13350
  const subscriptionIdToRenew = (_props$subscriptionId = props.subscriptionIdToRenew) !== null && _props$subscriptionId !== void 0 ? _props$subscriptionId : pelcroStore.subscriptionIdToRenew;
13228
13351
  const selectedAddressId = (_props$selectedAddres = props.selectedAddressId) !== null && _props$selectedAddres !== void 0 ? _props$selectedAddres : pelcroStore.selectedAddressId;
13229
13352
  const giftRecipient = (_props$giftRecipient = props.giftRecipient) !== null && _props$giftRecipient !== void 0 ? _props$giftRecipient : pelcroStore.giftRecipient;
13353
+ const isGift = (_props$isGift = props.isGift) !== null && _props$isGift !== void 0 ? _props$isGift : pelcroStore.isGift;
13230
13354
  const isRenewingGift = (_props$isRenewingGift = props.isRenewingGift) !== null && _props$isRenewingGift !== void 0 ? _props$isRenewingGift : pelcroStore.isRenewingGift;
13231
13355
  const invoice = (_props$invoice = props.invoice) !== null && _props$invoice !== void 0 ? _props$invoice : pelcroStore.invoice;
13232
13356
  useEffect(() => {
@@ -13244,53 +13368,134 @@ const PaymentMethodContainerWithoutStripe = ({
13244
13368
  }, []);
13245
13369
 
13246
13370
  function submitVantivPayment() {
13247
- if (!vantivInstanceRef.current) {
13248
- return console.error("Vantiv sdk script wasn't loaded, you need to load vantiv sdk before rendering the vantiv payment flow");
13249
- }
13371
+ if (!selectedPaymentMethodId) {
13372
+ if (!vantivInstanceRef.current) {
13373
+ return console.error("Vantiv sdk script wasn't loaded, you need to load vantiv sdk before rendering the vantiv payment flow");
13374
+ }
13250
13375
 
13251
- const orderId = `pelcro-${new Date().getTime()}`; // calls handleVantivPayment
13376
+ const orderId = `pelcro-${new Date().getTime()}`; // calls handleVantivPayment
13252
13377
 
13253
- vantivInstanceRef.current.getPaypageRegistrationId({
13254
- id: orderId,
13255
- orderId: orderId
13256
- });
13378
+ vantivInstanceRef.current.getPaypageRegistrationId({
13379
+ id: orderId,
13380
+ orderId: orderId
13381
+ });
13382
+ } else {
13383
+ handleVantivPayment(null);
13384
+ }
13257
13385
  }
13258
13386
 
13259
13387
  function handleVantivPayment(paymentRequest) {
13260
- const SUCCESS_STATUS = "870";
13388
+ if (paymentRequest) {
13389
+ const SUCCESS_STATUS = "870";
13261
13390
 
13262
- if (paymentRequest.response !== SUCCESS_STATUS) {
13263
- return handlePaymentError({
13264
- error: new Error(paymentRequest.message)
13265
- });
13391
+ if (paymentRequest.response !== SUCCESS_STATUS) {
13392
+ return handlePaymentError({
13393
+ error: new Error(paymentRequest.message)
13394
+ });
13395
+ }
13266
13396
  }
13267
13397
 
13268
13398
  const subscription = new Subscription(new VantivGateway());
13269
- const {
13270
- couponCode
13271
- } = state;
13272
- return subscription.execute({
13273
- type: SUBSCRIPTION_TYPES.CREATE_SUBSCRIPTION,
13274
- token: paymentRequest,
13275
- quantity: plan.quantity,
13276
- plan,
13277
- couponCode,
13278
- product,
13279
- addressId: selectedAddressId
13280
- }, (err, res) => {
13281
- if (err) {
13282
- return handlePaymentError(err);
13283
- }
13284
13399
 
13285
- onSuccess(res);
13286
- });
13400
+ if (type === "createPayment") {
13401
+ handleVantivSubscription();
13402
+ } // TODO: handle other types of payments
13403
+ // } else if (type === "orderCreate") {
13404
+ // purchase(stripeSource, state, dispatch);
13405
+ // } else if (type === "invoicePayment") {
13406
+ // payInvoice(new StripeGateway(), stripeSource.id, dispatch);
13407
+ // }
13408
+
13409
+
13410
+ function handleVantivSubscription() {
13411
+ const createSubscription = !isGift && !subscriptionIdToRenew;
13412
+ const renewSubscription = !isGift && subscriptionIdToRenew;
13413
+ const giftSubscriprition = isGift && !subscriptionIdToRenew;
13414
+ const renewGift = isRenewingGift;
13415
+ const {
13416
+ couponCode
13417
+ } = state;
13418
+ const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
13419
+
13420
+ if (renewGift) {
13421
+ return subscription.execute({
13422
+ type: SUBSCRIPTION_TYPES.RENEW_GIFTED_SUBSCRIPTION,
13423
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
13424
+ plan,
13425
+ couponCode,
13426
+ product,
13427
+ isExistingSource: isUsingExistingPaymentMethod,
13428
+ subscriptionIdToRenew,
13429
+ addressId: selectedAddressId
13430
+ }, (err, res) => {
13431
+ if (err) {
13432
+ return handlePaymentError(err);
13433
+ }
13434
+
13435
+ onSuccess(res);
13436
+ });
13437
+ } else if (giftSubscriprition) {
13438
+ return subscription.execute({
13439
+ type: SUBSCRIPTION_TYPES.CREATE_GIFTED_SUBSCRIPTION,
13440
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
13441
+ quantity: plan.quantity,
13442
+ plan,
13443
+ couponCode,
13444
+ product,
13445
+ isExistingSource: isUsingExistingPaymentMethod,
13446
+ giftRecipient,
13447
+ addressId: selectedAddressId
13448
+ }, (err, res) => {
13449
+ if (err) {
13450
+ return handlePaymentError(err);
13451
+ }
13452
+
13453
+ onSuccess(res);
13454
+ });
13455
+ } else if (renewSubscription) {
13456
+ return subscription.execute({
13457
+ type: SUBSCRIPTION_TYPES.RENEW_SUBSCRIPTION,
13458
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
13459
+ quantity: plan.quantity,
13460
+ plan,
13461
+ couponCode,
13462
+ product,
13463
+ isExistingSource: isUsingExistingPaymentMethod,
13464
+ subscriptionIdToRenew,
13465
+ addressId: selectedAddressId
13466
+ }, (err, res) => {
13467
+ if (err) {
13468
+ return handlePaymentError(err);
13469
+ }
13470
+
13471
+ onSuccess(res);
13472
+ });
13473
+ } else if (createSubscription) {
13474
+ return subscription.execute({
13475
+ type: SUBSCRIPTION_TYPES.CREATE_SUBSCRIPTION,
13476
+ token: isUsingExistingPaymentMethod ? selectedPaymentMethodId : paymentRequest,
13477
+ quantity: plan.quantity,
13478
+ plan,
13479
+ couponCode,
13480
+ product,
13481
+ isExistingSource: isUsingExistingPaymentMethod,
13482
+ addressId: selectedAddressId
13483
+ }, (err, res) => {
13484
+ if (err) {
13485
+ return handlePaymentError(err);
13486
+ }
13487
+
13488
+ onSuccess(res);
13489
+ });
13490
+ }
13491
+ }
13287
13492
  }
13288
13493
 
13289
13494
  const vantivInstanceRef = React__default.useRef(null);
13290
13495
  useEffect(() => {
13291
13496
  const cardProcessor = getSiteCardProcessor();
13292
13497
 
13293
- if (cardProcessor === "vantiv") {
13498
+ if (cardProcessor === "vantiv" && !selectedPaymentMethodId) {
13294
13499
  var _window$Pelcro$site$r;
13295
13500
 
13296
13501
  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;
@@ -13313,7 +13518,7 @@ const PaymentMethodContainerWithoutStripe = ({
13313
13518
  }
13314
13519
  });
13315
13520
  }
13316
- }, []);
13521
+ }, [selectedPaymentMethodId]);
13317
13522
 
13318
13523
  const initPaymentRequest = (state, dispatch) => {
13319
13524
  try {
@@ -14232,6 +14437,10 @@ const PaymentMethodContainerWithoutStripe = ({
14232
14437
  disableSubmit: true,
14233
14438
  isLoading: true
14234
14439
  }, (state, dispatch) => {
14440
+ if (getSiteCardProcessor() === "vantiv") {
14441
+ return submitVantivPayment();
14442
+ }
14443
+
14235
14444
  if (selectedPaymentMethodId) {
14236
14445
  // pay with selected method (source) if exists already
14237
14446
  return handlePayment({
@@ -14244,10 +14453,6 @@ const PaymentMethodContainerWithoutStripe = ({
14244
14453
  return updatePaymentSource(state, dispatch);
14245
14454
  }
14246
14455
 
14247
- if (getSiteCardProcessor() === "vantiv") {
14248
- return submitVantivPayment();
14249
- }
14250
-
14251
14456
  submitPayment(state);
14252
14457
  });
14253
14458
 
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.2",
4
+ "version": "3.2.0-beta.3",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",