{"version":3,"sources":["webpack:///./tsScripts/PaymentMethods/paypalMarketPlaceRequest.ts"],"names":["PaypalMarketPlaceRequest","config","getPayAmount","isOrderFulfilled","this","currentAmount","init","orderID","general","environment","demoMode","isoCurrencySymbol","paymentDescription","goalType","goalTypeInt","interactionId","transactionID","paypal","redirectUrl","window","Button","render","env","commit","style","size","color","shape","label","payment","data","value","url","request","post","then","response","statusCode","orderId","errorMessage","errorEl","document","getElementById","body","classList","remove","innerHTML","onAuthorize","dataToSend","add","billingData","email","userInfo","JSON","parse","localStorage","getItem","first_name","last_name","shipping_address","line1","postal_code","setItem","stringify","location","href","display"],"mappings":"q7BAAMA,EAAwB,WAM1B,WAAYC,EAAaC,EAAwBC,I,4FAA4B,4HACzEC,KAAKH,OAASA,EACdG,KAAKC,cAAgB,WACjB,OAAOH,KAEXE,KAAKD,iBAAmBA,EAExBC,KAAKE,O,UAmFR,O,EAlFA,G,EAAA,mBAED,WAAO,IAKCC,EALD,OACH,EAA+GH,KAAKH,OAAOO,QAAnHC,EAAW,EAAXA,YAAaC,EAAQ,EAARA,SAAUC,EAAiB,EAAjBA,kBAAmBC,EAAkB,EAAlBA,mBAAoBC,EAAQ,EAARA,SAAUC,EAAW,EAAXA,YAAaC,EAAa,EAAbA,cACrFC,EAAkBZ,KAAKH,OAAOgB,OAA9BD,cACFX,EAAgBD,KAAKC,cACrBa,EAAgBd,KAAKH,OAAOO,QAA5BU,YAGAC,OAAQF,OAAOG,OAAOC,OAAO,CAC/BC,IAAKb,EACLc,QAAQ,EACRC,MAAO,CACHC,KAAM,aACNC,MAAO,OACPC,MAAO,OACPC,MAAO,YAEXC,QAAS,WACL,IAAMC,EAAO,UAAH,OAAazB,IAAgB0B,MAAK,0BAAkBhB,EAAa,0BAAkBC,EAAa,iBAASN,EAAQ,qBAAaC,EAAiB,+BAAuBC,GAC1KoB,EAAM,oCAAH,OAAuCF,GAGhD,OAAaX,OAAQF,OAAOgB,QAAQC,KAAKF,GACpCG,MAAK,SAACC,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any;\r\n currentAmount; Function;\r\n isOrderFulfilled: Function;\r\n\r\n constructor(config: any, getPayAmount: Function, isOrderFulfilled: Function) {\r\n this.config = config;\r\n this.currentAmount = () => {\r\n return getPayAmount();\r\n }\r\n this.isOrderFulfilled = isOrderFulfilled;\r\n\r\n this.init();\r\n }\r\n\r\n init() {\r\n const { environment, demoMode, isoCurrencySymbol, paymentDescription, goalType, goalTypeInt, interactionId } = this.config.general;\r\n const { transactionID } = this.config.paypal;\r\n const currentAmount = this.currentAmount;\r\n let { redirectUrl } = this.config.general;\r\n let orderID: string;\r\n\r\n (window).paypal.Button.render({\r\n env: environment,\r\n commit: true,\r\n style: {\r\n size: 'responsive',\r\n color: 'blue',\r\n shape: 'rect',\r\n label: 'checkout'\r\n },\r\n payment: () => {\r\n const data = `amount=${currentAmount().value}&interactionId=${interactionId}&transactionId=${transactionID}&demo=${demoMode}¤cy=${isoCurrencySymbol}&paymentDescription=${paymentDescription}`;\r\n const url = `../PayPalMarketplace/CreateOrder?${data}`;\r\n\r\n\r\n return (window).paypal.request.post(url)\r\n .then((response) => {\r\n const { statusCode, orderId, errorMessage } = response;\r\n\r\n if (statusCode === 200) {\r\n orderID = orderId;\r\n return orderId;\r\n } else {\r\n const errorEl: HTMLElement = document.getElementById('error');\r\n document.body.classList.remove('whirl', 'ringed');\r\n errorEl.innerHTML = `${errorMessage[0]}`;\r\n }\r\n })\r\n },\r\n onAuthorize: () => {\r\n const dataToSend = `interactionId=${interactionId}&orderId=${orderID}&demo=${demoMode}&paymentDescription=${paymentDescription}&goalType=${goalTypeInt}`;\r\n const url = `../PayPalMarketplace/PayForOrder?${dataToSend}`;\r\n\r\n document.body.classList.add('whirl', 'ringed');\r\n\r\n return (window).paypal.request.post(url)\r\n .then((response) => {\r\n const { statusCode, billingData, errorMessage } = response;\r\n\r\n //redirectUrlPaypal += redirectUrlPaypal.includes(\"?\") ? \"&\" : \"?\";\r\n redirectUrl += `&donationAmount=${currentAmount().value}&email=${billingData?.email}`;\r\n\r\n if (statusCode === 200) {\r\n let userInfo = JSON.parse(localStorage.getItem(\"GiftAid_Info\"));\r\n\r\n if (billingData != null && userInfo == null) {\r\n userInfo = {\r\n 'title': \"\",\r\n 'forename': billingData.first_name,\r\n 'surname': billingData.last_name,\r\n 'addressline': billingData.shipping_address.line1,\r\n 'postcode': billingData.shipping_address.postal_code\r\n };\r\n localStorage.setItem(\"GiftAid_Info\", JSON.stringify(userInfo));\r\n }\r\n this.isOrderFulfilled();\r\n\r\n window.location.href = redirectUrl;\r\n } else {\r\n const errorEl: HTMLElement = document.getElementById('error');\r\n document.body.classList.remove('whirl', 'ringed');\r\n errorEl.innerHTML = \"Payment failed. Please try again.\";\r\n\r\n if (goalType === \"FULFILMENT_MENU\") {\r\n const errorMenuElement: HTMLElement = document.getElementById('menuError');\r\n errorMenuElement.style.display = \"block\";\r\n }\r\n }\r\n })\r\n },\r\n //onError: (err) => {\r\n // console.log(err);\r\n //}\r\n }, '#paypal-button');\r\n }\r\n}\r\n\r\nexport default PaypalMarketPlaceRequest;"],"sourceRoot":""}