@eonx/payment-elements
Version:
- [Configuration](#configuration) - [Create payment card](#create-payment-card) - [Capture payment](#capture-payment) - [Pay now](#pay-now) - [Void payment](#void-payment) - [Types](#types) - [Error handling](#error-handling)
2 lines (1 loc) • 33.2 kB
JavaScript
var C=(e=>(e[e.KeyRequired=10]="KeyRequired",e[e.UrlRequired=11]="UrlRequired",e[e.UnhandledError=12]="UnhandledError",e[e.KeyExpired=13]="KeyExpired",e))(C||{}),E=(e=>(e[e.ContainerRequired=20]="ContainerRequired",e[e.MountFailed=21]="MountFailed",e[e.IncorrectUrl=22]="IncorrectUrl",e))(E||{}),c=(e=>(e[e.CaptureFailed=40]="CaptureFailed",e[e.IntentIdRequired=41]="IntentIdRequired",e[e.IntentFailed=42]="IntentFailed",e[e.CardRequired=43]="CardRequired",e[e.MultipleCards=44]="MultipleCards",e[e.UnknownGateway=45]="UnknownGateway",e[e.SdkFailed=46]="SdkFailed",e[e.SecureFailed=47]="SecureFailed",e[e.OrderFailed=48]="OrderFailed",e[e.AttachCardFailed=49]="AttachCardFailed",e[e.InitiateAuthWithErrorFailed=50]="InitiateAuthWithErrorFailed",e[e.InitiateAuthProceededFailed=51]="InitiateAuthProceededFailed",e[e.AuthenticatePayerWithErrorFailed=52]="AuthenticatePayerWithErrorFailed",e[e.AuthenticatePayerProceedFailed=53]="AuthenticatePayerProceedFailed",e))(c||{}),T=(e=>(e[e.IntentIdRequired=50]="IntentIdRequired",e))(T||{}),A=(e=>(e[e.Failed=60]="Failed",e))(A||{}),I=(e=>(e[e.IntentIdRequired=70]="IntentIdRequired",e[e.IntentFetchFailed=71]="IntentFetchFailed",e[e.IntentFailed=72]="IntentFailed",e[e.CardFetchFailed=73]="CardFetchFailed",e[e.CardAttachFailed=74]="CardAttachFailed",e[e.NotEnoughComplete=75]="NotEnoughComplete",e[e.AlreadyCaptured=76]="AlreadyCaptured",e[e.CaptureFailed=77]="CaptureFailed",e))(I||{});const _={[C.KeyRequired]:"API key required",[C.UrlRequired]:"Payment API URL not found",[C.UnhandledError]:"Error interacting with Payment API",[C.KeyExpired]:"API key is expired",[E.ContainerRequired]:"HTML container required",[E.MountFailed]:"Failed to render payment UI",[E.IncorrectUrl]:"Invalid payment elements URL",[A.Failed]:"Failed to create payment card",[c.IntentIdRequired]:"Order intent ID has required for capture",[c.IntentFailed]:"Failed to retrieve order intent",[c.CardRequired]:"Payment source required",[c.CaptureFailed]:"Failed to complete payment",[c.MultipleCards]:"Multiple cards are not supported",[c.UnknownGateway]:"Payment gateway has not supported",[c.SdkFailed]:"Failed to load third-party SDK",[c.SecureFailed]:"3D Secure verification failed. Please contact your bank.",[c.OrderFailed]:"Unable to apply payment for your order",[c.AttachCardFailed]:"Failed to attach payment card",[c.InitiateAuthWithErrorFailed]:"3D Secure verification failed. Please contact your bank.",[c.InitiateAuthProceededFailed]:"3D Secure verification failed. Please contact your bank.",[c.AuthenticatePayerWithErrorFailed]:"3D Secure verification failed. Please contact your bank.",[c.AuthenticatePayerProceedFailed]:"3D Secure verification failed. Please contact your bank.",[T.IntentIdRequired]:"Order intent ID has required for void",[I.IntentFailed]:"Failed to verify order",[I.IntentFetchFailed]:"Failed to retrieve order intent",[I.CardFetchFailed]:"Failed to fetch payment card from order intent",[I.IntentIdRequired]:"Order intent ID has required for checkout",[I.CardAttachFailed]:"Failed to attach payment card",[I.CaptureFailed]:"Failed to complete payment"},ee=[C.KeyExpired];class g extends Error{constructor(t){const n=t.extends,r=(()=>{const a=n==null?void 0:n.code;return a&&ee.includes(a)?a:t.code})(),i=t.message||_[r]||"Unhandled error";super(i),this.violations={},this.name="PaymentElementsError",this.code=r,this.data=t.data||(n==null?void 0:n.data),this.violations=t.violations||(n==null?void 0:n.violations)||{},this.description=t.description||(n==null?void 0:n.description)||(n==null?void 0:n.message)||"",this.responseStatus=t.responseStatus||(n==null?void 0:n.responseStatus)}get isCritical(){const t=this.responseStatus&&this.responseStatus>=500,n=[C.UnhandledError,c.CaptureFailed,c.UnknownGateway,c.SdkFailed,c.SecureFailed,c.AttachCardFailed,c.IntentFailed,c.OrderFailed].includes(this.code);return t||n}get hasViolations(){return Object.keys(this.violations).length>0}toString(){return JSON.stringify({name:this.name,violations:this.violations,code:this.code,data:this.data,message:this.message,description:this.description,responseStatus:this.responseStatus})}log(){console.error(this.code||"",this.message,this)}}class te{constructor(){this.baseUrl="",this.apiKey=""}configure(t){this.baseUrl=t.baseUrl||this.baseUrl,this.apiKey=t.apiKey||this.apiKey}async fetch(t){var l,p;const n=t.apiKey||this.apiKey;if(!n)return[new g({code:C.KeyRequired}),null];if(!this.baseUrl)return[new g({code:C.UrlRequired}),null];const r=new URL(t.url,this.baseUrl),i=await window.fetch(r.toString(),{...t,method:t.method||"GET",headers:{"Content-Type":"application/json",Accept:"application/json",Authorization:`Basic ${btoa(n)}`,...t.headers||{}},body:(()=>t.bodyRaw?t.bodyRaw:t.body&&typeof t.body=="object"?JSON.stringify(t.body):t.body)()});let a=null;try{a=await i.json()}catch{}if(i.ok)return[null,a];{const f=(a==null?void 0:a.violations)||{},v={};let y="";return f instanceof Array?y=f[0]:Object.keys(f).forEach(u=>{f[u]==="string"?v[u]=[f[u]]:v[u]=f[u]}),[new g({code:(()=>(a==null?void 0:a.code)===10601?C.KeyExpired:C.UnhandledError)(),message:(a==null?void 0:a.message)||((l=a==null?void 0:a.exception)==null?void 0:l.message),description:y||((p=a==null?void 0:a.exception)==null?void 0:p.message),data:a,violations:v,responseStatus:i.status}),null]}}}const ne=new te;function b(){return{api:ne}}function re(e){return{all:e=e||new Map,on:function(t,n){var r=e.get(t);r?r.push(n):e.set(t,[n])},off:function(t,n){var r=e.get(t);r&&(n?r.splice(r.indexOf(n)>>>0,1):e.set(t,[]))},emit:function(t,n){var r=e.get(t);r&&r.slice().map(function(i){i(n)}),(r=e.get("*"))&&r.slice().map(function(i){i(t,n)})}}}const Y=re();var x=(e=>(e.Ready="ui-ready",e.SetHeight="ui-set-height",e.Mounted="ui-mounted",e.DataChanged="ui-data-changed",e.ElementReady="ui-element-ready",e))(x||{}),M=(e=>(e.Success="element-success",e.Error="element-error",e.Process="element-process",e))(M||{}),w=(e=>(e.Submit="sdk-submit",e.EnableSubmit="sdk-submit-enable",e.DisableSubmit="sdk-submit-disable",e.PreFill="sdk-prefill",e.Config="sdk-config",e))(w||{}),D=(e=>(e.SetConfig="set-config",e))(D||{});let m={};const k={uiStagingUrl:"https://sdk-elements.staging.v3.payment-gateway.eonx.com",uiProdUrl:"https://sdk-elements.prod.v3.payment-gateway.eonx.com",apiStagingUrl:"https://api.staging.v3.payment-gateway.eonx.com",apiProdUrl:"https://api.prod.v3.payment-gateway.eonx.com"};function ie(){return m.uiUrl?m.uiUrl:m.test?k.uiStagingUrl:k.uiProdUrl}function Z(){return m.test?k.apiStagingUrl:k.apiProdUrl}function ae(e){var i,a,l;const t=((i=m.themes)==null?void 0:i.base)||((a=m.themes)==null?void 0:a["*"])||{},n=e||m.theme||"",r=((l=m.themes)==null?void 0:l[n])||{};return{name:n,...t,...r,fonts:[...t.fonts||[],...r.fonts||[]],styles:{...t.styles||{},...r.styles||{}}}}function oe(){return m.currency||"AUD"}function ce(){return!!m.test}function se(e){m={...m||{},...e||{}};const{api:t}=b();t.configure({baseUrl:Z(),apiKey:(m==null?void 0:m.apiKey)||""}),Y.emit(D.SetConfig,m)}function K(){return{setup:k,config:m,getCurrency:oe,getPaymentGatewayUrl:Z,isTest:ce,getUiUrl:ie,getTheme:ae}}function H(e){const{getUiUrl:t}=K(),n={container:void 0,observer:void 0,handlers:{}};let r=null;try{r=new URL(String(e.url),t())}catch{}const i=le((r==null?void 0:r.toString())||"",{autoLayout:!!e.autoLayout});function a(o){if(!r)return l(new g({code:E.IncorrectUrl}));const s=o&&typeof o=="string"?document.querySelector(o):o;if(!(s instanceof HTMLElement))return l(new g({code:E.ContainerRequired}));window.addEventListener("message",p),i.addEventListener("error",d=>{l(new g({code:E.MountFailed,data:d}))},!0),n.container=s,s.innerHTML="",s.append(i),y()}function l(o){const s=n.handlers[M.Error];if(s instanceof Function)return s(o);u()}function p(o){try{const s=JSON.parse(o.data);if(o.origin===(r==null?void 0:r.origin)){const d=n.handlers[s.type];d instanceof Function&&d(s.payload)}}catch{}}function f(o,s){const d=JSON.stringify({frameId:i.id,type:o,payload:s});i.contentWindow&&i.contentWindow.postMessage(d,new URL(String(i.src)).origin)}function v(o,s){s&&(n.handlers[o]=s)}function y(){n.observer=new MutationObserver(()=>{n.container&&!document.body.contains(n.container)&&u()}),n.observer.observe(document.body,{childList:!0,subtree:!0})}function u(){var o;i.parentElement&&i.parentElement.removeChild(i),window.removeEventListener("message",p),Y.off(D.SetConfig,U),(o=n.observer)==null||o.disconnect(),n.container=void 0,n.observer=void 0;for(const s in n.handlers)delete n.handlers[s]}function h(o){!o||v(M.Success,o)}function S(o){!o||v(M.Error,s=>{try{const d=JSON.parse(s);o(new g({code:d.code,violations:d.violations,data:d.data,message:d.message,description:d.description,responseStatus:d.responseStatus}))}catch(d){const R=d;o(new g({code:E.MountFailed,message:s,description:R.message}))}})}function z(o){v(x.ElementReady,o)}function P(o){v(x.Mounted,()=>{i.style.setProperty("opacity","100%"),i.style.setProperty("position","static"),o instanceof Function&&o()})}function O(o){!o||v(M.Process,o)}v(x.Ready,()=>{const{config:o,getTheme:s,getCurrency:d,isTest:R,getPaymentGatewayUrl:V}=K();f(w.Config,{frameId:i.id,origin:window.location.origin,currency:d(),expiryFullYear:o.expiryFullYear,theme:s(e.theme),paymentGatewayUrl:V(),query:e.query,test:R()})}),e.autoLayout&&v(x.SetHeight,o=>{i.style.setProperty("height",`${o}px`)});function U(){const{config:o,getTheme:s,getCurrency:d,isTest:R,getPaymentGatewayUrl:V}=K();f(w.Config,{currency:d(),theme:s(),test:R(),paymentGatewayUrl:V(),expiryFullYear:o.expiryFullYear})}function $(o){const{getTheme:s}=K();f(w.Config,{theme:s(o)})}return Y.on(D.SetConfig,U),{send:f,handle:v,mount:a,dispose:u,changeTheme:$,onSuccess:h,onError:S,onProcess:O,onMounted:P,onReady:z}}function le(e,t){const n=document.createElement("iframe");return n.setAttribute("src",e),n.setAttribute("id",`eonx-frame-${Date.now()}`),n.setAttribute("frameborder","0"),n.setAttribute("scrolling","no"),n.setAttribute("allow","payment *"),n.setAttribute("allowtransparency","true"),n.style.setProperty("overflow","hidden","important"),n.style.setProperty("min-width","100%","important"),n.style.setProperty("border","none","important"),n.style.setProperty("padding","0","important"),n.style.setProperty("user-select","none","important"),n.style.setProperty("min-height","100%"),n.style.setProperty("opacity","0"),n.style.setProperty("position","absolute"),t.autoLayout?(n.style.setProperty("height","auto"),n.style.setProperty("margin","-4px","important"),n.style.setProperty("width","calc(100% + 8px)")):(n.style.setProperty("height","100%"),n.style.setProperty("width","100%")),n}function de(e){const t=H({url:"/create-card",theme:e.theme,autoLayout:!0,query:{apiKey:e.apiKey,cardholder:e.cardholder}});t.onError(e.onError),t.onSuccess(e.onSuccess),t.onMounted(e.onMounted),t.onProcess(e.onProcess),t.mount(e.container);function n(){t.send(w.Submit)}function r(l){t.send(w.PreFill,l)}function i(){t.send(w.EnableSubmit)}function a(){t.send(w.DisableSubmit)}return t.handle(x.DataChanged,e.onChange),{prefill:r,disableSubmit:a,enableSubmit:i,submit:n,changeTheme:t.changeTheme,dispose:t.dispose}}function N(e){e.apiKey&&b().api.configure({apiKey:e.apiKey});function t(r){const i=r instanceof g?r:new g(r);e.onError?e.onError(i):i.log()}function n(r){e.onSuccess&&e.onSuccess(r)}return{emitError:t,emitSuccess:n}}function ue(e){const{api:t}=b();return t.fetch({method:"GET",url:`/order-intents/${e}`})}function he(){const{api:e}=b();return e.fetch({url:"/order-intents?order[createdAt]=desc"})}async function pe(e){var p;const{api:t}=b(),{source:n}=e,r={sources:n?[n]:[]},[i,a]=await t.fetch({method:"POST",url:`/order-intents/${e.orderIntentId}/capture`,body:r}),l=((p=a==null?void 0:a.order)==null?void 0:p.generalStatus)||"";return i||!/completed/.test(l)?[new g({code:c.CaptureFailed,extends:i}),null]:[null,a]}async function ye(e){const{api:t}=b();return t.fetch({method:"POST",url:`/order-intents/${e.orderIntentId}/sources`,body:{amount:e.amount,reference:e.reference,type:e.paymentMethodType,consumerOwningEntity:e.consumerOwningEntity,paymentConfig:e.paymentConfig}})}function me(e){const{api:t}=b();return t.fetch({url:"/order-intents",method:"POST",body:e})}function ge(e){const{api:t}=b();return t.fetch({url:`/order-intents/${e}/void`,method:"POST"})}function fe(e){return(e.sources||[]).find(t=>/fatzebra|tyro|nab/i.test(t.gateway))}function q(){return{getOrders:he,getOrderDetails:ue,captureOrderPayment:pe,getCardSourceFromOrder:fe,attachSourceToOrder:ye,createOrder:me,voidOrder:ge}}function ve(e){const{emitError:t,emitSuccess:n}=N({apiKey:e.apiKey,onError:e.onError,onSuccess:e.onSuccess});let r=null;async function i(){const{getOrderDetails:y,getCardSourceFromOrder:u}=q(),{orderIntentId:h,apiKey:S}=e;if(!S)return t({code:C.KeyRequired});if(!h)return t({code:c.IntentIdRequired});if(e.attachCard){const[U,$]=await a();if(U||!$)return t({code:c.AttachCardFailed,extends:U})}const[z,P]=await y(h);if(z||!P)return t({code:c.IntentFailed,extends:z});const O=u(P);P.securityTokenRequired&&O?l({source:O,orderIntent:P}):await p()}function a(){const{attachSourceToOrder:y}=q(),{orderIntentId:u,attachCard:h}=e;return h?y({orderIntentId:u,reference:h.reference,paymentMethodType:h.type,amount:h.amount,consumerOwningEntity:h.consumerOwningEntity,paymentConfig:h.paymentConfig}):[]}function l(y){var u;r=H({url:"/verify",theme:e.theme,autoLayout:!0,query:{orderIntent:y.orderIntent,sourceToVerify:y.source,apiKey:e.apiKey,isVerificationCodeRequired:!!e.isVerificationCodeRequired&&!e.verificationCode,height:(u=e.height)!=null?u:400,meta:e.meta}}),r.onError(h=>{t(h),r==null||r.dispose()}),r.onSuccess(h=>p(h)),r.onMounted(e.onMounted),e.onVerify?e.onVerify({mount:r.mount,dispose:r.dispose}):t({code:E.ContainerRequired})}async function p(y){const{captureOrderPayment:u}=q();y&&e.verificationCode&&(y.verificationCode=e.verificationCode);const[h,S]=await u({source:y,orderIntentId:e.orderIntentId});S?n(S):h&&t(h),f()}function f(){r==null||r.dispose()}function v(y){r==null||r.changeTheme(y)}return i().catch(t),{dispose:f,changeTheme:v}}async function Ce(e){if(!e.orderIntentId)throw new g({code:T.IntentIdRequired});const{voidOrder:t}=q();N({apiKey:e.apiKey});const[n,r]=await t(e.orderIntentId);if(n)throw n;return r}function be(e){var p;const t=e,n=(p=t.order)==null?void 0:p.intentId,r=e.orderIntentId||n,i=e.card||{cardholder:t.cardholder,number:t.number,expiryYear:0,expiryMonth:0},a=H({url:"/pay-now",theme:e.theme,autoLayout:!0,query:{apiKey:e.apiKey,card:i.number?i:void 0,isVerificationCodeRequired:!!e.isVerificationCodeRequired,sourceConfig:e.sourceConfig,isActionsVisible:e.isActionsVisible,orderIntentId:r}});a.onError(e.onError),a.onSuccess(e.onSuccess),a.onMounted(e.onMounted),a.onProcess(e.onProcess),a.onReady(e.onReady),a.mount(e.container);function l(){a.send(w.Submit)}return{changeTheme:a.changeTheme,submit:l,dispose:a.dispose}}const F={cardNumberRequired:"Card number is required",invalidCardNumber:"Invalid card number",invalidCardLength:"Invalid card number length",invalidCvvLength:"Invalid CVV length",incompleteCvv:"The security code is incomplete",invalidExpiryDate:"Invalid expiry date",unsupportedCard:"This card is not supported",expiryInPast:"Expiry date is in the past",expiryYearInRange:"Expiry year is out of range",expiryFormatInvalid:(()=>`Expiry date must be in format 01/${String(new Date().getFullYear()).slice(2,4)}`)(),expiryFullFormatInvalid:(()=>{const e=String(new Date().getFullYear());return`Expiry date must be in format 01/${e.slice(2,4)} or 01/${e}`})()},Ee=[{background:"",type:"maestro",label:"Maestro",patterns:/^(5018|502|503|56|58|639|6220|67)/,format:/(\d{1,4})/g,length:/^(12|13|14|15|16|17|18|19)/,cvcLength:[3],luhn:!0},{type:"forbrugsforeningen",label:"Forbrugsforeningen",patterns:/^600/,format:/(\d{1,4})/g,length:/^16$/,cvcLength:[3],luhn:!0},{type:"dankort",label:"Dankort",patterns:/^5019/,format:/(\d{1,4})/g,length:/^16$/,cvcLength:[3],luhn:!0},{type:"visa",label:"Visa",patterns:/^4/,format:/(\d{1,4})/g,length:/^(13|16)/,cvcLength:[3],luhn:!0,image:"data:image/svg+xml,%3Csvg viewBox='0 0 24 16' xmlns='http://www.w3.org/2000/svg' %3E%3Cg fill='none' fill-rule='nonzero' %3E%3Crect fill='%23FFF' height='15.5' rx='2' stroke='%23000' stroke-opacity='.2' stroke-width='.5' width='23.5' x='.25' y='.25' /%3E%3Cpath d='M2.788 5.914A7.201 7.201 0 0 0 1 5.237l.028-.125h2.737c.371.013.672.125.77.519l.595 2.836.182.854 1.666-4.21h1.799l-2.674 6.167H4.304L2.788 5.914Zm7.312 5.37H8.399l1.064-6.172h1.7L10.1 11.284Zm6.167-6.021-.232 1.333-.153-.066a3.054 3.054 0 0 0-1.268-.236c-.671 0-.972.269-.98.531 0 .29.365.48.96.762.98.44 1.435.979 1.428 1.681-.014 1.28-1.176 2.108-2.96 2.108-.764-.007-1.5-.158-1.898-.328l.238-1.386.224.099c.553.23.917.328 1.596.328.49 0 1.015-.19 1.022-.604 0-.27-.224-.466-.882-.769-.644-.295-1.505-.788-1.491-1.674C11.878 5.84 13.06 5 14.74 5c.658 0 1.19.138 1.526.263Zm2.26 3.834h1.415c-.07-.308-.392-1.786-.392-1.786l-.12-.531c-.083.23-.23.604-.223.59l-.68 1.727Zm2.1-3.985L22 11.284h-1.575s-.154-.71-.203-.926h-2.184l-.357.926h-1.785l2.527-5.66c.175-.4.483-.512.889-.512h1.316Z' fill='%23171E6C' /%3E%3C/g%3E%3C/svg%3E",background:"linear-gradient(270deg, #0b2c59 0%, #2770b6 100%)"},{type:"mastercard",label:"MasterCard",patterns:/^(51|52|53|54|55|22|23|24|25|26|27)/,format:/(\d{1,4})/g,length:/^(13|16)/,cvcLength:[3],luhn:!0,image:"data:image/svg+xml,%3Csvg viewBox='0 0 24 16' xmlns='http://www.w3.org/2000/svg'%3E%3Crect fill='%23252525' height='16' rx='2' width='24'/%3E%3Ccircle cx='9' cy='8' fill='%23eb001b' r='5'/%3E%3Ccircle cx='15' cy='8' fill='%23f79e1b' r='5'/%3E%3Cpath d='M12 4c1.214.912 2 2.364 2 4s-.786 3.088-2 4c-1.214-.912-2-2.364-2-4s.786-3.088 2-4z' fill='%23ff5f00'/%3E%3C/svg%3E",background:"linear-gradient(270deg, #131313 0%, #797979 100%)"},{type:"amex",label:"American Express",patterns:/^(34|37)/,format:/(\d{1,4})(\d{1,6})?(\d{1,5})?/,length:/^15$/,cvcLength:[3,4],luhn:!0,image:"data:image/svg+xml,%3Csvg viewBox='0 0 24 16' xmlns='http://www.w3.org/2000/svg'%3E%3Crect fill='%23016fd0' height='16' rx='2' width='24'/%3E%3Cpath d='M13.764 13.394V7.692l10.148.01v1.574l-1.173 1.254 1.173 1.265v1.608h-1.873l-.995-1.098-.988 1.102z' fill='%23fffffe'/%3E%3Cpath d='M14.442 12.769v-4.45h3.772v1.026h-2.55v.695h2.49v1.008h-2.49v.684h2.55v1.037z' fill='%23016fd0'/%3E%3Cpath d='m18.195 12.769 2.088-2.227-2.088-2.222h1.616l1.275 1.41 1.28-1.41h1.546v.035l-2.043 2.187 2.043 2.164v.063H22.35l-1.298-1.424-1.285 1.424z' fill='%23016fd0'/%3E%3Cpath d='M14.237 2.632h2.446l.86 1.95v-1.95h3.02l.52 1.462.523-1.462h2.306v5.701H11.725z' fill='%23fffffe'/%3E%3Cg fill='%23016fd0'%3E%3Cpath d='m14.7 3.251-1.974 4.446h1.354l.373-.89h2.018l.372.89h1.387L16.265 3.25zm.17 2.558.592-1.415.592 1.415z'/%3E%3Cpath d='M18.212 7.696V3.25l1.903.006.98 2.733.985-2.74h1.832v4.446l-1.179.01V4.653L21.62 7.696h-1.075l-1.136-3.054v3.054z'/%3E%3C/g%3E%3C/svg%3E",background:"linear-gradient(270deg, #44629a 0%, #6093c9 100%)"},{type:"dinersclub",label:"Diners Club International",patterns:/^(30|36|38|39)/,format:/(\d{1,4})(\d{1,6})?(\d{1,4})?/,length:/^14$/,cvcLength:[3],luhn:!0},{type:"discover",label:"Discover",patterns:/^(60|64|65|622)/,format:/(\d{1,4})/g,length:/^16$/,cvcLength:[3],luhn:!0,image:"data:image/svg+xml, %3Csvg viewBox='0 0 24 16' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M21.997 15.75H22c.955.008 1.74-.773 1.751-1.746V2.006a1.789 1.789 0 0 0-.52-1.25A1.72 1.72 0 0 0 21.997.25H2.001A1.718 1.718 0 0 0 .77.757c-.33.33-.517.779-.521 1.247v11.99c.004.47.191.92.52 1.25.329.328.771.51 1.233.506h19.994Zm0 .5h-.002.002Z' fill='%23FFF' stroke='%23000' stroke-opacity='.2' stroke-width='.5'/%3E%3Cpath d='M12.612 16h9.385A1.986 1.986 0 0 0 24 14.03v-2.358A38.74 38.74 0 0 1 12.612 16Z' fill='%23F27712'/%3E%3Cpath d='M23.172 9.296h-.852l-.96-1.266h-.091v1.266h-.695V6.152H21.6c.803 0 1.266.33 1.266.927 0 .488-.29.802-.81.902l1.116 1.315Zm-1.026-2.193c0-.306-.232-.463-.662-.463h-.215v.952h.199c.446 0 .678-.166.678-.489Zm-4.005-.951h1.97v.53h-1.275v.703h1.225v.538h-1.225v.852h1.274v.53h-1.97V6.152Zm-2.235 3.227L14.4 6.143h.761l.952 2.119.96-2.119h.745L16.295 9.38h-.389Zm-6.298-.008c-1.059 0-1.887-.72-1.887-1.655 0-.91.845-1.647 1.904-1.647.298 0 .546.058.852.19v.729a1.241 1.241 0 0 0-.869-.356c-.662 0-1.167.48-1.167 1.084 0 .637.497 1.092 1.2 1.092.315 0 .555-.1.836-.347v.728a2.13 2.13 0 0 1-.869.182ZM7.506 8.336c0 .613-.505 1.035-1.233 1.035-.53 0-.91-.182-1.233-.596l.455-.389c.157.282.422.422.753.422.315 0 .538-.19.538-.438 0-.141-.066-.249-.207-.331a2.88 2.88 0 0 0-.48-.183c-.653-.206-.877-.43-.877-.868 0-.514.48-.903 1.109-.903.397 0 .753.125 1.051.356l-.364.414a.761.761 0 0 0-.563-.248c-.298 0-.513.149-.513.347 0 .166.124.257.538.398.794.248 1.026.48 1.026.993v-.009ZM4.088 6.152h.695v3.153h-.695V6.152ZM1.854 9.305H.828V6.152h1.026c1.125 0 1.903.645 1.903 1.572 0 .472-.231.919-.637 1.217-.348.248-.737.364-1.274.364h.008Zm.81-2.367c-.23-.182-.496-.248-.95-.248h-.191v2.085h.19c.447 0 .728-.083.952-.248.24-.199.38-.497.38-.803 0-.306-.14-.596-.38-.786Z' fill='%23000'/%3E%3Cpath d='M12.414 6.069c-.91 0-1.655.728-1.655 1.63 0 .96.711 1.68 1.655 1.68a1.64 1.64 0 0 0 1.655-1.655c0-.927-.72-1.655-1.655-1.655Z' fill='%23F27712'/%3E%3C/svg%3E"},{type:"unionpay",label:"UnionPay",patterns:/^(62|88)/,format:/(\d{1,4})/g,length:/^(16|17|18|19)/,cvcLength:[3],luhn:!1,image:"data:image/svg+xml,%3Csvg viewBox='0 0 24 16' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4.546 0h5.794c.808 0 1.311.726 1.123 1.619L8.765 14.368c-.19.89-1 1.616-1.81 1.616H1.164c-.808 0-1.312-.726-1.123-1.616L2.738 1.619C2.927.726 3.736 0 4.546 0' fill='%23dd2423'/%3E%3Cpath d='M9.858 0h6.662c.809 0 .444.726.254 1.619l-2.697 12.749c-.19.89-.13 1.616-.94 1.616H6.474c-.81 0-1.312-.726-1.122-1.616L8.05 1.619C8.241.726 9.05 0 9.858 0' fill='%2316315e'/%3E%3Cpath d='M16.256 0h5.794c.81 0 1.313.726 1.122 1.619l-2.697 12.749c-.19.89-1 1.616-1.81 1.616h-5.791c-.81 0-1.313-.726-1.123-1.616l2.697-12.749C14.637.726 15.446 0 16.256 0' fill='%23036862'/%3E%3Cpath d='M6.059 4.086c-.596.006-.772 0-.828-.015l-.425 2.156c-.086.413-.15.708-.363.898a.612.612 0 0 1-.428.164c-.264 0-.418-.145-.444-.419l-.005-.094.08-.556s.423-1.86.498-2.106a.195.195 0 0 0 .006-.028c-.821.008-.967 0-.977-.015-.005.02-.025.135-.025.135l-.431 2.097-.037.178-.072.582c0 .172.03.313.092.432.196.378.756.435 1.073.435.408 0 .791-.096 1.05-.27.449-.292.566-.749.671-1.155l.049-.208s.434-1.932.508-2.183c.003-.014.004-.022.008-.028zm1.479 1.558c-.105 0-.296.028-.468.121-.063.036-.122.076-.184.117l.056-.224-.03-.037c-.365.081-.447.092-.784.144l-.028.02c-.04.358-.074.626-.22 1.328-.054.259-.112.52-.17.778l.016.033c.346-.02.45-.02.75-.015l.025-.029c.038-.215.043-.265.127-.7.04-.207.123-.66.164-.822a.523.523 0 0 1 .22-.076c.167 0 .147.162.14.226a8.84 8.84 0 0 1-.13.764l-.043.195c-.03.145-.061.285-.09.428l.012.029c.34-.02.444-.02.735-.015l.034-.029c.053-.335.068-.425.161-.914l.047-.225c.091-.44.137-.662.068-.844-.073-.203-.247-.253-.408-.253zm1.652.46c-.18.039-.296.064-.41.08-.115.021-.225.04-.4.066l-.014.014-.013.01c-.018.144-.03.268-.055.414-.02.15-.052.321-.103.567-.04.189-.06.254-.083.32-.022.067-.046.131-.09.316l.01.017.008.016c.164-.009.27-.015.38-.016.11-.004.224 0 .4.001l.015-.013.017-.016c.025-.167.03-.212.045-.293.015-.087.042-.208.107-.531.03-.152.065-.303.097-.458.033-.154.068-.306.1-.458l-.004-.018zm.004-.62c-.164-.107-.453-.073-.647.075-.194.144-.216.35-.052.458.162.104.451.073.644-.076.193-.148.217-.351.055-.457zm.994 2.473c.333 0 .674-.1.93-.4.198-.243.288-.604.32-.753.102-.493.022-.723-.078-.863-.151-.214-.42-.283-.698-.283-.167 0-.565.019-.876.334-.224.228-.327.537-.389.833-.063.302-.135.846.319 1.048.14.066.342.084.472.084zm-.026-1.109c.077-.373.167-.687.398-.687.181 0 .194.233.114.608-.014.083-.08.392-.17.524-.062.097-.136.156-.218.156-.024 0-.169 0-.17-.236a1.76 1.76 0 0 1 .046-.365zm2.107 1.061.026-.029c.037-.215.043-.265.124-.7.041-.207.126-.66.165-.822.075-.038.148-.076.221-.076.167 0 .147.162.14.226-.006.108-.067.46-.131.764l-.04.195c-.03.145-.063.285-.093.428l.013.03c.342-.021.441-.021.734-.016l.035-.029c.051-.336.065-.425.161-.914l.046-.225c.091-.44.138-.662.07-.844-.075-.203-.251-.253-.41-.253-.104 0-.297.028-.468.121a3.058 3.058 0 0 0-.182.117l.052-.224-.028-.037c-.365.081-.448.092-.784.144l-.026.02c-.041.358-.074.626-.22 1.328-.055.259-.112.52-.17.778l.016.033c.346-.02.45-.02.749-.015zm2.509.015.15-.8s.108-.5.115-.519c0 0 .034-.052.068-.073h.05c.475 0 1.01 0 1.43-.34.286-.233.481-.577.569-.996a1.65 1.65 0 0 0 .039-.346c0-.16-.03-.32-.114-.443-.214-.33-.64-.336-1.132-.338l-.243.002c-.63.009-.883.006-.986-.008l-.026.14-.225 1.154-.566 2.563c.55-.008.776-.008.87.004zm.418-2.045.239-1.145.007-.059.004-.045.096.011.506.048c.195.083.276.298.22.578-.052.255-.202.47-.396.574-.16.088-.355.095-.556.095h-.13zm1.494.99c-.064.298-.137.841.315 1.035a.81.81 0 0 0 .404.08c.139-.008.267-.085.386-.195l-.032.136.02.03c.325-.016.426-.016.778-.013l.032-.027c.052-.332.1-.655.234-1.292.065-.305.13-.606.197-.91l-.01-.033c-.364.074-.462.09-.811.144l-.027.024-.01.09a.515.515 0 0 0-.255-.23c-.156-.068-.52.019-.835.334-.22.224-.326.532-.386.827zm.763.018c.078-.366.167-.677.399-.677.146 0 .223.15.208.403l-.042.205c-.023.11-.048.217-.073.325a.823.823 0 0 1-.085.19.387.387 0 0 1-.283.151c-.024 0-.166 0-.171-.232-.002-.115.02-.234.047-.365zm3.987-1.21-.028-.036c-.36.08-.425.093-.756.142l-.024.027-.004.017v-.006c-.247.625-.24.49-.44.982l-.002-.06-.05-1.066-.032-.036c-.377.08-.385.093-.733.142l-.028.027c-.003.013-.003.027-.006.042l.003.006c.043.244.033.19.076.576.02.19.048.38.068.567.034.313.054.468.096.946-.235.426-.291.588-.517.963l.001.003-.159.278c-.018.029-.035.049-.058.057a.22.22 0 0 1-.104.017h-.089l-.13.48.45.009a.549.549 0 0 0 .519-.32l.283-.534h-.005l.03-.038c.19-.45 1.639-3.185 1.639-3.185zm-4.75 6.308h-.191l.706-2.573h.235l.074-.265.007.295c-.008.182.122.344.464.317h.395l.137-.495h-.15c-.085 0-.125-.024-.12-.075l-.007-.3h-.732v.002c-.237.005-.944.025-1.088.067-.173.049-.355.193-.355.193l.071-.265h-.685l-.143.526-.716 2.613h-.139l-.136.492h1.365l-.046.164h.672l.045-.164h.189zm-.56-2.05c-.11.034-.314.135-.314.135l.181-.658h.545l-.132.48s-.168.01-.28.043zm.01.94s-.17.023-.283.051c-.111.037-.32.154-.32.154l.188-.684h.548zm-.305 1.116h-.546l.158-.577h.545zm1.315-1.595h.787l-.113.403h-.797l-.12.44h.698l-.529.82a.223.223 0 0 1-.107.098.293.293 0 0 1-.141.045h-.194l-.133.483h.506c.264 0 .419-.132.534-.305l.362-.546.078.554a.257.257 0 0 0 .13.189c.05.028.103.076.177.083.08.004.137.007.175.007h.249l.15-.54h-.099c-.056 0-.153-.011-.17-.03-.016-.024-.016-.06-.025-.116l-.08-.556h-.322l.141-.185h.797l.122-.441h-.737l.115-.403h.735l.136-.498h-2.19zm-6.648 1.708.184-.673h.755l.138-.5h-.756l.115-.415h.739l.137-.484H9.966l-.134.484h.42l-.112.414h-.421l-.14.51h.42l-.245.89c-.033.117.015.162.046.217a.205.205 0 0 0 .135.109c.074.018.125.029.194.029h.851l.152-.555-.377.058c-.073 0-.275-.01-.253-.084zm.086-3.221-.19.38a.438.438 0 0 1-.112.16c-.03.02-.087.028-.17.028h-.1l-.134.487h.331a.7.7 0 0 0 .34-.097c.064-.037.08-.016.129-.067l.112-.107h1.035l.137-.507h-.757l.132-.277zm1.53 3.23c-.019-.027-.006-.077.021-.18l.283-1.03h1.007c.147-.003.253-.005.321-.01a.617.617 0 0 0 .243-.09.474.474 0 0 0 .176-.179c.043-.066.113-.21.173-.433l.356-1.305-1.045.007s-.321.052-.463.11a1.887 1.887 0 0 0-.347.244l.094-.358h-.645l-.904 3.298a2.21 2.21 0 0 0-.058.277c-.002.06.069.12.115.165.054.045.134.038.21.045.08.007.196.01.354.01h.496l.152-.565-.444.046a.114.114 0 0 1-.096-.052zm.487-1.907h1.057l-.067.232c-.01.005-.032-.012-.14.002h-.915zm.212-.778h1.066l-.077.28s-.502-.006-.583.01c-.354.068-.56.276-.56.276zm.802 1.787a.126.126 0 0 1-.042.071c-.022.016-.057.021-.108.021h-.151l.009-.282H12.7l-.025 1.38c-.001.1.007.158.074.204.066.058.27.065.545.065h.392l.142-.517-.342.02-.113.008c-.016-.007-.03-.014-.047-.032-.015-.016-.039-.006-.035-.106l.003-.354.358-.016c.194 0 .277-.07.347-.136.068-.063.09-.136.115-.234l.06-.313h-.493z' fill='%23fefefe'/%3E%3C/svg%3E"},{type:"jcb",label:"JCB",patterns:/^35/,format:/(\d{1,4})/g,length:/^16$/,cvcLength:[3],luhn:!0,image:"data:image/svg+xml,%3Csvg viewBox='0 0 23 16' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M.205 16h4.518c1.028 0 2.26-1.195 2.26-2.133V0h-4.52C1.436 0 .205 1.195.205 3.2z' fill='%23047ab1'/%3E%3Cpath d='M2.77 10.816a9.77 9.77 0 0 1-2.565-.341V9.3a4.592 4.592 0 0 0 2.146.619c.87 0 1.356-.576 1.356-1.365V5.333h2.146v3.222c0 1.258-.7 2.261-3.084 2.261z' fill='%23fff'/%3E%3Cpath d='M8.112 16h4.517c1.028 0 2.26-1.195 2.26-2.133V0H10.37C9.343 0 8.11 1.195 8.11 3.2z' fill='%23d42d06'/%3E%3Cpath d='M8.112 6.08c.655-.597 1.784-.97 3.614-.885.994.042 2.033.32 2.033.32v1.184a4.785 4.785 0 0 0-1.954-.608c-1.39-.118-2.236.618-2.236 1.909s.847 2.027 2.236 1.92a4.853 4.853 0 0 0 1.954-.619v1.174s-1.04.288-2.033.33c-1.83.086-2.96-.288-3.614-.885z' fill='%23fff'/%3E%3Cpath d='M16.018 16h4.518c1.028 0 2.259-1.195 2.259-2.133V0h-4.518c-1.028 0-2.26 1.195-2.26 3.2z' fill='%2367b637'/%3E%3Cpath d='M21.665 9.28c0 .853-.7 1.387-1.638 1.387h-4.01V5.333h3.649l.26.011c.824.043 1.434.501 1.434 1.29 0 .62-.418 1.153-1.174 1.28v.033c.835.053 1.48.554 1.48 1.333zm-2.88-3.104a1.087 1.087 0 0 0-.147-.01h-1.355v1.343h1.502a.667.667 0 0 0 .52-.672c0-.362-.238-.608-.52-.661zm.17 2.176a1.028 1.028 0 0 0-.181-.01h-1.491v1.46h1.49l.181-.02c.283-.065.52-.342.52-.715 0-.374-.226-.64-.52-.715z' fill='%23fff'/%3E%3C/svg%3E"}];function L(e){return Ee.find(t=>t.patterns.test(e))}function we(e){const t=L(e);return t?t.type:""}function G(e){if(!e)return F.cardNumberRequired;const t=L(e);return t?t.length.test(String(e.length))?!t.luhn||Q(e)?!0:F.invalidCardNumber:F.invalidCardLength:F.unsupportedCard}function j(e,t=""){if(t.length<3)return F.incompleteCvv;if(e){const n=L(e);if(n&&!n.cvcLength.includes(t.length))return F.invalidCvvLength}return!0}function B(e,t){const n=e?`0${e}`.slice(-2):"MM",r=t?`0${String(t)}`.slice(-2):"YY";return e&&t?`${n}/${r}`:""}function W(e){let t=0,n=0;if(typeof e=="string"){e=e.replace(/\//g,""),t=parseInt(e.slice(0,2));const r=new Date().getFullYear(),i=`${e.slice(2,6)}`;i.length>=2&&(n=i.length===2?parseInt(String(r).slice(0,2)+i):parseInt(i))}else e&&typeof e=="object"&&(t=parseInt(String(e.month)),n=parseInt(String(e.year)));return{month:t||0,year:n||0}}function J(e,t){const n=Date.now(),{year:r,month:i}=W(e),a=i>0&&i<=12,l=[2,4].includes(String(r).length);if(!a||!l)return t?F.expiryFullFormatInvalid:F.expiryFormatInvalid;if((new Date(r,i,-1).getTime()||0)<n)return F.expiryInPast;const p=new Date().getFullYear();return r>=p&&r<p+50?!0:F.expiryYearInRange}function Q(e){if(/[^0-9-\s]+/.test(e))return!1;let t=0,n=!1;e=e.replace(/\D/g,"");for(let r=e.length-1;r>=0;r--){const i=e.charAt(r);let a=parseInt(i,10);n&&(a*=2)>9&&(a-=9),t+=a,n=!n}return t%10===0}class Fe{constructor(t){this.raw=t,this.isHidden=!0,this.expiryMonth=(t==null?void 0:t.expiryMonth)||0,this.expiryYear=(t==null?void 0:t.expiryYear)||0,this.number=(t==null?void 0:t.pan)||"",this.cardholder=(t==null?void 0:t.cardholder)||""}get mask(){const t=[];for(let n=0;n<16;n++){const r={blockEnd:n%4===3};this.isHidden&&n<12?r.isEmpty=!0:parseInt(this.number[n])>=0?r.value=this.number[n]:r.isEmpty=!0,t.push(r)}return t}get numberByGroups(){var t;return((t=this.number.match(/.{1,4}/g))==null?void 0:t.join(" "))||""}get expiryString(){return B(this.expiryMonth,this.expiryYear)}get image(){var t;return((t=this.type)==null?void 0:t.image)||""}get background(){var t;return((t=this.type)==null?void 0:t.background)||""}get type(){return L(this.number)}hide(){this.isHidden=!0}show(){this.isHidden=!1}}async function Ie(e){const{api:t}=b();return t.fetch({url:`/credit-cards/${e}`})}function X(e){const t={},n={number:G(e.number),verificationCode:j(e.number,e.cvc),expiry:J({year:e.expiryYear,month:e.expiryMonth})};return Object.keys(n).forEach(r=>{const i=n[r];typeof i=="string"&&(t[r]=[i])}),t}async function xe(e){const{api:t}=b(),n=X({number:e.number,cardholder:e.cardholder,expiryYear:e.expiryYear,expiryMonth:e.expiryMonth,cvc:e.verificationCode});if(Object.keys(n).length>0)return[new g({code:A.Failed,violations:n}),null];const[r,i]=await t.fetch({method:"POST",url:"/credit-cards",body:{cardholder:e.cardholder,currency:`/currencies/${e.currency||"AUD"}`,description:e.description||"",number:e.number,verificationCode:e.verificationCode,expiryMonth:e.expiryMonth,expiryYear:(()=>{const a=new Date().getFullYear();return String(e.expiryYear).length===2?parseInt(String(a).slice(0,2)+e.expiryYear):e.expiryYear})()}});return r?[new g({code:A.Failed,extends:r}),null]:[null,i]}function Se(){return{tokenizeCard:xe,validateCard:X,getCardDetails:Ie}}export{C as ApiError,c as CapturePaymentError,A as CreateCardError,M as ElementEvent,g as Error,E as FrameError,I as PayNowError,Fe as PaymentCard,w as SdkEvent,x as UiEvent,T as VoidPaymentError,B as buildExpiryDateString,ve as capturePayment,se as configurePaymentElements,de as createPaymentCard,L as getCardTypeByNumber,we as getPaymentSystem,Q as luhnCheck,W as parseExpiryDate,be as payNow,Se as useCard,q as useOrder,b as usePaymentApi,j as validateCardCvv,J as validateCardExpiryDate,G as validateCardNumber,Ce as voidPayment};