@moneyhash/js-sdk
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -1,1 +0,1 @@ | ||
"use strict";var O=Object.defineProperty,J=Object.defineProperties;var z=Object.getOwnPropertyDescriptors;var F=Object.getOwnPropertySymbols;var K=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var _=(n,e,t)=>e in n?O(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,b=(n,e)=>{for(var t in e||(e={}))K.call(e,t)&&_(n,t,e[t]);if(F)for(var t of F(e))G.call(e,t)&&_(n,t,e[t]);return n},T=(n,e)=>J(n,z(e));var m=(n,e,t)=>(_(n,typeof e!="symbol"?e+"":e,t),t),Q=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var f=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)};var u=(n,e,t)=>(Q(n,e,"access private method"),t);var y=(n,e,t)=>new Promise((r,s)=>{var o=i=>{try{a(t.next(i))}catch(c){s(c)}},d=i=>{try{a(t.throw(i))}catch(c){s(c)}},a=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,d);a((t=t.apply(n,e)).next())});const p=require("./sdkEmbed-d5b15674.cjs");function X(){return typeof window!="undefined"}const g=class{constructor(){X()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=p.getIframeUrl(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.0.5");const r=document.createElement("iframe");r.id="moneyhash-headless-sdk",r.src=t.toString(),r.hidden=!0,document.body.appendChild(r),g.messagingService=new p.MessagingService({target:r.contentWindow,targetOrigin:e}),g.isCommunicationReady=new Promise(s=>{var d;const o=a=>{var i;a.data.type==="headlessSDK:init"&&(s(),(i=g.messagingService)==null||i.removeListener(o))};(d=g.messagingService)==null||d.onReceive(o)})}request(r){return y(this,arguments,function*({api:e,payload:t}){return yield g.isCommunicationReady,new Promise((s,o)=>{var a,i;(a=g.messagingService)==null||a.send({type:e,data:t});const d=c=>{var w;const{type:l,data:h}=c.data;l===e&&(h.status==="resolved"?s(h.payload):o(h.payload),(w=g.messagingService)==null||w.removeListener(d))};(i=g.messagingService)==null||i.onReceive(d)})})}};let E=g;m(E,"messagingService",null),m(E,"isCommunicationReady");class ${constructor(){m(this,"promise");m(this,"resolve");m(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function Z(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function H(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function ee(n){return(Array.isArray(n)?n.length:Object.keys(n).length)===0}function te(n,e){return new Promise((t,r)=>{if(document.getElementById(e)){t(void 0);return}const o=document.createElement("script");o.src=n,o.id=e,o.addEventListener("load",()=>{t(void 0)}),o.addEventListener("error",()=>{r(new Error("Script failed to load"))}),document.body.appendChild(o)})}function N(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function re(n){const e=["cardHolderName","cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!n.includes(t))return t;return null}const V=new Set(["method","customerBalance","savedCard"]);var I,j,L,q,A,W,k,M,S,x,U,D,C,Y,R,B;class se{constructor(e){f(this,I);f(this,L);f(this,A);f(this,k);f(this,S);f(this,U);f(this,C);f(this,R);m(this,"options");m(this,"sdkApiHandler",new E);m(this,"sdkEmbed");m(this,"vaultSubmitListener",{current:null});m(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new p.SDKEmbed(T(b({},e),{headless:!0})),u(this,U,D).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}proceedWith({intentId:e,type:t,id:r,metaData:s}){return p.throwIf(!V.has(t),`type must be a valid one (${[...V].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:r,lang:this.sdkEmbed.lang,metaData:s}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return p.throwIf(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(c){return y(this,arguments,function*({intentId:e,currency:t,amount:r,countryCode:s,onCancel:o=()=>{},onError:d,onComplete:a,billingData:i={}}){if(yield te("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const l=new ApplePaySession(3,{countryCode:s,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${r}`}}),{state:h,intent:w}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(h==="INTENT_FORM"){if(ee(i))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",lang:this.sdkEmbed.lang,billingData:i}})}}catch(v){throw yield this.resetSelectedMethod(e),v}l.onvalidatemerchant=v=>{fetch(`${N()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:w.secret,validation_url:v.validationURL})}).then(P=>P.ok?P.json():Promise.reject()).then(P=>l.completeMerchantValidation(P)).catch(d)},l.onpaymentauthorized=v=>{fetch(`${N()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:v.payment.token,secret:w.secret})}).then(P=>P.ok?P.json():Promise.reject()).then(()=>{l.completePayment(ApplePaySession.STATUS_SUCCESS),a()}).catch(()=>{l.completePayment(ApplePaySession.STATUS_FAILURE),d()})},l.oncancel=o,l.begin()})}renderForm({selector:e,intentId:t}){return p.throwIf(!e,"selector is required for renderForm"),p.throwIf(!t,"intentId is required for renderForm"),this.sdkEmbed.render({selector:e,intentId:t})}setLocale(e){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}elements({styles:e}){const t=[];return u(this,S,x).call(this,t),{create:({elementType:r,elementOptions:s})=>{const o=new Map,d=document.querySelector(s.selector);return p.throwIf(!d,`Couldn't find an element with selector ${s.selector}!`),d.classList.add("MoneyHashElement"),t.push(a=>{var c,l,h;const{type:i}=a.data;i===`${r}@focus`&&(d.classList.add("MoneyHashElement--focus"),(c=o.get(`${r}@focus`))==null||c()),i===`${r}@blur`&&(d.classList.remove("MoneyHashElement--focus"),(l=o.get(`${r}@blur`))==null||l()),i===`${r}@changeInput`&&((h=o.get(`${r}@changeInput`))==null||h())}),{mount:()=>{this.mountedCardElements.push(r),u(this,C,Y).call(this,{container:d,elementType:r,elementOptions:s,styles:b(b({},e),s.styles)})},on:(a,i)=>{o.set(`${r}@${a}`,i)}}}}}submitForm(o){return y(this,arguments,function*({intentId:e,accessToken:t,billingData:r,shippingData:s}){const d=re(this.mountedCardElements);p.throwIf(!!d,`You must mount ${d} element!`);const a=new $;let i,c;t&&(this.vaultSubmitListener.current=h=>{const{type:w,data:v}=h.data;w==="vaultSubmit:success"&&a.resolve(v),w==="vaultSubmit:error"&&a.reject(v)},c=u(this,R,B).call(this,t),i=yield a.promise);const l=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:r,shippingData:s,cardEmbed:i}});return c&&c.remove(),l})}submitCvv(r){return y(this,arguments,function*({intentId:e,cvv:t}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,lang:this.sdkEmbed.lang}})})}renderUrl(e,t){return y(this,null,function*(){switch(t){case"IFRAME":return u(this,I,j).call(this,e);case"POPUP_IFRAME":return u(this,L,q).call(this,e);case"REDIRECT":return u(this,A,W).call(this,e);default:return null}})}}I=new WeakSet,j=function(e){return y(this,null,function*(){const t=document.querySelector("#rendered-url-iframe-container");p.throwIf(!t,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const r=document.createElement("iframe");r.src=e,r.style.setProperty("border","0","important"),r.style.setProperty("width","100%","important"),r.style.setProperty("height","100%","important"),t==null||t.replaceChildren(r),yield u(this,k,M).call(this),r.remove()})},L=new WeakSet,q=function(e){return y(this,null,function*(){const t=window.open(`${e}`,"","width=600,height=400,left=200,top=200");p.throwIf(!t,"Popup blocked by browser!"),yield u(this,k,M).call(this),t==null||t.close()})},A=new WeakSet,W=function(e){return y(this,null,function*(){window.open(e,"_blank")})},k=new WeakSet,M=function(){return y(this,null,function*(){const e=new $,t=r=>{var d,a,i,c;const{type:s,data:o}=r.data;switch(s){case"onComplete":(a=(d=this.options).onComplete)==null||a.call(d,b({type:this.options.type},o)),e.resolve(()=>null),window.removeEventListener("message",t);break;case"onFail":(c=(i=this.options).onFail)==null||c.call(i,b({type:this.options.type},o)),e.resolve(()=>null),window.removeEventListener("message",t);break;default:e.resolve(()=>null);break}};return window.addEventListener("message",t),e.promise})},S=new WeakSet,x=function(e){const t=r=>{e.forEach(s=>{s(r)})};window.addEventListener("message",t)},U=new WeakSet,D=function(e){const t=r=>{e.current&&e.current(r)};window.addEventListener("message",t)},C=new WeakSet,Y=function({container:e,elementType:t,elementOptions:r,styles:s}){var i,c;const o=H(),d=new URL(`${o}/vaultField/vaultField.html`);d.searchParams.set("host",btoa(window.location.origin)),d.searchParams.set("type",t),d.searchParams.set("placeholder",(i=r.placeholder)!=null?i:""),d.searchParams.set("color",(s==null?void 0:s.color)||"#000"),d.searchParams.set("placeholderColor",(s==null?void 0:s.placeholderColor)||"#ccc"),d.searchParams.set("backgroundColor",(s==null?void 0:s.backgroundColor)||"transparent");const a=document.createElement("iframe");a.src=d.toString(),a.style.height=(c=r.height)!=null?c:"40px",a.style.setProperty("overflow","hidden","important"),a.style.setProperty("display","block","important"),a.style.setProperty("width","100%","important"),a.style.setProperty("maxWidth","100%","important"),a.style.setProperty("border","0","important"),a.style.setProperty("margin","0","important"),a.style.setProperty("padding","0","important"),a.style.setProperty("userSelect","none","important"),a.style.setProperty("colorScheme","light only","important"),e.replaceChildren(a)},R=new WeakSet,B=function(e){const t=H(),r=Z(),s=new URL(`${t}/vaultSubmit/vaultSubmit.html`);s.searchParams.set("host",btoa(window.location.origin)),s.searchParams.set("vault_api_url",`${r}/api/v1/tokens/`),s.searchParams.set("access_token",e);const o=document.createElement("iframe");return o.id="moneyhash-submit-iframe",o.src=s.toString(),o.hidden=!0,document.body.appendChild(o),o};module.exports=se; | ||
"use strict";var O=Object.defineProperty,J=Object.defineProperties;var z=Object.getOwnPropertyDescriptors;var F=Object.getOwnPropertySymbols;var K=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var _=(n,e,t)=>e in n?O(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,P=(n,e)=>{for(var t in e||(e={}))K.call(e,t)&&_(n,t,e[t]);if(F)for(var t of F(e))G.call(e,t)&&_(n,t,e[t]);return n},$=(n,e)=>J(n,z(e));var h=(n,e,t)=>(_(n,typeof e!="symbol"?e+"":e,t),t),Q=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var v=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)};var g=(n,e,t)=>(Q(n,e,"access private method"),t);var f=(n,e,t)=>new Promise((r,s)=>{var o=i=>{try{a(t.next(i))}catch(c){s(c)}},d=i=>{try{a(t.throw(i))}catch(c){s(c)}},a=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,d);a((t=t.apply(n,e)).next())});const u=require("./sdkEmbed-955a36b1.cjs");function X(){return typeof window!="undefined"}const w=class{constructor(){X()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=u.getIframeUrl(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.0.6");const r=document.createElement("iframe");r.id="moneyhash-headless-sdk",r.src=t.toString(),r.hidden=!0,document.body.appendChild(r),w.messagingService=new u.MessagingService({target:r.contentWindow,targetOrigin:e}),w.isCommunicationReady=new Promise(s=>{var d;const o=a=>{var i;a.data.type==="headlessSDK:init"&&(s(),(i=w.messagingService)==null||i.removeListener(o))};(d=w.messagingService)==null||d.onReceive(o)})}request(r){return f(this,arguments,function*({api:e,payload:t}){return yield w.isCommunicationReady,new Promise((s,o)=>{var a,i;(a=w.messagingService)==null||a.send({type:e,data:t});const d=c=>{var m;const{type:l,data:y}=c.data;l===e&&(y.status==="resolved"?s(y.payload):o(y.payload),(m=w.messagingService)==null||m.removeListener(d))};(i=w.messagingService)==null||i.onReceive(d)})})}};let E=w;h(E,"messagingService",null),h(E,"isCommunicationReady");class N{constructor(){h(this,"promise");h(this,"resolve");h(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function Z(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function T(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function ee(n){return(Array.isArray(n)?n.length:Object.keys(n).length)===0}function te(n,e){return new Promise((t,r)=>{if(document.getElementById(e)){t(void 0);return}const o=document.createElement("script");o.src=n,o.id=e,o.addEventListener("load",()=>{t(void 0)}),o.addEventListener("error",()=>{r(new Error("Script failed to load"))}),document.body.appendChild(o)})}function H(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function re(n){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!n.includes(t))return t;return null}const q=new Set(["method","customerBalance","savedCard"]);var I,V,L,j,A,W,k,M,S,x,U,D,C,Y,R,B;class se{constructor(e){v(this,I);v(this,L);v(this,A);v(this,k);v(this,S);v(this,U);v(this,C);v(this,R);h(this,"options");h(this,"sdkApiHandler",new E);h(this,"sdkEmbed");h(this,"vaultSubmitListener",{current:null});h(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new u.SDKEmbed($(P({},e),{headless:!0})),g(this,U,D).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}proceedWith({intentId:e,type:t,id:r,metaData:s}){return u.throwIf(!q.has(t),`type must be a valid one (${[...q].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:r,lang:this.sdkEmbed.lang,metaData:s}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return u.throwIf(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(c){return f(this,arguments,function*({intentId:e,currency:t,amount:r,countryCode:s,onCancel:o=()=>{},onError:d,onComplete:a,billingData:i={}}){if(yield te("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const l=new ApplePaySession(3,{countryCode:s,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${r}`}}),{state:y,intent:m}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(y==="INTENT_FORM"){if(ee(i))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",lang:this.sdkEmbed.lang,billingData:i}})}}catch(p){throw yield this.resetSelectedMethod(e),p}l.onvalidatemerchant=p=>{fetch(`${H()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:m.secret,validation_url:p.validationURL})}).then(b=>b.ok?b.json():Promise.reject()).then(b=>l.completeMerchantValidation(b)).catch(d)},l.onpaymentauthorized=p=>{fetch(`${H()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:p.payment.token,secret:m.secret})}).then(b=>b.ok?b.json():Promise.reject()).then(()=>{l.completePayment(ApplePaySession.STATUS_SUCCESS),a()}).catch(()=>{l.completePayment(ApplePaySession.STATUS_FAILURE),d()})},l.oncancel=o,l.begin()})}renderForm({selector:e,intentId:t}){return u.throwIf(!e,"selector is required for renderForm"),u.throwIf(!t,"intentId is required for renderForm"),this.sdkEmbed.render({selector:e,intentId:t})}setLocale(e){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}elements({styles:e}){const t=[];return g(this,S,x).call(this,t),{create:({elementType:r,elementOptions:s})=>{const o=new Map,d=document.querySelector(s.selector);return u.throwIf(!d,`Couldn't find an element with selector ${s.selector}!`),d.classList.add("MoneyHashElement"),t.push(a=>{var l,y,m,p;const{type:i,data:c}=a.data;i===`${r}@focus`&&(d.classList.add("MoneyHashElement--focus"),(l=o.get(`${r}@focus`))==null||l()),i===`${r}@blur`&&(d.classList.remove("MoneyHashElement--focus"),(y=o.get(`${r}@blur`))==null||y()),i===`${r}@changeInput`&&((m=o.get(`${r}@changeInput`))==null||m()),i===`${r}@cardNumberChange`&&((p=o.get(`${r}@cardNumberChange`))==null||p(c))}),{mount:()=>{this.mountedCardElements.push(r),g(this,C,Y).call(this,{container:d,elementType:r,elementOptions:s,styles:P(P({},e),s.styles)})},on:(a,i)=>{o.set(`${r}@${a}`,i)}}}}}submitForm(o){return f(this,arguments,function*({intentId:e,accessToken:t,billingData:r,shippingData:s}){const d=re(this.mountedCardElements);u.throwIf(!!d,`You must mount ${d} element!`);const a=new N;let i,c;t&&(this.vaultSubmitListener.current=y=>{const{type:m,data:p}=y.data;m==="vaultSubmit:success"&&a.resolve(p),m==="vaultSubmit:error"&&a.reject(p)},c=g(this,R,B).call(this,t),i=yield a.promise);const l=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:r,shippingData:s,cardEmbed:i}});return c&&c.remove(),l})}submitCvv(r){return f(this,arguments,function*({intentId:e,cvv:t}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,lang:this.sdkEmbed.lang}})})}renderUrl(e,t){return f(this,null,function*(){switch(t){case"IFRAME":return g(this,I,V).call(this,e);case"POPUP_IFRAME":return g(this,L,j).call(this,e);case"REDIRECT":return g(this,A,W).call(this,e);default:return null}})}}I=new WeakSet,V=function(e){return f(this,null,function*(){const t=document.querySelector("#rendered-url-iframe-container");u.throwIf(!t,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const r=document.createElement("iframe");r.src=e,r.style.setProperty("border","0","important"),r.style.setProperty("width","100%","important"),r.style.setProperty("height","100%","important"),t==null||t.replaceChildren(r),yield g(this,k,M).call(this),r.remove()})},L=new WeakSet,j=function(e){return f(this,null,function*(){const t=window.open(`${e}`,"","width=600,height=400,left=200,top=200");u.throwIf(!t,"Popup blocked by browser!"),yield g(this,k,M).call(this),t==null||t.close()})},A=new WeakSet,W=function(e){return f(this,null,function*(){window.open(e,"_blank")})},k=new WeakSet,M=function(){return f(this,null,function*(){const e=new N,t=r=>{var d,a,i,c;const{type:s,data:o}=r.data;switch(s){case"onComplete":(a=(d=this.options).onComplete)==null||a.call(d,P({type:this.options.type},o)),e.resolve(()=>null),window.removeEventListener("message",t);break;case"onFail":(c=(i=this.options).onFail)==null||c.call(i,P({type:this.options.type},o)),e.resolve(()=>null),window.removeEventListener("message",t);break;default:e.resolve(()=>null);break}};return window.addEventListener("message",t),e.promise})},S=new WeakSet,x=function(e){const t=r=>{e.forEach(s=>{s(r)})};window.addEventListener("message",t)},U=new WeakSet,D=function(e){const t=r=>{e.current&&e.current(r)};window.addEventListener("message",t)},C=new WeakSet,Y=function({container:e,elementType:t,elementOptions:r,styles:s}){var i,c;const o=T(),d=new URL(`${o}/vaultField/vaultField.html`);d.searchParams.set("host",btoa(window.location.origin)),d.searchParams.set("type",t),d.searchParams.set("placeholder",(i=r.placeholder)!=null?i:""),d.searchParams.set("color",(s==null?void 0:s.color)||"#000"),d.searchParams.set("placeholderColor",(s==null?void 0:s.placeholderColor)||"#ccc"),d.searchParams.set("backgroundColor",(s==null?void 0:s.backgroundColor)||"transparent");const a=document.createElement("iframe");a.src=d.toString(),a.style.height=(c=r.height)!=null?c:"40px",a.style.setProperty("overflow","hidden","important"),a.style.setProperty("display","block","important"),a.style.setProperty("width","100%","important"),a.style.setProperty("maxWidth","100%","important"),a.style.setProperty("border","0","important"),a.style.setProperty("margin","0","important"),a.style.setProperty("padding","0","important"),a.style.setProperty("userSelect","none","important"),a.style.setProperty("colorScheme","light only","important"),e.replaceChildren(a)},R=new WeakSet,B=function(e){const t=T(),r=Z(),s=new URL(`${t}/vaultSubmit/vaultSubmit.html`);s.searchParams.set("host",btoa(window.location.origin)),s.searchParams.set("vault_api_url",`${r}/api/v1/tokens/`),s.searchParams.set("access_token",e);const o=document.createElement("iframe");return o.id="moneyhash-submit-iframe",o.src=s.toString(),o.hidden=!0,document.body.appendChild(o),o};module.exports=se; |
@@ -62,2 +62,7 @@ export declare interface AbstractIntent { | ||
declare type CardNumberChangeData = { | ||
first6Digits: number; | ||
cardImageUrl: string; | ||
}; | ||
export declare type CustomerBalances = [ | ||
@@ -74,6 +79,6 @@ { | ||
mount: () => void; | ||
on: (event: ElementEvents, callback: () => void) => void; | ||
on<T extends ElementEvents>(event: T, callback: (data: T extends "cardNumberChange" ? CardNumberChangeData : never) => void): void; | ||
}; | ||
declare type ElementEvents = "focus" | "blur" | "changeInput"; | ||
declare type ElementEvents = "focus" | "blur" | "changeInput" | "cardNumberChange"; | ||
@@ -80,0 +85,0 @@ declare type ElementProps = { |
@@ -5,3 +5,3 @@ var O = Object.defineProperty, J = Object.defineProperties; | ||
var K = Object.prototype.hasOwnProperty, G = Object.prototype.propertyIsEnumerable; | ||
var _ = (n, e, t) => e in n ? O(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, b = (n, e) => { | ||
var _ = (n, e, t) => e in n ? O(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, P = (n, e) => { | ||
for (var t in e || (e = {})) | ||
@@ -13,8 +13,8 @@ K.call(e, t) && _(n, t, e[t]); | ||
return n; | ||
}, T = (n, e) => J(n, z(e)); | ||
var m = (n, e, t) => (_(n, typeof e != "symbol" ? e + "" : e, t), t), Q = (n, e, t) => { | ||
}, $ = (n, e) => J(n, z(e)); | ||
var u = (n, e, t) => (_(n, typeof e != "symbol" ? e + "" : e, t), t), Q = (n, e, t) => { | ||
if (!e.has(n)) | ||
throw TypeError("Cannot " + t); | ||
}; | ||
var g = (n, e, t) => { | ||
var v = (n, e, t) => { | ||
if (e.has(n)) | ||
@@ -24,4 +24,4 @@ throw TypeError("Cannot add the same private member more than once"); | ||
}; | ||
var u = (n, e, t) => (Q(n, e, "access private method"), t); | ||
var h = (n, e, t) => new Promise((s, r) => { | ||
var y = (n, e, t) => (Q(n, e, "access private method"), t); | ||
var g = (n, e, t) => new Promise((r, s) => { | ||
var o = (i) => { | ||
@@ -31,3 +31,3 @@ try { | ||
} catch (c) { | ||
r(c); | ||
s(c); | ||
} | ||
@@ -38,12 +38,12 @@ }, d = (i) => { | ||
} catch (c) { | ||
r(c); | ||
s(c); | ||
} | ||
}, a = (i) => i.done ? s(i.value) : Promise.resolve(i.value).then(o, d); | ||
}, a = (i) => i.done ? r(i.value) : Promise.resolve(i.value).then(o, d); | ||
a((t = t.apply(n, e)).next()); | ||
}); | ||
import { M as X, g as Z, S as ee, t as w } from "./sdkEmbed-957d3f53.js"; | ||
import { M as X, g as Z, S as ee, t as w } from "./sdkEmbed-13f4e15c.js"; | ||
function te() { | ||
return typeof window != "undefined"; | ||
} | ||
const y = class { | ||
const f = class { | ||
constructor() { | ||
@@ -56,24 +56,24 @@ te() && this.initSDKCommunicationIframe(); | ||
const e = Z(), t = new URL(`${e}/embed/headless-sdk`); | ||
t.searchParams.set("sdk", "true"), t.searchParams.set("parent", window.location.origin), t.searchParams.set("version", "js@1.0.5"); | ||
const s = document.createElement("iframe"); | ||
s.id = "moneyhash-headless-sdk", s.src = t.toString(), s.hidden = !0, document.body.appendChild(s), y.messagingService = new X({ | ||
target: s.contentWindow, | ||
t.searchParams.set("sdk", "true"), t.searchParams.set("parent", window.location.origin), t.searchParams.set("version", "js@1.0.6"); | ||
const r = document.createElement("iframe"); | ||
r.id = "moneyhash-headless-sdk", r.src = t.toString(), r.hidden = !0, document.body.appendChild(r), f.messagingService = new X({ | ||
target: r.contentWindow, | ||
targetOrigin: e | ||
}), y.isCommunicationReady = new Promise((r) => { | ||
}), f.isCommunicationReady = new Promise((s) => { | ||
var d; | ||
const o = (a) => { | ||
var i; | ||
a.data.type === "headlessSDK:init" && (r(), (i = y.messagingService) == null || i.removeListener(o)); | ||
a.data.type === "headlessSDK:init" && (s(), (i = f.messagingService) == null || i.removeListener(o)); | ||
}; | ||
(d = y.messagingService) == null || d.onReceive(o); | ||
(d = f.messagingService) == null || d.onReceive(o); | ||
}); | ||
} | ||
request(s) { | ||
return h(this, arguments, function* ({ | ||
request(r) { | ||
return g(this, arguments, function* ({ | ||
api: e, | ||
payload: t | ||
}) { | ||
return yield y.isCommunicationReady, new Promise((r, o) => { | ||
return yield f.isCommunicationReady, new Promise((s, o) => { | ||
var a, i; | ||
(a = y.messagingService) == null || a.send({ | ||
(a = f.messagingService) == null || a.send({ | ||
type: e, | ||
@@ -83,7 +83,7 @@ data: t | ||
const d = (c) => { | ||
var f; | ||
const { type: l, data: p } = c.data; | ||
l === e && (p.status === "resolved" ? r(p.payload) : o(p.payload), (f = y.messagingService) == null || f.removeListener(d)); | ||
var m; | ||
const { type: l, data: h } = c.data; | ||
l === e && (h.status === "resolved" ? s(h.payload) : o(h.payload), (m = f.messagingService) == null || m.removeListener(d)); | ||
}; | ||
(i = y.messagingService) == null || i.onReceive(d); | ||
(i = f.messagingService) == null || i.onReceive(d); | ||
}); | ||
@@ -93,9 +93,9 @@ }); | ||
}; | ||
let E = y; | ||
m(E, "messagingService", null), m(E, "isCommunicationReady"); | ||
class $ { | ||
let E = f; | ||
u(E, "messagingService", null), u(E, "isCommunicationReady"); | ||
class N { | ||
constructor() { | ||
m(this, "promise"); | ||
m(this, "resolve"); | ||
m(this, "reject"); | ||
u(this, "promise"); | ||
u(this, "resolve"); | ||
u(this, "reject"); | ||
this.promise = new Promise((e, t) => { | ||
@@ -106,15 +106,15 @@ this.resolve = e, this.reject = t; | ||
} | ||
function se() { | ||
function re() { | ||
var e; | ||
return (e = window.MONEYHASH_VAULT_API_URL) != null ? e : "https://vault.moneyhash.io"; | ||
} | ||
function H() { | ||
function T() { | ||
var e; | ||
return (e = window.MONEYHASH_VAULT_INPUT_IFRAME_URL) != null ? e : "https://vault-form.moneyhash.io"; | ||
} | ||
function re(n) { | ||
function se(n) { | ||
return (Array.isArray(n) ? n.length : Object.keys(n).length) === 0; | ||
} | ||
function ne(n, e) { | ||
return new Promise((t, s) => { | ||
return new Promise((t, r) => { | ||
if (document.getElementById(e)) { | ||
@@ -128,7 +128,7 @@ t(void 0); | ||
}), o.addEventListener("error", () => { | ||
s(new Error("Script failed to load")); | ||
r(new Error("Script failed to load")); | ||
}), document.body.appendChild(o); | ||
}); | ||
} | ||
function N() { | ||
function H() { | ||
var e; | ||
@@ -139,3 +139,2 @@ return (e = window.API_URL) != null ? e : "https://web.moneyhash.io"; | ||
const e = [ | ||
"cardHolderName", | ||
"cardNumber", | ||
@@ -159,18 +158,18 @@ "cardCvv", | ||
constructor(e) { | ||
g(this, L); | ||
g(this, S); | ||
g(this, A); | ||
g(this, k); | ||
g(this, I); | ||
g(this, U); | ||
g(this, C); | ||
g(this, R); | ||
m(this, "options"); | ||
m(this, "sdkApiHandler", new E()); | ||
m(this, "sdkEmbed"); | ||
m(this, "vaultSubmitListener", { | ||
v(this, L); | ||
v(this, S); | ||
v(this, A); | ||
v(this, k); | ||
v(this, I); | ||
v(this, U); | ||
v(this, C); | ||
v(this, R); | ||
u(this, "options"); | ||
u(this, "sdkApiHandler", new E()); | ||
u(this, "sdkEmbed"); | ||
u(this, "vaultSubmitListener", { | ||
current: null | ||
}); | ||
m(this, "mountedCardElements", []); | ||
this.options = e, this.sdkEmbed = new ee(T(b({}, e), { headless: !0 })), u(this, U, D).call(this, this.vaultSubmitListener); | ||
u(this, "mountedCardElements", []); | ||
this.options = e, this.sdkEmbed = new ee($(P({}, e), { headless: !0 })), y(this, U, D).call(this, this.vaultSubmitListener); | ||
} | ||
@@ -266,4 +265,4 @@ /** | ||
type: t, | ||
id: s, | ||
metaData: r | ||
id: r, | ||
metaData: s | ||
}) { | ||
@@ -281,5 +280,5 @@ return w( | ||
intentId: e, | ||
id: s, | ||
id: r, | ||
lang: this.sdkEmbed.lang, | ||
metaData: r | ||
metaData: s | ||
} | ||
@@ -381,7 +380,7 @@ }); | ||
payWithApplePay(c) { | ||
return h(this, arguments, function* ({ | ||
return g(this, arguments, function* ({ | ||
intentId: e, | ||
currency: t, | ||
amount: s, | ||
countryCode: r, | ||
amount: r, | ||
countryCode: s, | ||
onCancel: o = () => { | ||
@@ -399,3 +398,3 @@ }, | ||
const l = new ApplePaySession(3, { | ||
countryCode: r, | ||
countryCode: s, | ||
currencyCode: t, | ||
@@ -407,5 +406,5 @@ supportedNetworks: ["visa", "masterCard", "amex", "discover", "mada"], | ||
type: "final", | ||
amount: `${s}` | ||
amount: `${r}` | ||
} | ||
}), { state: p, intent: f } = yield this.proceedWith({ | ||
}), { state: h, intent: m } = yield this.proceedWith({ | ||
intentId: e, | ||
@@ -416,4 +415,4 @@ type: "method", | ||
try { | ||
if (p === "INTENT_FORM") { | ||
if (re(i)) | ||
if (h === "INTENT_FORM") { | ||
if (se(i)) | ||
throw new Error( | ||
@@ -432,7 +431,7 @@ "Billing data is missing while calling payWithApplePay" | ||
} | ||
} catch (v) { | ||
throw yield this.resetSelectedMethod(e), v; | ||
} catch (p) { | ||
throw yield this.resetSelectedMethod(e), p; | ||
} | ||
l.onvalidatemerchant = (v) => { | ||
fetch(`${N()}/api/v1/providers/applepay/session/`, { | ||
l.onvalidatemerchant = (p) => { | ||
fetch(`${H()}/api/v1/providers/applepay/session/`, { | ||
method: "post", | ||
@@ -443,10 +442,10 @@ headers: { | ||
body: JSON.stringify({ | ||
secret: f.secret, | ||
validation_url: v.validationURL | ||
secret: m.secret, | ||
validation_url: p.validationURL | ||
}) | ||
}).then((P) => P.ok ? P.json() : Promise.reject()).then( | ||
(P) => l.completeMerchantValidation(P) | ||
}).then((b) => b.ok ? b.json() : Promise.reject()).then( | ||
(b) => l.completeMerchantValidation(b) | ||
).catch(d); | ||
}, l.onpaymentauthorized = (v) => { | ||
fetch(`${N()}/api/v1/providers/applepay/token/`, { | ||
}, l.onpaymentauthorized = (p) => { | ||
fetch(`${H()}/api/v1/providers/applepay/token/`, { | ||
method: "post", | ||
@@ -457,6 +456,6 @@ headers: { | ||
body: JSON.stringify({ | ||
token_data: v.payment.token, | ||
secret: f.secret | ||
token_data: p.payment.token, | ||
secret: m.secret | ||
}) | ||
}).then((P) => P.ok ? P.json() : Promise.reject()).then(() => { | ||
}).then((b) => b.ok ? b.json() : Promise.reject()).then(() => { | ||
l.completePayment(ApplePaySession.STATUS_SUCCESS), a(); | ||
@@ -524,3 +523,3 @@ }).catch(() => { | ||
const t = []; | ||
return u(this, I, x).call(this, t), { | ||
return y(this, I, x).call(this, t), { | ||
/** | ||
@@ -547,24 +546,24 @@ * Creates card field element | ||
*/ | ||
create: ({ elementType: s, elementOptions: r }) => { | ||
create: ({ elementType: r, elementOptions: s }) => { | ||
const o = /* @__PURE__ */ new Map(), d = document.querySelector( | ||
r.selector | ||
s.selector | ||
); | ||
return w( | ||
!d, | ||
`Couldn't find an element with selector ${r.selector}!` | ||
`Couldn't find an element with selector ${s.selector}!` | ||
), d.classList.add("MoneyHashElement"), t.push((a) => { | ||
var c, l, p; | ||
const { type: i } = a.data; | ||
i === `${s}@focus` && (d.classList.add("MoneyHashElement--focus"), (c = o.get(`${s}@focus`)) == null || c()), i === `${s}@blur` && (d.classList.remove("MoneyHashElement--focus"), (l = o.get(`${s}@blur`)) == null || l()), i === `${s}@changeInput` && ((p = o.get(`${s}@changeInput`)) == null || p()); | ||
var l, h, m, p; | ||
const { type: i, data: c } = a.data; | ||
i === `${r}@focus` && (d.classList.add("MoneyHashElement--focus"), (l = o.get(`${r}@focus`)) == null || l()), i === `${r}@blur` && (d.classList.remove("MoneyHashElement--focus"), (h = o.get(`${r}@blur`)) == null || h()), i === `${r}@changeInput` && ((m = o.get(`${r}@changeInput`)) == null || m()), i === `${r}@cardNumberChange` && ((p = o.get(`${r}@cardNumberChange`)) == null || p(c)); | ||
}), { | ||
mount: () => { | ||
this.mountedCardElements.push(s), u(this, C, Y).call(this, { | ||
this.mountedCardElements.push(r), y(this, C, Y).call(this, { | ||
container: d, | ||
elementType: s, | ||
elementOptions: r, | ||
styles: b(b({}, e), r.styles) | ||
elementType: r, | ||
elementOptions: s, | ||
styles: P(P({}, e), s.styles) | ||
}); | ||
}, | ||
on: (a, i) => { | ||
o.set(`${s}@${a}`, i); | ||
o.set(`${r}@${a}`, i); | ||
} | ||
@@ -590,7 +589,7 @@ }; | ||
submitForm(o) { | ||
return h(this, arguments, function* ({ | ||
return g(this, arguments, function* ({ | ||
intentId: e, | ||
accessToken: t, | ||
billingData: s, | ||
shippingData: r | ||
billingData: r, | ||
shippingData: s | ||
}) { | ||
@@ -602,8 +601,8 @@ const d = ae(this.mountedCardElements); | ||
); | ||
const a = new $(); | ||
const a = new N(); | ||
let i, c; | ||
t && (this.vaultSubmitListener.current = (p) => { | ||
const { type: f, data: v } = p.data; | ||
f === "vaultSubmit:success" && a.resolve(v), f === "vaultSubmit:error" && a.reject(v); | ||
}, c = u(this, R, B).call(this, t), i = yield a.promise); | ||
t && (this.vaultSubmitListener.current = (h) => { | ||
const { type: m, data: p } = h.data; | ||
m === "vaultSubmit:success" && a.resolve(p), m === "vaultSubmit:error" && a.reject(p); | ||
}, c = y(this, R, B).call(this, t), i = yield a.promise); | ||
const l = yield this.sdkApiHandler.request({ | ||
@@ -615,4 +614,4 @@ api: "sdk:submitNativeForm", | ||
lang: this.sdkEmbed.lang, | ||
billingData: s, | ||
shippingData: r, | ||
billingData: r, | ||
shippingData: s, | ||
cardEmbed: i | ||
@@ -634,4 +633,4 @@ } | ||
*/ | ||
submitCvv(s) { | ||
return h(this, arguments, function* ({ | ||
submitCvv(r) { | ||
return g(this, arguments, function* ({ | ||
intentId: e, | ||
@@ -660,10 +659,10 @@ cvv: t | ||
renderUrl(e, t) { | ||
return h(this, null, function* () { | ||
return g(this, null, function* () { | ||
switch (t) { | ||
case "IFRAME": | ||
return u(this, L, j).call(this, e); | ||
return y(this, L, j).call(this, e); | ||
case "POPUP_IFRAME": | ||
return u(this, S, q).call(this, e); | ||
return y(this, S, q).call(this, e); | ||
case "REDIRECT": | ||
return u(this, A, W).call(this, e); | ||
return y(this, A, W).call(this, e); | ||
default: | ||
@@ -676,3 +675,3 @@ return null; | ||
L = new WeakSet(), j = function(e) { | ||
return h(this, null, function* () { | ||
return g(this, null, function* () { | ||
const t = document.querySelector("#rendered-url-iframe-container"); | ||
@@ -683,7 +682,7 @@ w( | ||
); | ||
const s = document.createElement("iframe"); | ||
s.src = e, s.style.setProperty("border", "0", "important"), s.style.setProperty("width", "100%", "important"), s.style.setProperty("height", "100%", "important"), t == null || t.replaceChildren(s), yield u(this, k, M).call(this), s.remove(); | ||
const r = document.createElement("iframe"); | ||
r.src = e, r.style.setProperty("border", "0", "important"), r.style.setProperty("width", "100%", "important"), r.style.setProperty("height", "100%", "important"), t == null || t.replaceChildren(r), yield y(this, k, M).call(this), r.remove(); | ||
}); | ||
}, S = new WeakSet(), q = function(e) { | ||
return h(this, null, function* () { | ||
return g(this, null, function* () { | ||
const t = window.open( | ||
@@ -694,16 +693,16 @@ `${e}`, | ||
); | ||
w(!t, "Popup blocked by browser!"), yield u(this, k, M).call(this), t == null || t.close(); | ||
w(!t, "Popup blocked by browser!"), yield y(this, k, M).call(this), t == null || t.close(); | ||
}); | ||
}, A = new WeakSet(), W = function(e) { | ||
return h(this, null, function* () { | ||
return g(this, null, function* () { | ||
window.open(e, "_blank"); | ||
}); | ||
}, k = new WeakSet(), M = function() { | ||
return h(this, null, function* () { | ||
const e = new $(), t = (s) => { | ||
return g(this, null, function* () { | ||
const e = new N(), t = (r) => { | ||
var d, a, i, c; | ||
const { type: r, data: o } = s.data; | ||
switch (r) { | ||
const { type: s, data: o } = r.data; | ||
switch (s) { | ||
case "onComplete": | ||
(a = (d = this.options).onComplete) == null || a.call(d, b({ | ||
(a = (d = this.options).onComplete) == null || a.call(d, P({ | ||
type: this.options.type | ||
@@ -713,3 +712,3 @@ }, o)), e.resolve(() => null), window.removeEventListener("message", t); | ||
case "onFail": | ||
(c = (i = this.options).onFail) == null || c.call(i, b({ | ||
(c = (i = this.options).onFail) == null || c.call(i, P({ | ||
type: this.options.type | ||
@@ -726,5 +725,5 @@ }, o)), e.resolve(() => null), window.removeEventListener("message", t); | ||
}, I = new WeakSet(), x = function(e) { | ||
const t = (s) => { | ||
e.forEach((r) => { | ||
r(s); | ||
const t = (r) => { | ||
e.forEach((s) => { | ||
s(r); | ||
}); | ||
@@ -734,4 +733,4 @@ }; | ||
}, U = new WeakSet(), D = function(e) { | ||
const t = (s) => { | ||
e.current && e.current(s); | ||
const t = (r) => { | ||
e.current && e.current(r); | ||
}; | ||
@@ -742,23 +741,23 @@ window.addEventListener("message", t); | ||
elementType: t, | ||
elementOptions: s, | ||
styles: r | ||
elementOptions: r, | ||
styles: s | ||
}) { | ||
var i, c; | ||
const o = H(), d = new URL(`${o}/vaultField/vaultField.html`); | ||
d.searchParams.set("host", btoa(window.location.origin)), d.searchParams.set("type", t), d.searchParams.set("placeholder", (i = s.placeholder) != null ? i : ""), d.searchParams.set("color", (r == null ? void 0 : r.color) || "#000"), d.searchParams.set( | ||
const o = T(), d = new URL(`${o}/vaultField/vaultField.html`); | ||
d.searchParams.set("host", btoa(window.location.origin)), d.searchParams.set("type", t), d.searchParams.set("placeholder", (i = r.placeholder) != null ? i : ""), d.searchParams.set("color", (s == null ? void 0 : s.color) || "#000"), d.searchParams.set( | ||
"placeholderColor", | ||
(r == null ? void 0 : r.placeholderColor) || "#ccc" | ||
(s == null ? void 0 : s.placeholderColor) || "#ccc" | ||
), d.searchParams.set( | ||
"backgroundColor", | ||
(r == null ? void 0 : r.backgroundColor) || "transparent" | ||
(s == null ? void 0 : s.backgroundColor) || "transparent" | ||
); | ||
const a = document.createElement("iframe"); | ||
a.src = d.toString(), a.style.height = (c = s.height) != null ? c : "40px", a.style.setProperty("overflow", "hidden", "important"), a.style.setProperty("display", "block", "important"), a.style.setProperty("width", "100%", "important"), a.style.setProperty("maxWidth", "100%", "important"), a.style.setProperty("border", "0", "important"), a.style.setProperty("margin", "0", "important"), a.style.setProperty("padding", "0", "important"), a.style.setProperty("userSelect", "none", "important"), a.style.setProperty("colorScheme", "light only", "important"), e.replaceChildren(a); | ||
a.src = d.toString(), a.style.height = (c = r.height) != null ? c : "40px", a.style.setProperty("overflow", "hidden", "important"), a.style.setProperty("display", "block", "important"), a.style.setProperty("width", "100%", "important"), a.style.setProperty("maxWidth", "100%", "important"), a.style.setProperty("border", "0", "important"), a.style.setProperty("margin", "0", "important"), a.style.setProperty("padding", "0", "important"), a.style.setProperty("userSelect", "none", "important"), a.style.setProperty("colorScheme", "light only", "important"), e.replaceChildren(a); | ||
}, R = new WeakSet(), B = function(e) { | ||
const t = H(), s = se(), r = new URL( | ||
const t = T(), r = re(), s = new URL( | ||
`${t}/vaultSubmit/vaultSubmit.html` | ||
); | ||
r.searchParams.set("host", btoa(window.location.origin)), r.searchParams.set("vault_api_url", `${s}/api/v1/tokens/`), r.searchParams.set("access_token", e); | ||
s.searchParams.set("host", btoa(window.location.origin)), s.searchParams.set("vault_api_url", `${r}/api/v1/tokens/`), s.searchParams.set("access_token", e); | ||
const o = document.createElement("iframe"); | ||
return o.id = "moneyhash-submit-iframe", o.src = r.toString(), o.hidden = !0, document.body.appendChild(o), o; | ||
return o.id = "moneyhash-submit-iframe", o.src = s.toString(), o.hidden = !0, document.body.appendChild(o), o; | ||
}; | ||
@@ -765,0 +764,0 @@ export { |
@@ -1,1 +0,1 @@ | ||
(function(d,i){typeof exports=="object"&&typeof module!="undefined"?module.exports=i():typeof define=="function"&&define.amd?define(i):(d=typeof globalThis!="undefined"?globalThis:d||self,d.MoneyHash=i())})(this,function(){var M,z,_,K,F,G,C,q,$,Q,T,X,H,Z,j,ee;"use strict";var ae=Object.defineProperty,oe=Object.defineProperties;var de=Object.getOwnPropertyDescriptors;var Y=Object.getOwnPropertySymbols;var ce=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var V=(d,i,c)=>i in d?ae(d,i,{enumerable:!0,configurable:!0,writable:!0,value:c}):d[i]=c,k=(d,i)=>{for(var c in i||(i={}))ce.call(i,c)&&V(d,c,i[c]);if(Y)for(var c of Y(i))le.call(i,c)&&V(d,c,i[c]);return d},J=(d,i)=>oe(d,de(i));var p=(d,i,c)=>(V(d,typeof i!="symbol"?i+"":i,c),c),me=(d,i,c)=>{if(!i.has(d))throw TypeError("Cannot "+c)};var L=(d,i,c)=>{if(i.has(d))throw TypeError("Cannot add the same private member more than once");i instanceof WeakSet?i.add(d):i.set(d,c)};var P=(d,i,c)=>(me(d,i,"access private method"),c);var w=(d,i,c)=>new Promise((R,f)=>{var N=S=>{try{A(c.next(S))}catch(I){f(I)}},U=S=>{try{A(c.throw(S))}catch(I){f(I)}},A=S=>S.done?R(S.value):Promise.resolve(S.value).then(N,U);A((c=c.apply(d,i)).next())});class d{constructor(e){p(this,"target");p(this,"targetOrigin");p(this,"listeners");p(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(t=>t!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(t=>{t(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function i(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function c(){return typeof window!="undefined"}const b=class{constructor(){c()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=i(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.0.5");const s=document.createElement("iframe");s.id="moneyhash-headless-sdk",s.src=t.toString(),s.hidden=!0,document.body.appendChild(s),b.messagingService=new d({target:s.contentWindow,targetOrigin:e}),b.isCommunicationReady=new Promise(n=>{var o;const a=r=>{var l;r.data.type==="headlessSDK:init"&&(n(),(l=b.messagingService)==null||l.removeListener(a))};(o=b.messagingService)==null||o.onReceive(a)})}request(s){return w(this,arguments,function*({api:e,payload:t}){return yield b.isCommunicationReady,new Promise((n,a)=>{var r,l;(r=b.messagingService)==null||r.send({type:e,data:t});const o=u=>{var v;const{type:h,data:g}=u.data;h===e&&(g.status==="resolved"?n(g.payload):a(g.payload),(v=b.messagingService)==null||v.removeListener(o))};(l=b.messagingService)==null||l.onReceive(o)})})}};let R=b;p(R,"messagingService",null),p(R,"isCommunicationReady");function f(m,e){if(m)throw new Error(e)}function N(m,e){m&&console.warn(e)}const U=new Set(["payment","payout"]),A=new Set(["en","fr","ar"]);class S{constructor(e){p(this,"options");p(this,"messagingService",null);p(this,"iframe",null);p(this,"isCommunicationReady",null);f(!U.has(e.type),`MoneyHash constructor must be called with valid type (${[...U].join(" | ")})!`),this.options=e}get lang(){var t;const e=(t=this.options.locale)==null?void 0:t.split("-")[0];return N(!!e&&!A.has(e),`Supported languages (${[...A].join(" | ")})`),e||"en"}render({selector:e,intentId:t}){var r,l;(r=this.messagingService)==null||r.abortService();const s=i(),n=new URL(`${s}/embed/${this.options.type}/${t}`);n.searchParams.set("sdk","true"),n.searchParams.set("parent",window.location.origin),n.searchParams.set("version","js@1.0.5");const a=(l=this.options.locale)==null?void 0:l.split("-")[0];a&&n.searchParams.set("lang",a),this.iframe=document.createElement("iframe"),this.iframe.src=n.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0";const o=document.querySelector(e);return f(!o,`Couldn't find an element with selector ${e}!`),o.replaceChildren(this.iframe),this.messagingService=new d({target:this.iframe.contentWindow,targetOrigin:s}),this.isCommunicationReady=new Promise(u=>{var g;const h=v=>{var y;v.data.type==="sdk:init"&&(u(),(y=this.messagingService)==null||y.removeListener(h))};(g=this.messagingService)==null||g.onReceive(h)}),this.messagingService.onReceive((u,h)=>{var y,E,B,D;const{type:g,data:v}=u.data;switch(g){case"sdk:init":{h({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(E=(y=this.options).onComplete)==null||E.call(y,k({type:this.options.type},v)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(D=(B=this.options).onFail)==null||D.call(B,k({type:this.options.type},v)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}}}),this.isCommunicationReady}setLocale(e){return w(this,null,function*(){var t;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(t=this.messagingService)==null||t.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return w(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class I{constructor(){p(this,"promise");p(this,"resolve");p(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function te(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function O(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function se(m){return(Array.isArray(m)?m.length:Object.keys(m).length)===0}function ne(m,e){return new Promise((t,s)=>{if(document.getElementById(e)){t(void 0);return}const a=document.createElement("script");a.src=m,a.id=e,a.addEventListener("load",()=>{t(void 0)}),a.addEventListener("error",()=>{s(new Error("Script failed to load"))}),document.body.appendChild(a)})}function W(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function ie(m){const e=["cardHolderName","cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!m.includes(t))return t;return null}const x=new Set(["method","customerBalance","savedCard"]);class re{constructor(e){L(this,M);L(this,_);L(this,F);L(this,C);L(this,$);L(this,T);L(this,H);L(this,j);p(this,"options");p(this,"sdkApiHandler",new R);p(this,"sdkEmbed");p(this,"vaultSubmitListener",{current:null});p(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new S(J(k({},e),{headless:!0})),P(this,T,X).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}proceedWith({intentId:e,type:t,id:s,metaData:n}){return f(!x.has(t),`type must be a valid one (${[...x].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:s,lang:this.sdkEmbed.lang,metaData:n}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return f(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(u){return w(this,arguments,function*({intentId:e,currency:t,amount:s,countryCode:n,onCancel:a=()=>{},onError:o,onComplete:r,billingData:l={}}){if(yield ne("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const h=new ApplePaySession(3,{countryCode:n,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${s}`}}),{state:g,intent:v}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(g==="INTENT_FORM"){if(se(l))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",lang:this.sdkEmbed.lang,billingData:l}})}}catch(y){throw yield this.resetSelectedMethod(e),y}h.onvalidatemerchant=y=>{fetch(`${W()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:v.secret,validation_url:y.validationURL})}).then(E=>E.ok?E.json():Promise.reject()).then(E=>h.completeMerchantValidation(E)).catch(o)},h.onpaymentauthorized=y=>{fetch(`${W()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:y.payment.token,secret:v.secret})}).then(E=>E.ok?E.json():Promise.reject()).then(()=>{h.completePayment(ApplePaySession.STATUS_SUCCESS),r()}).catch(()=>{h.completePayment(ApplePaySession.STATUS_FAILURE),o()})},h.oncancel=a,h.begin()})}renderForm({selector:e,intentId:t}){return f(!e,"selector is required for renderForm"),f(!t,"intentId is required for renderForm"),this.sdkEmbed.render({selector:e,intentId:t})}setLocale(e){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}elements({styles:e}){const t=[];return P(this,$,Q).call(this,t),{create:({elementType:s,elementOptions:n})=>{const a=new Map,o=document.querySelector(n.selector);return f(!o,`Couldn't find an element with selector ${n.selector}!`),o.classList.add("MoneyHashElement"),t.push(r=>{var u,h,g;const{type:l}=r.data;l===`${s}@focus`&&(o.classList.add("MoneyHashElement--focus"),(u=a.get(`${s}@focus`))==null||u()),l===`${s}@blur`&&(o.classList.remove("MoneyHashElement--focus"),(h=a.get(`${s}@blur`))==null||h()),l===`${s}@changeInput`&&((g=a.get(`${s}@changeInput`))==null||g())}),{mount:()=>{this.mountedCardElements.push(s),P(this,H,Z).call(this,{container:o,elementType:s,elementOptions:n,styles:k(k({},e),n.styles)})},on:(r,l)=>{a.set(`${s}@${r}`,l)}}}}}submitForm(a){return w(this,arguments,function*({intentId:e,accessToken:t,billingData:s,shippingData:n}){const o=ie(this.mountedCardElements);f(!!o,`You must mount ${o} element!`);const r=new I;let l,u;t&&(this.vaultSubmitListener.current=g=>{const{type:v,data:y}=g.data;v==="vaultSubmit:success"&&r.resolve(y),v==="vaultSubmit:error"&&r.reject(y)},u=P(this,j,ee).call(this,t),l=yield r.promise);const h=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:s,shippingData:n,cardEmbed:l}});return u&&u.remove(),h})}submitCvv(s){return w(this,arguments,function*({intentId:e,cvv:t}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,lang:this.sdkEmbed.lang}})})}renderUrl(e,t){return w(this,null,function*(){switch(t){case"IFRAME":return P(this,M,z).call(this,e);case"POPUP_IFRAME":return P(this,_,K).call(this,e);case"REDIRECT":return P(this,F,G).call(this,e);default:return null}})}}return M=new WeakSet,z=function(e){return w(this,null,function*(){const t=document.querySelector("#rendered-url-iframe-container");f(!t,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const s=document.createElement("iframe");s.src=e,s.style.setProperty("border","0","important"),s.style.setProperty("width","100%","important"),s.style.setProperty("height","100%","important"),t==null||t.replaceChildren(s),yield P(this,C,q).call(this),s.remove()})},_=new WeakSet,K=function(e){return w(this,null,function*(){const t=window.open(`${e}`,"","width=600,height=400,left=200,top=200");f(!t,"Popup blocked by browser!"),yield P(this,C,q).call(this),t==null||t.close()})},F=new WeakSet,G=function(e){return w(this,null,function*(){window.open(e,"_blank")})},C=new WeakSet,q=function(){return w(this,null,function*(){const e=new I,t=s=>{var o,r,l,u;const{type:n,data:a}=s.data;switch(n){case"onComplete":(r=(o=this.options).onComplete)==null||r.call(o,k({type:this.options.type},a)),e.resolve(()=>null),window.removeEventListener("message",t);break;case"onFail":(u=(l=this.options).onFail)==null||u.call(l,k({type:this.options.type},a)),e.resolve(()=>null),window.removeEventListener("message",t);break;default:e.resolve(()=>null);break}};return window.addEventListener("message",t),e.promise})},$=new WeakSet,Q=function(e){const t=s=>{e.forEach(n=>{n(s)})};window.addEventListener("message",t)},T=new WeakSet,X=function(e){const t=s=>{e.current&&e.current(s)};window.addEventListener("message",t)},H=new WeakSet,Z=function({container:e,elementType:t,elementOptions:s,styles:n}){var l,u;const a=O(),o=new URL(`${a}/vaultField/vaultField.html`);o.searchParams.set("host",btoa(window.location.origin)),o.searchParams.set("type",t),o.searchParams.set("placeholder",(l=s.placeholder)!=null?l:""),o.searchParams.set("color",(n==null?void 0:n.color)||"#000"),o.searchParams.set("placeholderColor",(n==null?void 0:n.placeholderColor)||"#ccc"),o.searchParams.set("backgroundColor",(n==null?void 0:n.backgroundColor)||"transparent");const r=document.createElement("iframe");r.src=o.toString(),r.style.height=(u=s.height)!=null?u:"40px",r.style.setProperty("overflow","hidden","important"),r.style.setProperty("display","block","important"),r.style.setProperty("width","100%","important"),r.style.setProperty("maxWidth","100%","important"),r.style.setProperty("border","0","important"),r.style.setProperty("margin","0","important"),r.style.setProperty("padding","0","important"),r.style.setProperty("userSelect","none","important"),r.style.setProperty("colorScheme","light only","important"),e.replaceChildren(r)},j=new WeakSet,ee=function(e){const t=O(),s=te(),n=new URL(`${t}/vaultSubmit/vaultSubmit.html`);n.searchParams.set("host",btoa(window.location.origin)),n.searchParams.set("vault_api_url",`${s}/api/v1/tokens/`),n.searchParams.set("access_token",e);const a=document.createElement("iframe");return a.id="moneyhash-submit-iframe",a.src=n.toString(),a.hidden=!0,document.body.appendChild(a),a},re}); | ||
(function(d,i){typeof exports=="object"&&typeof module!="undefined"?module.exports=i():typeof define=="function"&&define.amd?define(i):(d=typeof globalThis!="undefined"?globalThis:d||self,d.MoneyHash=i())})(this,function(){var M,z,_,K,F,G,C,V,$,Q,H,X,T,Z,j,ee;"use strict";var ae=Object.defineProperty,oe=Object.defineProperties;var de=Object.getOwnPropertyDescriptors;var Y=Object.getOwnPropertySymbols;var ce=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var q=(d,i,l)=>i in d?ae(d,i,{enumerable:!0,configurable:!0,writable:!0,value:l}):d[i]=l,k=(d,i)=>{for(var l in i||(i={}))ce.call(i,l)&&q(d,l,i[l]);if(Y)for(var l of Y(i))le.call(i,l)&&q(d,l,i[l]);return d},J=(d,i)=>oe(d,de(i));var p=(d,i,l)=>(q(d,typeof i!="symbol"?i+"":i,l),l),me=(d,i,l)=>{if(!i.has(d))throw TypeError("Cannot "+l)};var L=(d,i,l)=>{if(i.has(d))throw TypeError("Cannot add the same private member more than once");i instanceof WeakSet?i.add(d):i.set(d,l)};var P=(d,i,l)=>(me(d,i,"access private method"),l);var w=(d,i,l)=>new Promise((R,v)=>{var N=S=>{try{A(l.next(S))}catch(I){v(I)}},U=S=>{try{A(l.throw(S))}catch(I){v(I)}},A=S=>S.done?R(S.value):Promise.resolve(S.value).then(N,U);A((l=l.apply(d,i)).next())});class d{constructor(e){p(this,"target");p(this,"targetOrigin");p(this,"listeners");p(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(t=>t!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(t=>{t(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function i(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function l(){return typeof window!="undefined"}const b=class{constructor(){l()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=i(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.0.6");const s=document.createElement("iframe");s.id="moneyhash-headless-sdk",s.src=t.toString(),s.hidden=!0,document.body.appendChild(s),b.messagingService=new d({target:s.contentWindow,targetOrigin:e}),b.isCommunicationReady=new Promise(n=>{var o;const a=r=>{var c;r.data.type==="headlessSDK:init"&&(n(),(c=b.messagingService)==null||c.removeListener(a))};(o=b.messagingService)==null||o.onReceive(a)})}request(s){return w(this,arguments,function*({api:e,payload:t}){return yield b.isCommunicationReady,new Promise((n,a)=>{var r,c;(r=b.messagingService)==null||r.send({type:e,data:t});const o=u=>{var y;const{type:h,data:f}=u.data;h===e&&(f.status==="resolved"?n(f.payload):a(f.payload),(y=b.messagingService)==null||y.removeListener(o))};(c=b.messagingService)==null||c.onReceive(o)})})}};let R=b;p(R,"messagingService",null),p(R,"isCommunicationReady");function v(m,e){if(m)throw new Error(e)}function N(m,e){m&&console.warn(e)}const U=new Set(["payment","payout"]),A=new Set(["en","fr","ar"]);class S{constructor(e){p(this,"options");p(this,"messagingService",null);p(this,"iframe",null);p(this,"isCommunicationReady",null);v(!U.has(e.type),`MoneyHash constructor must be called with valid type (${[...U].join(" | ")})!`),this.options=e}get lang(){var t;const e=(t=this.options.locale)==null?void 0:t.split("-")[0];return N(!!e&&!A.has(e),`Supported languages (${[...A].join(" | ")})`),e||"en"}render({selector:e,intentId:t}){var r,c;(r=this.messagingService)==null||r.abortService();const s=i(),n=new URL(`${s}/embed/${this.options.type}/${t}`);n.searchParams.set("sdk","true"),n.searchParams.set("parent",window.location.origin),n.searchParams.set("version","js@1.0.6");const a=(c=this.options.locale)==null?void 0:c.split("-")[0];a&&n.searchParams.set("lang",a),this.iframe=document.createElement("iframe"),this.iframe.src=n.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0";const o=document.querySelector(e);return v(!o,`Couldn't find an element with selector ${e}!`),o.replaceChildren(this.iframe),this.messagingService=new d({target:this.iframe.contentWindow,targetOrigin:s}),this.isCommunicationReady=new Promise(u=>{var f;const h=y=>{var g;y.data.type==="sdk:init"&&(u(),(g=this.messagingService)==null||g.removeListener(h))};(f=this.messagingService)==null||f.onReceive(h)}),this.messagingService.onReceive((u,h)=>{var g,E,B,D;const{type:f,data:y}=u.data;switch(f){case"sdk:init":{h({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(E=(g=this.options).onComplete)==null||E.call(g,k({type:this.options.type},y)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(D=(B=this.options).onFail)==null||D.call(B,k({type:this.options.type},y)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}}}),this.isCommunicationReady}setLocale(e){return w(this,null,function*(){var t;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(t=this.messagingService)==null||t.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return w(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class I{constructor(){p(this,"promise");p(this,"resolve");p(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function te(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function O(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function se(m){return(Array.isArray(m)?m.length:Object.keys(m).length)===0}function ne(m,e){return new Promise((t,s)=>{if(document.getElementById(e)){t(void 0);return}const a=document.createElement("script");a.src=m,a.id=e,a.addEventListener("load",()=>{t(void 0)}),a.addEventListener("error",()=>{s(new Error("Script failed to load"))}),document.body.appendChild(a)})}function W(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function ie(m){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!m.includes(t))return t;return null}const x=new Set(["method","customerBalance","savedCard"]);class re{constructor(e){L(this,M);L(this,_);L(this,F);L(this,C);L(this,$);L(this,H);L(this,T);L(this,j);p(this,"options");p(this,"sdkApiHandler",new R);p(this,"sdkEmbed");p(this,"vaultSubmitListener",{current:null});p(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new S(J(k({},e),{headless:!0})),P(this,H,X).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}proceedWith({intentId:e,type:t,id:s,metaData:n}){return v(!x.has(t),`type must be a valid one (${[...x].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:s,lang:this.sdkEmbed.lang,metaData:n}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return v(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(u){return w(this,arguments,function*({intentId:e,currency:t,amount:s,countryCode:n,onCancel:a=()=>{},onError:o,onComplete:r,billingData:c={}}){if(yield ne("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const h=new ApplePaySession(3,{countryCode:n,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${s}`}}),{state:f,intent:y}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(f==="INTENT_FORM"){if(se(c))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",lang:this.sdkEmbed.lang,billingData:c}})}}catch(g){throw yield this.resetSelectedMethod(e),g}h.onvalidatemerchant=g=>{fetch(`${W()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:y.secret,validation_url:g.validationURL})}).then(E=>E.ok?E.json():Promise.reject()).then(E=>h.completeMerchantValidation(E)).catch(o)},h.onpaymentauthorized=g=>{fetch(`${W()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:g.payment.token,secret:y.secret})}).then(E=>E.ok?E.json():Promise.reject()).then(()=>{h.completePayment(ApplePaySession.STATUS_SUCCESS),r()}).catch(()=>{h.completePayment(ApplePaySession.STATUS_FAILURE),o()})},h.oncancel=a,h.begin()})}renderForm({selector:e,intentId:t}){return v(!e,"selector is required for renderForm"),v(!t,"intentId is required for renderForm"),this.sdkEmbed.render({selector:e,intentId:t})}setLocale(e){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}elements({styles:e}){const t=[];return P(this,$,Q).call(this,t),{create:({elementType:s,elementOptions:n})=>{const a=new Map,o=document.querySelector(n.selector);return v(!o,`Couldn't find an element with selector ${n.selector}!`),o.classList.add("MoneyHashElement"),t.push(r=>{var h,f,y,g;const{type:c,data:u}=r.data;c===`${s}@focus`&&(o.classList.add("MoneyHashElement--focus"),(h=a.get(`${s}@focus`))==null||h()),c===`${s}@blur`&&(o.classList.remove("MoneyHashElement--focus"),(f=a.get(`${s}@blur`))==null||f()),c===`${s}@changeInput`&&((y=a.get(`${s}@changeInput`))==null||y()),c===`${s}@cardNumberChange`&&((g=a.get(`${s}@cardNumberChange`))==null||g(u))}),{mount:()=>{this.mountedCardElements.push(s),P(this,T,Z).call(this,{container:o,elementType:s,elementOptions:n,styles:k(k({},e),n.styles)})},on:(r,c)=>{a.set(`${s}@${r}`,c)}}}}}submitForm(a){return w(this,arguments,function*({intentId:e,accessToken:t,billingData:s,shippingData:n}){const o=ie(this.mountedCardElements);v(!!o,`You must mount ${o} element!`);const r=new I;let c,u;t&&(this.vaultSubmitListener.current=f=>{const{type:y,data:g}=f.data;y==="vaultSubmit:success"&&r.resolve(g),y==="vaultSubmit:error"&&r.reject(g)},u=P(this,j,ee).call(this,t),c=yield r.promise);const h=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:s,shippingData:n,cardEmbed:c}});return u&&u.remove(),h})}submitCvv(s){return w(this,arguments,function*({intentId:e,cvv:t}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,lang:this.sdkEmbed.lang}})})}renderUrl(e,t){return w(this,null,function*(){switch(t){case"IFRAME":return P(this,M,z).call(this,e);case"POPUP_IFRAME":return P(this,_,K).call(this,e);case"REDIRECT":return P(this,F,G).call(this,e);default:return null}})}}return M=new WeakSet,z=function(e){return w(this,null,function*(){const t=document.querySelector("#rendered-url-iframe-container");v(!t,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const s=document.createElement("iframe");s.src=e,s.style.setProperty("border","0","important"),s.style.setProperty("width","100%","important"),s.style.setProperty("height","100%","important"),t==null||t.replaceChildren(s),yield P(this,C,V).call(this),s.remove()})},_=new WeakSet,K=function(e){return w(this,null,function*(){const t=window.open(`${e}`,"","width=600,height=400,left=200,top=200");v(!t,"Popup blocked by browser!"),yield P(this,C,V).call(this),t==null||t.close()})},F=new WeakSet,G=function(e){return w(this,null,function*(){window.open(e,"_blank")})},C=new WeakSet,V=function(){return w(this,null,function*(){const e=new I,t=s=>{var o,r,c,u;const{type:n,data:a}=s.data;switch(n){case"onComplete":(r=(o=this.options).onComplete)==null||r.call(o,k({type:this.options.type},a)),e.resolve(()=>null),window.removeEventListener("message",t);break;case"onFail":(u=(c=this.options).onFail)==null||u.call(c,k({type:this.options.type},a)),e.resolve(()=>null),window.removeEventListener("message",t);break;default:e.resolve(()=>null);break}};return window.addEventListener("message",t),e.promise})},$=new WeakSet,Q=function(e){const t=s=>{e.forEach(n=>{n(s)})};window.addEventListener("message",t)},H=new WeakSet,X=function(e){const t=s=>{e.current&&e.current(s)};window.addEventListener("message",t)},T=new WeakSet,Z=function({container:e,elementType:t,elementOptions:s,styles:n}){var c,u;const a=O(),o=new URL(`${a}/vaultField/vaultField.html`);o.searchParams.set("host",btoa(window.location.origin)),o.searchParams.set("type",t),o.searchParams.set("placeholder",(c=s.placeholder)!=null?c:""),o.searchParams.set("color",(n==null?void 0:n.color)||"#000"),o.searchParams.set("placeholderColor",(n==null?void 0:n.placeholderColor)||"#ccc"),o.searchParams.set("backgroundColor",(n==null?void 0:n.backgroundColor)||"transparent");const r=document.createElement("iframe");r.src=o.toString(),r.style.height=(u=s.height)!=null?u:"40px",r.style.setProperty("overflow","hidden","important"),r.style.setProperty("display","block","important"),r.style.setProperty("width","100%","important"),r.style.setProperty("maxWidth","100%","important"),r.style.setProperty("border","0","important"),r.style.setProperty("margin","0","important"),r.style.setProperty("padding","0","important"),r.style.setProperty("userSelect","none","important"),r.style.setProperty("colorScheme","light only","important"),e.replaceChildren(r)},j=new WeakSet,ee=function(e){const t=O(),s=te(),n=new URL(`${t}/vaultSubmit/vaultSubmit.html`);n.searchParams.set("host",btoa(window.location.origin)),n.searchParams.set("vault_api_url",`${s}/api/v1/tokens/`),n.searchParams.set("access_token",e);const a=document.createElement("iframe");return a.id="moneyhash-submit-iframe",a.src=n.toString(),a.hidden=!0,document.body.appendChild(a),a},re}); |
@@ -1,1 +0,1 @@ | ||
"use strict";var o=Object.defineProperty;var i=(s,e,r)=>e in s?o(s,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[e]=r;var t=(s,e,r)=>(i(s,typeof e!="symbol"?e+"":e,r),r);const d=require("./sdkEmbed-d5b15674.cjs");class n{constructor(e){t(this,"options");t(this,"sdkEmbed");this.options=e,this.sdkEmbed=new d.SDKEmbed(e)}start({selector:e,intentId:r}){return d.throwIf(!e,"selector is required for start"),d.throwIf(!r,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:r})}setLocale(e){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}}module.exports=n; | ||
"use strict";var o=Object.defineProperty;var i=(s,e,r)=>e in s?o(s,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[e]=r;var t=(s,e,r)=>(i(s,typeof e!="symbol"?e+"":e,r),r);const d=require("./sdkEmbed-955a36b1.cjs");class n{constructor(e){t(this,"options");t(this,"sdkEmbed");this.options=e,this.sdkEmbed=new d.SDKEmbed(e)}start({selector:e,intentId:r}){return d.throwIf(!e,"selector is required for start"),d.throwIf(!r,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:r})}setLocale(e){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}}module.exports=n; |
var o = Object.defineProperty; | ||
var i = (s, e, r) => e in s ? o(s, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : s[e] = r; | ||
var t = (s, e, r) => (i(s, typeof e != "symbol" ? e + "" : e, r), r); | ||
import { S as a, t as d } from "./sdkEmbed-957d3f53.js"; | ||
import { S as a, t as d } from "./sdkEmbed-13f4e15c.js"; | ||
class b { | ||
@@ -6,0 +6,0 @@ constructor(e) { |
@@ -1,1 +0,1 @@ | ||
(function(i,t){typeof exports=="object"&&typeof module!="undefined"?module.exports=t():typeof define=="function"&&define.amd?define(t):(i=typeof globalThis!="undefined"?globalThis:i||self,i.MoneyHash=t())})(this,function(){"use strict";var F=Object.defineProperty;var O=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var v=(i,t,s)=>t in i?F(i,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[t]=s,w=(i,t)=>{for(var s in t||(t={}))U.call(t,s)&&v(i,s,t[s]);if(O)for(var s of O(t))$.call(t,s)&&v(i,s,t[s]);return i};var a=(i,t,s)=>(v(i,typeof t!="symbol"?t+"":t,s),s);var b=(i,t,s)=>new Promise((p,o)=>{var m=n=>{try{h(s.next(n))}catch(e){o(e)}},f=n=>{try{h(s.throw(n))}catch(e){o(e)}},h=n=>n.done?p(n.value):Promise.resolve(n.value).then(m,f);h((s=s.apply(i,t)).next())});class i{constructor(e){a(this,"target");a(this,"targetOrigin");a(this,"listeners");a(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(r=>r!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(r=>{r(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function t(n,e){if(n)throw new Error(e)}function s(n,e){n&&console.warn(e)}function p(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}const o=new Set(["payment","payout"]),m=new Set(["en","fr","ar"]);class f{constructor(e){a(this,"options");a(this,"messagingService",null);a(this,"iframe",null);a(this,"isCommunicationReady",null);t(!o.has(e.type),`MoneyHash constructor must be called with valid type (${[...o].join(" | ")})!`),this.options=e}get lang(){var r;const e=(r=this.options.locale)==null?void 0:r.split("-")[0];return s(!!e&&!m.has(e),`Supported languages (${[...m].join(" | ")})`),e||"en"}render({selector:e,intentId:r}){var L,M;(L=this.messagingService)==null||L.abortService();const S=p(),c=new URL(`${S}/embed/${this.options.type}/${r}`);c.searchParams.set("sdk","true"),c.searchParams.set("parent",window.location.origin),c.searchParams.set("version","js@1.0.5");const R=(M=this.options.locale)==null?void 0:M.split("-")[0];R&&c.searchParams.set("lang",R),this.iframe=document.createElement("iframe"),this.iframe.src=c.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0";const E=document.querySelector(e);return t(!E,`Couldn't find an element with selector ${e}!`),E.replaceChildren(this.iframe),this.messagingService=new i({target:this.iframe.contentWindow,targetOrigin:S}),this.isCommunicationReady=new Promise(y=>{var l;const g=u=>{var d;u.data.type==="sdk:init"&&(y(),(d=this.messagingService)==null||d.removeListener(g))};(l=this.messagingService)==null||l.onReceive(g)}),this.messagingService.onReceive((y,g)=>{var d,k,I,C;const{type:l,data:u}=y.data;switch(l){case"sdk:init":{g({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(k=(d=this.options).onComplete)==null||k.call(d,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(C=(I=this.options).onFail)==null||C.call(I,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}}}),this.isCommunicationReady}setLocale(e){return b(this,null,function*(){var r;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(r=this.messagingService)==null||r.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return b(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class h{constructor(e){a(this,"options");a(this,"sdkEmbed");this.options=e,this.sdkEmbed=new f(e)}start({selector:e,intentId:r}){return t(!e,"selector is required for start"),t(!r,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:r})}setLocale(e){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}}return h}); | ||
(function(i,t){typeof exports=="object"&&typeof module!="undefined"?module.exports=t():typeof define=="function"&&define.amd?define(t):(i=typeof globalThis!="undefined"?globalThis:i||self,i.MoneyHash=t())})(this,function(){"use strict";var F=Object.defineProperty;var O=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var v=(i,t,s)=>t in i?F(i,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[t]=s,w=(i,t)=>{for(var s in t||(t={}))U.call(t,s)&&v(i,s,t[s]);if(O)for(var s of O(t))$.call(t,s)&&v(i,s,t[s]);return i};var a=(i,t,s)=>(v(i,typeof t!="symbol"?t+"":t,s),s);var b=(i,t,s)=>new Promise((p,o)=>{var m=n=>{try{h(s.next(n))}catch(e){o(e)}},f=n=>{try{h(s.throw(n))}catch(e){o(e)}},h=n=>n.done?p(n.value):Promise.resolve(n.value).then(m,f);h((s=s.apply(i,t)).next())});class i{constructor(e){a(this,"target");a(this,"targetOrigin");a(this,"listeners");a(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(r=>r!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(r=>{r(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function t(n,e){if(n)throw new Error(e)}function s(n,e){n&&console.warn(e)}function p(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}const o=new Set(["payment","payout"]),m=new Set(["en","fr","ar"]);class f{constructor(e){a(this,"options");a(this,"messagingService",null);a(this,"iframe",null);a(this,"isCommunicationReady",null);t(!o.has(e.type),`MoneyHash constructor must be called with valid type (${[...o].join(" | ")})!`),this.options=e}get lang(){var r;const e=(r=this.options.locale)==null?void 0:r.split("-")[0];return s(!!e&&!m.has(e),`Supported languages (${[...m].join(" | ")})`),e||"en"}render({selector:e,intentId:r}){var L,M;(L=this.messagingService)==null||L.abortService();const S=p(),c=new URL(`${S}/embed/${this.options.type}/${r}`);c.searchParams.set("sdk","true"),c.searchParams.set("parent",window.location.origin),c.searchParams.set("version","js@1.0.6");const R=(M=this.options.locale)==null?void 0:M.split("-")[0];R&&c.searchParams.set("lang",R),this.iframe=document.createElement("iframe"),this.iframe.src=c.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0";const E=document.querySelector(e);return t(!E,`Couldn't find an element with selector ${e}!`),E.replaceChildren(this.iframe),this.messagingService=new i({target:this.iframe.contentWindow,targetOrigin:S}),this.isCommunicationReady=new Promise(y=>{var l;const g=u=>{var d;u.data.type==="sdk:init"&&(y(),(d=this.messagingService)==null||d.removeListener(g))};(l=this.messagingService)==null||l.onReceive(g)}),this.messagingService.onReceive((y,g)=>{var d,k,I,C;const{type:l,data:u}=y.data;switch(l){case"sdk:init":{g({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(k=(d=this.options).onComplete)==null||k.call(d,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(C=(I=this.options).onFail)==null||C.call(I,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}}}),this.isCommunicationReady}setLocale(e){return b(this,null,function*(){var r;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(r=this.messagingService)==null||r.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return b(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class h{constructor(e){a(this,"options");a(this,"sdkEmbed");this.options=e,this.sdkEmbed=new f(e)}start({selector:e,intentId:r}){return t(!e,"selector is required for start"),t(!r,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:r})}setLocale(e){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}}return h}); |
{ | ||
"name": "@moneyhash/js-sdk", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "MoneyHash JavaScript SDK", | ||
@@ -5,0 +5,0 @@ "type": "module", |
358855
2086