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

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
@@ -11899,7 +11899,10 @@ const loadPaymentSDKs = () => {
11899
11899
  window.Pelcro.helpers.loadSDK("https://code.jquery.com/jquery-3.6.0.slim.min.js", "vantiv-jquery-sdk");
11900
11900
  }
11901
11901
  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");
11902
+ const eProtectApi3PreLiveURL = "https://request.eprotect.vantivprelive.com/eProtect/eProtect-api3.js";
11903
+ const eProtectApi3ProductionURL = "https://request.eprotect.vantivcnp.com/eProtect/eProtect-api3.js";
11904
+ const eProtectApi3scriptUrlToUse = window.Pelcro.site.read().vantiv_gateway_settings.environment === "production" ? eProtectApi3ProductionURL : eProtectApi3PreLiveURL;
11905
+ window.Pelcro.helpers.loadSDK(eProtectApi3scriptUrlToUse, "vantiv-eprotect-api");
11903
11906
  if (!window.EprotectIframeClient) {
11904
11907
  const PRELIVE_URL = "https://request.eprotect.vantivprelive.com/eProtect/js/eProtect-iframe-client.min.js";
11905
11908
  const PRODUCTION_URL = "https://request.eprotect.vantivcnp.com/eProtect/js/eProtect-iframe-client3.min.js";
@@ -21188,7 +21191,7 @@ const DonationEmail = props => /*#__PURE__*/React__default['default'].createElem
21188
21191
  * @return {JSX}
21189
21192
  */
21190
21193
  const ApplePayButton = _ref => {
21191
- var _window$Pelcro$site$r, _ref2, _ref3, _state$updatedPrice, _props$plan;
21194
+ var _window$Pelcro$site$r, _order$, _ref2, _ref3, _ref4, _ref5, _state$updatedPrice, _props$plan;
21192
21195
  let {
21193
21196
  onClick,
21194
21197
  props,
@@ -21200,7 +21203,8 @@ const ApplePayButton = _ref => {
21200
21203
  } = React.useContext(store$k);
21201
21204
  const {
21202
21205
  plan,
21203
- invoice
21206
+ invoice,
21207
+ order
21204
21208
  } = usePelcro();
21205
21209
  const {
21206
21210
  pay_page_id: payPageId,
@@ -21208,7 +21212,25 @@ const ApplePayButton = _ref => {
21208
21212
  apple_pay_merchant_id: ApplePayMerchantId,
21209
21213
  apple_pay_enabled: ApplePayEnabled
21210
21214
  } = (_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;
21215
+ const getOrderItemsTotal = () => {
21216
+ if (!order) {
21217
+ return null;
21218
+ }
21219
+ const isQuickPurchase = !Array.isArray(order);
21220
+ if (isQuickPurchase) {
21221
+ return order.price * order.quantity;
21222
+ }
21223
+ if (order.length === 0) {
21224
+ return null;
21225
+ }
21226
+ return order.reduce((total, item) => {
21227
+ return total + item.price * item.quantity;
21228
+ }, 0);
21229
+ };
21230
+ const orderPrice = getOrderItemsTotal();
21231
+ 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;
21232
+ const orderLabel = !Array.isArray(order) ? order === null || order === void 0 ? void 0 : order.name : "Order";
21233
+ const updatedPrice = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_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 && _ref5 !== void 0 ? _ref5 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref4 !== void 0 ? _ref4 : orderPrice) !== null && _ref3 !== void 0 ? _ref3 : invoice.amount_remaining) !== null && _ref2 !== void 0 ? _ref2 : null;
21212
21234
  React.useEffect(() => {
21213
21235
  if (window.ApplePaySession) {
21214
21236
  // Indicates whether the device supports Apple Pay and whether the user has an active card in Wallet.
@@ -21241,11 +21263,11 @@ const ApplePayButton = _ref => {
21241
21263
  // @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/creating_an_apple_pay_session
21242
21264
  const ApplePayPaymentRequest = {
21243
21265
  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()),
21266
+ currencyCode: (plan === null || plan === void 0 ? void 0 : plan.currency.toUpperCase()) || orderCurrency.toUpperCase() || (invoice === null || invoice === void 0 ? void 0 : invoice.currency.toUpperCase()),
21245
21267
  merchantCapabilities: ["supports3DS"],
21246
21268
  supportedNetworks: ["visa", "masterCard", "amex", "discover"],
21247
21269
  total: {
21248
- label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21270
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice.id}`,
21249
21271
  type: "final",
21250
21272
  amount: updatedPrice / 100
21251
21273
  }
@@ -21293,12 +21315,12 @@ const ApplePayButton = _ref => {
21293
21315
  // Define ApplePayPaymentMethodUpdate based on the selected payment method.
21294
21316
  // No updates or errors are needed, pass an empty object.
21295
21317
  const newTotal = {
21296
- label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21318
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice.id}`,
21297
21319
  type: "final",
21298
21320
  amount: updatedPrice / 100
21299
21321
  };
21300
21322
  const newLineItems = [{
21301
- label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21323
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice.id}`,
21302
21324
  type: "final",
21303
21325
  amount: updatedPrice / 100
21304
21326
  }];
@@ -21311,14 +21333,14 @@ const ApplePayButton = _ref => {
21311
21333
  // // Define ApplePayShippingMethodUpdate based on the selected shipping method.
21312
21334
  // // No updates or errors are needed, pass an empty object.
21313
21335
  // const newTotal = {
21314
- // label: plan?.nickname || `invoice #${invoice.id}`,
21336
+ // label: plan?.nickname || orderLabel || `invoice #${invoice.id}`,
21315
21337
  // type: "final",
21316
21338
  // amount: updatedPrice / 100
21317
21339
  // };
21318
21340
 
21319
21341
  // const newLineItems = [
21320
21342
  // {
21321
- // label: plan?.nickname || `invoice #${invoice.id}`,
21343
+ // label: plan?.nickname || orderLabel || `invoice #${invoice.id}`,
21322
21344
  // type: "final",
21323
21345
  // amount: updatedPrice / 100
21324
21346
  // }
@@ -27019,7 +27041,7 @@ const OrderCreateView = props => {
27019
27041
  type: "orderCreate",
27020
27042
  showCoupon: true,
27021
27043
  showExternalPaymentMethods: false,
27022
- showApplePayButton: false,
27044
+ showApplePayButton: true,
27023
27045
  showOrderButton: showOrderButton,
27024
27046
  order: order
27025
27047
  }, props))));
package/dist/index.esm.js CHANGED
@@ -11869,7 +11869,10 @@ const loadPaymentSDKs = () => {
11869
11869
  window.Pelcro.helpers.loadSDK("https://code.jquery.com/jquery-3.6.0.slim.min.js", "vantiv-jquery-sdk");
11870
11870
  }
11871
11871
  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");
11872
+ const eProtectApi3PreLiveURL = "https://request.eprotect.vantivprelive.com/eProtect/eProtect-api3.js";
11873
+ const eProtectApi3ProductionURL = "https://request.eprotect.vantivcnp.com/eProtect/eProtect-api3.js";
11874
+ const eProtectApi3scriptUrlToUse = window.Pelcro.site.read().vantiv_gateway_settings.environment === "production" ? eProtectApi3ProductionURL : eProtectApi3PreLiveURL;
11875
+ window.Pelcro.helpers.loadSDK(eProtectApi3scriptUrlToUse, "vantiv-eprotect-api");
11873
11876
  if (!window.EprotectIframeClient) {
11874
11877
  const PRELIVE_URL = "https://request.eprotect.vantivprelive.com/eProtect/js/eProtect-iframe-client.min.js";
11875
11878
  const PRODUCTION_URL = "https://request.eprotect.vantivcnp.com/eProtect/js/eProtect-iframe-client3.min.js";
@@ -21158,7 +21161,7 @@ const DonationEmail = props => /*#__PURE__*/React__default.createElement(Email,
21158
21161
  * @return {JSX}
21159
21162
  */
21160
21163
  const ApplePayButton = _ref => {
21161
- var _window$Pelcro$site$r, _ref2, _ref3, _state$updatedPrice, _props$plan;
21164
+ var _window$Pelcro$site$r, _order$, _ref2, _ref3, _ref4, _ref5, _state$updatedPrice, _props$plan;
21162
21165
  let {
21163
21166
  onClick,
21164
21167
  props,
@@ -21170,7 +21173,8 @@ const ApplePayButton = _ref => {
21170
21173
  } = useContext(store$k);
21171
21174
  const {
21172
21175
  plan,
21173
- invoice
21176
+ invoice,
21177
+ order
21174
21178
  } = usePelcro();
21175
21179
  const {
21176
21180
  pay_page_id: payPageId,
@@ -21178,7 +21182,25 @@ const ApplePayButton = _ref => {
21178
21182
  apple_pay_merchant_id: ApplePayMerchantId,
21179
21183
  apple_pay_enabled: ApplePayEnabled
21180
21184
  } = (_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;
21185
+ const getOrderItemsTotal = () => {
21186
+ if (!order) {
21187
+ return null;
21188
+ }
21189
+ const isQuickPurchase = !Array.isArray(order);
21190
+ if (isQuickPurchase) {
21191
+ return order.price * order.quantity;
21192
+ }
21193
+ if (order.length === 0) {
21194
+ return null;
21195
+ }
21196
+ return order.reduce((total, item) => {
21197
+ return total + item.price * item.quantity;
21198
+ }, 0);
21199
+ };
21200
+ const orderPrice = getOrderItemsTotal();
21201
+ 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;
21202
+ const orderLabel = !Array.isArray(order) ? order === null || order === void 0 ? void 0 : order.name : "Order";
21203
+ const updatedPrice = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_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 && _ref5 !== void 0 ? _ref5 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref4 !== void 0 ? _ref4 : orderPrice) !== null && _ref3 !== void 0 ? _ref3 : invoice.amount_remaining) !== null && _ref2 !== void 0 ? _ref2 : null;
21182
21204
  useEffect(() => {
21183
21205
  if (window.ApplePaySession) {
21184
21206
  // Indicates whether the device supports Apple Pay and whether the user has an active card in Wallet.
@@ -21211,11 +21233,11 @@ const ApplePayButton = _ref => {
21211
21233
  // @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/creating_an_apple_pay_session
21212
21234
  const ApplePayPaymentRequest = {
21213
21235
  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()),
21236
+ currencyCode: (plan === null || plan === void 0 ? void 0 : plan.currency.toUpperCase()) || orderCurrency.toUpperCase() || (invoice === null || invoice === void 0 ? void 0 : invoice.currency.toUpperCase()),
21215
21237
  merchantCapabilities: ["supports3DS"],
21216
21238
  supportedNetworks: ["visa", "masterCard", "amex", "discover"],
21217
21239
  total: {
21218
- label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21240
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice.id}`,
21219
21241
  type: "final",
21220
21242
  amount: updatedPrice / 100
21221
21243
  }
@@ -21263,12 +21285,12 @@ const ApplePayButton = _ref => {
21263
21285
  // Define ApplePayPaymentMethodUpdate based on the selected payment method.
21264
21286
  // No updates or errors are needed, pass an empty object.
21265
21287
  const newTotal = {
21266
- label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21288
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice.id}`,
21267
21289
  type: "final",
21268
21290
  amount: updatedPrice / 100
21269
21291
  };
21270
21292
  const newLineItems = [{
21271
- label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || `invoice #${invoice.id}`,
21293
+ label: (plan === null || plan === void 0 ? void 0 : plan.nickname) || orderLabel || `invoice #${invoice.id}`,
21272
21294
  type: "final",
21273
21295
  amount: updatedPrice / 100
21274
21296
  }];
@@ -21281,14 +21303,14 @@ const ApplePayButton = _ref => {
21281
21303
  // // Define ApplePayShippingMethodUpdate based on the selected shipping method.
21282
21304
  // // No updates or errors are needed, pass an empty object.
21283
21305
  // const newTotal = {
21284
- // label: plan?.nickname || `invoice #${invoice.id}`,
21306
+ // label: plan?.nickname || orderLabel || `invoice #${invoice.id}`,
21285
21307
  // type: "final",
21286
21308
  // amount: updatedPrice / 100
21287
21309
  // };
21288
21310
 
21289
21311
  // const newLineItems = [
21290
21312
  // {
21291
- // label: plan?.nickname || `invoice #${invoice.id}`,
21313
+ // label: plan?.nickname || orderLabel || `invoice #${invoice.id}`,
21292
21314
  // type: "final",
21293
21315
  // amount: updatedPrice / 100
21294
21316
  // }
@@ -26989,7 +27011,7 @@ const OrderCreateView = props => {
26989
27011
  type: "orderCreate",
26990
27012
  showCoupon: true,
26991
27013
  showExternalPaymentMethods: false,
26992
- showApplePayButton: false,
27014
+ showApplePayButton: true,
26993
27015
  showOrderButton: showOrderButton,
26994
27016
  order: order
26995
27017
  }, 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.13",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",