@pelcro/react-pelcro-js 3.26.0-beta.11 → 3.26.0-beta.12

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
@@ -9518,6 +9518,17 @@ const calcAndFormatItemsTotal = (items, currency) => {
9518
9518
  return getFormattedPriceByLocal(totalWithoutDividingBy100, currency, getPageOrDefaultLanguage());
9519
9519
  };
9520
9520
 
9521
+ /**
9522
+ * @param {object[]} items
9523
+ * @returns {number} the total order price
9524
+ */
9525
+ const calcOrderAmount = items => {
9526
+ if (!Array.isArray(items)) return;
9527
+ return items.reduce((prevAmount, item) => {
9528
+ return prevAmount + item.price * item.quantity;
9529
+ }, 0);
9530
+ };
9531
+
9521
9532
  /**
9522
9533
  * returns true if the URL contains a supported view trigger URL
9523
9534
  * @param {string} viewID
@@ -11899,7 +11910,10 @@ const loadPaymentSDKs = () => {
11899
11910
  window.Pelcro.helpers.loadSDK("https://code.jquery.com/jquery-3.6.0.slim.min.js", "vantiv-jquery-sdk");
11900
11911
  }
11901
11912
  window.Pelcro.helpers.loadSDK("https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "vantiv-jquery-sdk");
11902
- window.Pelcro.helpers.loadSDK("https://request.eprotect.vantivprelive.com/eProtect/eProtect-api3.js", "vantiv-eprotect-api");
11913
+ const eProtectApi3PreLiveURL = "https://request.eprotect.vantivprelive.com/eProtect/eProtect-api3.js";
11914
+ const eProtectApi3ProductionURL = "https://request.eprotect.vantivcnp.com/eProtect/eProtect-api3.js";
11915
+ const eProtectApi3scriptUrlToUse = window.Pelcro.site.read().vantiv_gateway_settings.environment === "production" ? eProtectApi3ProductionURL : eProtectApi3PreLiveURL;
11916
+ window.Pelcro.helpers.loadSDK(eProtectApi3scriptUrlToUse, "vantiv-eprotect-api");
11903
11917
  if (!window.EprotectIframeClient) {
11904
11918
  const PRELIVE_URL = "https://request.eprotect.vantivprelive.com/eProtect/js/eProtect-iframe-client.min.js";
11905
11919
  const PRODUCTION_URL = "https://request.eprotect.vantivcnp.com/eProtect/js/eProtect-iframe-client3.min.js";
@@ -21188,7 +21202,7 @@ const DonationEmail = props => /*#__PURE__*/React__default['default'].createElem
21188
21202
  * @return {JSX}
21189
21203
  */
