1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 21:52:35 +01:00
invoiceninja/public/js/clients/payments/braintree-paypal.js

2 lines
2.7 KiB
JavaScript
Raw Normal View History

/*! For license information please see braintree-paypal.js.LICENSE.txt */
2021-10-27 18:23:59 +02:00
(()=>{function e(e,n){for(var t=0;t<n.length;t++){var a=n[t];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}(new(function(){function n(){!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,n)}var t,a,o;return t=n,o=[{key:"getPaymentDetails",value:function(){return{flow:"vault"}}},{key:"handleErrorMessage",value:function(e){var n=document.getElementById("errors");n.innerText=e,n.hidden=!1}}],(a=[{key:"initBraintreeDataCollector",value:function(){window.braintree.client.create({authorization:document.querySelector("meta[name=client-token]").content},(function(e,n){window.braintree.dataCollector.create({client:n,paypal:!0},(function(e,n){e||(document.querySelector("input[name=client-data]").value=n.deviceData)}))}))}},{key:"handlePaymentWithToken",value:function(){Array.from(document.getElementsByClassName("toggle-payment-with-token")).forEach((function(e){return e.addEventListener("click",(function(e){document.getElementById("paypal-button").classList.add("hidden"),document.getElementById("save-card--container").style.display="none",document.querySelector("input[name=token]").value=e.target.dataset.token,document.getElementById("pay-now-with-token").classList.remove("hidden"),document.getElementById("pay-now").classList.add("hidden")}))}));var e=document.getElementById("pay-now-with-token");e.addEventListener("click",(function(n){e.disabled=!0,e.querySelector("svg").classList.remove("hidden"),e.querySelector("span").classList.add("hidden"),document.getElementById("server-response").submit()}))}},{key:"handle",value:function(){this.initBraintreeDataCollector(),this.handlePaymentWithToken(),braintree.client.create({authorization:document.querySelector("meta[name=client-token]").content}).then((function(e){return braintree.paypalCheckout.create({client:e})})).then((function(e){return e.loadPayPalSDK({vault:!0}).then((function(e){return paypal.Buttons({fundingSource:paypal.FUNDING.PAYPAL,createBillingAgreement:function(){return e.createPayment(n.getPaymentDetails())},onApprove:function(n,t){return e.tokenizePayment(n).then((function(e){var n=document.querySelector('input[name="token-billing-checkbox"]:checked');n&&(document.querySelector('input[name="store_card"]').value=n.value),document.querySelector("input[name=gateway_response]").value=JSON.stringify(e),document.getElementById("server-response").submit()}))},onCancel:function(e){},onError:function(e){console.log(e.message),n.handleErrorMessage(e.message)}}).render("#paypal-button")}))})).catch((function(e){console.log(e.message),n.handleErrorMessage(e.message)}))}}])&&e(t.prototype,a),o&&e(t,o),n}())).handle()})();