/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/paper-paypal-component@1.3.2/dist/paypal/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
var express=require("express"),XMLHttpRequest=require("xmlhttprequest").XMLHttpRequest,btoa=require("btoa"),url=require("url"),path=require("path"),paypal={},helper={};paypal.version="0.0.1",paypal.config={clientID:"",secret:""},paypal.urls={auth:{url:"https://api.sandbox.paypal.com/v1/oauth2/token",headers:[{header:"Accept",value:"application/json"}],data:{grant_type:"client_credentials"}},payment:{url:"https://api.sandbox.paypal.com/v1/payments/payment",headers:[{header:"Content-Type",value:"application/json"}],data:{}},execute:{url:"https://api.sandbox.paypal.com/v1/payments/payment/[paymentId]/execute/",headers:[{header:"Content-Type",value:"application/json"}],data:{}}},paypal.init=function(e,a){console.log("[paypal] Paypal module ready to use"),e.get("/config.json",(function(e,t){t.sendFile(a+"/config.json")})),e.get("/paypal/paypal-api.js",(function(e,a){a.sendFile(path.resolve("dist/paypal/paypal-api.js"))})),e.get("/paypal/gettoken",(function(e,a){var t=e.protocol+"://"+e.get("host");paypal.getConfig(t,e,a)})),e.post("/paypal/payment",(function(e,a){var t=e.body.transaction;paypal.payment({type:"POST",data:t,callback:function(e){a.status(e.status),a.setHeader("content-Type","application/json"),a.send(e.responseText)},failure:function(e){a.status(e.status),a.setHeader("content-Type","application/json"),a.send({error:"transaction error"})},headers:[{header:"Authorization",value:e.get("Authorization")},{header:"Content-Type",value:"application/json"}]})})),e.post("/paypal/execute",(function(e,a){var t={payer_id:{payer_id:e.body.payer_id},paymentId:e.body.paymentId};console.log(t),paypal.execute({type:"POST",data:t,callback:function(e){a.status(e.status),a.setHeader("content-Type","application/json"),a.send(e.responseText)},failure:function(e){a.status(e.status),a.setHeader("content-Type","application/json"),a.send({error:"transaction error"})},headers:[{header:"Authorization",value:e.get("Authorization")},{header:"Content-Type",value:"application/json"}]})}))},paypal.getConfig=function(e,a,t){e=void 0!==e?e:null,t=void 0!==t?t:null;helper.ajax({url:e+"/config.json",type:"GET",callback:function(e){var a=JSON.parse(e.responseText);console.log("[0;34m[paypal] Config loaded with success[0m"),paypal.config=a,paypal.oauth({endPoint:paypal.urls.auth.url,user:paypal.config.clientID,password:paypal.config.secret,callback:function(e){JSON.parse(e.responseText)&&(t.setHeader("Content-Type","application/json"),t.send(JSON.stringify(JSON.parse(e.responseText))))}})}})},paypal.showConfig=function(){console.log(paypal.config)},paypal.oauth=function(e){var a=void 0!==e.endPoint?e.endPoint:paypal.urls.auth.url,t=void 0!==e.user?e.user:null,n=void 0!==e.password?e.password:null,o=void 0!==e.callback?e.callback:function(){};helper.ajax({url:a+"?grant_type=client_credentials",type:"POST",callback:o,user:t,password:n})},paypal.payment=function(e){var a=void 0!==e.endPoint?e.endPoint:paypal.urls.payment.url,t=void 0!==e.headers?e.headers:paypal.urls.payment.headers,n=void 0!==e.data?e.data:{},o=void 0!==e.callback?e.callback:function(){},p=void 0!==e.failure?e.failure:function(){};helper.ajax({url:a,type:"POST",data:n,callback:o,failure:p,headers:t})},paypal.execute=function(e){var a=void 0!==e.endPoint?e.endPoint:paypal.urls.execute.url,t=void 0!==e.headers?e.headers:paypal.urls.execute.headers,n=void 0!==e.data?e.data:{},o=void 0!==e.callback?e.callback:function(){},p=void 0!==e.failure?e.failure:function(){};a=a.replace("[paymentId]",n.paymentId),helper.ajax({url:a,type:"POST",data:n.payer_id,callback:o,failure:p,headers:t})},helper.ajax=function(e){var a=void 0!==e.url?e.url:"/",t=void 0!==e.type?e.type:"GET",n=void 0!==e.data?helper.encodeData(e.data):helper.encodeData({}),o=void 0!==e.callback?e.callback:function(){},p=void 0!==e.failure?e.failure:function(){},l=void 0!==e.headers?e.headers:[{header:"X-Requested-With",value:"XMLHttpRequest"}],r=void 0!==e.user?e.user:null,s=void 0!==e.password?e.password:null,i=new XMLHttpRequest;i.open(t,a,!0,r,s),i.withCredentials=!0;for(var u=0;u<l.length;u++)i.setRequestHeader(l[u].header,l[u].value);if(""!==n&&"post"==t.toLowerCase()){i.setRequestHeader("Content-type","application/json");n=JSON.stringify(e.data)}i.onload=function(){i.status>=200&&i.status<400?o(i):(console.log(i.status," error: ",i.responseText),p(i))},i.onerror=function(){console.log(i.status)},i.send(n)},helper.encodeData=function(e){var a=Object.keys(e).map((function(a){return encodeURIComponent(a)+"="+encodeURIComponent(e[a])})).join("&");return encodeURI(a)},exports.version=paypal.version,exports.init=paypal.init,exports.login=paypal.login,exports.getConfig=paypal.getConfig,exports.showConfig=paypal.showConfig;
//# sourceMappingURL=/sm/3a4c2b1b1201b70772d3a97dd180513918af7c0342254cb25986e4c6fcdaf118.map