21190
21204
  const ApplePayButton = _ref => {
21191
- var _window$Pelcro$site$r, _ref2, _ref3, _state$updatedPrice, _props$plan;
21205
+ var _window$Pelcro$site$r, _order$, _ref2, _ref3, _ref4, _state$updatedPrice, _props$plan;
21192
21206
  let {
21193
21207
  onClick,
21194
21208
  props,
@@ -21200,7 +21214,8 @@ const ApplePayButton = _ref => {
21200
21214
  } = React.useContext(store$k);
21201
21215
  const {
21202
21216
  plan,
21203
- invoice
21217
+ invoice,
21218
+ order
21204
21219
  } = usePelcro();
21205
21220
  const {
21206
21221
  pay_page_id: payPageId,
@@ -21208,7 +21223,10 @@ const ApplePayButton = _ref => {
21208
21223
  apple_pay_merchant_id: ApplePayMerchantId,
21209
21224
  apple_pay_enabled: ApplePayEnabled
21210
21225
  } = (_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.vantiv_gateway_settings;
21211
- const updatedPrice = (_ref2 = (_ref3 = (_state$updatedPrice = state.updatedPrice) !== null && _state$updatedPrice !== void 0 ? _state$updatedPrice : props === null || props === void 0 ? void 0 : (_props$plan = props.plan) === null || _props$plan === void 0 ? void 0 : _props$plan.amount) !== null && _ref3 !== void 0 ? _ref3 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref2 !== void 0 ? _ref2 : invoice.amount_remaining;
21226
+ const orderPrice = !Array.isArray(order) ? order === null || order === void 0 ? void 0 : order.price : calcOrderAmount(order);
21227
+ const orderCurrency = !Array.isArray(order) ? order === null || order === void 0 ? void 0 : order.currency : (_order$ = order[0]) === null || _order$ === void 0 ? void 0 : _order$.currency;
21228
+ const orderLabel = !Array.isArray(order) ? order === null || order === void 0 ? void 0 : order.name : "Order";
21229
+ const updatedPrice = (_ref2 = (_ref3 = (_ref4 = (_state$updatedPrice = state.updatedPrice) !== null && _state$updatedPrice !== void 0 ? _state$updatedPrice : props === null || props === void 0 ? void 0 : (_props$plan = props.plan) === null || _props$plan === void 0 ? void 0 : _props$plan.amount) !== null && _ref4 !== void 0 ? _ref4 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref3 !== void 0 ? _ref3 : orderPrice) !== null && _ref2 !== void 0 ? _ref2 : invoice.amount_remaining;
21212
21230
  React.useEffect(() => {
21213
21231
  if (window.ApplePaySession) {
21214
21232
  // Indicates whether the device supports Apple Pay and whether the user has an active card in Wallet.
@@ -21241,11 +21259,11 @@ const ApplePayButton = _ref => {
21241
21259
  // @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/creating_an_apple_pay_session
21242
21260
  const ApplePayPaymentRequest = {
21243
21261
  countryCode: ((_window = window) === null || _window === void 0 ? void 0 : (_window$Pelcro = _window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$user = _window$Pelcro.user) === null || _window$Pelcro$user === void 0 ? void 0 : (_window$Pelcro$user$l = _window$Pelcro$user.location) === null || _window$Pelcro$user$l === void 0 ? void 0 : _window$Pelcro$user$l.countryCode) || "US",
21244
- currencyCode: (plan === null || plan === void 0 ? void 0 : plan.currency.toUpperCase()) || (invoice === null || invoice === void 0 ? void 0 : invoice.currency.toUpperCase()),
21262
+ currencyCode: (plan === null || plan === void 0 ? void 0 : plan.currency.toUpperCase()) || orderCurrency.toUpperCase() || (invoice === null || invoice === void 0 ? void 0 : invoice.currency.toUpperCase()),
21245
21263
  merchantCapabilities: ["supports3DS"],
21246
21264
  supportedNetworks: ["visa", "masterCard", "amex", "discover"],
21247
21265
  total: {
21248
- label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21266
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice.id}`,
21249
21267
  type: "final",
21250
21268
  amount: updatedPrice / 100
21251
21269
  }
@@ -21293,12 +21311,12 @@ const ApplePayButton = _ref => {
21293
21311
  // Define ApplePayPaymentMethodUpdate based on the selected payment method.
21294
21312
  // No updates or errors are needed, pass an empty object.
21295
21313
  const newTotal = {
21296
- label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21314
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice.id}`,
21297
21315
  type: "final",
21298
21316
  amount: updatedPrice / 100
21299
21317
  };
21300
21318
  const newLineItems = [{
21301
- label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21319
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice.id}`,
21302
21320
  type: "final",
21303
21321
  amount: updatedPrice / 100
21304
21322
  }];
@@ -21311,14 +21329,14 @@ const ApplePayButton = _ref => {
21311
21329
  // // Define ApplePayShippingMethodUpdate based on the selected shipping method.
21312
21330
  // // No updates or errors are needed, pass an empty object.
21313
21331
  // const newTotal = {
21314
- // label: plan?.nickname || `invoice #${invoice.id}`,
21332
+ // label: plan?.nickname || orderLabel || `invoice #${invoice.id}`,
21315
21333
  // type: "final",
21316
21334
  // amount: updatedPrice / 100
21317
21335
  // };
21318
21336
 
21319
21337
  // const newLineItems = [
21320
21338
  // {
21321
- // label: plan?.nickname || `invoice #${invoice.id}`,
21339
+ // label: plan?.nickname || orderLabel || `invoice #${invoice.id}`,
21322
21340
  // type: "final",
21323
21341
  // amount: updatedPrice / 100
21324
21342
  // }
@@ -27019,7 +27037,7 @@ const OrderCreateView = props => {
27019
27037
  type: "orderCreate",
27020
27038
  showCoupon: true,
27021
27039
  showExternalPaymentMethods: false,
27022
- showApplePayButton: false,
27040
+ showApplePayButton: true,
27023
27041
  showOrderButton: showOrderButton,
27024
27042
  order: order
27025
27043
  }, props))));
package/dist/index.esm.js CHANGED
@@ -9488,6 +9488,17 @@ const calcAndFormatItemsTotal = (items, currency) => {
9488
9488
  return getFormattedPriceByLocal(totalWithoutDividingBy100, currency, getPageOrDefaultLanguage());
9489
9489
  };
9490
9490
 
9491
+ /**
9492
+ * @param {object[]} items
9493
+ * @returns {number} the total order price
9494
+ */
9495
+ const calcOrderAmount = items => {
9496
+ if (!Array.isArray(items)) return;
9497
+ return items.reduce((prevAmount, item) => {
9498
+ return prevAmount + item.price * item.quantity;
9499
+ }, 0);
9500
+ };
9501
+
9491
9502
  /**
9492
9503
  * returns true if the URL contains a supported view trigger URL
9493
9504
  * @param {string} viewID
@@ -11869,7 +11880,10 @@ const loadPaymentSDKs = () => {
11869
11880
  window.Pelcro.helpers.loadSDK("https://code.jquery.com/jquery-3.6.0.slim.min.js", "vantiv-jquery-sdk");
11870
11881
  }
11871
11882
  window.Pelcro.helpers.loadSDK("https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "vantiv-jquery-sdk");
11872
- window.Pelcro.helpers.loadSDK("https://request.eprotect.vantivprelive.com/eProtect/eProtect-api3.js", "vantiv-eprotect-api");
11883
+ const eProtectApi3PreLiveURL = "https://request.eprotect.vantivprelive.com/eProtect/eProtect-api3.js";
11884
+ const eProtectApi3ProductionURL = "https://request.eprotect.vantivcnp.com/eProtect/eProtect-api3.js";
11885
+ const eProtectApi3scriptUrlToUse = window.Pelcro.site.read().vantiv_gateway_settings.environment === "production" ? eProtectApi3ProductionURL : eProtectApi3PreLiveURL;
11886
+ window.Pelcro.helpers.loadSDK(eProtectApi3scriptUrlToUse, "vantiv-eprotect-api");
11873
11887
  if (!window.EprotectIframeClient) {
11874
11888
  const PRELIVE_URL = "https://request.eprotect.vantivprelive.com/eProtect/js/eProtect-iframe-client.min.js";
11875
11889
  const PRODUCTION_URL = "https://request.eprotect.vantivcnp.com/eProtect/js/eProtect-iframe-client3.min.js";
@@ -21158,7 +21172,7 @@ const DonationEmail = props => /*#__PURE__*/React__default.createElement(Email,
21158
21172
  * @return {JSX}
21159
21173
  */
21160
21174
  const ApplePayButton = _ref => {
21161
- var _window$Pelcro$site$r, _ref2, _ref3, _state$updatedPrice, _props$plan;
21175
+ var _window$Pelcro$site$r, _order$, _ref2, _ref3, _ref4, _state$updatedPrice, _props$plan;
21162
21176
  let {
21163
21177
  onClick,
21164
21178
  props,
@@ -21170,7 +21184,8 @@ const ApplePayButton = _ref => {
21170
21184
  } = useContext(store$k);
21171
21185
  const {
21172
21186
  plan,
21173
- invoice
21187
+ invoice,
21188
+ order
21174
21189
  } = usePelcro();
21175
21190
  const {
21176
21191
  pay_page_id: payPageId,
@@ -21178,7 +21193,10 @@ const ApplePayButton = _ref => {
21178
21193
  apple_pay_merchant_id: ApplePayMerchantId,
21179
21194
  apple_pay_enabled: ApplePayEnabled
21180
21195
  } = (_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.vantiv_gateway_settings;
21181
- const updatedPrice = (_ref2 = (_ref3 = (_state$updatedPrice = state.updatedPrice) !== null && _state$updatedPrice !== void 0 ? _state$updatedPrice : props === null || props === void 0 ? void 0 : (_props$plan = props.plan) === null || _props$plan === void 0 ? void 0 : _props$plan.amount) !== null && _ref3 !== void 0 ? _ref3 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref2 !== void 0 ? _ref2 : invoice.amount_remaining;
21196
+ const orderPrice = !Array.isArray(order) ? order === null || order === void 0 ? void 0 : order.price : calcOrderAmount(order);
21197
+ const orderCurrency = !Array.isArray(order) ? order === null || order === void 0 ? void 0 : order.currency : (_order$ = order[0]) === null || _order$ === void 0 ? void 0 : _order$.currency;
21198
+ const orderLabel = !Array.isArray(order) ? order === null || order === void 0 ? void 0 : order.name : "Order";
21199
+ const updatedPrice = (_ref2 = (_ref3 = (_ref4 = (_state$updatedPrice = state.updatedPrice) !== null && _state$updatedPrice !== void 0 ? _state$updatedPrice : props === null || props === void 0 ? void 0 : (_props$plan = props.plan) === null || _props$plan === void 0 ? void 0 : _props$plan.amount) !== null && _ref4 !== void 0 ? _ref4 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref3 !== void 0 ? _ref3 : orderPrice) !== null && _ref2 !== void 0 ? _ref2 : invoice.amount_remaining;
21182
21200
  useEffect(() => {
21183
21201
  if (window.ApplePaySession) {
21184
21202
  // Indicates whether the device supports Apple Pay and whether the user has an active card in Wallet.
@@ -21211,11 +21229,11 @@ const ApplePayButton = _ref => {
21211
21229
  // @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/creating_an_apple_pay_session
21212
21230
  const ApplePayPaymentRequest = {
21213
21231
  countryCode: ((_window = window) === null || _window === void 0 ? void 0 : (_window$Pelcro = _window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$user = _window$Pelcro.user) === null || _window$Pelcro$user === void 0 ? void 0 : (_window$Pelcro$user$l = _window$Pelcro$user.location) === null || _window$Pelcro$user$l === void 0 ? void 0 : _window$Pelcro$user$l.countryCode) || "US",
21214
- currencyCode: (plan === null || plan === void 0 ? void 0 : plan.currency.toUpperCase()) || (invoice === null || invoice === void 0 ? void 0 : invoice.currency.toUpperCase()),
21232
+ currencyCode: (plan === null || plan === void 0 ? void 0 : plan.currency.toUpperCase()) || orderCurrency.toUpperCase() || (invoice === null || invoice === void 0 ? void 0 : invoice.currency.toUpperCase()),
21215
21233
  merchantCapabilities: ["supports3DS"],
21216
21234
  supportedNetworks: ["visa", "masterCard", "amex", "discover"],
21217
21235
  total: {
21218
- label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21236
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice.id}`,
21219
21237
  type: "final",
21220
21238
  amount: updatedPrice / 100
21221
21239
  }
@@ -21263,12 +21281,12 @@ const ApplePayButton = _ref => {
21263
21281
  // Define ApplePayPaymentMethodUpdate based on the selected payment method.
21264
21282
  // No updates or errors are needed, pass an empty object.
21265
21283
  const newTotal = {
21266
- label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21284
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice.id}`,
21267
21285
  type: "final",
21268
21286
  amount: updatedPrice / 100
21269
21287
  };
21270
21288
  const newLineItems = [{
21271
- label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21289
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice.id}`,
21272
21290
  type: "final",
21273
21291
  amount: updatedPrice / 100
21274
21292
  }];
@@ -21281,14 +21299,14 @@ const ApplePayButton = _ref => {
21281
21299
  // // Define ApplePayShippingMethodUpdate based on the selected shipping method.
21282
21300
  // // No updates or errors are needed, pass an empty object.
21283
21301
  // const newTotal = {
21284
- // label: plan?.nickname || `invoice #${invoice.id}`,
21302
+ // label: plan?.nickname || orderLabel || `invoice #${invoice.id}`,
21285
21303
  // type: "final",
21286
21304
  // amount: updatedPrice / 100
21287
21305
  // };
21288
21306
 
21289
21307
  // const newLineItems = [
21290
21308
  // {
21291
- // label: plan?.nickname || `invoice #${invoice.id}`,
21309
+ // label: plan?.nickname || orderLabel || `invoice #${invoice.id}`,
21292
21310
  // type: "final",
21293
21311
  // amount: updatedPrice / 100
21294
21312
  // }
@@ -26989,7 +27007,7 @@ const OrderCreateView = props => {
26989
27007
  type: "orderCreate",
26990
27008
  showCoupon: true,
26991
27009
  showExternalPaymentMethods: false,
26992
- showApplePayButton: false,
27010
+ showApplePayButton: true,
26993
27011
  showOrderButton: showOrderButton,
26994
27012
  order: order
26995
27013
  }, props))));
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.26.0-beta.11",
4
+ "version": "3.26.0-beta.12",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",