@pelcro/react-pelcro-js 3.50.0 → 3.52.0
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 +426 -189
- package/dist/index.esm.js +425 -188
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import React__default, { useContext, useState, useRef, useEffect, useReducer, useLayoutEffect, Component, memo, createElement, Fragment, useMemo, forwardRef, createContext, useCallback, isValidElement, cloneElement } from 'react';
|
|
3
|
-
import ReactDOM, { render as render$1 } from 'react-dom';
|
|
4
3
|
import PropTypes from 'prop-types';
|
|
4
|
+
import ReactDOM from 'react-dom';
|
|
5
5
|
|
|
6
6
|
function _typeof$3(obj) {
|
|
7
7
|
"@babel/helpers - typeof";
|
|
@@ -2544,7 +2544,7 @@ var voidElements = {
|
|
|
2544
2544
|
"wbr": true
|
|
2545
2545
|
};
|
|
2546
2546
|
|
|
2547
|
-
var t$1=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function n$1(n){var r={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},i=n.match(/<\/?([^\s]+?)[/\s>]/);if(i&&(r.name=i[1],(voidElements[i[1]]||"/"===n.charAt(n.length-2))&&(r.voidElement=!0),r.name.startsWith("!--"))){var s=n.indexOf("--\x3e");return {type:"comment",comment:-1!==s?n.slice(4,s):""}}for(var a=new RegExp(t$1),c=null;null!==(c=a.exec(n));)if(c[0].trim())if(c[1]){var o=c[1].trim(),l=[o,""];o.indexOf("=")>-1&&(l=o.split("=")),r.attrs[l[0]]=l[1],a.lastIndex--;}else c[2]&&(r.attrs[c[2]]=c[3].trim().substring(1,c[3].length-1));return r}var r=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,i$2=/^\s*$/,s$1=Object.create(null);function a$1(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(a$1,"")+"</"+t.name+">";case"comment":return e+"\x3c!--"+t.comment+"--\x3e"}}var c$
|
|
2547
|
+
var t$1=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function n$1(n){var r={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},i=n.match(/<\/?([^\s]+?)[/\s>]/);if(i&&(r.name=i[1],(voidElements[i[1]]||"/"===n.charAt(n.length-2))&&(r.voidElement=!0),r.name.startsWith("!--"))){var s=n.indexOf("--\x3e");return {type:"comment",comment:-1!==s?n.slice(4,s):""}}for(var a=new RegExp(t$1),c=null;null!==(c=a.exec(n));)if(c[0].trim())if(c[1]){var o=c[1].trim(),l=[o,""];o.indexOf("=")>-1&&(l=o.split("=")),r.attrs[l[0]]=l[1],a.lastIndex--;}else c[2]&&(r.attrs[c[2]]=c[3].trim().substring(1,c[3].length-1));return r}var r=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,i$2=/^\s*$/,s$1=Object.create(null);function a$1(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(a$1,"")+"</"+t.name+">";case"comment":return e+"\x3c!--"+t.comment+"--\x3e"}}var c$1={parse:function(e,t){t||(t={}),t.components||(t.components=s$1);var a,c=[],o=[],l=-1,m=!1;if(0!==e.indexOf("<")){var u=e.indexOf("<");c.push({type:"text",content:-1===u?e:e.substring(0,u)});}return e.replace(r,function(r,s){if(m){if(r!=="</"+a.name+">")return;m=!1;}var u,f="/"!==r.charAt(1),h=r.startsWith("\x3c!--"),p=s+r.length,d=e.charAt(p);if(h){var v=n$1(r);return l<0?(c.push(v),c):((u=o[l]).children.push(v),c)}if(f&&(l++,"tag"===(a=n$1(r)).type&&t.components[a.name]&&(a.type="component",m=!0),a.voidElement||m||!d||"<"===d||a.children.push({type:"text",content:e.slice(p,e.indexOf("<",p))}),0===l&&c.push(a),(u=o[l-1])&&u.children.push(a),o[l]=a),(!f||a.voidElement)&&(l>-1&&(a.voidElement||a.name===r.slice(2,-1))&&(l--,a=-1===l?c:o[l]),!m&&"<"!==d&&d)){u=-1===l?c:o[l].children;var x=e.indexOf("<",p),g=e.slice(p,-1===x?void 0:x);i$2.test(g)&&(g=" "),(x>-1&&l+u.length>=0||" "!==g)&&u.push({type:"text",content:g});}}),c},stringify:function(e){return e.reduce(function(e,t){return e+a$1("",t)},"")}};
|
|
2548
2548
|
|
|
2549
2549
|
var classCallCheck = createCommonjsModule(function (module) {
|
|
2550
2550
|
function _classCallCheck(instance, Constructor) {
|
|
@@ -2806,7 +2806,7 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts) {
|
|
|
2806
2806
|
|
|
2807
2807
|
getData(children);
|
|
2808
2808
|
var interpolatedString = i18n.services.interpolator.interpolate(targetString, _objectSpread$5(_objectSpread$5({}, data), combinedTOpts), i18n.language);
|
|
2809
|
-
var ast = c$
|
|
2809
|
+
var ast = c$1.parse("<0>".concat(interpolatedString, "</0>"));
|
|
2810
2810
|
|
|
2811
2811
|
function renderInner(child, node, rootReactNode) {
|
|
2812
2812
|
var childs = getChildren(child);
|
|
@@ -7068,8 +7068,6 @@ exports.default = create;
|
|
|
7068
7068
|
|
|
7069
7069
|
var createStore = unwrapExports(vanilla);
|
|
7070
7070
|
|
|
7071
|
-
function c$1(c,r,d){const u={count:0},s=t=>{const o=useRef(u.count);return useEffect(()=>{o.current+=1,o.current===u.count+1&&(o.current-=1,r.setState(t));}),null};if(s.displayName=`((${c})) devtool`,!d){let t=document.getElementById("simple-zustand-devtools");t||(t=document.createElement("div"),t.id="simple-zustand-devtools"),document.body.appendChild(t),d=t;}const m=e=>{e&&(render$1(React__default.createElement(s,Object.assign({},e)),d),u.count+=1);};m(r.getState()),r.subscribe(m);}
|
|
7072
|
-
|
|
7073
7071
|
var _extends_1 = createCommonjsModule(function (module) {
|
|
7074
7072
|
function _extends() {
|
|
7075
7073
|
module.exports = _extends = Object.assign || function (target) {
|
|
@@ -9271,7 +9269,8 @@ const usePelcro = createPelcroHook(pelcroStore);
|
|
|
9271
9269
|
|
|
9272
9270
|
/* istanbul ignore next */
|
|
9273
9271
|
if (process.env.NODE_ENV === "development") {
|
|
9274
|
-
|
|
9272
|
+
// mountStoreDevtool("Pelcro Store", usePelcro);
|
|
9273
|
+
console.log("Pelcro Store devtools disabled - simple-zustand-devtools incompatible with React 16");
|
|
9275
9274
|
}
|
|
9276
9275
|
|
|
9277
9276
|
/**
|
|
@@ -11652,6 +11651,101 @@ function getFourDigitYear(lastTwoDigits) {
|
|
|
11652
11651
|
return fourDigitYear;
|
|
11653
11652
|
}
|
|
11654
11653
|
|
|
11654
|
+
/**
|
|
11655
|
+
* Loads Braintree Drop-in UI script
|
|
11656
|
+
* @returns {Promise} Promise that resolves when script is loaded
|
|
11657
|
+
*/
|
|
11658
|
+
function loadBraintreeScript() {
|
|
11659
|
+
return new Promise((resolve, reject) => {
|
|
11660
|
+
// Check if script is already loaded
|
|
11661
|
+
if (window.braintree) {
|
|
11662
|
+
console.log("Braintree script already loaded");
|
|
11663
|
+
resolve(window.braintree);
|
|
11664
|
+
return;
|
|
11665
|
+
}
|
|
11666
|
+
console.log("Loading Braintree script...");
|
|
11667
|
+
const script = document.createElement("script");
|
|
11668
|
+
script.src = "https://js.braintreegateway.com/web/dropin/1.45.1/js/dropin.js";
|
|
11669
|
+
script.onload = () => {
|
|
11670
|
+
console.log("Braintree script loaded successfully");
|
|
11671
|
+
resolve(window.braintree);
|
|
11672
|
+
};
|
|
11673
|
+
script.onerror = error => {
|
|
11674
|
+
console.error("Failed to load Braintree script:", error);
|
|
11675
|
+
reject(new Error("Failed to load Braintree script"));
|
|
11676
|
+
};
|
|
11677
|
+
document.head.appendChild(script);
|
|
11678
|
+
});
|
|
11679
|
+
}
|
|
11680
|
+
|
|
11681
|
+
/**
|
|
11682
|
+
* Creates Braintree Drop-in UI instance
|
|
11683
|
+
* @param {string} authorization - Braintree authorization token
|
|
11684
|
+
* @param {string} selector - CSS selector for the container
|
|
11685
|
+
* @param {Object} options - Additional options for dropin creation
|
|
11686
|
+
* @returns {Promise} Promise that resolves with the dropin instance
|
|
11687
|
+
*/
|
|
11688
|
+
function createBraintreeDropin(authorization, selector) {
|
|
11689
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
11690
|
+
console.log("Creating Braintree Drop-in with:", {
|
|
11691
|
+
authorization: authorization ? "present" : "missing",
|
|
11692
|
+
selector,
|
|
11693
|
+
options
|
|
11694
|
+
});
|
|
11695
|
+
return loadBraintreeScript().then(() => {
|
|
11696
|
+
console.log("Braintree script loaded, creating dropin...");
|
|
11697
|
+
return new Promise((resolve, reject) => {
|
|
11698
|
+
window.braintree.dropin.create({
|
|
11699
|
+
authorization,
|
|
11700
|
+
selector,
|
|
11701
|
+
...options
|
|
11702
|
+
}, (err, instance) => {
|
|
11703
|
+
if (err) {
|
|
11704
|
+
console.error("Braintree dropin creation failed:", err);
|
|
11705
|
+
reject(err);
|
|
11706
|
+
} else {
|
|
11707
|
+
console.log("Braintree dropin created successfully:", instance);
|
|
11708
|
+
resolve(instance);
|
|
11709
|
+
}
|
|
11710
|
+
});
|
|
11711
|
+
});
|
|
11712
|
+
});
|
|
11713
|
+
}
|
|
11714
|
+
|
|
11715
|
+
/**
|
|
11716
|
+
* Requests payment method from Braintree Drop-in UI
|
|
11717
|
+
* @param {Object} instance - Braintree dropin instance
|
|
11718
|
+
* @returns {Promise} Promise that resolves with payment method payload
|
|
11719
|
+
*/
|
|
11720
|
+
function requestBraintreePaymentMethod(instance) {
|
|
11721
|
+
return new Promise((resolve, reject) => {
|
|
11722
|
+
instance.requestPaymentMethod((err, payload) => {
|
|
11723
|
+
if (err) {
|
|
11724
|
+
reject(err);
|
|
11725
|
+
} else {
|
|
11726
|
+
resolve(payload);
|
|
11727
|
+
}
|
|
11728
|
+
});
|
|
11729
|
+
});
|
|
11730
|
+
}
|
|
11731
|
+
|
|
11732
|
+
/**
|
|
11733
|
+
* Requests payment method from Braintree Hosted Fields
|
|
11734
|
+
* @param {Object} hostedFieldsInstance - Braintree hosted fields instance
|
|
11735
|
+
* @returns {Promise} Promise that resolves with payment method payload
|
|
11736
|
+
*/
|
|
11737
|
+
function requestBraintreeHostedFieldsPaymentMethod(hostedFieldsInstance) {
|
|
11738
|
+
return new Promise((resolve, reject) => {
|
|
11739
|
+
hostedFieldsInstance.tokenize((err, payload) => {
|
|
11740
|
+
if (err) {
|
|
11741
|
+
reject(err);
|
|
11742
|
+
} else {
|
|
11743
|
+
resolve(payload);
|
|
11744
|
+
}
|
|
11745
|
+
});
|
|
11746
|
+
});
|
|
11747
|
+
}
|
|
11748
|
+
|
|
11655
11749
|
/**
|
|
11656
11750
|
* @typedef {Object} OptionsType
|
|
11657
11751
|
* @property {boolean} loadPaymentSDKs
|
|
@@ -11762,6 +11856,7 @@ const loadPaymentSDKs = () => {
|
|
|
11762
11856
|
// "braintree-3D-secure-sdk"
|
|
11763
11857
|
// );
|
|
11764
11858
|
window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/hosted-fields.min.js", "braintree-hosted-fields-sdk");
|
|
11859
|
+
window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/dropin/1.45.1/js/dropin.js", "braintree-dropin-sdk");
|
|
11765
11860
|
}
|
|
11766
11861
|
|
|
11767
11862
|
// Load Vantiv SDKs
|
|
@@ -11806,16 +11901,16 @@ const initSecuritySdk = () => {
|
|
|
11806
11901
|
});
|
|
11807
11902
|
};
|
|
11808
11903
|
const initGATracking = () => {
|
|
11809
|
-
var _window, _window$Pelcro, _window$Pelcro$uiSett;
|
|
11904
|
+
var _window, _window$Pelcro, _window$Pelcro$uiSett, _window2, _window2$Pelcro, _window2$Pelcro$uiSet;
|
|
11810
11905
|
const enableReactGA4 = (_window = window) === null || _window === void 0 ? void 0 : (_window$Pelcro = _window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$uiSett = _window$Pelcro.uiSettings) === null || _window$Pelcro$uiSett === void 0 ? void 0 : _window$Pelcro$uiSett.enableReactGA4;
|
|
11906
|
+
// Respect disablePageViewEvents flag from uiSettings
|
|
11907
|
+
const disablePageViewEvents = ((_window2 = window) === null || _window2 === void 0 ? void 0 : (_window2$Pelcro = _window2.Pelcro) === null || _window2$Pelcro === void 0 ? void 0 : (_window2$Pelcro$uiSet = _window2$Pelcro.uiSettings) === null || _window2$Pelcro$uiSet === void 0 ? void 0 : _window2$Pelcro$uiSet.disablePageViewEvents) || false;
|
|
11811
11908
|
if (window.Pelcro.site.read().google_analytics_id) {
|
|
11812
11909
|
if (enableReactGA4) {
|
|
11813
|
-
// Initialize ReactGA4 with your tracking ID
|
|
11814
|
-
ReactGA4.initialize(window.Pelcro.site.read().google_analytics_id);
|
|
11815
|
-
// Enable e-commerce tracking
|
|
11910
|
+
// Initialize ReactGA4 with your tracking ID and options, only once
|
|
11816
11911
|
ReactGA4.initialize(window.Pelcro.site.read().google_analytics_id, {
|
|
11817
11912
|
gaOptions: {
|
|
11818
|
-
send_page_view: true,
|
|
11913
|
+
send_page_view: disablePageViewEvents ? false : true,
|
|
11819
11914
|
ecommerce: {
|
|
11820
11915
|
enabled: true
|
|
11821
11916
|
}
|
|
@@ -11829,8 +11924,8 @@ const initGATracking = () => {
|
|
|
11829
11924
|
}
|
|
11830
11925
|
};
|
|
11831
11926
|
const dispatchModalDisplayEvents = modalName => {
|
|
11832
|
-
var
|
|
11833
|
-
const enableReactGA4 = (
|
|
11927
|
+
var _window3, _window3$Pelcro, _window3$Pelcro$uiSet, _modalName$replace, _modalName$replace2;
|
|
11928
|
+
const enableReactGA4 = (_window3 = window) === null || _window3 === void 0 ? void 0 : (_window3$Pelcro = _window3.Pelcro) === null || _window3$Pelcro === void 0 ? void 0 : (_window3$Pelcro$uiSet = _window3$Pelcro.uiSettings) === null || _window3$Pelcro$uiSet === void 0 ? void 0 : _window3$Pelcro$uiSet.enableReactGA4;
|
|
11834
11929
|
const formattedAction = modalName === null || modalName === void 0 ? void 0 : (_modalName$replace = modalName.replace("pelcro-", "")) === null || _modalName$replace === void 0 ? void 0 : _modalName$replace.replaceAll("-", " ");
|
|
11835
11930
|
if (enableReactGA4) {
|
|
11836
11931
|
ReactGA4.event(`${formattedAction} viewed`, {
|
|
@@ -16424,10 +16519,6 @@ var es_13 = es.StripeProvider;
|
|
|
16424
16519
|
|
|
16425
16520
|
function _classPrivateFieldInitSpec$1(obj, privateMap, value) { _checkPrivateRedeclaration$1(obj, privateMap); privateMap.set(obj, value); }
|
|
16426
16521
|
function _checkPrivateRedeclaration$1(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
16427
|
-
/**
|
|
16428
|
-
* @TODO: All payment related business logic should end up moving
|
|
16429
|
-
* to this service, and out of react components.
|
|
16430
|
-
*/
|
|
16431
16522
|
|
|
16432
16523
|
/**
|
|
16433
16524
|
* Enum for payment types
|
|
@@ -16563,6 +16654,16 @@ class StripeGateway {
|
|
|
16563
16654
|
console.error("Unsupported payment method: Stripe Gateway");
|
|
16564
16655
|
}
|
|
16565
16656
|
});
|
|
16657
|
+
_defineProperty$3(this, "createDropin", function (authorization, selector) {
|
|
16658
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
16659
|
+
return createBraintreeDropin(authorization, selector, options);
|
|
16660
|
+
});
|
|
16661
|
+
_defineProperty$3(this, "requestPaymentMethod", instance => {
|
|
16662
|
+
return requestBraintreePaymentMethod(instance);
|
|
16663
|
+
});
|
|
16664
|
+
_defineProperty$3(this, "loadScript", () => {
|
|
16665
|
+
return loadBraintreeScript();
|
|
16666
|
+
});
|
|
16566
16667
|
_classPrivateFieldInitSpec$1(this, _createSubscription, {
|
|
16567
16668
|
writable: true,
|
|
16568
16669
|
value: (options, callback) => {
|
|
@@ -17760,6 +17861,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
17760
17861
|
onSuccess = () => {},
|
|
17761
17862
|
onGiftRenewalSuccess = () => {},
|
|
17762
17863
|
onFailure = () => {},
|
|
17864
|
+
onPriceUpdate = () => {},
|
|
17763
17865
|
...props
|
|
17764
17866
|
} = _ref;
|
|
17765
17867
|
const [vantivPaymentRequest, setVantivPaymentRequest] = useState(null);
|
|
@@ -17806,6 +17908,79 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
17806
17908
|
});
|
|
17807
17909
|
updateTotalAmountWithTax();
|
|
17808
17910
|
}, []);
|
|
17911
|
+
// Helper function to calculate total amount for payment methods
|
|
17912
|
+
const calculateTotalAmount = (state, plan, invoice, order) => {
|
|
17913
|
+
var _ref2, _ref3, _state$updatedPrice;
|
|
17914
|
+
const getOrderItemsTotal = () => {
|
|
17915
|
+
if (!order) {
|
|
17916
|
+
return null;
|
|
17917
|
+
}
|
|
17918
|
+
const isQuickPurchase = !Array.isArray(order);
|
|
17919
|
+
if (isQuickPurchase) {
|
|
17920
|
+
return order.price * order.quantity;
|
|
17921
|
+
}
|
|
17922
|
+
if (order.length === 0) {
|
|
17923
|
+
return null;
|
|
17924
|
+
}
|
|
17925
|
+
return order.reduce((total, item) => {
|
|
17926
|
+
return total + item.price * item.quantity;
|
|
17927
|
+
}, 0);
|
|
17928
|
+
};
|
|
17929
|
+
return (_ref2 = (_ref3 = (_state$updatedPrice = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice !== void 0 ? _state$updatedPrice : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref3 !== void 0 ? _ref3 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref2 !== void 0 ? _ref2 : getOrderItemsTotal();
|
|
17930
|
+
};
|
|
17931
|
+
|
|
17932
|
+
// Helper function to get currency from the appropriate source
|
|
17933
|
+
const getCurrencyFromPaymentType = (plan, order, invoice) => {
|
|
17934
|
+
if (plan) {
|
|
17935
|
+
return plan.currency;
|
|
17936
|
+
} else if (order) {
|
|
17937
|
+
var _order$;
|
|
17938
|
+
// Handle both single order and array of orders
|
|
17939
|
+
const isQuickPurchase = !Array.isArray(order);
|
|
17940
|
+
return isQuickPurchase ? order.currency : (_order$ = order[0]) === null || _order$ === void 0 ? void 0 : _order$.currency;
|
|
17941
|
+
} else if (invoice) {
|
|
17942
|
+
return invoice.currency;
|
|
17943
|
+
}
|
|
17944
|
+
return "USD"; // Default fallback
|
|
17945
|
+
};
|
|
17946
|
+
|
|
17947
|
+
// Helper function to get payment label
|
|
17948
|
+
const getPaymentLabel = (plan, order, invoice) => {
|
|
17949
|
+
var _window$Pelcro$site$r;
|
|
17950
|
+
if (plan) {
|
|
17951
|
+
return plan.nickname || plan.description || "Subscription";
|
|
17952
|
+
} else if (order) {
|
|
17953
|
+
// Handle both single order and array of orders
|
|
17954
|
+
const isQuickPurchase = !Array.isArray(order);
|
|
17955
|
+
if (isQuickPurchase) {
|
|
17956
|
+
return order.name || "Order";
|
|
17957
|
+
} else {
|
|
17958
|
+
return order.length === 1 ? order[0].name : "Order";
|
|
17959
|
+
}
|
|
17960
|
+
} else if (invoice) {
|
|
17961
|
+
return `Invoice #${invoice.id}`;
|
|
17962
|
+
}
|
|
17963
|
+
return ((_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.name) || "Payment";
|
|
17964
|
+
};
|
|
17965
|
+
|
|
17966
|
+
// Helper function to format amount for payment methods (Apple Pay, Google Pay)
|
|
17967
|
+
const formatPaymentAmount = function (totalAmount, currency) {
|
|
17968
|
+
var _window$Pelcro2, _window$Pelcro2$utils, _window$Pelcro2$utils2, _currency$toUpperCase;
|
|
17969
|
+
let paymentMethod = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
|
|
17970
|
+
if (!totalAmount) return "0.00";
|
|
17971
|
+
const isZeroDecimal = ((_window$Pelcro2 = window.Pelcro) === null || _window$Pelcro2 === void 0 ? void 0 : (_window$Pelcro2$utils = _window$Pelcro2.utils) === null || _window$Pelcro2$utils === void 0 ? void 0 : (_window$Pelcro2$utils2 = _window$Pelcro2$utils.isCurrencyZeroDecimal) === null || _window$Pelcro2$utils2 === void 0 ? void 0 : _window$Pelcro2$utils2.call(_window$Pelcro2$utils, currency)) || ["BIF", "CLP", "DJF", "GNF", "JPY", "KMF", "KRW", "MGA", "PYG", "RWF", "UGX", "VND", "VUV", "XAF", "XOF", "XPF"].includes(currency === null || currency === void 0 ? void 0 : (_currency$toUpperCase = currency.toUpperCase) === null || _currency$toUpperCase === void 0 ? void 0 : _currency$toUpperCase.call(currency));
|
|
17972
|
+
|
|
17973
|
+
// Payment methods expect amount in major currency unit (dollars, not cents)
|
|
17974
|
+
let finalAmount;
|
|
17975
|
+
if (isZeroDecimal) {
|
|
17976
|
+
finalAmount = Math.round(totalAmount).toString();
|
|
17977
|
+
} else {
|
|
17978
|
+
// Convert from cents to dollars and format with 2 decimal places
|
|
17979
|
+
finalAmount = (totalAmount / 100).toFixed(2);
|
|
17980
|
+
}
|
|
17981
|
+
console.log(`${paymentMethod} amount:`, finalAmount, "currency:", currency, "type:", type);
|
|
17982
|
+
return String(finalAmount);
|
|
17983
|
+
};
|
|
17809
17984
|
|
|
17810
17985
|
/* ====== Start Cybersource integration ======== */
|
|
17811
17986
|
const cybersourceErrorHandle = err => {
|
|
@@ -17815,10 +17990,10 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
17815
17990
|
const errorMessages = [];
|
|
17816
17991
|
|
|
17817
17992
|
// enumerable error (ex: validation errors)
|
|
17818
|
-
Object.values(err === null || err === void 0 ? void 0 : (_err$details2 = err.details) === null || _err$details2 === void 0 ? void 0 : (_err$details2$respons = _err$details2.responseStatus) === null || _err$details2$respons === void 0 ? void 0 : _err$details2$respons.details).forEach(
|
|
17993
|
+
Object.values(err === null || err === void 0 ? void 0 : (_err$details2 = err.details) === null || _err$details2 === void 0 ? void 0 : (_err$details2$respons = _err$details2.responseStatus) === null || _err$details2$respons === void 0 ? void 0 : _err$details2$respons.details).forEach(_ref4 => {
|
|
17819
17994
|
let {
|
|
17820
17995
|
message
|
|
17821
|
-
} =
|
|
17996
|
+
} = _ref4;
|
|
17822
17997
|
errorMessages.push(message);
|
|
17823
17998
|
});
|
|
17824
17999
|
|
|
@@ -18036,10 +18211,10 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
18036
18211
|
// No longer needed - microform instance is stored directly in initCybersourceScript
|
|
18037
18212
|
|
|
18038
18213
|
const appendCybersourceFingerprintScripts = () => {
|
|
18039
|
-
var _window$Pelcro$site$
|
|
18214
|
+
var _window$Pelcro$site$r2, _window$Pelcro$site$r3, _window$Pelcro$site$r4, _window$Pelcro$site$r5;
|
|
18040
18215
|
const uniqueId = crypto.randomUUID();
|
|
18041
|
-
const sessionID = ((_window$Pelcro$site$
|
|
18042
|
-
const orgID = (_window$Pelcro$site$
|
|
18216
|
+
const sessionID = ((_window$Pelcro$site$r2 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r2 === void 0 ? void 0 : (_window$Pelcro$site$r3 = _window$Pelcro$site$r2.cybersource_gateway_settings) === null || _window$Pelcro$site$r3 === void 0 ? void 0 : _window$Pelcro$site$r3.merchant_id) + uniqueId;
|
|
18217
|
+
const orgID = (_window$Pelcro$site$r4 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r4 === void 0 ? void 0 : (_window$Pelcro$site$r5 = _window$Pelcro$site$r4.cybersource_gateway_settings) === null || _window$Pelcro$site$r5 === void 0 ? void 0 : _window$Pelcro$site$r5.org_id;
|
|
18043
18218
|
const fingerPrintScript = document.querySelector(`script[src="https://h.online-metrix.net/fp/tags.js?org_id=${orgID}&session_id=${sessionID}"]`);
|
|
18044
18219
|
const fingerPringIframe = document.querySelector(`iframe[src="https://h.online-metrix.net/fp/tags?org_id=${orgID}&session_id=${sessionID}"]`);
|
|
18045
18220
|
if (!fingerPrintScript && !fingerPringIframe) {
|
|
@@ -18145,7 +18320,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
18145
18320
|
|
|
18146
18321
|
/* ====== Start Tap integration ======== */
|
|
18147
18322
|
const submitUsingTap = state => {
|
|
18148
|
-
var
|
|
18323
|
+
var _ref5, _ref6, _ref7, _state$updatedPrice2;
|
|
18149
18324
|
const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
|
|
18150
18325
|
if (isUsingExistingPaymentMethod) {
|
|
18151
18326
|
// no need to create a new source using tap
|
|
@@ -18169,7 +18344,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
18169
18344
|
return total + item.price * item.quantity;
|
|
18170
18345
|
}, 0);
|
|
18171
18346
|
};
|
|
18172
|
-
const totalAmount = (
|
|
18347
|
+
const totalAmount = (_ref5 = (_ref6 = (_ref7 = (_state$updatedPrice2 = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice2 !== void 0 ? _state$updatedPrice2 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref7 !== void 0 ? _ref7 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref6 !== void 0 ? _ref6 : getOrderItemsTotal()) !== null && _ref5 !== void 0 ? _ref5 : 10;
|
|
18173
18348
|
tapInstanceRef.current.createToken(tapInstanceCard.current).then(function (result) {
|
|
18174
18349
|
if (result.error) {
|
|
18175
18350
|
// Inform the user if there was an error
|
|
@@ -18379,8 +18554,8 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
18379
18554
|
}
|
|
18380
18555
|
}
|
|
18381
18556
|
const initTapScript = () => {
|
|
18382
|
-
var _window$Pelcro$site$
|
|
18383
|
-
const tapKey = window.Tapjsli((_window$Pelcro$site$
|
|
18557
|
+
var _window$Pelcro$site$r6;
|
|
18558
|
+
const tapKey = window.Tapjsli((_window$Pelcro$site$r6 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r6 === void 0 ? void 0 : _window$Pelcro$site$r6.tap_gateway_settings.publishable_key);
|
|
18384
18559
|
let elements = tapKey.elements({});
|
|
18385
18560
|
let style = {
|
|
18386
18561
|
base: {
|
|
@@ -18430,8 +18605,8 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
18430
18605
|
};
|
|
18431
18606
|
/* ====== End Tap integration ======== */
|
|
18432
18607
|
|
|
18433
|
-
/* ====== Start Braintree integration
|
|
18434
|
-
const
|
|
18608
|
+
/* ====== Start Braintree Drop-in UI integration ======== */
|
|
18609
|
+
const braintreeDropinRef = React__default.useRef(null);
|
|
18435
18610
|
function getClientToken() {
|
|
18436
18611
|
return new Promise((resolve, reject) => {
|
|
18437
18612
|
window.Pelcro.payment.generateClientToken({
|
|
@@ -18450,18 +18625,46 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
18450
18625
|
async function initializeBraintree() {
|
|
18451
18626
|
if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
|
|
18452
18627
|
if (cardProcessor === "braintree" && !selectedPaymentMethodId) {
|
|
18628
|
+
// Clear container before initializing
|
|
18629
|
+
const dropinContainer = document.getElementById("dropin-container");
|
|
18630
|
+
if (dropinContainer) dropinContainer.innerHTML = "";
|
|
18453
18631
|
const braintreeToken = await getClientToken();
|
|
18454
18632
|
const isBraintreeEnabled = Boolean(braintreeToken);
|
|
18455
18633
|
if (!isBraintreeEnabled) {
|
|
18456
18634
|
console.error("Braintree integration is currently not enabled on this site's config");
|
|
18457
18635
|
return;
|
|
18458
18636
|
}
|
|
18637
|
+
console.log("braintreeToken", plan);
|
|
18459
18638
|
if (type !== "updatePaymentSource") {
|
|
18460
|
-
|
|
18461
|
-
|
|
18462
|
-
|
|
18463
|
-
|
|
18464
|
-
|
|
18639
|
+
console.log("Setting skeleton loader to true at start of Braintree initialization");
|
|
18640
|
+
dispatch({
|
|
18641
|
+
type: SKELETON_LOADER,
|
|
18642
|
+
payload: true
|
|
18643
|
+
});
|
|
18644
|
+
try {
|
|
18645
|
+
var _window$Pelcro$site$r7, _window$Pelcro$site$r8;
|
|
18646
|
+
// Ensure the DOM element exists before creating Drop-in UI
|
|
18647
|
+
const dropinContainer = document.querySelector("#dropin-container");
|
|
18648
|
+
if (!dropinContainer) {
|
|
18649
|
+
console.error("Drop-in container not found. Waiting for DOM to be ready...");
|
|
18650
|
+
dispatch({
|
|
18651
|
+
type: SKELETON_LOADER,
|
|
18652
|
+
payload: false
|
|
18653
|
+
});
|
|
18654
|
+
return;
|
|
18655
|
+
}
|
|
18656
|
+
|
|
18657
|
+
// Small delay to ensure DOM is fully rendered
|
|
18658
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
18659
|
+
|
|
18660
|
+
// Calculate Google Pay amount using the same logic as Apple Pay
|
|
18661
|
+
const totalAmount = calculateTotalAmount(state, plan, invoice, order);
|
|
18662
|
+
const currency = getCurrencyFromPaymentType(plan, order, invoice);
|
|
18663
|
+
const googlePayAmount = formatPaymentAmount(totalAmount, currency, "Google Pay");
|
|
18664
|
+
|
|
18665
|
+
// Create Braintree Drop-in UI instance
|
|
18666
|
+
braintreeDropinRef.current = await createBraintreeDropin(braintreeToken, "#dropin-container", {
|
|
18667
|
+
// Customize the Drop-in UI appearance
|
|
18465
18668
|
styles: {
|
|
18466
18669
|
input: {
|
|
18467
18670
|
"font-size": "14px"
|
|
@@ -18473,48 +18676,85 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
18473
18676
|
color: "green"
|
|
18474
18677
|
}
|
|
18475
18678
|
},
|
|
18476
|
-
|
|
18477
|
-
|
|
18478
|
-
|
|
18479
|
-
|
|
18480
|
-
|
|
18481
|
-
|
|
18482
|
-
|
|
18483
|
-
|
|
18679
|
+
// Disable PayPal to avoid conflicts with existing PayPal SDK
|
|
18680
|
+
// paypal: {
|
|
18681
|
+
// flow: "vault"
|
|
18682
|
+
// },
|
|
18683
|
+
// Enable Apple Pay if available
|
|
18684
|
+
applePay: {
|
|
18685
|
+
displayName: ((_window$Pelcro$site$r7 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r7 === void 0 ? void 0 : _window$Pelcro$site$r7.name) || "Pelcro",
|
|
18686
|
+
paymentRequest: {
|
|
18687
|
+
total: {
|
|
18688
|
+
label: getPaymentLabel(plan, order, invoice),
|
|
18689
|
+
amount: (() => {
|
|
18690
|
+
const totalAmount = calculateTotalAmount(state, plan, invoice, order);
|
|
18691
|
+
const currency = getCurrencyFromPaymentType(plan, order, invoice);
|
|
18692
|
+
return formatPaymentAmount(totalAmount, currency, "Apple Pay");
|
|
18693
|
+
})()
|
|
18694
|
+
}
|
|
18695
|
+
}
|
|
18696
|
+
},
|
|
18697
|
+
// Enable Google Pay for both orders and subscriptions
|
|
18698
|
+
googlePay: {
|
|
18699
|
+
googlePayVersion: 2,
|
|
18700
|
+
merchantId: (_window$Pelcro$site$r8 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r8 === void 0 ? void 0 : _window$Pelcro$site$r8.google_merchant_id,
|
|
18701
|
+
transactionInfo: {
|
|
18702
|
+
totalPriceStatus: "FINAL",
|
|
18703
|
+
totalPrice: googlePayAmount,
|
|
18704
|
+
currencyCode: (() => {
|
|
18705
|
+
const currency = getCurrencyFromPaymentType(plan, order, invoice);
|
|
18706
|
+
return (currency === null || currency === void 0 ? void 0 : currency.toUpperCase()) || "USD";
|
|
18707
|
+
})()
|
|
18484
18708
|
},
|
|
18485
|
-
|
|
18486
|
-
|
|
18487
|
-
|
|
18709
|
+
// Add button configuration
|
|
18710
|
+
button: {
|
|
18711
|
+
color: "black",
|
|
18712
|
+
type: type === "createPayment" ? "subscribe" : "buy"
|
|
18488
18713
|
}
|
|
18489
18714
|
}
|
|
18490
|
-
};
|
|
18715
|
+
});
|
|
18716
|
+
console.log("Setting skeleton loader to false after successful Braintree initialization");
|
|
18491
18717
|
dispatch({
|
|
18492
18718
|
type: SKELETON_LOADER,
|
|
18493
|
-
payload:
|
|
18719
|
+
payload: false
|
|
18494
18720
|
});
|
|
18495
|
-
|
|
18496
|
-
|
|
18497
|
-
|
|
18498
|
-
|
|
18499
|
-
|
|
18500
|
-
|
|
18501
|
-
|
|
18721
|
+
|
|
18722
|
+
// Clear any error alerts that were shown during initialization
|
|
18723
|
+
dispatch({
|
|
18724
|
+
type: SHOW_ALERT,
|
|
18725
|
+
payload: {
|
|
18726
|
+
type: "error",
|
|
18727
|
+
content: ""
|
|
18502
18728
|
}
|
|
18503
18729
|
});
|
|
18504
|
-
|
|
18505
|
-
|
|
18506
|
-
|
|
18507
|
-
|
|
18508
|
-
|
|
18509
|
-
|
|
18510
|
-
|
|
18511
|
-
|
|
18512
|
-
|
|
18513
|
-
|
|
18514
|
-
|
|
18730
|
+
} catch (error) {
|
|
18731
|
+
var _error$message, _error$message2, _error$message3, _error$message4;
|
|
18732
|
+
console.error("Failed to initialize Braintree Drop-in UI:", error);
|
|
18733
|
+
|
|
18734
|
+
// Check if it's a Google Pay specific error
|
|
18735
|
+
if (error !== null && error !== void 0 && (_error$message = error.message) !== null && _error$message !== void 0 && _error$message.includes("OR_BIBED_06") || error !== null && error !== void 0 && (_error$message2 = error.message) !== null && _error$message2 !== void 0 && _error$message2.includes("Google Pay")) {
|
|
18736
|
+
console.warn("Google Pay configuration issue detected. " + `Transaction type: ${type}. ` + "This might be due to merchant settings or unsupported payment flow.");
|
|
18737
|
+
}
|
|
18738
|
+
dispatch({
|
|
18739
|
+
type: SKELETON_LOADER,
|
|
18740
|
+
payload: false
|
|
18515
18741
|
});
|
|
18516
|
-
|
|
18742
|
+
|
|
18743
|
+
// Don't show error to user for Google Pay configuration issues
|
|
18744
|
+
// as it's expected for subscriptions
|
|
18745
|
+
if (!(error !== null && error !== void 0 && (_error$message3 = error.message) !== null && _error$message3 !== void 0 && _error$message3.includes("OR_BIBED_06")) && !(error !== null && error !== void 0 && (_error$message4 = error.message) !== null && _error$message4 !== void 0 && _error$message4.includes("Google Pay"))) {
|
|
18746
|
+
dispatch({
|
|
18747
|
+
type: SHOW_ALERT,
|
|
18748
|
+
payload: {
|
|
18749
|
+
type: "error",
|
|
18750
|
+
content: "Failed to initialize payment form. Please refresh and try again."
|
|
18751
|
+
}
|
|
18752
|
+
});
|
|
18753
|
+
}
|
|
18754
|
+
}
|
|
18517
18755
|
} else if (type == "updatePaymentSource" && paymentMethodToEdit) {
|
|
18756
|
+
// For updating payment methods, we still use hosted fields
|
|
18757
|
+
// as Drop-in UI doesn't support partial updates
|
|
18518
18758
|
const {
|
|
18519
18759
|
properties
|
|
18520
18760
|
} = paymentMethodToEdit !== null && paymentMethodToEdit !== void 0 ? paymentMethodToEdit : {};
|
|
@@ -18522,9 +18762,14 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
18522
18762
|
exp_month: expMonth,
|
|
18523
18763
|
exp_year: expYear
|
|
18524
18764
|
} = properties !== null && properties !== void 0 ? properties : {};
|
|
18525
|
-
|
|
18526
|
-
|
|
18527
|
-
|
|
18765
|
+
dispatch({
|
|
18766
|
+
type: SKELETON_LOADER,
|
|
18767
|
+
payload: true
|
|
18768
|
+
});
|
|
18769
|
+
try {
|
|
18770
|
+
const clientInstance = await new window.braintree.client.create({
|
|
18771
|
+
authorization: braintreeToken
|
|
18772
|
+
});
|
|
18528
18773
|
const options = {
|
|
18529
18774
|
client: clientInstance,
|
|
18530
18775
|
styles: {
|
|
@@ -18546,41 +18791,28 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
18546
18791
|
expirationYear: {
|
|
18547
18792
|
container: "#expiration-year",
|
|
18548
18793
|
prefill: expYear
|
|
18794
|
+
},
|
|
18795
|
+
cvv: {
|
|
18796
|
+
container: "#cvv"
|
|
18549
18797
|
}
|
|
18550
18798
|
}
|
|
18551
18799
|
};
|
|
18800
|
+
braintreeDropinRef.current = await window.braintree.hostedFields.create(options);
|
|
18801
|
+
|
|
18802
|
+
// dispatch({
|
|
18803
|
+
// type: SKELETON_LOADER,
|
|
18804
|
+
// payload: false
|
|
18805
|
+
// });
|
|
18806
|
+
} catch (error) {
|
|
18807
|
+
console.error("Failed to initialize Braintree hosted fields:", error);
|
|
18552
18808
|
dispatch({
|
|
18553
18809
|
type: SKELETON_LOADER,
|
|
18554
|
-
payload:
|
|
18555
|
-
});
|
|
18556
|
-
return window.braintree.hostedFields.create(options);
|
|
18557
|
-
});
|
|
18558
|
-
braintreeInstanceRef.current.then(hostedFieldInstance => {
|
|
18559
|
-
hostedFieldInstance.on("notEmpty", function (event) {
|
|
18560
|
-
const field = event.fields[event.emittedBy];
|
|
18561
|
-
if (field.isPotentiallyValid) {
|
|
18562
|
-
field.container.classList.remove("pelcro-input-invalid");
|
|
18563
|
-
}
|
|
18564
|
-
});
|
|
18565
|
-
hostedFieldInstance.on("validityChange", function (event) {
|
|
18566
|
-
const field = event.fields[event.emittedBy];
|
|
18567
|
-
|
|
18568
|
-
// Remove any previously applied error or warning classes
|
|
18569
|
-
field.container.classList.remove("is-valid");
|
|
18570
|
-
field.container.classList.remove("pelcro-input-invalid");
|
|
18571
|
-
if (field.isValid) {
|
|
18572
|
-
field.container.classList.add("is-valid");
|
|
18573
|
-
} else if (field.isPotentiallyValid) ; else {
|
|
18574
|
-
field.container.classList.add("pelcro-input-invalid");
|
|
18575
|
-
}
|
|
18810
|
+
payload: false
|
|
18576
18811
|
});
|
|
18577
|
-
}
|
|
18812
|
+
}
|
|
18578
18813
|
}
|
|
18579
18814
|
}
|
|
18580
18815
|
}
|
|
18581
|
-
useEffect(() => {
|
|
18582
|
-
initializeBraintree();
|
|
18583
|
-
}, [selectedPaymentMethodId, paymentMethodToEdit]);
|
|
18584
18816
|
const braintreeErrorHandler = tokenizeErr => {
|
|
18585
18817
|
var _tokenizeErr$details, _tokenizeErr$details2;
|
|
18586
18818
|
const cardNumber = document.querySelector("#card-number");
|
|
@@ -18643,51 +18875,55 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
18643
18875
|
// no need to create a new source using braintree
|
|
18644
18876
|
return handleBraintreePayment(null, state.couponCode);
|
|
18645
18877
|
}
|
|
18646
|
-
if (!
|
|
18647
|
-
|
|
18648
|
-
|
|
18649
|
-
|
|
18650
|
-
|
|
18651
|
-
|
|
18652
|
-
|
|
18653
|
-
|
|
18654
|
-
|
|
18655
|
-
|
|
18656
|
-
|
|
18657
|
-
|
|
18658
|
-
|
|
18659
|
-
|
|
18660
|
-
|
|
18661
|
-
type: SHOW_ALERT,
|
|
18662
|
-
payload: {
|
|
18663
|
-
type: "error",
|
|
18664
|
-
content: braintreeErrorHandler(tokenizeErr)
|
|
18665
|
-
}
|
|
18666
|
-
});
|
|
18878
|
+
if (!braintreeDropinRef.current) {
|
|
18879
|
+
console.error("Braintree Drop-in UI wasn't initialized, please try again");
|
|
18880
|
+
dispatch({
|
|
18881
|
+
type: DISABLE_SUBMIT,
|
|
18882
|
+
payload: false
|
|
18883
|
+
});
|
|
18884
|
+
dispatch({
|
|
18885
|
+
type: LOADING,
|
|
18886
|
+
payload: false
|
|
18887
|
+
});
|
|
18888
|
+
return dispatch({
|
|
18889
|
+
type: SHOW_ALERT,
|
|
18890
|
+
payload: {
|
|
18891
|
+
type: "error",
|
|
18892
|
+
content: "Braintree Drop-in UI wasn't initialized, please try again"
|
|
18667
18893
|
}
|
|
18668
|
-
|
|
18669
|
-
// Directly handle the payment with the tokenized payload
|
|
18670
|
-
handleBraintreePayment(payload, state.couponCode);
|
|
18671
18894
|
});
|
|
18895
|
+
}
|
|
18896
|
+
dispatch({
|
|
18897
|
+
type: LOADING,
|
|
18898
|
+
payload: true
|
|
18899
|
+
});
|
|
18900
|
+
dispatch({
|
|
18901
|
+
type: DISABLE_SUBMIT,
|
|
18902
|
+
payload: true
|
|
18903
|
+
});
|
|
18904
|
+
|
|
18905
|
+
// Use appropriate method based on payment type
|
|
18906
|
+
const paymentMethodPromise = type === "updatePaymentSource" ? requestBraintreeHostedFieldsPaymentMethod(braintreeDropinRef.current) : requestBraintreePaymentMethod(braintreeDropinRef.current);
|
|
18907
|
+
paymentMethodPromise.then(payload => {
|
|
18908
|
+
// Drop-in UI handles 3D Secure automatically, just proceed with payment
|
|
18909
|
+
handleBraintreePayment(payload, state.couponCode);
|
|
18672
18910
|
}).catch(error => {
|
|
18673
|
-
|
|
18674
|
-
|
|
18675
|
-
|
|
18676
|
-
|
|
18677
|
-
|
|
18678
|
-
|
|
18679
|
-
|
|
18680
|
-
|
|
18681
|
-
|
|
18682
|
-
|
|
18683
|
-
|
|
18684
|
-
|
|
18685
|
-
|
|
18686
|
-
|
|
18687
|
-
|
|
18688
|
-
|
|
18689
|
-
});
|
|
18690
|
-
}
|
|
18911
|
+
console.error("Braintree payment error:", error);
|
|
18912
|
+
dispatch({
|
|
18913
|
+
type: DISABLE_SUBMIT,
|
|
18914
|
+
payload: false
|
|
18915
|
+
});
|
|
18916
|
+
dispatch({
|
|
18917
|
+
type: LOADING,
|
|
18918
|
+
payload: false
|
|
18919
|
+
});
|
|
18920
|
+
return dispatch({
|
|
18921
|
+
type: SHOW_ALERT,
|
|
18922
|
+
payload: {
|
|
18923
|
+
type: "error",
|
|
18924
|
+
content: braintreeErrorHandler(error)
|
|
18925
|
+
}
|
|
18926
|
+
});
|
|
18691
18927
|
});
|
|
18692
18928
|
};
|
|
18693
18929
|
const handleBraintreePayment = (braintreePaymentRequest, couponCode) => {
|
|
@@ -18737,7 +18973,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
18737
18973
|
content: t("messages.sourceCreated")
|
|
18738
18974
|
}
|
|
18739
18975
|
});
|
|
18740
|
-
refreshUser();
|
|
18741
18976
|
onSuccess(res);
|
|
18742
18977
|
});
|
|
18743
18978
|
}
|
|
@@ -19206,9 +19441,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
19206
19441
|
useEffect(() => {
|
|
19207
19442
|
if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
|
|
19208
19443
|
if (cardProcessor === "vantiv" && !selectedPaymentMethodId) {
|
|
19209
|
-
var _window$Pelcro$site$
|
|
19210
|
-
const payPageId = (_window$Pelcro$site$
|
|
19211
|
-
const reportGroup = (_window$Pelcro$site$
|
|
19444
|
+
var _window$Pelcro$site$r9, _window$Pelcro$site$r10;
|
|
19445
|
+
const payPageId = (_window$Pelcro$site$r9 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r9 === void 0 ? void 0 : _window$Pelcro$site$r9.vantiv_gateway_settings.pay_page_id;
|
|
19446
|
+
const reportGroup = (_window$Pelcro$site$r10 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r10 === void 0 ? void 0 : _window$Pelcro$site$r10.vantiv_gateway_settings.report_group;
|
|
19212
19447
|
vantivInstanceRef.current = new window.EprotectIframeClient({
|
|
19213
19448
|
paypageId: payPageId,
|
|
19214
19449
|
reportGroup: reportGroup,
|
|
@@ -19272,13 +19507,13 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
19272
19507
|
});
|
|
19273
19508
|
|
|
19274
19509
|
// When Google pay / Apple pay source created
|
|
19275
|
-
paymentRequest.on("source",
|
|
19510
|
+
paymentRequest.on("source", _ref8 => {
|
|
19276
19511
|
var _source$card;
|
|
19277
19512
|
let {
|
|
19278
19513
|
complete,
|
|
19279
19514
|
source,
|
|
19280
19515
|
...data
|
|
19281
|
-
} =
|
|
19516
|
+
} = _ref8;
|
|
19282
19517
|
dispatch({
|
|
19283
19518
|
type: DISABLE_COUPON_BUTTON,
|
|
19284
19519
|
payload: true
|
|
@@ -19293,11 +19528,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
19293
19528
|
});
|
|
19294
19529
|
complete("success");
|
|
19295
19530
|
if ((source === null || source === void 0 ? void 0 : (_source$card = source.card) === null || _source$card === void 0 ? void 0 : _source$card.three_d_secure) === "required") {
|
|
19296
|
-
return generate3DSecureSource(source).then(
|
|
19531
|
+
return generate3DSecureSource(source).then(_ref9 => {
|
|
19297
19532
|
let {
|
|
19298
19533
|
source,
|
|
19299
19534
|
error
|
|
19300
|
-
} =
|
|
19535
|
+
} = _ref9;
|
|
19301
19536
|
if (error) {
|
|
19302
19537
|
return handlePaymentError(error);
|
|
19303
19538
|
}
|
|
@@ -19328,9 +19563,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
19328
19563
|
* Updates the total amount after adding taxes only if site taxes are enabled
|
|
19329
19564
|
*/
|
|
19330
19565
|
const updateTotalAmountWithTax = () => {
|
|
19331
|
-
var _window$Pelcro$site$
|
|
19566
|
+
var _window$Pelcro$site$r11;
|
|
19332
19567
|
if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
|
|
19333
|
-
const taxesEnabled = (_window$Pelcro$site$
|
|
19568
|
+
const taxesEnabled = (_window$Pelcro$site$r11 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r11 === void 0 ? void 0 : _window$Pelcro$site$r11.taxes_enabled;
|
|
19334
19569
|
if (taxesEnabled && type === "createPayment") {
|
|
19335
19570
|
dispatch({
|
|
19336
19571
|
type: DISABLE_SUBMIT,
|
|
@@ -19949,7 +20184,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
19949
20184
|
cardExpirationMonth: state === null || state === void 0 ? void 0 : state.month,
|
|
19950
20185
|
cardExpirationYear: state === null || state === void 0 ? void 0 : state.year
|
|
19951
20186
|
}, (err, orderResponse) => {
|
|
19952
|
-
var _window$
|
|
20187
|
+
var _window$Pelcro3, _window$Pelcro3$user, _window$Pelcro3$user$;
|
|
19953
20188
|
if (err) {
|
|
19954
20189
|
toggleAuthenticationSuccessPendingView(false);
|
|
19955
20190
|
dispatch({
|
|
@@ -19980,7 +20215,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
19980
20215
|
});
|
|
19981
20216
|
}
|
|
19982
20217
|
window.Pelcro.user.refresh({
|
|
19983
|
-
auth_token: (_window$
|
|
20218
|
+
auth_token: (_window$Pelcro3 = window.Pelcro) === null || _window$Pelcro3 === void 0 ? void 0 : (_window$Pelcro3$user = _window$Pelcro3.user) === null || _window$Pelcro3$user === void 0 ? void 0 : (_window$Pelcro3$user$ = _window$Pelcro3$user.read()) === null || _window$Pelcro3$user$ === void 0 ? void 0 : _window$Pelcro3$user$.auth_token
|
|
19984
20219
|
}, (err, res) => {
|
|
19985
20220
|
dispatch({
|
|
19986
20221
|
type: DISABLE_SUBMIT,
|
|
@@ -20019,11 +20254,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
20019
20254
|
const createPaymentSource = (state, dispatch) => {
|
|
20020
20255
|
return stripe.createSource({
|
|
20021
20256
|
type: "card"
|
|
20022
|
-
}).then(
|
|
20257
|
+
}).then(_ref10 => {
|
|
20023
20258
|
let {
|
|
20024
20259
|
source,
|
|
20025
20260
|
error
|
|
20026
|
-
} =
|
|
20261
|
+
} = _ref10;
|
|
20027
20262
|
if (error) {
|
|
20028
20263
|
return handlePaymentError(error);
|
|
20029
20264
|
}
|
|
@@ -20137,11 +20372,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
20137
20372
|
} = paymentMethodToDelete;
|
|
20138
20373
|
return stripe.createSource({
|
|
20139
20374
|
type: "card"
|
|
20140
|
-
}).then(
|
|
20375
|
+
}).then(_ref11 => {
|
|
20141
20376
|
let {
|
|
20142
20377
|
source,
|
|
20143
20378
|
error
|
|
20144
|
-
} =
|
|
20379
|
+
} = _ref11;
|
|
20145
20380
|
if (error) {
|
|
20146
20381
|
return handlePaymentError(error);
|
|
20147
20382
|
}
|
|
@@ -20241,12 +20476,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
20241
20476
|
}
|
|
20242
20477
|
stripe.createSource({
|
|
20243
20478
|
type: "card"
|
|
20244
|
-
}).then(
|
|
20245
|
-
var
|
|
20479
|
+
}).then(_ref12 => {
|
|
20480
|
+
var _ref13, _ref14, _state$updatedPrice3;
|
|
20246
20481
|
let {
|
|
20247
20482
|
source,
|
|
20248
20483
|
error
|
|
20249
|
-
} =
|
|
20484
|
+
} = _ref12;
|
|
20250
20485
|
if (error) {
|
|
20251
20486
|
return handlePaymentError(error);
|
|
20252
20487
|
}
|
|
@@ -20265,7 +20500,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
20265
20500
|
return total + item.price * item.quantity;
|
|
20266
20501
|
}, 0);
|
|
20267
20502
|
};
|
|
20268
|
-
(
|
|
20503
|
+
(_ref13 = (_ref14 = (_state$updatedPrice3 = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice3 !== void 0 ? _state$updatedPrice3 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref14 !== void 0 ? _ref14 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref13 !== void 0 ? _ref13 : getOrderItemsTotal();
|
|
20269
20504
|
return handlePayment(source);
|
|
20270
20505
|
}).catch(error => {
|
|
20271
20506
|
return handlePaymentError(error);
|
|
@@ -20277,11 +20512,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
20277
20512
|
* @return {Promise}
|
|
20278
20513
|
*/
|
|
20279
20514
|
const resolveTaxCalculation = () => {
|
|
20280
|
-
var _window$Pelcro$site$
|
|
20515
|
+
var _window$Pelcro$site$r12;
|
|
20281
20516
|
if (type === "invoicePayment") {
|
|
20282
20517
|
return new Promise(resolve => resolve());
|
|
20283
20518
|
}
|
|
20284
|
-
const taxesEnabled = (_window$Pelcro$site$
|
|
20519
|
+
const taxesEnabled = (_window$Pelcro$site$r12 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r12 === void 0 ? void 0 : _window$Pelcro$site$r12.taxes_enabled;
|
|
20285
20520
|
return new Promise((resolve, reject) => {
|
|
20286
20521
|
// resolve early if taxes isn't enabled
|
|
20287
20522
|
if (!taxesEnabled) {
|
|
@@ -20523,10 +20758,10 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
20523
20758
|
setVantivPaymentRequest(action.payload);
|
|
20524
20759
|
});
|
|
20525
20760
|
case SET_UPDATED_PRICE:
|
|
20526
|
-
return
|
|
20761
|
+
return lib_5({
|
|
20527
20762
|
...state,
|
|
20528
20763
|
updatedPrice: action.payload
|
|
20529
|
-
});
|
|
20764
|
+
}, () => onPriceUpdate(action.payload));
|
|
20530
20765
|
case SET_TAX_AMOUNT:
|
|
20531
20766
|
return lib_7({
|
|
20532
20767
|
...state,
|
|
@@ -20639,6 +20874,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
|
|
|
20639
20874
|
return state;
|
|
20640
20875
|
}
|
|
20641
20876
|
}, initialState$l);
|
|
20877
|
+
useEffect(() => {
|
|
20878
|
+
initializeBraintree();
|
|
20879
|
+
}, [selectedPaymentMethodId, paymentMethodToEdit, state.updatedPrice]);
|
|
20642
20880
|
return /*#__PURE__*/React__default.createElement("div", {
|
|
20643
20881
|
style: {
|
|
20644
20882
|
...style
|
|
@@ -20941,32 +21179,21 @@ const CheckoutForm = _ref => {
|
|
|
20941
21179
|
}, "Expiration Year *"), /*#__PURE__*/React__default.createElement("div", {
|
|
20942
21180
|
id: "expiration-year",
|
|
20943
21181
|
className: "pelcro-input-field plc-h-12 plc-bg-white"
|
|
21182
|
+
})), /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("label", {
|
|
21183
|
+
htmlFor: "cvv"
|
|
21184
|
+
}, "CVV *"), /*#__PURE__*/React__default.createElement("div", {
|
|
21185
|
+
id: "cvv",
|
|
21186
|
+
className: "pelcro-input-field plc-h-12 plc-bg-white"
|
|
20944
21187
|
})))) : /*#__PURE__*/React__default.createElement("div", {
|
|
20945
21188
|
className: "plc-w-full plc-h-40 plc-bg-gray-300 plc-rounded plc-animate-pulse"
|
|
20946
21189
|
}));
|
|
20947
21190
|
}
|
|
20948
|
-
return /*#__PURE__*/React__default.createElement("div", null,
|
|
21191
|
+
return /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("div", {
|
|
20949
21192
|
className: "plc-max-w-[50em]"
|
|
20950
|
-
}, /*#__PURE__*/React__default.createElement("
|
|
20951
|
-
|
|
20952
|
-
|
|
20953
|
-
|
|
20954
|
-
className: "pelcro-input-field plc-h-12 plc-bg-white"
|
|
20955
|
-
}), /*#__PURE__*/React__default.createElement("div", {
|
|
20956
|
-
className: "plc-flex plc-items-start plc-space-x-8 plc-my-6"
|
|
20957
|
-
}, /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("label", {
|
|
20958
|
-
htmlFor: "expiration-date"
|
|
20959
|
-
}, "Expiration Date *"), /*#__PURE__*/React__default.createElement("div", {
|
|
20960
|
-
id: "expiration-date",
|
|
20961
|
-
className: "pelcro-input-field plc-h-12 plc-bg-white"
|
|
20962
|
-
})), /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("label", {
|
|
20963
|
-
htmlFor: "cvv"
|
|
20964
|
-
}, "CVC *"), /*#__PURE__*/React__default.createElement("div", {
|
|
20965
|
-
id: "cvv",
|
|
20966
|
-
className: "pelcro-input-field plc-h-12 plc-bg-white"
|
|
20967
|
-
})))) : /*#__PURE__*/React__default.createElement("div", {
|
|
20968
|
-
className: "plc-w-full plc-h-40 plc-bg-gray-300 plc-rounded plc-animate-pulse"
|
|
20969
|
-
}));
|
|
21193
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
|
21194
|
+
id: "dropin-container",
|
|
21195
|
+
className: "plc-w-full plc-min-h-[300px]"
|
|
21196
|
+
})));
|
|
20970
21197
|
}
|
|
20971
21198
|
if (cardProcessor === "stripe") {
|
|
20972
21199
|
if (type === "updatePaymentSource") {
|
|
@@ -22111,7 +22338,8 @@ function PaymentMethodView(_ref) {
|
|
|
22111
22338
|
showSubscriptionButton,
|
|
22112
22339
|
showOrderButton,
|
|
22113
22340
|
showApplePayButton,
|
|
22114
|
-
order
|
|
22341
|
+
order,
|
|
22342
|
+
onPriceUpdate
|
|
22115
22343
|
} = _ref;
|
|
22116
22344
|
const {
|
|
22117
22345
|
t
|
|
@@ -22154,7 +22382,8 @@ function PaymentMethodView(_ref) {
|
|
|
22154
22382
|
onSuccess: onSuccess,
|
|
22155
22383
|
onGiftRenewalSuccess: onGiftRenewalSuccess,
|
|
22156
22384
|
onFailure: onFailure,
|
|
22157
|
-
freeOrders: showOrderButton
|
|
22385
|
+
freeOrders: showOrderButton,
|
|
22386
|
+
onPriceUpdate: onPriceUpdate
|
|
22158
22387
|
}, /*#__PURE__*/React__default.createElement(AlertWithContext, {
|
|
22159
22388
|
className: "plc-mb-2"
|
|
22160
22389
|
}), showSubscriptionButton && /*#__PURE__*/React__default.createElement(SubscriptionCreateFreePlanButton, null), showOrderButton && /*#__PURE__*/React__default.createElement(OrderCreateFreeButton, null), !showSubscriptionButton && !showOrderButton && /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(BankRedirection, null), /*#__PURE__*/React__default.createElement(BankAuthenticationSuccess, null), /*#__PURE__*/React__default.createElement(SelectedPaymentMethod, null), supportsTap && (!isUserFirstName || !isUserLastName || !isUserPhone) && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", {
|
|
@@ -22184,7 +22413,7 @@ function PaymentMethodView(_ref) {
|
|
|
22184
22413
|
label: t("labels.isDefault")
|
|
22185
22414
|
}), /*#__PURE__*/React__default.createElement("div", {
|
|
22186
22415
|
className: "plc-grid plc-mt-4 plc-gap-y-2"
|
|
22187
|
-
}, /*#__PURE__*/React__default.createElement(SubmitPaymentMethod, null), showExternalPaymentMethods &&
|
|
22416
|
+
}, /*#__PURE__*/React__default.createElement(SubmitPaymentMethod, null), showExternalPaymentMethods && cardProcessor === "braintree" && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, !supportsVantiv && !supportsCybersource && !supportsTap && /*#__PURE__*/React__default.createElement(PelcroPaymentRequestButton, null), /*#__PURE__*/React__default.createElement(PaypalSubscribeButton, null)), showApplePayButton && supportsVantiv && /*#__PURE__*/React__default.createElement(ApplePayButton, null))))));
|
|
22188
22417
|
}
|
|
22189
22418
|
|
|
22190
22419
|
const SubscriptionRenewView = _ref => {
|
|
@@ -22201,8 +22430,11 @@ const SubscriptionRenewView = _ref => {
|
|
|
22201
22430
|
product,
|
|
22202
22431
|
plan
|
|
22203
22432
|
} = usePelcro();
|
|
22433
|
+
const [updatedPrice, setUpdatedPrice] = useState(null);
|
|
22204
22434
|
const skipPayment = (_window$Pelcro = window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$uiSett = _window$Pelcro.uiSettings) === null || _window$Pelcro$uiSett === void 0 ? void 0 : _window$Pelcro$uiSett.skipPaymentForFreePlans;
|
|
22205
|
-
|
|
22435
|
+
|
|
22436
|
+
// Check both original plan amount and final amount after coupon
|
|
22437
|
+
const showSubscriptionButton = skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || updatedPrice === 0);
|
|
22206
22438
|
const getPricingText = plan => {
|
|
22207
22439
|
const autoRenewed = plan.auto_renew;
|
|
22208
22440
|
const {
|
|
@@ -22239,7 +22471,8 @@ const SubscriptionRenewView = _ref => {
|
|
|
22239
22471
|
onSuccess: onSuccess,
|
|
22240
22472
|
onGiftRenewalSuccess: onGiftRenewalSuccess,
|
|
22241
22473
|
onFailure: onFailure,
|
|
22242
|
-
showSubscriptionButton: showSubscriptionButton
|
|
22474
|
+
showSubscriptionButton: showSubscriptionButton,
|
|
22475
|
+
onPriceUpdate: setUpdatedPrice
|
|
22243
22476
|
}));
|
|
22244
22477
|
};
|
|
22245
22478
|
|
|
@@ -23572,8 +23805,11 @@ const SubscriptionCreateView = _ref => {
|
|
|
23572
23805
|
product,
|
|
23573
23806
|
plan
|
|
23574
23807
|
} = usePelcro();
|
|
23808
|
+
const [updatedPrice, setUpdatedPrice] = useState(null);
|
|
23575
23809
|
const skipPayment = (_window$Pelcro = window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$uiSett = _window$Pelcro.uiSettings) === null || _window$Pelcro$uiSett === void 0 ? void 0 : _window$Pelcro$uiSett.skipPaymentForFreePlans;
|
|
23576
|
-
|
|
23810
|
+
|
|
23811
|
+
// Check both original plan amount and final amount after coupon
|
|
23812
|
+
const showSubscriptionButton = skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || updatedPrice === 0);
|
|
23577
23813
|
const getPricingText = plan => {
|
|
23578
23814
|
var _plan$quantity;
|
|
23579
23815
|
const autoRenewed = plan.auto_renew;
|
|
@@ -23611,7 +23847,8 @@ const SubscriptionCreateView = _ref => {
|
|
|
23611
23847
|
showApplePayButton: true,
|
|
23612
23848
|
onSuccess: onSuccess,
|
|
23613
23849
|
onFailure: onFailure,
|
|
23614
|
-
showSubscriptionButton: showSubscriptionButton
|
|
23850
|
+
showSubscriptionButton: showSubscriptionButton,
|
|
23851
|
+
onPriceUpdate: setUpdatedPrice
|
|
23615
23852
|
}));
|
|
23616
23853
|
};
|
|
23617
23854
|
|