{"version":3,"sources":["webpack:///./tsScripts/PaymentMethods/stripePaymentRequest.ts"],"names":["StripePaymentRequest","config","key","getPayAmount","readCookie","isOrderFulfilled","general","stripeConnectId","trim","this","stripe","window","Stripe","stripeAccount","apiVersion","currentAmount","createPaymentRequest","createElements","setupChangeListener","isBlank","str","test","isoCurrencySymbol","goalType","isSubscription","companyName","planName","requestConfig","isGift","requestShipping","country","currency","toLowerCase","total","amount","unitValue","label","requestPayerEmail","requestPayerName","paymentRequest","elements","prButton","create","style","paymentRequestButton","type","theme","height","canMakePayment","then","result","console","log","mount","document","getElementById","display","on","ev","paymentRequestHandler","demoMode","interactionId","version","goalTypeInt","planID","paymentDescription","companyId","meta","stripeRedirectUrl","createCustomerRequest","demo","email","payerEmail","fullName","payerName","addressLine1","paymentMethod","billing_details","address","line1","addressLine2","line2","city","state","postcode","postal_code","fetch","method","headers","body","JSON","stringify","emailResponse","json","customerId","createPaymentIntentRequest","currencyCode","description","subscriptionPlanId","walletName","response","clientSecretKey","paymentIntentId","returnUrl","value","confirmCardPayment","payment_method","id","return_url","handleActions","confirmResult","error","complete","location","href","paymentIntent","status","editableValue","querySelector","addEventListener","e","update"],"mappings":"geACA,0oO,OACA,IAGMA,EAAoB,WAWtB,WAAYC,EAAaC,EAAaC,EAAwBC,EAAsBC,IAfxF,4FAeoH,sOAExGJ,EAAOK,QAAQC,iBAAmBN,EAAOK,QAAQC,gBAAgBC,OACjEC,KAAKC,OAAeC,OAAQC,OAAOV,EAC/B,CACIW,cAAeZ,EAAOK,QAAQC,gBAC9BO,WAAY,eAGpBL,KAAKC,OAAeC,OAAQC,OAAOV,EAC/B,CACIY,WAAY,eAIxBL,KAAKR,OAASA,EACdQ,KAAKM,cAAgB,WACjB,OAAOZ,KAEXM,KAAKO,uBACLP,KAAKQ,iBACLR,KAAKS,sBACLT,KAAKL,WAAaA,EAClBK,KAAKU,QAAU,SAACC,GACZ,OAASA,GAAO,QAAQC,KAAKD,IAEjCX,KAAKJ,iBAAmBA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RJ,EACA,CAAEK,eAAgBhD,EAAGkB,cAAc+B,GAAIC,WAAYL,GACnD,CAAEM,eAAe,IACnB5D,MAAK,SAAU6D,GACTA,EAAcC,MAIdrD,EAAGsD,SAAS,SAIZtD,EAAGsD,SAAS,WACZrG,OAAOsG,SAASC,KAAOX,EAIoB,oBAAvCO,EAAcK,cAAcC,OAE5B3G,KAAKC,OAAO+F,mBAAmBJ,GAAiBpD,MAAK,SAAUC,GACvDA,EAAO6D,QAIPpG,OAAOsG,SAASC,KAAOX,MAK/B5F,OAAOsG,SAASC,KAAOX,MAGhC,gDAvFN,EAxFL,8KAgLK,+EAED,WAAsB,WACdc,EAAyB/D,SAASgE,cAAc,eAEpD,EAA4D7G,KAAKR,OAAOK,QAAhEiB,EAAQ,EAARA,SAAUG,EAAQ,EAARA,SAAUD,EAAW,EAAXA,YAAaD,EAAc,EAAdA,eAEzC6F,EAAcE,iBAAiB,UAAU,SAACC,GAEtC,EAAKjF,eAAekF,OAAO,CACvBxF,MAAO,CACHC,OAAQ,EAAKnB,gBAAgBoB,UAC7BC,MAAQZ,EAAc,UAAOD,EAAQ,YAAIG,GAAQ,UAAQH,EAAQ,YAAIE,cA5LzF,8EAgMK,EA5LqB,GA+LXzB","file":"stripePaymentRequest.217ba08d697a9ad424e3.js","sourcesContent":["import { client } from \"braintree-web\";\r\n\r\n/*\r\n Stripe Payment Request\r\n*/\r\nclass StripePaymentRequest {\r\n\r\n stripe: any;\r\n paymentRequest: any;\r\n config: any;\r\n currentAmount: Function;\r\n readCookie: Function;\r\n isBlank: Function;\r\n ready: Function;\r\n isOrderFulfilled: Function;\r\n\r\n constructor(config: any, key: String, getPayAmount: Function, readCookie: Function, isOrderFulfilled: Function) {\r\n \r\n if (config.general.stripeConnectId && config.general.stripeConnectId.trim()) {\r\n this.stripe = (window).Stripe(key,\r\n {\r\n stripeAccount: config.general.stripeConnectId,\r\n apiVersion: \"2020-08-27\"\r\n }) as any;\r\n } else {\r\n this.stripe = (window).Stripe(key,\r\n {\r\n apiVersion: \"2020-08-27\"\r\n }) as any; // Get stripe from Global window.\r\n }\r\n \r\n this.config = config;\r\n this.currentAmount = () => {\r\n return getPayAmount();\r\n }\r\n this.createPaymentRequest();\r\n this.createElements();\r\n this.setupChangeListener();\r\n this.readCookie = readCookie;\r\n this.isBlank = (str) => {\r\n return (!str || /^\\s*$/.test(str));\r\n }\r\n this.isOrderFulfilled = isOrderFulfilled;\r\n }\r\n\r\n createPaymentRequest() {\r\n const { isoCurrencySymbol, goalType, isSubscription, companyName, planName, isGift } = this.config.general;\r\n\r\n let requestConfig = {\r\n requestShipping: false,\r\n country: 'GB',\r\n currency: `${isoCurrencySymbol.toLowerCase()}`,\r\n total: {\r\n amount: this.currentAmount().unitValue,\r\n label: (isSubscription) ? `${goalType} ${planName}` : `${goalType} ${companyName}`,\r\n },\r\n requestPayerEmail: true,\r\n requestPayerName: true,\r\n };\r\n\r\n this.paymentRequest = this.stripe.paymentRequest(requestConfig);\r\n }\r\n\r\n createElements() {\r\n\r\n const elements: any = this.stripe.elements();\r\n const { goalType } = this.config.general;\r\n\r\n const prButton: any = elements.create('paymentRequestButton', {\r\n paymentRequest: this.paymentRequest,\r\n style: {\r\n paymentRequestButton: {\r\n type: goalType === \"DONATION\" ? \"donate\" : \"default\",\r\n theme: 'dark',\r\n height: '50px'\r\n }\r\n }\r\n });\r\n\r\n this.paymentRequest.canMakePayment().then((result) => {\r\n console.log(\"can make payment: \", result);\r\n if (result) {\r\n prButton.mount('#payment-request-button');\r\n } else {\r\n document.getElementById('payment-request-button').style.display = 'none';\r\n }\r\n });\r\n\r\n this.paymentRequest.on('paymentmethod', (ev) => this.paymentRequestHandler(ev));\r\n }\r\n\r\n async paymentRequestHandler(ev) {\r\n\r\n const { demoMode, isoCurrencySymbol, interactionId, version, goalTypeInt, planID, paymentDescription, companyId, isSubscription, meta, stripeRedirectUrl } = this.config.general;\r\n\r\n let createCustomerRequest: object = {\r\n companyId: this.config.general.companyId,\r\n demo: this.config.general.demoMode,\r\n email: ev.payerEmail,\r\n fullName: ev.payerName,\r\n addressLine1: ev.paymentMethod.billing_details.address.line1,\r\n addressLine2: ev.paymentMethod.billing_details.address.line2,\r\n city: ev.paymentMethod.billing_details.address.city,\r\n state: ev.paymentMethod.billing_details.address.state,\r\n postcode: ev.paymentMethod.billing_details.address.postal_code,\r\n country: ev.paymentMethod.billing_details.address.country\r\n };\r\n\r\n const emailResponse = await fetch(\"/Stripe/GetOrCreateCustomer\", {\r\n method: \"POST\",\r\n headers: { \"Content-Type\": \"application/json\" },\r\n body: JSON.stringify(createCustomerRequest),\r\n });\r\n\r\n const { customerId } = await emailResponse.json();\r\n\r\n // Fetch the payment intent\r\n let createPaymentIntentRequest: object = {\r\n demo: demoMode,\r\n currencyCode: isoCurrencySymbol.toLowerCase(),\r\n amount: this.currentAmount().unitValue,\r\n interactionId: interactionId,\r\n goalType: goalTypeInt,\r\n version: version,\r\n description: paymentDescription,\r\n companyId: companyId,\r\n customerId: customerId,\r\n meta: meta,\r\n isSubscription: isSubscription,\r\n subscriptionPlanId: planID,\r\n walletName: ev.walletName\r\n };\r\n\r\n const response = await fetch(\"/Stripe/CreatePaymentIntent\", {\r\n method: \"POST\",\r\n headers: { \"Content-Type\": \"application/json\" },\r\n body: JSON.stringify(createPaymentIntentRequest),\r\n });\r\n\r\n const { clientSecretKey, paymentIntentId } = await response.json();\r\n let returnUrl = `${stripeRedirectUrl}&donationAmount=${this.currentAmount().value}&email=${ev.payerEmail}`;\r\n\r\n // Confirm the PaymentIntent without handling potential next actions (yet).\r\n this.stripe.confirmCardPayment(\r\n clientSecretKey,\r\n { payment_method: ev.paymentMethod.id, return_url: returnUrl},\r\n { handleActions: false }\r\n ).then(function (confirmResult) {\r\n if (confirmResult.error) {\r\n // Report to the browser that the payment failed, prompting it to\r\n // re-show the payment interface, or show an error message and close\r\n // the payment interface.\r\n ev.complete('fail');\r\n } else {\r\n // Report to the browser that the confirmation was successful, prompting\r\n // it to close the browser payment method collection interface.\r\n ev.complete('success');\r\n window.location.href = returnUrl; // Send to RedirectUrl\r\n // Check if the PaymentIntent requires any actions and if so let Stripe.js\r\n // handle the flow. If using an API version older than \"2019-02-11\"\r\n // instead check for: `paymentIntent.status === \"requires_source_action\"`.\r\n if (confirmResult.paymentIntent.status === \"requires_action\") {\r\n // Let Stripe.js handle the rest of the payment flow.\r\n this.stripe.confirmCardPayment(clientSecretKey).then(function (result) {\r\n if (result.error) {\r\n // The payment failed -- ask your customer for a new payment method.\r\n } else {\r\n // The payment has succeeded.\r\n window.location.href = returnUrl; // Send to RedirectUrl\r\n }\r\n });\r\n } else {\r\n // The payment has succeeded.\r\n window.location.href = returnUrl; // Send to RedirectUrl\r\n }\r\n }\r\n });\r\n };\r\n\r\n setupChangeListener() {\r\n let editableValue: Element = document.querySelector('.editableH1');\r\n\r\n const { goalType, planName, companyName, isSubscription } = this.config.general;\r\n\r\n editableValue.addEventListener('change', (e) => {\r\n\r\n this.paymentRequest.update({\r\n total: {\r\n amount: this.currentAmount().unitValue,\r\n label: (isSubscription) ? `${goalType} ${planName}` : `${goalType} ${companyName}`\r\n }\r\n });\r\n });\r\n }\r\n}\r\n\r\nexport default StripePaymentRequest;\r\n"],"sourceRoot":""}