@moneyhash/js-sdk
Advanced tools
Comparing version 1.0.0-beta.1 to 1.0.0-beta.2
@@ -1,1 +0,1 @@ | ||
"use strict";var N=Object.defineProperty,q=Object.defineProperties;var H=Object.getOwnPropertyDescriptors;var R=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable;var I=(a,e,t)=>e in a?N(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,S=(a,e)=>{for(var t in e||(e={}))W.call(e,t)&&I(a,t,e[t]);if(R)for(var t of R(e))D.call(e,t)&&I(a,t,e[t]);return a},_=(a,e)=>q(a,H(e));var m=(a,e,t)=>(I(a,typeof e!="symbol"?e+"":e,t),t),x=(a,e,t)=>{if(!e.has(a))throw TypeError("Cannot "+t)};var v=(a,e,t)=>{if(e.has(a))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(a):e.set(a,t)};var P=(a,e,t)=>(x(a,e,"access private method"),t);var w=(a,e,t)=>new Promise((i,s)=>{var n=o=>{try{r(t.next(o))}catch(c){s(c)}},d=o=>{try{r(t.throw(o))}catch(c){s(c)}},r=o=>o.done?i(o.value):Promise.resolve(o.value).then(n,d);r((t=t.apply(a,e)).next())});const u=require("./sdkEmbed-4faaafcd.cjs");function B(){return typeof window!="undefined"}const h=class{constructor(){B()&&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.0-beta.1");const i=document.createElement("iframe");i.id="moneyhash-headless-sdk",i.src=t.toString(),i.hidden=!0,document.body.appendChild(i),h.messagingService=new u.MessagingService({target:i.contentWindow,targetOrigin:e}),h.isCommunicationReady=new Promise(s=>{var d;const n=r=>{var o;r.data.type==="headlessSDK:init"&&(s(),(o=h.messagingService)==null||o.removeListener(n))};(d=h.messagingService)==null||d.onReceive(n)})}request(i){return w(this,arguments,function*({api:e,payload:t}){return yield h.isCommunicationReady,new Promise((s,n)=>{var r,o;(r=h.messagingService)==null||r.send({type:e,data:t});const d=c=>{var y;const{type:l,data:p}=c.data;l===e&&(p.status==="resolved"?s(p.payload):n(p.payload),(y=h.messagingService)==null||y.removeListener(d))};(o=h.messagingService)==null||o.onReceive(d)})})}};let b=h;m(b,"messagingService",null),m(b,"isCommunicationReady");class Y{constructor(){m(this,"promise");m(this,"resolve");m(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function J(){return"https://vault-staging.moneyhash.io"}function C(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:{}.VITE_VAULT_INPUT_IFRAME_URL}function O(a){return(Array.isArray(a)?a.length:Object.keys(a).length)===0}function z(a,e){return new Promise((t,i)=>{if(document.getElementById(e)){t(void 0);return}const n=document.createElement("script");n.src=a,n.id=e,n.addEventListener("load",()=>{t(void 0)}),n.addEventListener("error",()=>{i(new Error("Script failed to load"))}),document.body.appendChild(n)})}function T(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}const M=new Set(["method","customerBalance","savedCard"]);var L,F,A,V,k,$,E,j;class K{constructor(e){v(this,L);v(this,A);v(this,k);v(this,E);m(this,"options");m(this,"sdkApiHandler",new b);m(this,"sdkEmbed");m(this,"vaultSubmitListener",{current:null});this.options=e,this.sdkEmbed=new u.SDKEmbed(_(S({},e),{headless:!0})),P(this,A,V).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:i,metaData:s}){return u.throwIf(!M.has(t),`type must be a valid one (${[...M].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:i,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 w(this,arguments,function*({intentId:e,currency:t,amount:i,countryCode:s,onCancel:n=()=>{},onError:d,onComplete:r,billingData:o={}}){if(yield z("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:`${i}`}}),{__providerId__:p,state:y,intent:U}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(y==="INTENT_FORM"){if(O(o))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",providerId:p,lang:this.sdkEmbed.lang,billingData:o}})}}catch(f){throw yield this.resetSelectedMethod(e),f}l.onvalidatemerchant=f=>{fetch(`${T()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:U.secret,validation_url:f.validationURL})}).then(g=>g.ok?g.json():Promise.reject()).then(g=>l.completeMerchantValidation(g)).catch(d)},l.onpaymentauthorized=f=>{fetch(`${T()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:f.payment.token,secret:U.secret})}).then(g=>g.ok?g.json():Promise.reject()).then(()=>{l.completePayment(ApplePaySession.STATUS_SUCCESS),r()}).catch(()=>{l.completePayment(ApplePaySession.STATUS_FAILURE),d()})},l.oncancel=n,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(t){return w(this,arguments,function*({styles:e}){const i=[];return P(this,L,F).call(this,i),{create:({elementType:s,elementOptions:n})=>{const d=new Map,r=document.querySelector(n.selector);return u.throwIf(!r,`Couldn't find an element with selector ${n.selector}!`),r.classList.add("moneyhash-element"),i.push(o=>{var l,p;const{type:c}=o.data;c===`${s}@focus`&&(r.classList.add("moneyhash-focus"),(l=d.get(`${s}@focus`))==null||l()),c===`${s}@blur`&&(r.classList.remove("moneyhash-focus"),(p=d.get(`${s}@blur`))==null||p())}),{mount:()=>P(this,k,$).call(this,{container:r,elementType:s,elementOptions:n,styles:S(S({},e),n.styles)}),on:(o,c)=>{d.set(`${s}@${o}`,c)}}}}})}submitForm(d){return w(this,arguments,function*({intentId:e,accessToken:t,providerId:i,billingData:s,shippingData:n}){const r=new Y;let o,c;t&&(this.vaultSubmitListener.current=l=>{const{type:p,data:y}=l.data;p==="vaultSubmit:success"&&r.resolve(y),p==="vaultSubmit:error"&&r.reject(y)},c=P(this,E,j).call(this,t),o=yield r.promise),yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",providerId:i,lang:this.sdkEmbed.lang,billingData:s,shippingData:n,cardEmbed:o}}),c&&c.remove()})}}L=new WeakSet,F=function(e){const t=i=>{e.forEach(s=>{s(i)})};window.addEventListener("message",t)},A=new WeakSet,V=function(e){const t=i=>{e.current&&e.current(i)};window.addEventListener("message",t)},k=new WeakSet,$=function({container:e,elementType:t,elementOptions:i,styles:s}){var o,c;const n=C(),d=new URL(`${n}/vaultField/vaultField.html`);d.searchParams.set("parent",window.location.origin),d.searchParams.set("type",t),d.searchParams.set("placeholder",(o=i.placeholder)!=null?o:""),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 r=document.createElement("iframe");r.src=d.toString(),r.style.height=(c=i.height)!=null?c:"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)},E=new WeakSet,j=function(e){const t=C(),i=J(),s=new URL(`${t}/vaultSubmit/vaultSubmit.html`);s.searchParams.set("parent",window.location.origin),s.searchParams.set("vault_api_url",`${i}/api/v1/tokens/`),s.searchParams.set("access_token",e);const n=document.createElement("iframe");return n.id="moneyhash-submit-iframe",n.src=s.toString(),n.hidden=!0,document.body.appendChild(n),n};module.exports=K; | ||
"use strict";var B=Object.defineProperty,O=Object.defineProperties;var Y=Object.getOwnPropertyDescriptors;var M=Object.getOwnPropertySymbols;var J=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var _=(a,e,t)=>e in a?B(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,k=(a,e)=>{for(var t in e||(e={}))J.call(e,t)&&_(a,t,e[t]);if(M)for(var t of M(e))z.call(e,t)&&_(a,t,e[t]);return a},F=(a,e)=>O(a,Y(e));var p=(a,e,t)=>(_(a,typeof e!="symbol"?e+"":e,t),t),K=(a,e,t)=>{if(!e.has(a))throw TypeError("Cannot "+t)};var u=(a,e,t)=>{if(e.has(a))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(a):e.set(a,t)};var y=(a,e,t)=>(K(a,e,"access private method"),t);var w=(a,e,t)=>new Promise((r,s)=>{var d=o=>{try{n(t.next(o))}catch(l){s(l)}},i=o=>{try{n(t.throw(o))}catch(l){s(l)}},n=o=>o.done?r(o.value):Promise.resolve(o.value).then(d,i);n((t=t.apply(a,e)).next())});const g=require("./sdkEmbed-b6ce67bb.cjs");function G(){return typeof window!="undefined"}const m=class{constructor(){G()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=g.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.0-beta.2");const r=document.createElement("iframe");r.id="moneyhash-headless-sdk",r.src=t.toString(),r.hidden=!0,document.body.appendChild(r),m.messagingService=new g.MessagingService({target:r.contentWindow,targetOrigin:e}),m.isCommunicationReady=new Promise(s=>{var i;const d=n=>{var o;n.data.type==="headlessSDK:init"&&(s(),(o=m.messagingService)==null||o.removeListener(d))};(i=m.messagingService)==null||i.onReceive(d)})}request(r){return w(this,arguments,function*({api:e,payload:t}){return yield m.isCommunicationReady,new Promise((s,d)=>{var n,o;(n=m.messagingService)==null||n.send({type:e,data:t});const i=l=>{var b;const{type:c,data:h}=l.data;c===e&&(h.status==="resolved"?s(h.payload):d(h.payload),(b=m.messagingService)==null||b.removeListener(i))};(o=m.messagingService)==null||o.onReceive(i)})})}};let P=m;p(P,"messagingService",null),p(P,"isCommunicationReady");class Q{constructor(){p(this,"promise");p(this,"resolve");p(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function X(){return"https://vault-staging.moneyhash.io"}function T(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault.moneyhash.io"}function Z(a){return(Array.isArray(a)?a.length:Object.keys(a).length)===0}function ee(a,e){return new Promise((t,r)=>{if(document.getElementById(e)){t(void 0);return}const d=document.createElement("script");d.src=a,d.id=e,d.addEventListener("load",()=>{t(void 0)}),d.addEventListener("error",()=>{r(new Error("Script failed to load"))}),document.body.appendChild(d)})}function $(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}const j=new Set(["method","customerBalance","savedCard"]);var S,q,I,V,A,N,E,H,L,W,U,D,R,x;class te{constructor(e){u(this,S);u(this,I);u(this,A);u(this,E);u(this,L);u(this,U);u(this,R);p(this,"options");p(this,"sdkApiHandler",new P);p(this,"sdkEmbed");p(this,"vaultSubmitListener",{current:null});this.options=e,this.sdkEmbed=new g.SDKEmbed(F(k({},e),{headless:!0})),y(this,L,W).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 g.throwIf(!j.has(t),`type must be a valid one (${[...j].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 g.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(l){return w(this,arguments,function*({intentId:e,currency:t,amount:r,countryCode:s,onCancel:d=()=>{},onError:i,onComplete:n,billingData:o={}}){if(yield ee("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const c=new ApplePaySession(3,{countryCode:s,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${r}`}}),{__providerId__:h,state:b,intent:C}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(b==="INTENT_FORM"){if(Z(o))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",providerId:h,lang:this.sdkEmbed.lang,billingData:o}})}}catch(v){throw yield this.resetSelectedMethod(e),v}c.onvalidatemerchant=v=>{fetch(`${$()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:C.secret,validation_url:v.validationURL})}).then(f=>f.ok?f.json():Promise.reject()).then(f=>c.completeMerchantValidation(f)).catch(i)},c.onpaymentauthorized=v=>{fetch(`${$()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:v.payment.token,secret:C.secret})}).then(f=>f.ok?f.json():Promise.reject()).then(()=>{c.completePayment(ApplePaySession.STATUS_SUCCESS),n()}).catch(()=>{c.completePayment(ApplePaySession.STATUS_FAILURE),i()})},c.oncancel=d,c.begin()})}renderForm({selector:e,intentId:t}){return g.throwIf(!e,"selector is required for renderForm"),g.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 y(this,E,H).call(this,t),{create:({elementType:r,elementOptions:s})=>{const d=new Map,i=document.querySelector(s.selector);return g.throwIf(!i,`Couldn't find an element with selector ${s.selector}!`),i.classList.add("moneyhash-element"),t.push(n=>{var l,c;const{type:o}=n.data;o===`${r}@focus`&&(i.classList.add("moneyhash-element_focus"),(l=d.get(`${r}@focus`))==null||l()),o===`${r}@blur`&&(i.classList.remove("moneyhash-element_focus"),(c=d.get(`${r}@blur`))==null||c())}),{mount:()=>y(this,U,D).call(this,{container:i,elementType:r,elementOptions:s,styles:k(k({},e),s.styles)}),on:(n,o)=>{d.set(`${r}@${n}`,o)}}}}}submitForm(d){return w(this,arguments,function*({intentId:e,accessToken:t,billingData:r,shippingData:s}){const i=new Q;let n,o;t&&(this.vaultSubmitListener.current=l=>{const{type:c,data:h}=l.data;c==="vaultSubmit:success"&&i.resolve(h),c==="vaultSubmit:error"&&i.reject(h)},o=y(this,R,x).call(this,t),n=yield i.promise),yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:r,shippingData:s,cardEmbed:n}}),o&&o.remove()})}submitCvv(r){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){switch(t){case"IFRAME":return y(this,S,q).call(this,e);case"POPUP_IFRAME":return y(this,I,V).call(this,e);case"REDIRECT":return y(this,A,N).call(this,e);default:return null}}}S=new WeakSet,q=function(e){const t=document.querySelector("#rendered-url-iframe-container"),r=document.createElement("iframe");return r.src=e,r.style.setProperty("border","0","important"),r.style.setProperty("width","100vw","important"),r.style.setProperty("height","100vh","important"),t==null||t.replaceChildren(r),r},I=new WeakSet,V=function(e){return window.open(`${e}`,"","width=600,height=400,left=200,top=200")},A=new WeakSet,N=function(e){return window.open(e,"_blank")},E=new WeakSet,H=function(e){const t=r=>{e.forEach(s=>{s(r)})};window.addEventListener("message",t)},L=new WeakSet,W=function(e){const t=r=>{e.current&&e.current(r)};window.addEventListener("message",t)},U=new WeakSet,D=function({container:e,elementType:t,elementOptions:r,styles:s}){var o,l;const d=T(),i=new URL(`${d}/vaultField/vaultField.html`);i.searchParams.set("parent",window.location.origin),i.searchParams.set("type",t),i.searchParams.set("placeholder",(o=r.placeholder)!=null?o:""),i.searchParams.set("color",(s==null?void 0:s.color)||"#000"),i.searchParams.set("placeholderColor",(s==null?void 0:s.placeholderColor)||"#ccc"),i.searchParams.set("backgroundColor",(s==null?void 0:s.backgroundColor)||"transparent");const n=document.createElement("iframe");n.src=i.toString(),n.style.height=(l=r.height)!=null?l:"40px",n.style.setProperty("overflow","hidden","important"),n.style.setProperty("display","block","important"),n.style.setProperty("width","100%","important"),n.style.setProperty("maxWidth","100%","important"),n.style.setProperty("border","0","important"),n.style.setProperty("margin","0","important"),n.style.setProperty("padding","0","important"),n.style.setProperty("userSelect","none","important"),n.style.setProperty("colorScheme","light only","important"),e.replaceChildren(n)},R=new WeakSet,x=function(e){const t=T(),r=X(),s=new URL(`${t}/vaultSubmit/vaultSubmit.html`);s.searchParams.set("parent",window.location.origin),s.searchParams.set("vault_api_url",`${r}/api/v1/tokens/`),s.searchParams.set("access_token",e);const d=document.createElement("iframe");return d.id="moneyhash-submit-iframe",d.src=s.toString(),d.hidden=!0,document.body.appendChild(d),d};module.exports=te; |
@@ -424,3 +424,3 @@ export declare interface AbstractIntent { | ||
removeEventListeners(): Promise<void>; | ||
elements({ styles }: ElementsProps): Promise<{ | ||
elements({ styles }: ElementsProps): { | ||
create: ({ elementType, elementOptions }: ElementProps) => { | ||
@@ -430,10 +430,14 @@ mount: () => void; | ||
}; | ||
}>; | ||
submitForm({ intentId, accessToken, providerId, billingData, shippingData, }: { | ||
}; | ||
submitForm({ intentId, accessToken, billingData, shippingData, }: { | ||
intentId: string; | ||
accessToken?: string | null; | ||
providerId: string | null; | ||
billingData?: Record<string, unknown>; | ||
shippingData?: Record<string, unknown>; | ||
}): Promise<void>; | ||
submitCvv({ intentId, cvv }: { | ||
intentId: string; | ||
cvv: string; | ||
}): Promise<IntentDetails<TType>>; | ||
renderUrl(url: string, renderStrategy: "IFRAME" | "POPUP_IFRAME" | "REDIRECT"): HTMLIFrameElement | Window | null; | ||
} | ||
@@ -440,0 +444,0 @@ export default MoneyHashHeadless; |
@@ -1,18 +0,18 @@ | ||
var N = Object.defineProperty, q = Object.defineProperties; | ||
var H = Object.getOwnPropertyDescriptors; | ||
var R = Object.getOwnPropertySymbols; | ||
var W = Object.prototype.hasOwnProperty, D = Object.prototype.propertyIsEnumerable; | ||
var I = (a, e, t) => e in a ? N(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t, S = (a, e) => { | ||
var B = Object.defineProperty, O = Object.defineProperties; | ||
var Y = Object.getOwnPropertyDescriptors; | ||
var M = Object.getOwnPropertySymbols; | ||
var J = Object.prototype.hasOwnProperty, z = Object.prototype.propertyIsEnumerable; | ||
var _ = (a, e, t) => e in a ? B(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t, S = (a, e) => { | ||
for (var t in e || (e = {})) | ||
W.call(e, t) && I(a, t, e[t]); | ||
if (R) | ||
for (var t of R(e)) | ||
D.call(e, t) && I(a, t, e[t]); | ||
J.call(e, t) && _(a, t, e[t]); | ||
if (M) | ||
for (var t of M(e)) | ||
z.call(e, t) && _(a, t, e[t]); | ||
return a; | ||
}, _ = (a, e) => q(a, H(e)); | ||
var m = (a, e, t) => (I(a, typeof e != "symbol" ? e + "" : e, t), t), x = (a, e, t) => { | ||
}, F = (a, e) => O(a, Y(e)); | ||
var p = (a, e, t) => (_(a, typeof e != "symbol" ? e + "" : e, t), t), K = (a, e, t) => { | ||
if (!e.has(a)) | ||
throw TypeError("Cannot " + t); | ||
}; | ||
var f = (a, e, t) => { | ||
var u = (a, e, t) => { | ||
if (e.has(a)) | ||
@@ -22,26 +22,26 @@ throw TypeError("Cannot add the same private member more than once"); | ||
}; | ||
var v = (a, e, t) => (x(a, e, "access private method"), t); | ||
var P = (a, e, t) => new Promise((i, s) => { | ||
var n = (o) => { | ||
var y = (a, e, t) => (K(a, e, "access private method"), t); | ||
var v = (a, e, t) => new Promise((r, s) => { | ||
var d = (o) => { | ||
try { | ||
r(t.next(o)); | ||
} catch (c) { | ||
s(c); | ||
n(t.next(o)); | ||
} catch (l) { | ||
s(l); | ||
} | ||
}, d = (o) => { | ||
}, i = (o) => { | ||
try { | ||
r(t.throw(o)); | ||
} catch (c) { | ||
s(c); | ||
n(t.throw(o)); | ||
} catch (l) { | ||
s(l); | ||
} | ||
}, r = (o) => o.done ? i(o.value) : Promise.resolve(o.value).then(n, d); | ||
r((t = t.apply(a, e)).next()); | ||
}, n = (o) => o.done ? r(o.value) : Promise.resolve(o.value).then(d, i); | ||
n((t = t.apply(a, e)).next()); | ||
}); | ||
import { M as B, g as Y, S as J, t as w } from "./sdkEmbed-1f18cb9b.js"; | ||
function O() { | ||
import { M as G, g as Q, S as X, t as P } from "./sdkEmbed-7e9def06.js"; | ||
function Z() { | ||
return typeof window != "undefined"; | ||
} | ||
const h = class { | ||
const m = class { | ||
constructor() { | ||
O() && this.initSDKCommunicationIframe(); | ||
Z() && this.initSDKCommunicationIframe(); | ||
} | ||
@@ -51,34 +51,34 @@ initSDKCommunicationIframe() { | ||
return; | ||
const e = Y(), 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.0-beta.1"); | ||
const i = document.createElement("iframe"); | ||
i.id = "moneyhash-headless-sdk", i.src = t.toString(), i.hidden = !0, document.body.appendChild(i), h.messagingService = new B({ | ||
target: i.contentWindow, | ||
const e = Q(), 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.0-beta.2"); | ||
const r = document.createElement("iframe"); | ||
r.id = "moneyhash-headless-sdk", r.src = t.toString(), r.hidden = !0, document.body.appendChild(r), m.messagingService = new G({ | ||
target: r.contentWindow, | ||
targetOrigin: e | ||
}), h.isCommunicationReady = new Promise((s) => { | ||
var d; | ||
const n = (r) => { | ||
}), m.isCommunicationReady = new Promise((s) => { | ||
var i; | ||
const d = (n) => { | ||
var o; | ||
r.data.type === "headlessSDK:init" && (s(), (o = h.messagingService) == null || o.removeListener(n)); | ||
n.data.type === "headlessSDK:init" && (s(), (o = m.messagingService) == null || o.removeListener(d)); | ||
}; | ||
(d = h.messagingService) == null || d.onReceive(n); | ||
(i = m.messagingService) == null || i.onReceive(d); | ||
}); | ||
} | ||
request(i) { | ||
return P(this, arguments, function* ({ | ||
request(r) { | ||
return v(this, arguments, function* ({ | ||
api: e, | ||
payload: t | ||
}) { | ||
return yield h.isCommunicationReady, new Promise((s, n) => { | ||
var r, o; | ||
(r = h.messagingService) == null || r.send({ | ||
return yield m.isCommunicationReady, new Promise((s, d) => { | ||
var n, o; | ||
(n = m.messagingService) == null || n.send({ | ||
type: e, | ||
data: t | ||
}); | ||
const d = (c) => { | ||
var u; | ||
const { type: l, data: p } = c.data; | ||
l === e && (p.status === "resolved" ? s(p.payload) : n(p.payload), (u = h.messagingService) == null || u.removeListener(d)); | ||
const i = (l) => { | ||
var b; | ||
const { type: c, data: h } = l.data; | ||
c === e && (h.status === "resolved" ? s(h.payload) : d(h.payload), (b = m.messagingService) == null || b.removeListener(i)); | ||
}; | ||
(o = h.messagingService) == null || o.onReceive(d); | ||
(o = m.messagingService) == null || o.onReceive(i); | ||
}); | ||
@@ -88,9 +88,9 @@ }); | ||
}; | ||
let b = h; | ||
m(b, "messagingService", null), m(b, "isCommunicationReady"); | ||
class z { | ||
let w = m; | ||
p(w, "messagingService", null), p(w, "isCommunicationReady"); | ||
class ee { | ||
constructor() { | ||
m(this, "promise"); | ||
m(this, "resolve"); | ||
m(this, "reject"); | ||
p(this, "promise"); | ||
p(this, "resolve"); | ||
p(this, "reject"); | ||
this.promise = new Promise((e, t) => { | ||
@@ -101,14 +101,14 @@ this.resolve = e, this.reject = t; | ||
} | ||
function K() { | ||
function te() { | ||
return "https://vault-staging.moneyhash.io"; | ||
} | ||
function C() { | ||
function T() { | ||
var e; | ||
return (e = window.MONEYHASH_VAULT_INPUT_IFRAME_URL) != null ? e : {}.VITE_VAULT_INPUT_IFRAME_URL; | ||
return (e = window.MONEYHASH_VAULT_INPUT_IFRAME_URL) != null ? e : "https://vault.moneyhash.io"; | ||
} | ||
function G(a) { | ||
function re(a) { | ||
return (Array.isArray(a) ? a.length : Object.keys(a).length) === 0; | ||
} | ||
function Q(a, e) { | ||
return new Promise((t, i) => { | ||
function se(a, e) { | ||
return new Promise((t, r) => { | ||
if (document.getElementById(e)) { | ||
@@ -118,15 +118,15 @@ t(void 0); | ||
} | ||
const n = document.createElement("script"); | ||
n.src = a, n.id = e, n.addEventListener("load", () => { | ||
const d = document.createElement("script"); | ||
d.src = a, d.id = e, d.addEventListener("load", () => { | ||
t(void 0); | ||
}), n.addEventListener("error", () => { | ||
i(new Error("Script failed to load")); | ||
}), document.body.appendChild(n); | ||
}), d.addEventListener("error", () => { | ||
r(new Error("Script failed to load")); | ||
}), document.body.appendChild(d); | ||
}); | ||
} | ||
function M() { | ||
function $() { | ||
var e; | ||
return (e = window.API_URL) != null ? e : "https://web.moneyhash.io"; | ||
} | ||
const T = /* @__PURE__ */ new Set([ | ||
const j = /* @__PURE__ */ new Set([ | ||
"method", | ||
@@ -136,16 +136,19 @@ "customerBalance", | ||
]); | ||
var L, F, A, V, k, $, E, j; | ||
class ee { | ||
var k, V, A, q, E, N, L, H, I, W, U, D, R, x; | ||
class ie { | ||
constructor(e) { | ||
f(this, L); | ||
f(this, A); | ||
f(this, k); | ||
f(this, E); | ||
m(this, "options"); | ||
m(this, "sdkApiHandler", new b()); | ||
m(this, "sdkEmbed"); | ||
m(this, "vaultSubmitListener", { | ||
u(this, k); | ||
u(this, A); | ||
u(this, E); | ||
u(this, L); | ||
u(this, I); | ||
u(this, U); | ||
u(this, R); | ||
p(this, "options"); | ||
p(this, "sdkApiHandler", new w()); | ||
p(this, "sdkEmbed"); | ||
p(this, "vaultSubmitListener", { | ||
current: null | ||
}); | ||
this.options = e, this.sdkEmbed = new J(_(S({}, e), { headless: !0 })), v(this, A, V).call(this, this.vaultSubmitListener); | ||
this.options = e, this.sdkEmbed = new X(F(S({}, e), { headless: !0 })), y(this, I, W).call(this, this.vaultSubmitListener); | ||
} | ||
@@ -241,8 +244,8 @@ /** | ||
type: t, | ||
id: i, | ||
id: r, | ||
metaData: s | ||
}) { | ||
return w( | ||
!T.has(t), | ||
`type must be a valid one (${[...T].join( | ||
return P( | ||
!j.has(t), | ||
`type must be a valid one (${[...j].join( | ||
" | " | ||
@@ -256,3 +259,3 @@ )})` | ||
intentId: e, | ||
id: i, | ||
id: r, | ||
lang: this.sdkEmbed.lang, | ||
@@ -305,3 +308,3 @@ metaData: s | ||
}) { | ||
return w( | ||
return P( | ||
this.options.type === "payout", | ||
@@ -356,15 +359,15 @@ "deleteCard is allowed only for payment intent!" | ||
*/ | ||
payWithApplePay(c) { | ||
return P(this, arguments, function* ({ | ||
payWithApplePay(l) { | ||
return v(this, arguments, function* ({ | ||
intentId: e, | ||
currency: t, | ||
amount: i, | ||
amount: r, | ||
countryCode: s, | ||
onCancel: n = () => { | ||
onCancel: d = () => { | ||
}, | ||
onError: d, | ||
onComplete: r, | ||
onError: i, | ||
onComplete: n, | ||
billingData: o = {} | ||
}) { | ||
if (yield Q( | ||
if (yield se( | ||
"https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js", | ||
@@ -374,3 +377,3 @@ "moneyHash-apple-pay-sdk" | ||
return; | ||
const l = new ApplePaySession(3, { | ||
const c = new ApplePaySession(3, { | ||
countryCode: s, | ||
@@ -383,8 +386,8 @@ currencyCode: t, | ||
type: "final", | ||
amount: `${i}` | ||
amount: `${r}` | ||
} | ||
}), { | ||
__providerId__: p, | ||
state: u, | ||
intent: U | ||
__providerId__: h, | ||
state: b, | ||
intent: C | ||
} = yield this.proceedWith({ | ||
@@ -396,4 +399,4 @@ intentId: e, | ||
try { | ||
if (u === "INTENT_FORM") { | ||
if (G(o)) | ||
if (b === "INTENT_FORM") { | ||
if (re(o)) | ||
throw new Error( | ||
@@ -407,3 +410,3 @@ "Billing data is missing while calling payWithApplePay" | ||
paymentMethod: "APPLE_PAY", | ||
providerId: p, | ||
providerId: h, | ||
lang: this.sdkEmbed.lang, | ||
@@ -414,7 +417,7 @@ billingData: o | ||
} | ||
} catch (g) { | ||
throw yield this.resetSelectedMethod(e), g; | ||
} catch (f) { | ||
throw yield this.resetSelectedMethod(e), f; | ||
} | ||
l.onvalidatemerchant = (g) => { | ||
fetch(`${M()}/api/v1/providers/applepay/session/`, { | ||
c.onvalidatemerchant = (f) => { | ||
fetch(`${$()}/api/v1/providers/applepay/session/`, { | ||
method: "post", | ||
@@ -425,10 +428,10 @@ headers: { | ||
body: JSON.stringify({ | ||
secret: U.secret, | ||
validation_url: g.validationURL | ||
secret: C.secret, | ||
validation_url: f.validationURL | ||
}) | ||
}).then((y) => y.ok ? y.json() : Promise.reject()).then( | ||
(y) => l.completeMerchantValidation(y) | ||
).catch(d); | ||
}, l.onpaymentauthorized = (g) => { | ||
fetch(`${M()}/api/v1/providers/applepay/token/`, { | ||
}).then((g) => g.ok ? g.json() : Promise.reject()).then( | ||
(g) => c.completeMerchantValidation(g) | ||
).catch(i); | ||
}, c.onpaymentauthorized = (f) => { | ||
fetch(`${$()}/api/v1/providers/applepay/token/`, { | ||
method: "post", | ||
@@ -439,11 +442,11 @@ headers: { | ||
body: JSON.stringify({ | ||
token_data: g.payment.token, | ||
secret: U.secret | ||
token_data: f.payment.token, | ||
secret: C.secret | ||
}) | ||
}).then((y) => y.ok ? y.json() : Promise.reject()).then(() => { | ||
l.completePayment(ApplePaySession.STATUS_SUCCESS), r(); | ||
}).then((g) => g.ok ? g.json() : Promise.reject()).then(() => { | ||
c.completePayment(ApplePaySession.STATUS_SUCCESS), n(); | ||
}).catch(() => { | ||
l.completePayment(ApplePaySession.STATUS_FAILURE), d(); | ||
c.completePayment(ApplePaySession.STATUS_FAILURE), i(); | ||
}); | ||
}, l.oncancel = n, l.begin(); | ||
}, c.oncancel = d, c.begin(); | ||
}); | ||
@@ -468,3 +471,3 @@ } | ||
renderForm({ selector: e, intentId: t }) { | ||
return w(!e, "selector is required for renderForm"), w(!t, "intentId is required for renderForm"), this.sdkEmbed.render({ selector: e, intentId: t }); | ||
return P(!e, "selector is required for renderForm"), P(!t, "intentId is required for renderForm"), this.sdkEmbed.render({ selector: e, intentId: t }); | ||
} | ||
@@ -493,46 +496,43 @@ /** | ||
} | ||
elements(t) { | ||
return P(this, arguments, function* ({ styles: e }) { | ||
const i = []; | ||
return v(this, L, F).call(this, i), { | ||
create: ({ elementType: s, elementOptions: n }) => { | ||
const d = /* @__PURE__ */ new Map(), r = document.querySelector( | ||
n.selector | ||
); | ||
return w( | ||
!r, | ||
`Couldn't find an element with selector ${n.selector}!` | ||
), r.classList.add("moneyhash-element"), i.push((o) => { | ||
var l, p; | ||
const { type: c } = o.data; | ||
c === `${s}@focus` && (r.classList.add("moneyhash-focus"), (l = d.get(`${s}@focus`)) == null || l()), c === `${s}@blur` && (r.classList.remove("moneyhash-focus"), (p = d.get(`${s}@blur`)) == null || p()); | ||
}), { | ||
mount: () => v(this, k, $).call(this, { | ||
container: r, | ||
elementType: s, | ||
elementOptions: n, | ||
styles: S(S({}, e), n.styles) | ||
}), | ||
on: (o, c) => { | ||
d.set(`${s}@${o}`, c); | ||
} | ||
}; | ||
} | ||
}; | ||
}); | ||
elements({ styles: e }) { | ||
const t = []; | ||
return y(this, L, H).call(this, t), { | ||
create: ({ elementType: r, elementOptions: s }) => { | ||
const d = /* @__PURE__ */ new Map(), i = document.querySelector( | ||
s.selector | ||
); | ||
return P( | ||
!i, | ||
`Couldn't find an element with selector ${s.selector}!` | ||
), i.classList.add("moneyhash-element"), t.push((n) => { | ||
var l, c; | ||
const { type: o } = n.data; | ||
o === `${r}@focus` && (i.classList.add("moneyhash-element_focus"), (l = d.get(`${r}@focus`)) == null || l()), o === `${r}@blur` && (i.classList.remove("moneyhash-element_focus"), (c = d.get(`${r}@blur`)) == null || c()); | ||
}), { | ||
mount: () => y(this, U, D).call(this, { | ||
container: i, | ||
elementType: r, | ||
elementOptions: s, | ||
styles: S(S({}, e), s.styles) | ||
}), | ||
on: (n, o) => { | ||
d.set(`${r}@${n}`, o); | ||
} | ||
}; | ||
} | ||
}; | ||
} | ||
submitForm(d) { | ||
return P(this, arguments, function* ({ | ||
return v(this, arguments, function* ({ | ||
intentId: e, | ||
accessToken: t, | ||
providerId: i, | ||
billingData: s, | ||
shippingData: n | ||
billingData: r, | ||
shippingData: s | ||
}) { | ||
const r = new z(); | ||
let o, c; | ||
const i = new ee(); | ||
let n, o; | ||
t && (this.vaultSubmitListener.current = (l) => { | ||
const { type: p, data: u } = l.data; | ||
p === "vaultSubmit:success" && r.resolve(u), p === "vaultSubmit:error" && r.reject(u); | ||
}, c = v(this, E, j).call(this, t), o = yield r.promise), yield this.sdkApiHandler.request({ | ||
const { type: c, data: h } = l.data; | ||
c === "vaultSubmit:success" && i.resolve(h), c === "vaultSubmit:error" && i.reject(h); | ||
}, o = y(this, R, x).call(this, t), n = yield i.promise), yield this.sdkApiHandler.request({ | ||
api: "sdk:submitNativeForm", | ||
@@ -542,51 +542,81 @@ payload: { | ||
paymentMethod: "CARD", | ||
providerId: i, | ||
lang: this.sdkEmbed.lang, | ||
billingData: s, | ||
shippingData: n, | ||
cardEmbed: o | ||
billingData: r, | ||
shippingData: s, | ||
cardEmbed: n | ||
} | ||
}), c && c.remove(); | ||
}), o && o.remove(); | ||
}); | ||
} | ||
submitCvv(r) { | ||
return v(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) { | ||
switch (t) { | ||
case "IFRAME": | ||
return y(this, k, V).call(this, e); | ||
case "POPUP_IFRAME": | ||
return y(this, A, q).call(this, e); | ||
case "REDIRECT": | ||
return y(this, E, N).call(this, e); | ||
default: | ||
return null; | ||
} | ||
} | ||
} | ||
L = new WeakSet(), F = function(e) { | ||
const t = (i) => { | ||
k = new WeakSet(), V = function(e) { | ||
const t = document.querySelector("#rendered-url-iframe-container"), r = document.createElement("iframe"); | ||
return r.src = e, r.style.setProperty("border", "0", "important"), r.style.setProperty("width", "100vw", "important"), r.style.setProperty("height", "100vh", "important"), t == null || t.replaceChildren(r), r; | ||
}, A = new WeakSet(), q = function(e) { | ||
return window.open(`${e}`, "", "width=600,height=400,left=200,top=200"); | ||
}, E = new WeakSet(), N = function(e) { | ||
return window.open(e, "_blank"); | ||
}, L = new WeakSet(), H = function(e) { | ||
const t = (r) => { | ||
e.forEach((s) => { | ||
s(i); | ||
s(r); | ||
}); | ||
}; | ||
window.addEventListener("message", t); | ||
}, A = new WeakSet(), V = function(e) { | ||
const t = (i) => { | ||
e.current && e.current(i); | ||
}, I = new WeakSet(), W = function(e) { | ||
const t = (r) => { | ||
e.current && e.current(r); | ||
}; | ||
window.addEventListener("message", t); | ||
}, k = new WeakSet(), $ = function({ | ||
}, U = new WeakSet(), D = function({ | ||
container: e, | ||
elementType: t, | ||
elementOptions: i, | ||
elementOptions: r, | ||
styles: s | ||
}) { | ||
var o, c; | ||
const n = C(), d = new URL(`${n}/vaultField/vaultField.html`); | ||
d.searchParams.set("parent", window.location.origin), d.searchParams.set("type", t), d.searchParams.set("placeholder", (o = i.placeholder) != null ? o : ""), d.searchParams.set("color", (s == null ? void 0 : s.color) || "#000"), d.searchParams.set( | ||
var o, l; | ||
const d = T(), i = new URL(`${d}/vaultField/vaultField.html`); | ||
i.searchParams.set("parent", window.location.origin), i.searchParams.set("type", t), i.searchParams.set("placeholder", (o = r.placeholder) != null ? o : ""), i.searchParams.set("color", (s == null ? void 0 : s.color) || "#000"), i.searchParams.set( | ||
"placeholderColor", | ||
(s == null ? void 0 : s.placeholderColor) || "#ccc" | ||
), d.searchParams.set( | ||
), i.searchParams.set( | ||
"backgroundColor", | ||
(s == null ? void 0 : s.backgroundColor) || "transparent" | ||
); | ||
const r = document.createElement("iframe"); | ||
r.src = d.toString(), r.style.height = (c = i.height) != null ? c : "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); | ||
}, E = new WeakSet(), j = function(e) { | ||
const t = C(), i = K(), s = new URL( | ||
const n = document.createElement("iframe"); | ||
n.src = i.toString(), n.style.height = (l = r.height) != null ? l : "40px", n.style.setProperty("overflow", "hidden", "important"), n.style.setProperty("display", "block", "important"), n.style.setProperty("width", "100%", "important"), n.style.setProperty("maxWidth", "100%", "important"), n.style.setProperty("border", "0", "important"), n.style.setProperty("margin", "0", "important"), n.style.setProperty("padding", "0", "important"), n.style.setProperty("userSelect", "none", "important"), n.style.setProperty("colorScheme", "light only", "important"), e.replaceChildren(n); | ||
}, R = new WeakSet(), x = function(e) { | ||
const t = T(), r = te(), s = new URL( | ||
`${t}/vaultSubmit/vaultSubmit.html` | ||
); | ||
s.searchParams.set("parent", window.location.origin), s.searchParams.set("vault_api_url", `${i}/api/v1/tokens/`), s.searchParams.set("access_token", e); | ||
const n = document.createElement("iframe"); | ||
return n.id = "moneyhash-submit-iframe", n.src = s.toString(), n.hidden = !0, document.body.appendChild(n), n; | ||
s.searchParams.set("parent", window.location.origin), s.searchParams.set("vault_api_url", `${r}/api/v1/tokens/`), s.searchParams.set("access_token", e); | ||
const d = document.createElement("iframe"); | ||
return d.id = "moneyhash-submit-iframe", d.src = s.toString(), d.hidden = !0, document.body.appendChild(d), d; | ||
}; | ||
export { | ||
ee as default | ||
ie as default | ||
}; |
@@ -1,1 +0,1 @@ | ||
(function(r,i){typeof exports=="object"&&typeof module!="undefined"?module.exports=i():typeof define=="function"&&define.amd?define(i):(r=typeof globalThis!="undefined"?globalThis:r||self,r.MoneyHash=i())})(this,function(){var C,O,M,x,F,D,T,Y;"use strict";var Q=Object.defineProperty,X=Object.defineProperties;var Z=Object.getOwnPropertyDescriptors;var W=Object.getOwnPropertySymbols;var ee=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable;var j=(r,i,d)=>i in r?Q(r,i,{enumerable:!0,configurable:!0,writable:!0,value:d}):r[i]=d,k=(r,i)=>{for(var d in i||(i={}))ee.call(i,d)&&j(r,d,i[d]);if(W)for(var d of W(i))te.call(i,d)&&j(r,d,i[d]);return r},B=(r,i)=>X(r,Z(i));var m=(r,i,d)=>(j(r,typeof i!="symbol"?i+"":i,d),d),se=(r,i,d)=>{if(!i.has(r))throw TypeError("Cannot "+d)};var I=(r,i,d)=>{if(i.has(r))throw TypeError("Cannot add the same private member more than once");i instanceof WeakSet?i.add(r):i.set(r,d)};var U=(r,i,d)=>(se(r,i,"access private method"),d);var R=(r,i,d)=>new Promise((L,f)=>{var $=S=>{try{E(d.next(S))}catch(A){f(A)}},_=S=>{try{E(d.throw(S))}catch(A){f(A)}},E=S=>S.done?L(S.value):Promise.resolve(S.value).then($,_);E((d=d.apply(r,i)).next())});class r{constructor(e){m(this,"target");m(this,"targetOrigin");m(this,"listeners");m(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 d(){return typeof window!="undefined"}const v=class{constructor(){d()&&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.0-beta.1");const o=document.createElement("iframe");o.id="moneyhash-headless-sdk",o.src=t.toString(),o.hidden=!0,document.body.appendChild(o),v.messagingService=new r({target:o.contentWindow,targetOrigin:e}),v.isCommunicationReady=new Promise(s=>{var c;const a=n=>{var l;n.data.type==="headlessSDK:init"&&(s(),(l=v.messagingService)==null||l.removeListener(a))};(c=v.messagingService)==null||c.onReceive(a)})}request(o){return R(this,arguments,function*({api:e,payload:t}){return yield v.isCommunicationReady,new Promise((s,a)=>{var n,l;(n=v.messagingService)==null||n.send({type:e,data:t});const c=u=>{var y;const{type:h,data:g}=u.data;h===e&&(g.status==="resolved"?s(g.payload):a(g.payload),(y=v.messagingService)==null||y.removeListener(c))};(l=v.messagingService)==null||l.onReceive(c)})})}};let L=v;m(L,"messagingService",null),m(L,"isCommunicationReady");function f(p,e){if(p)throw new Error(e)}function $(p,e){p&&console.warn(e)}const _=new Set(["payment","payout"]),E=new Set(["en","fr","ar"]);class S{constructor(e){m(this,"options");m(this,"messagingService",null);m(this,"iframe",null);m(this,"isCommunicationReady",null);f(!_.has(e.type),`MoneyHash constructor must be called with valid type (${[..._].join(" | ")})!`),this.options=e}get lang(){var t;const e=(t=this.options.locale)==null?void 0:t.split("-")[0];return $(!!e&&!E.has(e),`Supported languages (${[...E].join(" | ")})`),e||"en"}render({selector:e,intentId:t}){var n,l;(n=this.messagingService)==null||n.abortService();const o=i(),s=new URL(`${o}/embed/${this.options.type}/${t}`);s.searchParams.set("sdk","true"),s.searchParams.set("parent",window.location.origin),s.searchParams.set("version","js@1.0.0-beta.1");const a=(l=this.options.locale)==null?void 0:l.split("-")[0];a&&s.searchParams.set("lang",a),this.iframe=document.createElement("iframe"),this.iframe.src=s.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0";const c=document.querySelector(e);return f(!c,`Couldn't find an element with selector ${e}!`),c.replaceChildren(this.iframe),this.messagingService=new r({target:this.iframe.contentWindow,targetOrigin:o}),this.isCommunicationReady=new Promise(u=>{var g;const h=y=>{var b;y.data.type==="sdk:init"&&(u(),(b=this.messagingService)==null||b.removeListener(h))};(g=this.messagingService)==null||g.onReceive(h)}),this.messagingService.onReceive((u,h)=>{var b,P,w,q;const{type:g,data:y}=u.data;switch(g){case"sdk:init":{h({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(P=(b=this.options).onComplete)==null||P.call(b,k({type:this.options.type},y)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(q=(w=this.options).onFail)==null||q.call(w,k({type:this.options.type},y)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}}}),this.isCommunicationReady}setLocale(e){return R(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 R(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class A{constructor(){m(this,"promise");m(this,"resolve");m(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function J(){return"https://vault-staging.moneyhash.io"}function V(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:{}.VITE_VAULT_INPUT_IFRAME_URL}function z(p){return(Array.isArray(p)?p.length:Object.keys(p).length)===0}function K(p,e){return new Promise((t,o)=>{if(document.getElementById(e)){t(void 0);return}const a=document.createElement("script");a.src=p,a.id=e,a.addEventListener("load",()=>{t(void 0)}),a.addEventListener("error",()=>{o(new Error("Script failed to load"))}),document.body.appendChild(a)})}function N(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}const H=new Set(["method","customerBalance","savedCard"]);class G{constructor(e){I(this,C);I(this,M);I(this,F);I(this,T);m(this,"options");m(this,"sdkApiHandler",new L);m(this,"sdkEmbed");m(this,"vaultSubmitListener",{current:null});this.options=e,this.sdkEmbed=new S(B(k({},e),{headless:!0})),U(this,M,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:o,metaData:s}){return f(!H.has(t),`type must be a valid one (${[...H].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:o,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 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 R(this,arguments,function*({intentId:e,currency:t,amount:o,countryCode:s,onCancel:a=()=>{},onError:c,onComplete:n,billingData:l={}}){if(yield K("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const h=new ApplePaySession(3,{countryCode:s,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${o}`}}),{__providerId__:g,state:y,intent:b}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(y==="INTENT_FORM"){if(z(l))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",providerId:g,lang:this.sdkEmbed.lang,billingData:l}})}}catch(P){throw yield this.resetSelectedMethod(e),P}h.onvalidatemerchant=P=>{fetch(`${N()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:b.secret,validation_url:P.validationURL})}).then(w=>w.ok?w.json():Promise.reject()).then(w=>h.completeMerchantValidation(w)).catch(c)},h.onpaymentauthorized=P=>{fetch(`${N()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:P.payment.token,secret:b.secret})}).then(w=>w.ok?w.json():Promise.reject()).then(()=>{h.completePayment(ApplePaySession.STATUS_SUCCESS),n()}).catch(()=>{h.completePayment(ApplePaySession.STATUS_FAILURE),c()})},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(t){return R(this,arguments,function*({styles:e}){const o=[];return U(this,C,O).call(this,o),{create:({elementType:s,elementOptions:a})=>{const c=new Map,n=document.querySelector(a.selector);return f(!n,`Couldn't find an element with selector ${a.selector}!`),n.classList.add("moneyhash-element"),o.push(l=>{var h,g;const{type:u}=l.data;u===`${s}@focus`&&(n.classList.add("moneyhash-focus"),(h=c.get(`${s}@focus`))==null||h()),u===`${s}@blur`&&(n.classList.remove("moneyhash-focus"),(g=c.get(`${s}@blur`))==null||g())}),{mount:()=>U(this,F,D).call(this,{container:n,elementType:s,elementOptions:a,styles:k(k({},e),a.styles)}),on:(l,u)=>{c.set(`${s}@${l}`,u)}}}}})}submitForm(c){return R(this,arguments,function*({intentId:e,accessToken:t,providerId:o,billingData:s,shippingData:a}){const n=new A;let l,u;t&&(this.vaultSubmitListener.current=h=>{const{type:g,data:y}=h.data;g==="vaultSubmit:success"&&n.resolve(y),g==="vaultSubmit:error"&&n.reject(y)},u=U(this,T,Y).call(this,t),l=yield n.promise),yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",providerId:o,lang:this.sdkEmbed.lang,billingData:s,shippingData:a,cardEmbed:l}}),u&&u.remove()})}}return C=new WeakSet,O=function(e){const t=o=>{e.forEach(s=>{s(o)})};window.addEventListener("message",t)},M=new WeakSet,x=function(e){const t=o=>{e.current&&e.current(o)};window.addEventListener("message",t)},F=new WeakSet,D=function({container:e,elementType:t,elementOptions:o,styles:s}){var l,u;const a=V(),c=new URL(`${a}/vaultField/vaultField.html`);c.searchParams.set("parent",window.location.origin),c.searchParams.set("type",t),c.searchParams.set("placeholder",(l=o.placeholder)!=null?l:""),c.searchParams.set("color",(s==null?void 0:s.color)||"#000"),c.searchParams.set("placeholderColor",(s==null?void 0:s.placeholderColor)||"#ccc"),c.searchParams.set("backgroundColor",(s==null?void 0:s.backgroundColor)||"transparent");const n=document.createElement("iframe");n.src=c.toString(),n.style.height=(u=o.height)!=null?u:"40px",n.style.setProperty("overflow","hidden","important"),n.style.setProperty("display","block","important"),n.style.setProperty("width","100%","important"),n.style.setProperty("maxWidth","100%","important"),n.style.setProperty("border","0","important"),n.style.setProperty("margin","0","important"),n.style.setProperty("padding","0","important"),n.style.setProperty("userSelect","none","important"),n.style.setProperty("colorScheme","light only","important"),e.replaceChildren(n)},T=new WeakSet,Y=function(e){const t=V(),o=J(),s=new URL(`${t}/vaultSubmit/vaultSubmit.html`);s.searchParams.set("parent",window.location.origin),s.searchParams.set("vault_api_url",`${o}/api/v1/tokens/`),s.searchParams.set("access_token",e);const a=document.createElement("iframe");return a.id="moneyhash-submit-iframe",a.src=s.toString(),a.hidden=!0,document.body.appendChild(a),a},G}); | ||
(function(o,n){typeof exports=="object"&&typeof module!="undefined"?module.exports=n():typeof define=="function"&&define.amd?define(n):(o=typeof globalThis!="undefined"?globalThis:o||self,o.MoneyHash=n())})(this,function(){var _,Y,M,J,F,z,T,K,$,G,j,Q,H,X;"use strict";var ie=Object.defineProperty,ne=Object.defineProperties;var re=Object.getOwnPropertyDescriptors;var D=Object.getOwnPropertySymbols;var ae=Object.prototype.hasOwnProperty,oe=Object.prototype.propertyIsEnumerable;var N=(o,n,c)=>n in o?ie(o,n,{enumerable:!0,configurable:!0,writable:!0,value:c}):o[n]=c,A=(o,n)=>{for(var c in n||(n={}))ae.call(n,c)&&N(o,c,n[c]);if(D)for(var c of D(n))oe.call(n,c)&&N(o,c,n[c]);return o},x=(o,n)=>ne(o,re(n));var m=(o,n,c)=>(N(o,typeof n!="symbol"?n+"":n,c),c),de=(o,n,c)=>{if(!n.has(o))throw TypeError("Cannot "+c)};var L=(o,n,c)=>{if(n.has(o))throw TypeError("Cannot add the same private member more than once");n instanceof WeakSet?n.add(o):n.set(o,c)};var E=(o,n,c)=>(de(o,n,"access private method"),c);var k=(o,n,c)=>new Promise((R,y)=>{var q=w=>{try{I(c.next(w))}catch(U){y(U)}},C=w=>{try{I(c.throw(w))}catch(U){y(U)}},I=w=>w.done?R(w.value):Promise.resolve(w.value).then(q,C);I((c=c.apply(o,n)).next())});class o{constructor(e){m(this,"target");m(this,"targetOrigin");m(this,"listeners");m(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 n(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function c(){return typeof window!="undefined"}const f=class{constructor(){c()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=n(),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.0-beta.2");const s=document.createElement("iframe");s.id="moneyhash-headless-sdk",s.src=t.toString(),s.hidden=!0,document.body.appendChild(s),f.messagingService=new o({target:s.contentWindow,targetOrigin:e}),f.isCommunicationReady=new Promise(i=>{var r;const d=a=>{var l;a.data.type==="headlessSDK:init"&&(i(),(l=f.messagingService)==null||l.removeListener(d))};(r=f.messagingService)==null||r.onReceive(d)})}request(s){return k(this,arguments,function*({api:e,payload:t}){return yield f.isCommunicationReady,new Promise((i,d)=>{var a,l;(a=f.messagingService)==null||a.send({type:e,data:t});const r=u=>{var b;const{type:h,data:g}=u.data;h===e&&(g.status==="resolved"?i(g.payload):d(g.payload),(b=f.messagingService)==null||b.removeListener(r))};(l=f.messagingService)==null||l.onReceive(r)})})}};let R=f;m(R,"messagingService",null),m(R,"isCommunicationReady");function y(p,e){if(p)throw new Error(e)}function q(p,e){p&&console.warn(e)}const C=new Set(["payment","payout"]),I=new Set(["en","fr","ar"]);class w{constructor(e){m(this,"options");m(this,"messagingService",null);m(this,"iframe",null);m(this,"isCommunicationReady",null);y(!C.has(e.type),`MoneyHash constructor must be called with valid type (${[...C].join(" | ")})!`),this.options=e}get lang(){var t;const e=(t=this.options.locale)==null?void 0:t.split("-")[0];return q(!!e&&!I.has(e),`Supported languages (${[...I].join(" | ")})`),e||"en"}render({selector:e,intentId:t}){var a,l;(a=this.messagingService)==null||a.abortService();const s=n(),i=new URL(`${s}/embed/${this.options.type}/${t}`);i.searchParams.set("sdk","true"),i.searchParams.set("parent",window.location.origin),i.searchParams.set("version","js@1.0.0-beta.2");const d=(l=this.options.locale)==null?void 0:l.split("-")[0];d&&i.searchParams.set("lang",d),this.iframe=document.createElement("iframe"),this.iframe.src=i.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0";const r=document.querySelector(e);return y(!r,`Couldn't find an element with selector ${e}!`),r.replaceChildren(this.iframe),this.messagingService=new o({target:this.iframe.contentWindow,targetOrigin:s}),this.isCommunicationReady=new Promise(u=>{var g;const h=b=>{var P;b.data.type==="sdk:init"&&(u(),(P=this.messagingService)==null||P.removeListener(h))};(g=this.messagingService)==null||g.onReceive(h)}),this.messagingService.onReceive((u,h)=>{var P,S,v,B;const{type:g,data:b}=u.data;switch(g){case"sdk:init":{h({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(S=(P=this.options).onComplete)==null||S.call(P,A({type:this.options.type},b)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(B=(v=this.options).onFail)==null||B.call(v,A({type:this.options.type},b)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}}}),this.isCommunicationReady}setLocale(e){return k(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 k(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class U{constructor(){m(this,"promise");m(this,"resolve");m(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function Z(){return"https://vault-staging.moneyhash.io"}function V(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault.moneyhash.io"}function ee(p){return(Array.isArray(p)?p.length:Object.keys(p).length)===0}function te(p,e){return new Promise((t,s)=>{if(document.getElementById(e)){t(void 0);return}const d=document.createElement("script");d.src=p,d.id=e,d.addEventListener("load",()=>{t(void 0)}),d.addEventListener("error",()=>{s(new Error("Script failed to load"))}),document.body.appendChild(d)})}function O(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}const W=new Set(["method","customerBalance","savedCard"]);class se{constructor(e){L(this,_);L(this,M);L(this,F);L(this,T);L(this,$);L(this,j);L(this,H);m(this,"options");m(this,"sdkApiHandler",new R);m(this,"sdkEmbed");m(this,"vaultSubmitListener",{current:null});this.options=e,this.sdkEmbed=new w(x(A({},e),{headless:!0})),E(this,$,G).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:i}){return y(!W.has(t),`type must be a valid one (${[...W].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:s,lang:this.sdkEmbed.lang,metaData:i}})}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 y(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 k(this,arguments,function*({intentId:e,currency:t,amount:s,countryCode:i,onCancel:d=()=>{},onError:r,onComplete:a,billingData:l={}}){if(yield te("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const h=new ApplePaySession(3,{countryCode:i,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${s}`}}),{__providerId__:g,state:b,intent:P}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(b==="INTENT_FORM"){if(ee(l))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",providerId:g,lang:this.sdkEmbed.lang,billingData:l}})}}catch(S){throw yield this.resetSelectedMethod(e),S}h.onvalidatemerchant=S=>{fetch(`${O()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:P.secret,validation_url:S.validationURL})}).then(v=>v.ok?v.json():Promise.reject()).then(v=>h.completeMerchantValidation(v)).catch(r)},h.onpaymentauthorized=S=>{fetch(`${O()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:S.payment.token,secret:P.secret})}).then(v=>v.ok?v.json():Promise.reject()).then(()=>{h.completePayment(ApplePaySession.STATUS_SUCCESS),a()}).catch(()=>{h.completePayment(ApplePaySession.STATUS_FAILURE),r()})},h.oncancel=d,h.begin()})}renderForm({selector:e,intentId:t}){return y(!e,"selector is required for renderForm"),y(!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 E(this,T,K).call(this,t),{create:({elementType:s,elementOptions:i})=>{const d=new Map,r=document.querySelector(i.selector);return y(!r,`Couldn't find an element with selector ${i.selector}!`),r.classList.add("moneyhash-element"),t.push(a=>{var u,h;const{type:l}=a.data;l===`${s}@focus`&&(r.classList.add("moneyhash-element_focus"),(u=d.get(`${s}@focus`))==null||u()),l===`${s}@blur`&&(r.classList.remove("moneyhash-element_focus"),(h=d.get(`${s}@blur`))==null||h())}),{mount:()=>E(this,j,Q).call(this,{container:r,elementType:s,elementOptions:i,styles:A(A({},e),i.styles)}),on:(a,l)=>{d.set(`${s}@${a}`,l)}}}}}submitForm(d){return k(this,arguments,function*({intentId:e,accessToken:t,billingData:s,shippingData:i}){const r=new U;let a,l;t&&(this.vaultSubmitListener.current=u=>{const{type:h,data:g}=u.data;h==="vaultSubmit:success"&&r.resolve(g),h==="vaultSubmit:error"&&r.reject(g)},l=E(this,H,X).call(this,t),a=yield r.promise),yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:s,shippingData:i,cardEmbed:a}}),l&&l.remove()})}submitCvv(s){return k(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){switch(t){case"IFRAME":return E(this,_,Y).call(this,e);case"POPUP_IFRAME":return E(this,M,J).call(this,e);case"REDIRECT":return E(this,F,z).call(this,e);default:return null}}}return _=new WeakSet,Y=function(e){const t=document.querySelector("#rendered-url-iframe-container"),s=document.createElement("iframe");return s.src=e,s.style.setProperty("border","0","important"),s.style.setProperty("width","100vw","important"),s.style.setProperty("height","100vh","important"),t==null||t.replaceChildren(s),s},M=new WeakSet,J=function(e){return window.open(`${e}`,"","width=600,height=400,left=200,top=200")},F=new WeakSet,z=function(e){return window.open(e,"_blank")},T=new WeakSet,K=function(e){const t=s=>{e.forEach(i=>{i(s)})};window.addEventListener("message",t)},$=new WeakSet,G=function(e){const t=s=>{e.current&&e.current(s)};window.addEventListener("message",t)},j=new WeakSet,Q=function({container:e,elementType:t,elementOptions:s,styles:i}){var l,u;const d=V(),r=new URL(`${d}/vaultField/vaultField.html`);r.searchParams.set("parent",window.location.origin),r.searchParams.set("type",t),r.searchParams.set("placeholder",(l=s.placeholder)!=null?l:""),r.searchParams.set("color",(i==null?void 0:i.color)||"#000"),r.searchParams.set("placeholderColor",(i==null?void 0:i.placeholderColor)||"#ccc"),r.searchParams.set("backgroundColor",(i==null?void 0:i.backgroundColor)||"transparent");const a=document.createElement("iframe");a.src=r.toString(),a.style.height=(u=s.height)!=null?u:"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)},H=new WeakSet,X=function(e){const t=V(),s=Z(),i=new URL(`${t}/vaultSubmit/vaultSubmit.html`);i.searchParams.set("parent",window.location.origin),i.searchParams.set("vault_api_url",`${s}/api/v1/tokens/`),i.searchParams.set("access_token",e);const d=document.createElement("iframe");return d.id="moneyhash-submit-iframe",d.src=i.toString(),d.hidden=!0,document.body.appendChild(d),d},se}); |
@@ -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-4faaafcd.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-b6ce67bb.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-1f18cb9b.js"; | ||
import { S as a, t as d } from "./sdkEmbed-7e9def06.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.0-beta.1");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.0-beta.2");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.0-beta.1", | ||
"version": "1.0.0-beta.2", | ||
"description": "MoneyHash JavaScript SDK", | ||
@@ -55,4 +55,3 @@ "type": "module", | ||
"prepare": "is-ci || husky install", | ||
"prerelease": "yarn build:production && yarn build:umd", | ||
"release": "np" | ||
"release": "release-it" | ||
}, | ||
@@ -59,0 +58,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
348761
1843