airwallex-payment-elements 1.9.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bin/airwallex.cjs.js +2 -2
- package/lib/bin/airwallex.cjs.js.map +1 -1
- package/lib/bin/airwallex.es.js +2 -2
- package/lib/bin/airwallex.es.js.map +1 -1
- package/lib/bin/airwallex.iife.js +2 -2
- package/lib/bin/airwallex.iife.js.map +1 -1
- package/package.json +1 -1
- package/types/airwallex.d.ts +16 -2
- package/types/dropInElement.d.ts +8 -2
- package/types/element.d.ts +37 -6
package/lib/bin/airwallex.cjs.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* Airwallex Checkout Component Version [1.
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e={prod:"checkout.airwallex.com",demo:"checkout-demo.airwallex.com",staging:"checkout-staging.airwallex.com",qa:"checkoutui.qa.awx.im",preview:"checkoutui.preview.awx.im",dev:"localhost:3000"},r=r=>`https://${e[r]||e.prod}`,t="/assets/elements.bundle.min.js?version=1.
|
|
1
|
+
/* Airwallex Checkout Component Version [1.10.0] */
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e={prod:"checkout.airwallex.com",demo:"checkout-demo.airwallex.com",staging:"checkout-staging.airwallex.com",qa:"checkoutui.qa.awx.im",preview:"checkoutui.preview.awx.im",dev:"localhost:3000"},r=r=>`https://${e[r]||e.prod}`,t="/assets/elements.bundle.min.js?version=1.10.0",o=e=>{const r=document.createElement("script");r.src=`${e}${t}`,r.crossOrigin="anonymous";const o=document.head||document.body;if(!o)throw new Error("Airwallex payment scripts requires a <head> or <body> html element in order to be loaded.");return o.appendChild(r),r},n=async e=>{if("undefined"==typeof window)return null;if(window.Airwallex)return window.Airwallex;let n=0;const l=async()=>{const n=document.querySelector(`script[src="${t}"], script[src="${t}/"]`)||o(r((null==e?void 0:e.env)||"prod"));return new Promise(((r,t)=>{n.addEventListener("load",(()=>{window.Airwallex?(window.Airwallex.init(e),r(window.Airwallex)):t(new Error("Failed to load Airwallex on load event"))})),n.addEventListener("error",(()=>{t(new Error("Failed to load Airwallex scripts")),n.remove&&n.remove()}))}))};for(;n<3;)try{return await l()}catch(e){n++,await new Promise((e=>window.setTimeout(e,500)))}return null},l=e=>{window.Airwallex?window.Airwallex.init(e):console.error("Please loadAirwallex() before init();")},a=e=>{if(window.Airwallex)return window.Airwallex.redirectToCheckout(e);console.error("Please loadAirwallex() before redirectToCheckout();")},i=(e,r)=>window.Airwallex?window.Airwallex.createElement(e,r):(console.error("Please loadAirwallex() before createElement();"),null),w=e=>window.Airwallex?window.Airwallex.destroyElement(e):(console.error("Please loadAirwallex() before destroyElement();"),!1),d=e=>window.Airwallex?window.Airwallex.getElement(e):(console.error("Please loadAirwallex() before getElement();"),null),s=async e=>{if(window.Airwallex)return window.Airwallex.confirmPaymentIntent(e);{const e="Please loadAirwallex() before confirmPaymentIntent();";throw console.error(e),new Error(e)}},c=async e=>{if(window.Airwallex)return window.Airwallex.confirmPaymentIntentWithSavedCard(e);{const e="Please loadAirwallex() before confirmPaymentIntentWithSavedCard();";throw console.error(e),new Error(e)}},x=async(e,r)=>{if(window.Airwallex)return window.Airwallex.createPaymentMethod(e,r);{const e="Please loadAirwallex() before createPaymentMethod();";throw console.error(e),new Error(e)}},m=async(e,r)=>{if(window.Airwallex)return window.Airwallex.getPaymentIntent(e,r);{const e="Please loadAirwallex() before getPaymentIntent();";throw console.error(e),new Error(e)}},A=async e=>{if(window.Airwallex)return window.Airwallex.createPaymentConsent(e);{const e="Please loadAirwallex() before createPaymentConsent();";throw console.error(e),new Error(e)}},u=e=>window.Airwallex.getDeviceFingerprint(e);var y={getGatewayUrl:r,loadAirwallex:n,loadAirwallexJs:o,init:l,redirectToCheckout:a,createElement:i,destroyElement:w,getDeviceFingerprint:u,getElement:d,getPaymentIntent:m,createPaymentMethod:x,createPaymentConsent:A,confirmPaymentIntent:s,confirmPaymentIntentWithSavedCard:c};exports.confirmPaymentIntent=s,exports.confirmPaymentIntentWithSavedCard=c,exports.createElement=i,exports.createPaymentConsent=A,exports.createPaymentMethod=x,exports.default=y,exports.destroyElement=w,exports.getDeviceFingerprint=u,exports.getElement=d,exports.getGatewayUrl=r,exports.getPaymentIntent=m,exports.init=l,exports.loadAirwallex=n,exports.loadAirwallexJs=o,exports.redirectToCheckout=a;
|
|
3
3
|
//# sourceMappingURL=airwallex.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"airwallex.cjs.js","sources":["../../src/index.ts"],"sourcesContent":["import Airwallex, {\n init as initFn,\n redirectToCheckout as redirectToCheckoutFn,\n createElement as createElementFn,\n destroyElement as destroyElementFn,\n getElement as getElementFn,\n confirmPaymentIntent as confirmPaymentIntentFn,\n confirmPaymentIntentWithSavedCard as confirmPaymentIntentWithSavedCardFn,\n createPaymentMethod as createPaymentMethodFn,\n getPaymentIntent as getPaymentIntentFn,\n createPaymentConsent as createPaymentConsentFn,\n AirwallexEnv,\n} from '../types/airwallex';\nimport { getDeviceFingerprint as getDeviceFingerprintFn } from '../types/fraud';\nimport { loadAirwallex as loadAirwallexFn } from '../types/index';\nimport { version } from '../package.json';\n\nconst ENV_HOST = {\n prod: 'checkout.airwallex.com',\n demo: 'checkout-demo.airwallex.com',\n staging: 'checkout-staging.airwallex.com',\n /**\n * Below env only for the npm package development\n * Should not using them when integrate with Airwallex\n */\n qa: 'checkoutui.qa.awx.im',\n preview: 'checkoutui.preview.awx.im',\n dev: 'localhost:3000',\n};\n\ndeclare global {\n interface Window {\n Airwallex: Airwallex;\n ReactNativeWebView: {\n postMessage: (message: string) => void;\n };\n }\n}\n\n/**\n * @example\n * ```ts \nimport { gatewayUrl } from 'airwallex-payment-elements';\nconst gatewayUrl = getGatewayUrl('prod');\n```\n */\n\nexport const getGatewayUrl = (env: AirwallexEnv): string => `https://${ENV_HOST[env] || ENV_HOST.prod}`;\n\nconst STATIC_JS_URL = `/assets/elements.bundle.min.js?version=${version}`;\n\n/**\n * @example\n * ```ts \nimport { loadAirwallexJs } from 'airwallex-payment-elements';\nconst gatewayUrl = getGatewayUrl('prod');\nloadAirwallexJs(gatewayUrl);\n```\n */\n\nexport const loadAirwallexJs = (gatewayUrl: string): HTMLScriptElement => {\n const script = document.createElement('script');\n script.src = `${gatewayUrl}${STATIC_JS_URL}`;\n script.crossOrigin = 'anonymous';\n\n const headOrBody = document.head || document.body;\n\n if (!headOrBody) {\n throw new Error('Airwallex payment scripts requires a <head> or <body> html element in order to be loaded.');\n }\n\n headOrBody.appendChild(script);\n\n return script;\n};\n\n/**\n * @example\n * ```ts \nimport { loadAirwallex } from 'airwallex-payment-elements';\nloadAirwallex({\n env: 'prod',\n locale: 'en',\n});\n```\n */\n\nexport const loadAirwallex: typeof loadAirwallexFn = async (options) => {\n if (typeof window === 'undefined') {\n return null;\n }\n\n if (window.Airwallex) {\n return window.Airwallex;\n }\n\n const MAX_RETRY_COUNT = 3;\n let RETRY_COUNT = 0;\n const sleep = () => new Promise((resolve) => window.setTimeout(resolve, 500));\n\n const tryToResolve = async (): Promise<Airwallex> => {\n const script: HTMLScriptElement =\n document.querySelector(`script[src=\"${STATIC_JS_URL}\"], script[src=\"${STATIC_JS_URL}/\"]`) ||\n loadAirwallexJs(getGatewayUrl(options?.env || 'prod'));\n\n return new Promise((resolve, reject) => {\n script.addEventListener('load', () => {\n if (window.Airwallex) {\n window.Airwallex.init(options);\n resolve(window.Airwallex);\n } else {\n reject(new Error('Failed to load Airwallex on load event'));\n }\n });\n\n script.addEventListener('error', () => {\n reject(new Error('Failed to load Airwallex scripts'));\n script.remove && script.remove();\n });\n });\n };\n\n while (RETRY_COUNT < MAX_RETRY_COUNT) {\n try {\n return await tryToResolve();\n } catch (error) {\n RETRY_COUNT++;\n await sleep();\n }\n }\n\n return null;\n};\n\n/**\n * @example\n * ```ts \nimport { init } from 'airwallex-payment-elements';\ninit({\n env: 'prod',\n locale: 'en',\n});\n```\n */\n\nexport const init: typeof initFn = (options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before init();');\n } else {\n window.Airwallex.init(options);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { redirectToCheckout } from 'airwallex-payment-elements';\nredirectToCheckout({\n env: 'prod',\n intent_id: 'replace-with-your-intent_id',\n client_secret: 'replace-with-your-client-secret',,\n successUrl: `${window.location.origin}/checkout-success?isTesting=N`,\n locale: 'replace-with-your-language',\n showTermLink: true,\n theme: {\n variant: 'bootstrap',\n fonts: [\n {\n src: 'https://checkout.airwallex.com/fonts/CircularXXWeb/CircularXXSub-BoldSubset.woff2',\n family: 'AxLLCircular',\n weight: '700',\n },\n {\n src: 'https://checkout.airwallex.com/fonts/CircularXXWeb/CircularXXWeb-Regular.woff2',\n family: 'AxLLCircular',\n weight: '400',\n },\n ],\n popupWidth: 418,\n popupHeight: 549,\n },\n applePayRequestOptions: {\n countryCode: 'US',\n },\n googlePayRequestOptions: {\n countryCode: 'US',\n },\n requiredBillingContactFields: ['email', 'name'],\n currency: 'HKD',\n});\n```\n */\n\nexport const redirectToCheckout: typeof redirectToCheckoutFn = (props) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before redirectToCheckout();');\n } else {\n return window.Airwallex.redirectToCheckout(props);\n }\n};\n\n/**\n * We encourage to use `dropIn` element, since it's easy to scale new payment methods\n * We suggest to NOT use `applePayButton`, `googlePayButton`, `wechat`, `qrcode`, `redirect`, `fullFeaturedCard` and `directDebit` elements\n * \n * @example\n * ```ts \nimport { createElement } from 'airwallex-payment-elements';\nconst element = createElement('dropIn', {\n intent_id: 'replace-with-your-intent_id',\n client_secret: 'replace-with-your-client-secret',\n currency: 'replace-with-your-intent-currency',\n // if you want to use apple pay, please pass merchant country code in applePayRequestOptions\n applePayRequestOptions: {\n countryCode: 'replace-with-your-country-code',\n },\n // if you want to use google pay, please pass merchant country code in googlePayRequestOptions\n googlePayRequestOptions: {\n countryCode: 'replace-with-your-country-code',\n },\n});\n```\n */\n\nexport const createElement: typeof createElementFn = (type, options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before createElement();');\n return null;\n } else {\n return window.Airwallex.createElement(type, options);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { destroyElement } from 'airwallex-payment-elements';\ndestroyElement('dropIn');\n```\n */\n\nexport const destroyElement: typeof destroyElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before destroyElement();');\n return false;\n } else {\n return window.Airwallex.destroyElement(type);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { getElement } from 'airwallex-payment-elements';\ngetElement('dropIn');\n```\n */\n\nexport const getElement: typeof getElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before getElement();');\n return null;\n } else {\n return window.Airwallex.getElement(type);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { confirmPaymentIntent } from 'airwallex-payment-elements';\nconfirmPaymentIntent({\n element: card, // Provide Card element\n intent_id: 'replace-with-your-intent_id', // Payment Intent ID\n client_secret: 'replace-with-your-client-secret', // Client Secret\n payment_method_options: {\n card: {\n auto_capture: true,\n },\n },\n})\n```\n */\n\nexport const confirmPaymentIntent: typeof confirmPaymentIntentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntent(data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { confirmPaymentIntentWithSavedCard } from 'airwallex-payment-elements';\nconfirmPaymentIntentWithSavedCard({\n element: card, // Provide Card element\n customer_id: 'replace-with-your-customer-id',\n methodId: 'replace-with-your-method-id',\n intent_id: 'replace-with-your-intent_id', // Payment Intent ID\n client_secret: 'replace-with-your-client-secret', // Client Secret\n})\n```\n */\n\nexport const confirmPaymentIntentWithSavedCard: typeof confirmPaymentIntentWithSavedCardFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntentWithSavedCard();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntentWithSavedCard(data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { createPaymentMethod } from 'airwallex-payment-elements';\ncreatePaymentMethod('replace-with-your-client-secret', {\n element: card, // Provide Card element\n customer_id: 'replace-with-your-customer-id',\n})\n```\n */\n\nexport const createPaymentMethod: typeof createPaymentMethodFn = async (client_secret, data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentMethod();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentMethod(client_secret, data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { getPaymentIntent } from 'airwallex-payment-elements';\ngetPaymentIntent('replace-with-your-intent_id', 'replace-with-your-client_secret')\n```\n */\n\nexport const getPaymentIntent: typeof getPaymentIntentFn = async (id, client_secret) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before getPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.getPaymentIntent(id, client_secret);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { createPaymentConsent } from 'airwallex-payment-elements';\ncreatePaymentConsent({\n intent_id: 'replace-with-your-intent_id',\n customer_id: 'replace-with-your-customer_id',\n cardname: 'replace-with-your-card_name',\n client_secret: 'replace-with-your-client_secret',\n currency: 'HKD,\n element: cardNumberElement,\n next_triggered_by: 'customer',\n billing: {\n email: 'test@airwallex.com',\n first_name: 'TEST',\n last_name: 'TEST',\n date_of_birth: '2020-07-05',\n phone_number: '13333333333',\n address: {\n city: 'shanghai',\n country_code: 'CN',\n postcode: '200000',\n state: 'Shanghai',\n street: 'Street',\n },\n },\n})\n```\n */\n\nexport const createPaymentConsent: typeof createPaymentConsentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentConsent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentConsent(data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { getDeviceFingerprint } from 'airwallex-payment-elements';\ngetDeviceFingerprint({\n intent_id: 'replace-with-your-intent_id',\n env: 'prod',\n})\n```\n */\n\nexport const getDeviceFingerprint: typeof getDeviceFingerprintFn = (data) => {\n return window.Airwallex.getDeviceFingerprint(data);\n};\n\nexport default {\n getGatewayUrl,\n loadAirwallex,\n loadAirwallexJs,\n init,\n redirectToCheckout,\n createElement,\n destroyElement,\n getDeviceFingerprint,\n getElement,\n getPaymentIntent,\n createPaymentMethod,\n createPaymentConsent,\n confirmPaymentIntent,\n confirmPaymentIntentWithSavedCard,\n};\n"],"names":["ENV_HOST","prod","demo","staging","qa","preview","dev","getGatewayUrl","env","STATIC_JS_URL","loadAirwallexJs","gatewayUrl","script","document","createElement","src","crossOrigin","headOrBody","head","body","Error","appendChild","loadAirwallex","async","options","window","Airwallex","RETRY_COUNT","tryToResolve","querySelector","Promise","resolve","reject","addEventListener","init","remove","error","setTimeout","console","redirectToCheckout","props","type","destroyElement","getElement","confirmPaymentIntent","data","err","confirmPaymentIntentWithSavedCard","createPaymentMethod","client_secret","getPaymentIntent","id","createPaymentConsent","getDeviceFingerprint"],"mappings":";oEAiBA,MAAMA,EAAW,CACfC,KAAM,yBACNC,KAAM,8BACNC,QAAS,iCAKTC,GAAI,uBACJC,QAAS,4BACTC,IAAK,kBAoBMC,EAAiBC,GAA8B,WAAWR,EAASQ,IAAQR,EAASC,OAE3FQ,EAAgB,+CAWTC,EAAmBC,IAC9B,MAAMC,EAASC,SAASC,cAAc,UACtCF,EAAOG,IAAM,GAAGJ,IAAaF,IAC7BG,EAAOI,YAAc,YAErB,MAAMC,EAAaJ,SAASK,MAAQL,SAASM,KAE7C,IAAKF,EACH,MAAM,IAAIG,MAAM,6FAKlB,OAFAH,EAAWI,YAAYT,GAEhBA,GAcIU,EAAwCC,MAAOC,IAC1D,GAAsB,oBAAXC,OACT,OAAO,KAGT,GAAIA,OAAOC,UACT,OAAOD,OAAOC,UAIhB,IAAI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UqB,kCAAkCF,GALrC,CACrB,MAAMC,EAAM,qEAEZ,MADAR,QAAQF,MAAMU,GACR,IAAI1B,MAAM0B,KAiBPE,EAAoDzB,MAAO0B,EAAeJ,KACrF,GAAKpB,OAAOC,UAKV,OAAOD,OAAOC,UAAUsB,oBAAoBC,EAAeJ,GALtC,CACrB,MAAMC,EAAM,uDAEZ,MADAR,QAAQF,MAAMU,GACR,IAAI1B,MAAM0B,KAcPI,EAA8C3B,MAAO4B,EAAIF,KACpE,GAAKxB,OAAOC,UAKV,OAAOD,OAAOC,UAAUwB,iBAAiBC,EAAIF,GALxB,CACrB,MAAMH,EAAM,oDAEZ,MADAR,QAAQF,MAAMU,GACR,IAAI1B,MAAM0B,KAoCPM,EAAsD7B,MAAOsB,IACxE,GAAKpB,OAAOC,UAKV,OAAOD,OAAOC,UAAU0B,qBAAqBP,GALxB,CACrB,MAAMC,EAAM,wDAEZ,MADAR,QAAQF,MAAMU,GACR,IAAI1B,MAAM0B,KAiBPO,EAAuDR,GAC3DpB,OAAOC,UAAU2B,qBAAqBR,GAG/C,MAAe,CACbtC,cAAAA,EACAe,cAAAA,EACAZ,gBAAAA,EACAwB,KAAAA,EACAK,mBAAAA,EACAzB,cAAAA,EACA4B,eAAAA,EACAW,qBAAAA,EACAV,WAAAA,EACAO,iBAAAA,EACAF,oBAAAA,EACAI,qBAAAA,EACAR,qBAAAA,EACAG,kCAAAA"}
|
|
1
|
+
{"version":3,"file":"airwallex.cjs.js","sources":["../../src/index.ts"],"sourcesContent":["import Airwallex, {\n init as initFn,\n redirectToCheckout as redirectToCheckoutFn,\n createElement as createElementFn,\n destroyElement as destroyElementFn,\n getElement as getElementFn,\n confirmPaymentIntent as confirmPaymentIntentFn,\n confirmPaymentIntentWithSavedCard as confirmPaymentIntentWithSavedCardFn,\n createPaymentMethod as createPaymentMethodFn,\n getPaymentIntent as getPaymentIntentFn,\n createPaymentConsent as createPaymentConsentFn,\n AirwallexEnv,\n} from '../types/airwallex';\nimport { getDeviceFingerprint as getDeviceFingerprintFn } from '../types/fraud';\nimport { loadAirwallex as loadAirwallexFn } from '../types/index';\nimport { version } from '../package.json';\n\nconst ENV_HOST = {\n prod: 'checkout.airwallex.com',\n demo: 'checkout-demo.airwallex.com',\n staging: 'checkout-staging.airwallex.com',\n /**\n * Below env only for the npm package development\n * Should not using them when integrate with Airwallex\n */\n qa: 'checkoutui.qa.awx.im',\n preview: 'checkoutui.preview.awx.im',\n dev: 'localhost:3000',\n};\n\ndeclare global {\n interface Window {\n Airwallex: Airwallex;\n ReactNativeWebView: {\n postMessage: (message: string) => void;\n };\n }\n}\n\n/**\n * @example\n * ```ts \nimport { gatewayUrl } from 'airwallex-payment-elements';\nconst gatewayUrl = getGatewayUrl('prod');\n```\n */\n\nexport const getGatewayUrl = (env: AirwallexEnv): string => `https://${ENV_HOST[env] || ENV_HOST.prod}`;\n\nconst STATIC_JS_URL = `/assets/elements.bundle.min.js?version=${version}`;\n\n/**\n * @example\n * ```ts \nimport { loadAirwallexJs } from 'airwallex-payment-elements';\nconst gatewayUrl = getGatewayUrl('prod');\nloadAirwallexJs(gatewayUrl);\n```\n */\n\nexport const loadAirwallexJs = (gatewayUrl: string): HTMLScriptElement => {\n const script = document.createElement('script');\n script.src = `${gatewayUrl}${STATIC_JS_URL}`;\n script.crossOrigin = 'anonymous';\n\n const headOrBody = document.head || document.body;\n\n if (!headOrBody) {\n throw new Error('Airwallex payment scripts requires a <head> or <body> html element in order to be loaded.');\n }\n\n headOrBody.appendChild(script);\n\n return script;\n};\n\n/**\n * @example\n * ```ts \nimport { loadAirwallex } from 'airwallex-payment-elements';\nloadAirwallex({\n env: 'prod',\n locale: 'en',\n});\n```\n */\n\nexport const loadAirwallex: typeof loadAirwallexFn = async (options) => {\n if (typeof window === 'undefined') {\n return null;\n }\n\n if (window.Airwallex) {\n return window.Airwallex;\n }\n\n const MAX_RETRY_COUNT = 3;\n let RETRY_COUNT = 0;\n const sleep = () => new Promise((resolve) => window.setTimeout(resolve, 500));\n\n const tryToResolve = async (): Promise<Airwallex> => {\n const script: HTMLScriptElement =\n document.querySelector(`script[src=\"${STATIC_JS_URL}\"], script[src=\"${STATIC_JS_URL}/\"]`) ||\n loadAirwallexJs(getGatewayUrl(options?.env || 'prod'));\n\n return new Promise((resolve, reject) => {\n script.addEventListener('load', () => {\n if (window.Airwallex) {\n window.Airwallex.init(options);\n resolve(window.Airwallex);\n } else {\n reject(new Error('Failed to load Airwallex on load event'));\n }\n });\n\n script.addEventListener('error', () => {\n reject(new Error('Failed to load Airwallex scripts'));\n script.remove && script.remove();\n });\n });\n };\n\n while (RETRY_COUNT < MAX_RETRY_COUNT) {\n try {\n return await tryToResolve();\n } catch (error) {\n RETRY_COUNT++;\n await sleep();\n }\n }\n\n return null;\n};\n\n/**\n * @example\n * ```ts \nimport { init } from 'airwallex-payment-elements';\ninit({\n env: 'prod',\n locale: 'en',\n});\n```\n */\n\nexport const init: typeof initFn = (options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before init();');\n } else {\n window.Airwallex.init(options);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { redirectToCheckout } from 'airwallex-payment-elements';\nredirectToCheckout({\n env: 'prod',\n intent_id: 'replace-with-your-intent_id',\n client_secret: 'replace-with-your-client-secret',,\n successUrl: `${window.location.origin}/checkout-success?isTesting=N`,\n locale: 'replace-with-your-language',\n showTermLink: true,\n theme: {\n variant: 'bootstrap',\n fonts: [\n {\n src: 'https://checkout.airwallex.com/fonts/CircularXXWeb/CircularXXSub-BoldSubset.woff2',\n family: 'AxLLCircular',\n weight: '700',\n },\n {\n src: 'https://checkout.airwallex.com/fonts/CircularXXWeb/CircularXXWeb-Regular.woff2',\n family: 'AxLLCircular',\n weight: '400',\n },\n ],\n popupWidth: 418,\n popupHeight: 549,\n },\n applePayRequestOptions: {\n countryCode: 'US',\n },\n googlePayRequestOptions: {\n countryCode: 'US',\n },\n requiredBillingContactFields: ['email', 'name'],\n currency: 'HKD',\n});\n```\n */\n\nexport const redirectToCheckout: typeof redirectToCheckoutFn = (props) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before redirectToCheckout();');\n } else {\n return window.Airwallex.redirectToCheckout(props);\n }\n};\n\n/**\n * We encourage to use `dropIn` element, since it's easy to scale new payment methods\n * We suggest to NOT use `applePayButton`, `googlePayButton`, `wechat`, `qrcode`, `redirect`, `fullFeaturedCard` and `directDebit` elements\n * \n * @example\n * ```ts \nimport { createElement } from 'airwallex-payment-elements';\nconst element = createElement('dropIn', {\n intent_id: 'replace-with-your-intent_id',\n client_secret: 'replace-with-your-client-secret',\n currency: 'replace-with-your-intent-currency',\n // if you want to use apple pay, please pass merchant country code in applePayRequestOptions\n applePayRequestOptions: {\n countryCode: 'replace-with-your-country-code',\n },\n // if you want to use google pay, please pass merchant country code in googlePayRequestOptions\n googlePayRequestOptions: {\n countryCode: 'replace-with-your-country-code',\n },\n});\n```\n */\n\nexport const createElement: typeof createElementFn = (type, options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before createElement();');\n return null;\n } else {\n return window.Airwallex.createElement(type, options);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { destroyElement } from 'airwallex-payment-elements';\ndestroyElement('dropIn');\n```\n */\n\nexport const destroyElement: typeof destroyElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before destroyElement();');\n return false;\n } else {\n return window.Airwallex.destroyElement(type);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { getElement } from 'airwallex-payment-elements';\ngetElement('dropIn');\n```\n */\n\nexport const getElement: typeof getElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before getElement();');\n return null;\n } else {\n return window.Airwallex.getElement(type);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { confirmPaymentIntent } from 'airwallex-payment-elements';\nconfirmPaymentIntent({\n element: card, // Provide Card element\n intent_id: 'replace-with-your-intent_id', // Payment Intent ID\n client_secret: 'replace-with-your-client-secret', // Client Secret\n payment_method_options: {\n card: {\n auto_capture: true,\n },\n },\n})\n```\n */\n\nexport const confirmPaymentIntent: typeof confirmPaymentIntentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntent(data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { confirmPaymentIntentWithSavedCard } from 'airwallex-payment-elements';\nconfirmPaymentIntentWithSavedCard({\n element: card, // Provide Card element\n customer_id: 'replace-with-your-customer-id',\n methodId: 'replace-with-your-method-id',\n intent_id: 'replace-with-your-intent_id', // Payment Intent ID\n client_secret: 'replace-with-your-client-secret', // Client Secret\n})\n```\n */\n\nexport const confirmPaymentIntentWithSavedCard: typeof confirmPaymentIntentWithSavedCardFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntentWithSavedCard();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntentWithSavedCard(data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { createPaymentMethod } from 'airwallex-payment-elements';\ncreatePaymentMethod('replace-with-your-client-secret', {\n element: card, // Provide Card element\n customer_id: 'replace-with-your-customer-id',\n})\n```\n */\n\nexport const createPaymentMethod: typeof createPaymentMethodFn = async (client_secret, data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentMethod();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentMethod(client_secret, data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { getPaymentIntent } from 'airwallex-payment-elements';\ngetPaymentIntent('replace-with-your-intent_id', 'replace-with-your-client_secret')\n```\n */\n\nexport const getPaymentIntent: typeof getPaymentIntentFn = async (id, client_secret) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before getPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.getPaymentIntent(id, client_secret);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { createPaymentConsent } from 'airwallex-payment-elements';\ncreatePaymentConsent({\n intent_id: 'replace-with-your-intent_id',\n customer_id: 'replace-with-your-customer_id',\n cardname: 'replace-with-your-card_name',\n client_secret: 'replace-with-your-client_secret',\n currency: 'HKD,\n element: cardNumberElement,\n next_triggered_by: 'customer',\n billing: {\n email: 'test@airwallex.com',\n first_name: 'TEST',\n last_name: 'TEST',\n date_of_birth: '2020-07-05',\n phone_number: '13333333333',\n address: {\n city: 'shanghai',\n country_code: 'CN',\n postcode: '200000',\n state: 'Shanghai',\n street: 'Street',\n },\n },\n})\n```\n */\n\nexport const createPaymentConsent: typeof createPaymentConsentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentConsent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentConsent(data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { getDeviceFingerprint } from 'airwallex-payment-elements';\ngetDeviceFingerprint({\n intent_id: 'replace-with-your-intent_id',\n env: 'prod',\n})\n```\n */\n\nexport const getDeviceFingerprint: typeof getDeviceFingerprintFn = (data) => {\n return window.Airwallex.getDeviceFingerprint(data);\n};\n\nexport default {\n getGatewayUrl,\n loadAirwallex,\n loadAirwallexJs,\n init,\n redirectToCheckout,\n createElement,\n destroyElement,\n getDeviceFingerprint,\n getElement,\n getPaymentIntent,\n createPaymentMethod,\n createPaymentConsent,\n confirmPaymentIntent,\n confirmPaymentIntentWithSavedCard,\n};\n"],"names":["ENV_HOST","prod","demo","staging","qa","preview","dev","getGatewayUrl","env","STATIC_JS_URL","loadAirwallexJs","gatewayUrl","script","document","createElement","src","crossOrigin","headOrBody","head","body","Error","appendChild","loadAirwallex","async","options","window","Airwallex","RETRY_COUNT","tryToResolve","querySelector","Promise","resolve","reject","addEventListener","init","remove","error","setTimeout","console","redirectToCheckout","props","type","destroyElement","getElement","confirmPaymentIntent","data","err","confirmPaymentIntentWithSavedCard","createPaymentMethod","client_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,cAAAA,EACAe,cAAAA,EACAZ,gBAAAA,EACAwB,KAAAA,EACAK,mBAAAA,EACAzB,cAAAA,EACA4B,eAAAA,EACAW,qBAAAA,EACAV,WAAAA,EACAO,iBAAAA,EACAF,oBAAAA,EACAI,qBAAAA,EACAR,qBAAAA,EACAG,kCAAAA"}
|
package/lib/bin/airwallex.es.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* Airwallex Checkout Component Version [1.
|
|
2
|
-
const e={prod:"checkout.airwallex.com",demo:"checkout-demo.airwallex.com",staging:"checkout-staging.airwallex.com",qa:"checkoutui.qa.awx.im",preview:"checkoutui.preview.awx.im",dev:"localhost:3000"},r=r=>`https://${e[r]||e.prod}`,o="/assets/elements.bundle.min.js?version=1.
|
|
1
|
+
/* Airwallex Checkout Component Version [1.10.0] */
|
|
2
|
+
const e={prod:"checkout.airwallex.com",demo:"checkout-demo.airwallex.com",staging:"checkout-staging.airwallex.com",qa:"checkoutui.qa.awx.im",preview:"checkoutui.preview.awx.im",dev:"localhost:3000"},r=r=>`https://${e[r]||e.prod}`,o="/assets/elements.bundle.min.js?version=1.10.0",n=e=>{const r=document.createElement("script");r.src=`${e}${o}`,r.crossOrigin="anonymous";const n=document.head||document.body;if(!n)throw new Error("Airwallex payment scripts requires a <head> or <body> html element in order to be loaded.");return n.appendChild(r),r},t=async e=>{if("undefined"==typeof window)return null;if(window.Airwallex)return window.Airwallex;let t=0;const l=async()=>{const t=document.querySelector(`script[src="${o}"], script[src="${o}/"]`)||n(r((null==e?void 0:e.env)||"prod"));return new Promise(((r,o)=>{t.addEventListener("load",(()=>{window.Airwallex?(window.Airwallex.init(e),r(window.Airwallex)):o(new Error("Failed to load Airwallex on load event"))})),t.addEventListener("error",(()=>{o(new Error("Failed to load Airwallex scripts")),t.remove&&t.remove()}))}))};for(;t<3;)try{return await l()}catch(e){t++,await new Promise((e=>window.setTimeout(e,500)))}return null},l=e=>{window.Airwallex?window.Airwallex.init(e):console.error("Please loadAirwallex() before init();")},a=e=>{if(window.Airwallex)return window.Airwallex.redirectToCheckout(e);console.error("Please loadAirwallex() before redirectToCheckout();")},i=(e,r)=>window.Airwallex?window.Airwallex.createElement(e,r):(console.error("Please loadAirwallex() before createElement();"),null),w=e=>window.Airwallex?window.Airwallex.destroyElement(e):(console.error("Please loadAirwallex() before destroyElement();"),!1),d=e=>window.Airwallex?window.Airwallex.getElement(e):(console.error("Please loadAirwallex() before getElement();"),null),c=async e=>{if(window.Airwallex)return window.Airwallex.confirmPaymentIntent(e);{const e="Please loadAirwallex() before confirmPaymentIntent();";throw console.error(e),new Error(e)}},s=async e=>{if(window.Airwallex)return window.Airwallex.confirmPaymentIntentWithSavedCard(e);{const e="Please loadAirwallex() before confirmPaymentIntentWithSavedCard();";throw console.error(e),new Error(e)}},m=async(e,r)=>{if(window.Airwallex)return window.Airwallex.createPaymentMethod(e,r);{const e="Please loadAirwallex() before createPaymentMethod();";throw console.error(e),new Error(e)}},x=async(e,r)=>{if(window.Airwallex)return window.Airwallex.getPaymentIntent(e,r);{const e="Please loadAirwallex() before getPaymentIntent();";throw console.error(e),new Error(e)}},A=async e=>{if(window.Airwallex)return window.Airwallex.createPaymentConsent(e);{const e="Please loadAirwallex() before createPaymentConsent();";throw console.error(e),new Error(e)}},u=e=>window.Airwallex.getDeviceFingerprint(e);var y={getGatewayUrl:r,loadAirwallex:t,loadAirwallexJs:n,init:l,redirectToCheckout:a,createElement:i,destroyElement:w,getDeviceFingerprint:u,getElement:d,getPaymentIntent:x,createPaymentMethod:m,createPaymentConsent:A,confirmPaymentIntent:c,confirmPaymentIntentWithSavedCard:s};export default y;export{c as confirmPaymentIntent,s as confirmPaymentIntentWithSavedCard,i as createElement,A as createPaymentConsent,m as createPaymentMethod,w as destroyElement,u as getDeviceFingerprint,d as getElement,r as getGatewayUrl,x as getPaymentIntent,l as init,t as loadAirwallex,n as loadAirwallexJs,a as redirectToCheckout};
|
|
3
3
|
//# sourceMappingURL=airwallex.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"airwallex.es.js","sources":["../../src/index.ts"],"sourcesContent":["import Airwallex, {\n init as initFn,\n redirectToCheckout as redirectToCheckoutFn,\n createElement as createElementFn,\n destroyElement as destroyElementFn,\n getElement as getElementFn,\n confirmPaymentIntent as confirmPaymentIntentFn,\n confirmPaymentIntentWithSavedCard as confirmPaymentIntentWithSavedCardFn,\n createPaymentMethod as createPaymentMethodFn,\n getPaymentIntent as getPaymentIntentFn,\n createPaymentConsent as createPaymentConsentFn,\n AirwallexEnv,\n} from '../types/airwallex';\nimport { getDeviceFingerprint as getDeviceFingerprintFn } from '../types/fraud';\nimport { loadAirwallex as loadAirwallexFn } from '../types/index';\nimport { version } from '../package.json';\n\nconst ENV_HOST = {\n prod: 'checkout.airwallex.com',\n demo: 'checkout-demo.airwallex.com',\n staging: 'checkout-staging.airwallex.com',\n /**\n * Below env only for the npm package development\n * Should not using them when integrate with Airwallex\n */\n qa: 'checkoutui.qa.awx.im',\n preview: 'checkoutui.preview.awx.im',\n dev: 'localhost:3000',\n};\n\ndeclare global {\n interface Window {\n Airwallex: Airwallex;\n ReactNativeWebView: {\n postMessage: (message: string) => void;\n };\n }\n}\n\n/**\n * @example\n * ```ts \nimport { gatewayUrl } from 'airwallex-payment-elements';\nconst gatewayUrl = getGatewayUrl('prod');\n```\n */\n\nexport const getGatewayUrl = (env: AirwallexEnv): string => `https://${ENV_HOST[env] || ENV_HOST.prod}`;\n\nconst STATIC_JS_URL = `/assets/elements.bundle.min.js?version=${version}`;\n\n/**\n * @example\n * ```ts \nimport { loadAirwallexJs } from 'airwallex-payment-elements';\nconst gatewayUrl = getGatewayUrl('prod');\nloadAirwallexJs(gatewayUrl);\n```\n */\n\nexport const loadAirwallexJs = (gatewayUrl: string): HTMLScriptElement => {\n const script = document.createElement('script');\n script.src = `${gatewayUrl}${STATIC_JS_URL}`;\n script.crossOrigin = 'anonymous';\n\n const headOrBody = document.head || document.body;\n\n if (!headOrBody) {\n throw new Error('Airwallex payment scripts requires a <head> or <body> html element in order to be loaded.');\n }\n\n headOrBody.appendChild(script);\n\n return script;\n};\n\n/**\n * @example\n * ```ts \nimport { loadAirwallex } from 'airwallex-payment-elements';\nloadAirwallex({\n env: 'prod',\n locale: 'en',\n});\n```\n */\n\nexport const loadAirwallex: typeof loadAirwallexFn = async (options) => {\n if (typeof window === 'undefined') {\n return null;\n }\n\n if (window.Airwallex) {\n return window.Airwallex;\n }\n\n const MAX_RETRY_COUNT = 3;\n let RETRY_COUNT = 0;\n const sleep = () => new Promise((resolve) => window.setTimeout(resolve, 500));\n\n const tryToResolve = async (): Promise<Airwallex> => {\n const script: HTMLScriptElement =\n document.querySelector(`script[src=\"${STATIC_JS_URL}\"], script[src=\"${STATIC_JS_URL}/\"]`) ||\n loadAirwallexJs(getGatewayUrl(options?.env || 'prod'));\n\n return new Promise((resolve, reject) => {\n script.addEventListener('load', () => {\n if (window.Airwallex) {\n window.Airwallex.init(options);\n resolve(window.Airwallex);\n } else {\n reject(new Error('Failed to load Airwallex on load event'));\n }\n });\n\n script.addEventListener('error', () => {\n reject(new Error('Failed to load Airwallex scripts'));\n script.remove && script.remove();\n });\n });\n };\n\n while (RETRY_COUNT < MAX_RETRY_COUNT) {\n try {\n return await tryToResolve();\n } catch (error) {\n RETRY_COUNT++;\n await sleep();\n }\n }\n\n return null;\n};\n\n/**\n * @example\n * ```ts \nimport { init } from 'airwallex-payment-elements';\ninit({\n env: 'prod',\n locale: 'en',\n});\n```\n */\n\nexport const init: typeof initFn = (options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before init();');\n } else {\n window.Airwallex.init(options);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { redirectToCheckout } from 'airwallex-payment-elements';\nredirectToCheckout({\n env: 'prod',\n intent_id: 'replace-with-your-intent_id',\n client_secret: 'replace-with-your-client-secret',,\n successUrl: `${window.location.origin}/checkout-success?isTesting=N`,\n locale: 'replace-with-your-language',\n showTermLink: true,\n theme: {\n variant: 'bootstrap',\n fonts: [\n {\n src: 'https://checkout.airwallex.com/fonts/CircularXXWeb/CircularXXSub-BoldSubset.woff2',\n family: 'AxLLCircular',\n weight: '700',\n },\n {\n src: 'https://checkout.airwallex.com/fonts/CircularXXWeb/CircularXXWeb-Regular.woff2',\n family: 'AxLLCircular',\n weight: '400',\n },\n ],\n popupWidth: 418,\n popupHeight: 549,\n },\n applePayRequestOptions: {\n countryCode: 'US',\n },\n googlePayRequestOptions: {\n countryCode: 'US',\n },\n requiredBillingContactFields: ['email', 'name'],\n currency: 'HKD',\n});\n```\n */\n\nexport const redirectToCheckout: typeof redirectToCheckoutFn = (props) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before redirectToCheckout();');\n } else {\n return window.Airwallex.redirectToCheckout(props);\n }\n};\n\n/**\n * We encourage to use `dropIn` element, since it's easy to scale new payment methods\n * We suggest to NOT use `applePayButton`, `googlePayButton`, `wechat`, `qrcode`, `redirect`, `fullFeaturedCard` and `directDebit` elements\n * \n * @example\n * ```ts \nimport { createElement } from 'airwallex-payment-elements';\nconst element = createElement('dropIn', {\n intent_id: 'replace-with-your-intent_id',\n client_secret: 'replace-with-your-client-secret',\n currency: 'replace-with-your-intent-currency',\n // if you want to use apple pay, please pass merchant country code in applePayRequestOptions\n applePayRequestOptions: {\n countryCode: 'replace-with-your-country-code',\n },\n // if you want to use google pay, please pass merchant country code in googlePayRequestOptions\n googlePayRequestOptions: {\n countryCode: 'replace-with-your-country-code',\n },\n});\n```\n */\n\nexport const createElement: typeof createElementFn = (type, options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before createElement();');\n return null;\n } else {\n return window.Airwallex.createElement(type, options);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { destroyElement } from 'airwallex-payment-elements';\ndestroyElement('dropIn');\n```\n */\n\nexport const destroyElement: typeof destroyElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before destroyElement();');\n return false;\n } else {\n return window.Airwallex.destroyElement(type);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { getElement } from 'airwallex-payment-elements';\ngetElement('dropIn');\n```\n */\n\nexport const getElement: typeof getElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before getElement();');\n return null;\n } else {\n return window.Airwallex.getElement(type);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { confirmPaymentIntent } from 'airwallex-payment-elements';\nconfirmPaymentIntent({\n element: card, // Provide Card element\n intent_id: 'replace-with-your-intent_id', // Payment Intent ID\n client_secret: 'replace-with-your-client-secret', // Client Secret\n payment_method_options: {\n card: {\n auto_capture: true,\n },\n },\n})\n```\n */\n\nexport const confirmPaymentIntent: typeof confirmPaymentIntentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntent(data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { confirmPaymentIntentWithSavedCard } from 'airwallex-payment-elements';\nconfirmPaymentIntentWithSavedCard({\n element: card, // Provide Card element\n customer_id: 'replace-with-your-customer-id',\n methodId: 'replace-with-your-method-id',\n intent_id: 'replace-with-your-intent_id', // Payment Intent ID\n client_secret: 'replace-with-your-client-secret', // Client Secret\n})\n```\n */\n\nexport const confirmPaymentIntentWithSavedCard: typeof confirmPaymentIntentWithSavedCardFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntentWithSavedCard();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntentWithSavedCard(data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { createPaymentMethod } from 'airwallex-payment-elements';\ncreatePaymentMethod('replace-with-your-client-secret', {\n element: card, // Provide Card element\n customer_id: 'replace-with-your-customer-id',\n})\n```\n */\n\nexport const createPaymentMethod: typeof createPaymentMethodFn = async (client_secret, data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentMethod();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentMethod(client_secret, data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { getPaymentIntent } from 'airwallex-payment-elements';\ngetPaymentIntent('replace-with-your-intent_id', 'replace-with-your-client_secret')\n```\n */\n\nexport const getPaymentIntent: typeof getPaymentIntentFn = async (id, client_secret) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before getPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.getPaymentIntent(id, client_secret);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { createPaymentConsent } from 'airwallex-payment-elements';\ncreatePaymentConsent({\n intent_id: 'replace-with-your-intent_id',\n customer_id: 'replace-with-your-customer_id',\n cardname: 'replace-with-your-card_name',\n client_secret: 'replace-with-your-client_secret',\n currency: 'HKD,\n element: cardNumberElement,\n next_triggered_by: 'customer',\n billing: {\n email: 'test@airwallex.com',\n first_name: 'TEST',\n last_name: 'TEST',\n date_of_birth: '2020-07-05',\n phone_number: '13333333333',\n address: {\n city: 'shanghai',\n country_code: 'CN',\n postcode: '200000',\n state: 'Shanghai',\n street: 'Street',\n },\n },\n})\n```\n */\n\nexport const createPaymentConsent: typeof createPaymentConsentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentConsent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentConsent(data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { getDeviceFingerprint } from 'airwallex-payment-elements';\ngetDeviceFingerprint({\n intent_id: 'replace-with-your-intent_id',\n env: 'prod',\n})\n```\n */\n\nexport const getDeviceFingerprint: typeof getDeviceFingerprintFn = (data) => {\n return window.Airwallex.getDeviceFingerprint(data);\n};\n\nexport default {\n getGatewayUrl,\n loadAirwallex,\n loadAirwallexJs,\n init,\n redirectToCheckout,\n createElement,\n destroyElement,\n getDeviceFingerprint,\n getElement,\n getPaymentIntent,\n createPaymentMethod,\n createPaymentConsent,\n confirmPaymentIntent,\n confirmPaymentIntentWithSavedCard,\n};\n"],"names":["ENV_HOST","prod","demo","staging","qa","preview","dev","getGatewayUrl","env","STATIC_JS_URL","loadAirwallexJs","gatewayUrl","script","document","createElement","src","crossOrigin","headOrBody","head","body","Error","appendChild","loadAirwallex","async","options","window","Airwallex","RETRY_COUNT","tryToResolve","querySelector","Promise","resolve","reject","addEventListener","init","remove","error","setTimeout","console","redirectToCheckout","props","type","destroyElement","getElement","confirmPaymentIntent","data","err","confirmPaymentIntentWithSavedCard","createPaymentMethod","client_secret","getPaymentIntent","id","createPaymentConsent","getDeviceFingerprint"],"mappings":";AAiBA,MAAMA,EAAW,CACfC,KAAM,yBACNC,KAAM,8BACNC,QAAS,iCAKTC,GAAI,uBACJC,QAAS,4BACTC,IAAK,kBAoBMC,EAAiBC,GAA8B,WAAWR,EAASQ,IAAQR,EAASC,OAE3FQ,EAAgB,+CAWTC,EAAmBC,IAC9B,MAAMC,EAASC,SAASC,cAAc,UACtCF,EAAOG,IAAM,GAAGJ,IAAaF,IAC7BG,EAAOI,YAAc,YAErB,MAAMC,EAAaJ,SAASK,MAAQL,SAASM,KAE7C,IAAKF,EACH,MAAM,IAAIG,MAAM,6FAKlB,OAFAH,EAAWI,YAAYT,GAEhBA,GAcIU,EAAwCC,MAAOC,IAC1D,GAAsB,oBAAXC,OACT,OAAO,KAGT,GAAIA,OAAOC,UACT,OAAOD,OAAOC,UAIhB,IAAIC,EAAc,EAClB,MAEMC,EAAeL,UACnB,MAAMX,EACJC,SAASgB,cAAc,eAAepB,oBAAgCA,SACtEC,EAAgBH,GAAciB,MAAAA,SAAAA,EAAShB,MAAO,SAEhD,OAAO,IAAIsB,SAAQ,CAACC,EAASC,KAC3BpB,EAAOqB,iBAAiB,QAAQ,KAC1BR,OAAOC,WACTD,OAAOC,UAAUQ,KAAKV,GACtBO,EAAQN,OAAOC,YAEfM,EAAO,IAAIZ,MAAM,8CAIrBR,E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GAAKxB,OAAOC,UAKV,OAAOD,OAAOC,UAAUwB,iBAAiBC,EAAIF,GALxB,CACrB,MAAMH,EAAM,oDAEZ,MADAR,QAAQF,MAAMU,GACR,IAAI1B,MAAM0B,KAoCPM,EAAsD7B,MAAOsB,IACxE,GAAKpB,OAAOC,UAKV,OAAOD,OAAOC,UAAU0B,qBAAqBP,GALxB,CACrB,MAAMC,EAAM,wDAEZ,MADAR,QAAQF,MAAMU,GACR,IAAI1B,MAAM0B,KAiBPO,EAAuDR,GAC3DpB,OAAOC,UAAU2B,qBAAqBR,GAG/C,MAAe,CACbtC,cAAAA,EACAe,cAAAA,EACAZ,gBAAAA,EACAwB,KAAAA,EACAK,mBAAAA,EACAzB,cAAAA,EACA4B,eAAAA,EACAW,qBAAAA,EACAV,WAAAA,EACAO,iBAAAA,EACAF,oBAAAA,EACAI,qBAAAA,EACAR,qBAAAA,EACAG,kCAAAA"}
|
|
1
|
+
{"version":3,"file":"airwallex.es.js","sources":["../../src/index.ts"],"sourcesContent":["import Airwallex, {\n init as initFn,\n redirectToCheckout as redirectToCheckoutFn,\n createElement as createElementFn,\n destroyElement as destroyElementFn,\n getElement as getElementFn,\n confirmPaymentIntent as confirmPaymentIntentFn,\n confirmPaymentIntentWithSavedCard as confirmPaymentIntentWithSavedCardFn,\n createPaymentMethod as createPaymentMethodFn,\n getPaymentIntent as getPaymentIntentFn,\n createPaymentConsent as createPaymentConsentFn,\n AirwallexEnv,\n} from '../types/airwallex';\nimport { getDeviceFingerprint as getDeviceFingerprintFn } from '../types/fraud';\nimport { loadAirwallex as loadAirwallexFn } from '../types/index';\nimport { version } from '../package.json';\n\nconst ENV_HOST = {\n prod: 'checkout.airwallex.com',\n demo: 'checkout-demo.airwallex.com',\n staging: 'checkout-staging.airwallex.com',\n /**\n * Below env only for the npm package development\n * Should not using them when integrate with Airwallex\n */\n qa: 'checkoutui.qa.awx.im',\n preview: 'checkoutui.preview.awx.im',\n dev: 'localhost:3000',\n};\n\ndeclare global {\n interface Window {\n Airwallex: Airwallex;\n ReactNativeWebView: {\n postMessage: (message: string) => void;\n };\n }\n}\n\n/**\n * @example\n * ```ts \nimport { gatewayUrl } from 'airwallex-payment-elements';\nconst gatewayUrl = getGatewayUrl('prod');\n```\n */\n\nexport const getGatewayUrl = (env: AirwallexEnv): string => `https://${ENV_HOST[env] || ENV_HOST.prod}`;\n\nconst STATIC_JS_URL = `/assets/elements.bundle.min.js?version=${version}`;\n\n/**\n * @example\n * ```ts \nimport { loadAirwallexJs } from 'airwallex-payment-elements';\nconst gatewayUrl = getGatewayUrl('prod');\nloadAirwallexJs(gatewayUrl);\n```\n */\n\nexport const loadAirwallexJs = (gatewayUrl: string): HTMLScriptElement => {\n const script = document.createElement('script');\n script.src = `${gatewayUrl}${STATIC_JS_URL}`;\n script.crossOrigin = 'anonymous';\n\n const headOrBody = document.head || document.body;\n\n if (!headOrBody) {\n throw new Error('Airwallex payment scripts requires a <head> or <body> html element in order to be loaded.');\n }\n\n headOrBody.appendChild(script);\n\n return script;\n};\n\n/**\n * @example\n * ```ts \nimport { loadAirwallex } from 'airwallex-payment-elements';\nloadAirwallex({\n env: 'prod',\n locale: 'en',\n});\n```\n */\n\nexport const loadAirwallex: typeof loadAirwallexFn = async (options) => {\n if (typeof window === 'undefined') {\n return null;\n }\n\n if (window.Airwallex) {\n return window.Airwallex;\n }\n\n const MAX_RETRY_COUNT = 3;\n let RETRY_COUNT = 0;\n const sleep = () => new Promise((resolve) => window.setTimeout(resolve, 500));\n\n const tryToResolve = async (): Promise<Airwallex> => {\n const script: HTMLScriptElement =\n document.querySelector(`script[src=\"${STATIC_JS_URL}\"], script[src=\"${STATIC_JS_URL}/\"]`) ||\n loadAirwallexJs(getGatewayUrl(options?.env || 'prod'));\n\n return new Promise((resolve, reject) => {\n script.addEventListener('load', () => {\n if (window.Airwallex) {\n window.Airwallex.init(options);\n resolve(window.Airwallex);\n } else {\n reject(new Error('Failed to load Airwallex on load event'));\n }\n });\n\n script.addEventListener('error', () => {\n reject(new Error('Failed to load Airwallex scripts'));\n script.remove && script.remove();\n });\n });\n };\n\n while (RETRY_COUNT < MAX_RETRY_COUNT) {\n try {\n return await tryToResolve();\n } catch (error) {\n RETRY_COUNT++;\n await sleep();\n }\n }\n\n return null;\n};\n\n/**\n * @example\n * ```ts \nimport { init } from 'airwallex-payment-elements';\ninit({\n env: 'prod',\n locale: 'en',\n});\n```\n */\n\nexport const init: typeof initFn = (options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before init();');\n } else {\n window.Airwallex.init(options);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { redirectToCheckout } from 'airwallex-payment-elements';\nredirectToCheckout({\n env: 'prod',\n intent_id: 'replace-with-your-intent_id',\n client_secret: 'replace-with-your-client-secret',,\n successUrl: `${window.location.origin}/checkout-success?isTesting=N`,\n locale: 'replace-with-your-language',\n showTermLink: true,\n theme: {\n variant: 'bootstrap',\n fonts: [\n {\n src: 'https://checkout.airwallex.com/fonts/CircularXXWeb/CircularXXSub-BoldSubset.woff2',\n family: 'AxLLCircular',\n weight: '700',\n },\n {\n src: 'https://checkout.airwallex.com/fonts/CircularXXWeb/CircularXXWeb-Regular.woff2',\n family: 'AxLLCircular',\n weight: '400',\n },\n ],\n popupWidth: 418,\n popupHeight: 549,\n },\n applePayRequestOptions: {\n countryCode: 'US',\n },\n googlePayRequestOptions: {\n countryCode: 'US',\n },\n requiredBillingContactFields: ['email', 'name'],\n currency: 'HKD',\n});\n```\n */\n\nexport const redirectToCheckout: typeof redirectToCheckoutFn = (props) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before redirectToCheckout();');\n } else {\n return window.Airwallex.redirectToCheckout(props);\n }\n};\n\n/**\n * We encourage to use `dropIn` element, since it's easy to scale new payment methods\n * We suggest to NOT use `applePayButton`, `googlePayButton`, `wechat`, `qrcode`, `redirect`, `fullFeaturedCard` and `directDebit` elements\n * \n * @example\n * ```ts \nimport { createElement } from 'airwallex-payment-elements';\nconst element = createElement('dropIn', {\n intent_id: 'replace-with-your-intent_id',\n client_secret: 'replace-with-your-client-secret',\n currency: 'replace-with-your-intent-currency',\n // if you want to use apple pay, please pass merchant country code in applePayRequestOptions\n applePayRequestOptions: {\n countryCode: 'replace-with-your-country-code',\n },\n // if you want to use google pay, please pass merchant country code in googlePayRequestOptions\n googlePayRequestOptions: {\n countryCode: 'replace-with-your-country-code',\n },\n});\n```\n */\n\nexport const createElement: typeof createElementFn = (type, options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before createElement();');\n return null;\n } else {\n return window.Airwallex.createElement(type, options);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { destroyElement } from 'airwallex-payment-elements';\ndestroyElement('dropIn');\n```\n */\n\nexport const destroyElement: typeof destroyElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before destroyElement();');\n return false;\n } else {\n return window.Airwallex.destroyElement(type);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { getElement } from 'airwallex-payment-elements';\ngetElement('dropIn');\n```\n */\n\nexport const getElement: typeof getElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before getElement();');\n return null;\n } else {\n return window.Airwallex.getElement(type);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { confirmPaymentIntent } from 'airwallex-payment-elements';\nconfirmPaymentIntent({\n element: card, // Provide Card element\n intent_id: 'replace-with-your-intent_id', // Payment Intent ID\n client_secret: 'replace-with-your-client-secret', // Client Secret\n payment_method_options: {\n card: {\n auto_capture: true,\n },\n },\n})\n```\n */\n\nexport const confirmPaymentIntent: typeof confirmPaymentIntentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntent(data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { confirmPaymentIntentWithSavedCard } from 'airwallex-payment-elements';\nconfirmPaymentIntentWithSavedCard({\n element: card, // Provide Card element\n customer_id: 'replace-with-your-customer-id',\n methodId: 'replace-with-your-method-id',\n intent_id: 'replace-with-your-intent_id', // Payment Intent ID\n client_secret: 'replace-with-your-client-secret', // Client Secret\n})\n```\n */\n\nexport const confirmPaymentIntentWithSavedCard: typeof confirmPaymentIntentWithSavedCardFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntentWithSavedCard();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntentWithSavedCard(data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { createPaymentMethod } from 'airwallex-payment-elements';\ncreatePaymentMethod('replace-with-your-client-secret', {\n element: card, // Provide Card element\n customer_id: 'replace-with-your-customer-id',\n})\n```\n */\n\nexport const createPaymentMethod: typeof createPaymentMethodFn = async (client_secret, data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentMethod();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentMethod(client_secret, data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { getPaymentIntent } from 'airwallex-payment-elements';\ngetPaymentIntent('replace-with-your-intent_id', 'replace-with-your-client_secret')\n```\n */\n\nexport const getPaymentIntent: typeof getPaymentIntentFn = async (id, client_secret) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before getPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.getPaymentIntent(id, client_secret);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { createPaymentConsent } from 'airwallex-payment-elements';\ncreatePaymentConsent({\n intent_id: 'replace-with-your-intent_id',\n customer_id: 'replace-with-your-customer_id',\n cardname: 'replace-with-your-card_name',\n client_secret: 'replace-with-your-client_secret',\n currency: 'HKD,\n element: cardNumberElement,\n next_triggered_by: 'customer',\n billing: {\n email: 'test@airwallex.com',\n first_name: 'TEST',\n last_name: 'TEST',\n date_of_birth: '2020-07-05',\n phone_number: '13333333333',\n address: {\n city: 'shanghai',\n country_code: 'CN',\n postcode: '200000',\n state: 'Shanghai',\n street: 'Street',\n },\n },\n})\n```\n */\n\nexport const createPaymentConsent: typeof createPaymentConsentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentConsent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentConsent(data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { getDeviceFingerprint } from 'airwallex-payment-elements';\ngetDeviceFingerprint({\n intent_id: 'replace-with-your-intent_id',\n env: 'prod',\n})\n```\n */\n\nexport const getDeviceFingerprint: typeof getDeviceFingerprintFn = (data) => {\n return window.Airwallex.getDeviceFingerprint(data);\n};\n\nexport default {\n getGatewayUrl,\n loadAirwallex,\n loadAirwallexJs,\n init,\n redirectToCheckout,\n createElement,\n destroyElement,\n getDeviceFingerprint,\n getElement,\n getPaymentIntent,\n createPaymentMethod,\n createPaymentConsent,\n confirmPaymentIntent,\n confirmPaymentIntentWithSavedCard,\n};\n"],"names":["ENV_HOST","prod","demo","staging","qa","preview","dev","getGatewayUrl","env","STATIC_JS_URL","loadAirwallexJs","gatewayUrl","script","document","createElement","src","crossOrigin","headOrBody","head","body","Error","appendChild","loadAirwallex","async","options","window","Airwallex","RETRY_COUNT","tryToResolve","querySelector","Promise","resolve","reject","addEventListener","init","remove","error","setTimeout","console","redirectToCheckout","props","type","destroyElement","getElement","confirmPaymentIntent","data","err","confirmPaymentIntentWithSavedCard","createPaymentMethod","client_secret","getPaymentIntent","id","createPaymentConsent","getDeviceFingerprint"],"mappings":";AAiBA,MAAMA,EAAW,CACfC,KAAM,yBACNC,KAAM,8BACNC,QAAS,iCAKTC,GAAI,uBACJC,QAAS,4BACTC,IAAK,kBAoBMC,EAAiBC,GAA8B,WAAWR,EAASQ,IAAQR,EAASC,OAE3FQ,EAAgB,gDAWTC,EAAmBC,IAC9B,MAAMC,EAASC,SAASC,cAAc,UACtCF,EAAOG,IAAM,GAAGJ,IAAaF,IAC7B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demo:"checkout-demo.airwallex.com",staging:"checkout-staging.airwallex.com",qa:"checkoutui.qa.awx.im",preview:"checkoutui.preview.awx.im",dev:"localhost:3000"},n=e=>`https://${r[e]||r.prod}`,t="/assets/elements.bundle.min.js?version=1.
|
|
1
|
+
/* Airwallex Checkout Component Version [1.10.0] */
|
|
2
|
+
var Airwallex=function(e){"use strict";const r={prod:"checkout.airwallex.com",demo:"checkout-demo.airwallex.com",staging:"checkout-staging.airwallex.com",qa:"checkoutui.qa.awx.im",preview:"checkoutui.preview.awx.im",dev:"localhost:3000"},n=e=>`https://${r[e]||r.prod}`,t="/assets/elements.bundle.min.js?version=1.10.0",o=e=>{const r=document.createElement("script");r.src=`${e}${t}`,r.crossOrigin="anonymous";const n=document.head||document.body;if(!n)throw new Error("Airwallex payment scripts requires a <head> or <body> html element in order to be loaded.");return n.appendChild(r),r},l=async e=>{if("undefined"==typeof window)return null;if(window.Airwallex)return window.Airwallex;let r=0;const l=async()=>{const r=document.querySelector(`script[src="${t}"], script[src="${t}/"]`)||o(n((null==e?void 0:e.env)||"prod"));return new Promise(((n,t)=>{r.addEventListener("load",(()=>{window.Airwallex?(window.Airwallex.init(e),n(window.Airwallex)):t(new Error("Failed to load Airwallex on load event"))})),r.addEventListener("error",(()=>{t(new Error("Failed to load Airwallex scripts")),r.remove&&r.remove()}))}))};for(;r<3;)try{return await l()}catch(e){r++,await new Promise((e=>window.setTimeout(e,500)))}return null},a=e=>{window.Airwallex?window.Airwallex.init(e):console.error("Please loadAirwallex() before init();")},i=e=>{if(window.Airwallex)return window.Airwallex.redirectToCheckout(e);console.error("Please loadAirwallex() before redirectToCheckout();")},w=(e,r)=>window.Airwallex?window.Airwallex.createElement(e,r):(console.error("Please loadAirwallex() before createElement();"),null),d=e=>window.Airwallex?window.Airwallex.destroyElement(e):(console.error("Please loadAirwallex() before destroyElement();"),!1),c=e=>window.Airwallex?window.Airwallex.getElement(e):(console.error("Please loadAirwallex() before getElement();"),null),s=async e=>{if(window.Airwallex)return window.Airwallex.confirmPaymentIntent(e);{const e="Please loadAirwallex() before confirmPaymentIntent();";throw console.error(e),new Error(e)}},m=async e=>{if(window.Airwallex)return window.Airwallex.confirmPaymentIntentWithSavedCard(e);{const e="Please loadAirwallex() before confirmPaymentIntentWithSavedCard();";throw console.error(e),new Error(e)}},x=async(e,r)=>{if(window.Airwallex)return window.Airwallex.createPaymentMethod(e,r);{const e="Please loadAirwallex() before createPaymentMethod();";throw console.error(e),new Error(e)}},u=async(e,r)=>{if(window.Airwallex)return window.Airwallex.getPaymentIntent(e,r);{const e="Please loadAirwallex() before getPaymentIntent();";throw console.error(e),new Error(e)}},A=async e=>{if(window.Airwallex)return window.Airwallex.createPaymentConsent(e);{const e="Please loadAirwallex() before createPaymentConsent();";throw console.error(e),new Error(e)}},y=e=>window.Airwallex.getDeviceFingerprint(e);var f={getGatewayUrl:n,loadAirwallex:l,loadAirwallexJs:o,init:a,redirectToCheckout:i,createElement:w,destroyElement:d,getDeviceFingerprint:y,getElement:c,getPaymentIntent:u,createPaymentMethod:x,createPaymentConsent:A,confirmPaymentIntent:s,confirmPaymentIntentWithSavedCard:m};return e.confirmPaymentIntent=s,e.confirmPaymentIntentWithSavedCard=m,e.createElement=w,e.createPaymentConsent=A,e.createPaymentMethod=x,e.default=f,e.destroyElement=d,e.getDeviceFingerprint=y,e.getElement=c,e.getGatewayUrl=n,e.getPaymentIntent=u,e.init=a,e.loadAirwallex=l,e.loadAirwallexJs=o,e.redirectToCheckout=i,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|
|
3
3
|
//# sourceMappingURL=airwallex.iife.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"airwallex.iife.js","sources":["../../src/index.ts"],"sourcesContent":["import Airwallex, {\n init as initFn,\n redirectToCheckout as redirectToCheckoutFn,\n createElement as createElementFn,\n destroyElement as destroyElementFn,\n getElement as getElementFn,\n confirmPaymentIntent as confirmPaymentIntentFn,\n confirmPaymentIntentWithSavedCard as confirmPaymentIntentWithSavedCardFn,\n createPaymentMethod as createPaymentMethodFn,\n getPaymentIntent as getPaymentIntentFn,\n createPaymentConsent as createPaymentConsentFn,\n AirwallexEnv,\n} from '../types/airwallex';\nimport { getDeviceFingerprint as getDeviceFingerprintFn } from '../types/fraud';\nimport { loadAirwallex as loadAirwallexFn } from '../types/index';\nimport { version } from '../package.json';\n\nconst ENV_HOST = {\n prod: 'checkout.airwallex.com',\n demo: 'checkout-demo.airwallex.com',\n staging: 'checkout-staging.airwallex.com',\n /**\n * Below env only for the npm package development\n * Should not using them when integrate with Airwallex\n */\n qa: 'checkoutui.qa.awx.im',\n preview: 'checkoutui.preview.awx.im',\n dev: 'localhost:3000',\n};\n\ndeclare global {\n interface Window {\n Airwallex: Airwallex;\n ReactNativeWebView: {\n postMessage: (message: string) => void;\n };\n }\n}\n\n/**\n * @example\n * ```ts \nimport { gatewayUrl } from 'airwallex-payment-elements';\nconst gatewayUrl = getGatewayUrl('prod');\n```\n */\n\nexport const getGatewayUrl = (env: AirwallexEnv): string => `https://${ENV_HOST[env] || ENV_HOST.prod}`;\n\nconst STATIC_JS_URL = `/assets/elements.bundle.min.js?version=${version}`;\n\n/**\n * @example\n * ```ts \nimport { loadAirwallexJs } from 'airwallex-payment-elements';\nconst gatewayUrl = getGatewayUrl('prod');\nloadAirwallexJs(gatewayUrl);\n```\n */\n\nexport const loadAirwallexJs = (gatewayUrl: string): HTMLScriptElement => {\n const script = document.createElement('script');\n script.src = `${gatewayUrl}${STATIC_JS_URL}`;\n script.crossOrigin = 'anonymous';\n\n const headOrBody = document.head || document.body;\n\n if (!headOrBody) {\n throw new Error('Airwallex payment scripts requires a <head> or <body> html element in order to be loaded.');\n }\n\n headOrBody.appendChild(script);\n\n return script;\n};\n\n/**\n * @example\n * ```ts \nimport { loadAirwallex } from 'airwallex-payment-elements';\nloadAirwallex({\n env: 'prod',\n locale: 'en',\n});\n```\n */\n\nexport const loadAirwallex: typeof loadAirwallexFn = async (options) => {\n if (typeof window === 'undefined') {\n return null;\n }\n\n if (window.Airwallex) {\n return window.Airwallex;\n }\n\n const MAX_RETRY_COUNT = 3;\n let RETRY_COUNT = 0;\n const sleep = () => new Promise((resolve) => window.setTimeout(resolve, 500));\n\n const tryToResolve = async (): Promise<Airwallex> => {\n const script: HTMLScriptElement =\n document.querySelector(`script[src=\"${STATIC_JS_URL}\"], script[src=\"${STATIC_JS_URL}/\"]`) ||\n loadAirwallexJs(getGatewayUrl(options?.env || 'prod'));\n\n return new Promise((resolve, reject) => {\n script.addEventListener('load', () => {\n if (window.Airwallex) {\n window.Airwallex.init(options);\n resolve(window.Airwallex);\n } else {\n reject(new Error('Failed to load Airwallex on load event'));\n }\n });\n\n script.addEventListener('error', () => {\n reject(new Error('Failed to load Airwallex scripts'));\n script.remove && script.remove();\n });\n });\n };\n\n while (RETRY_COUNT < MAX_RETRY_COUNT) {\n try {\n return await tryToResolve();\n } catch (error) {\n RETRY_COUNT++;\n await sleep();\n }\n }\n\n return null;\n};\n\n/**\n * @example\n * ```ts \nimport { init } from 'airwallex-payment-elements';\ninit({\n env: 'prod',\n locale: 'en',\n});\n```\n */\n\nexport const init: typeof initFn = (options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before init();');\n } else {\n window.Airwallex.init(options);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { redirectToCheckout } from 'airwallex-payment-elements';\nredirectToCheckout({\n env: 'prod',\n intent_id: 'replace-with-your-intent_id',\n client_secret: 'replace-with-your-client-secret',,\n successUrl: `${window.location.origin}/checkout-success?isTesting=N`,\n locale: 'replace-with-your-language',\n showTermLink: true,\n theme: {\n variant: 'bootstrap',\n fonts: [\n {\n src: 'https://checkout.airwallex.com/fonts/CircularXXWeb/CircularXXSub-BoldSubset.woff2',\n family: 'AxLLCircular',\n weight: '700',\n },\n {\n src: 'https://checkout.airwallex.com/fonts/CircularXXWeb/CircularXXWeb-Regular.woff2',\n family: 'AxLLCircular',\n weight: '400',\n },\n ],\n popupWidth: 418,\n popupHeight: 549,\n },\n applePayRequestOptions: {\n countryCode: 'US',\n },\n googlePayRequestOptions: {\n countryCode: 'US',\n },\n requiredBillingContactFields: ['email', 'name'],\n currency: 'HKD',\n});\n```\n */\n\nexport const redirectToCheckout: typeof redirectToCheckoutFn = (props) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before redirectToCheckout();');\n } else {\n return window.Airwallex.redirectToCheckout(props);\n }\n};\n\n/**\n * We encourage to use `dropIn` element, since it's easy to scale new payment methods\n * We suggest to NOT use `applePayButton`, `googlePayButton`, `wechat`, `qrcode`, `redirect`, `fullFeaturedCard` and `directDebit` elements\n * \n * @example\n * ```ts \nimport { createElement } from 'airwallex-payment-elements';\nconst element = createElement('dropIn', {\n intent_id: 'replace-with-your-intent_id',\n client_secret: 'replace-with-your-client-secret',\n currency: 'replace-with-your-intent-currency',\n // if you want to use apple pay, please pass merchant country code in applePayRequestOptions\n applePayRequestOptions: {\n countryCode: 'replace-with-your-country-code',\n },\n // if you want to use google pay, please pass merchant country code in googlePayRequestOptions\n googlePayRequestOptions: {\n countryCode: 'replace-with-your-country-code',\n },\n});\n```\n */\n\nexport const createElement: typeof createElementFn = (type, options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before createElement();');\n return null;\n } else {\n return window.Airwallex.createElement(type, options);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { destroyElement } from 'airwallex-payment-elements';\ndestroyElement('dropIn');\n```\n */\n\nexport const destroyElement: typeof destroyElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before destroyElement();');\n return false;\n } else {\n return window.Airwallex.destroyElement(type);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { getElement } from 'airwallex-payment-elements';\ngetElement('dropIn');\n```\n */\n\nexport const getElement: typeof getElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before getElement();');\n return null;\n } else {\n return window.Airwallex.getElement(type);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { confirmPaymentIntent } from 'airwallex-payment-elements';\nconfirmPaymentIntent({\n element: card, // Provide Card element\n intent_id: 'replace-with-your-intent_id', // Payment Intent ID\n client_secret: 'replace-with-your-client-secret', // Client Secret\n payment_method_options: {\n card: {\n auto_capture: true,\n },\n },\n})\n```\n */\n\nexport const confirmPaymentIntent: typeof confirmPaymentIntentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntent(data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { confirmPaymentIntentWithSavedCard } from 'airwallex-payment-elements';\nconfirmPaymentIntentWithSavedCard({\n element: card, // Provide Card element\n customer_id: 'replace-with-your-customer-id',\n methodId: 'replace-with-your-method-id',\n intent_id: 'replace-with-your-intent_id', // Payment Intent ID\n client_secret: 'replace-with-your-client-secret', // Client Secret\n})\n```\n */\n\nexport const confirmPaymentIntentWithSavedCard: typeof confirmPaymentIntentWithSavedCardFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntentWithSavedCard();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntentWithSavedCard(data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { createPaymentMethod } from 'airwallex-payment-elements';\ncreatePaymentMethod('replace-with-your-client-secret', {\n element: card, // Provide Card element\n customer_id: 'replace-with-your-customer-id',\n})\n```\n */\n\nexport const createPaymentMethod: typeof createPaymentMethodFn = async (client_secret, data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentMethod();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentMethod(client_secret, data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { getPaymentIntent } from 'airwallex-payment-elements';\ngetPaymentIntent('replace-with-your-intent_id', 'replace-with-your-client_secret')\n```\n */\n\nexport const getPaymentIntent: typeof getPaymentIntentFn = async (id, client_secret) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before getPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.getPaymentIntent(id, client_secret);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { createPaymentConsent } from 'airwallex-payment-elements';\ncreatePaymentConsent({\n intent_id: 'replace-with-your-intent_id',\n customer_id: 'replace-with-your-customer_id',\n cardname: 'replace-with-your-card_name',\n client_secret: 'replace-with-your-client_secret',\n currency: 'HKD,\n element: cardNumberElement,\n next_triggered_by: 'customer',\n billing: {\n email: 'test@airwallex.com',\n first_name: 'TEST',\n last_name: 'TEST',\n date_of_birth: '2020-07-05',\n phone_number: '13333333333',\n address: {\n city: 'shanghai',\n country_code: 'CN',\n postcode: '200000',\n state: 'Shanghai',\n street: 'Street',\n },\n },\n})\n```\n */\n\nexport const createPaymentConsent: typeof createPaymentConsentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentConsent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentConsent(data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { getDeviceFingerprint } from 'airwallex-payment-elements';\ngetDeviceFingerprint({\n intent_id: 'replace-with-your-intent_id',\n env: 'prod',\n})\n```\n */\n\nexport const getDeviceFingerprint: typeof getDeviceFingerprintFn = (data) => {\n return window.Airwallex.getDeviceFingerprint(data);\n};\n\nexport default {\n getGatewayUrl,\n loadAirwallex,\n loadAirwallexJs,\n init,\n redirectToCheckout,\n createElement,\n destroyElement,\n getDeviceFingerprint,\n getElement,\n getPaymentIntent,\n createPaymentMethod,\n createPaymentConsent,\n confirmPaymentIntent,\n confirmPaymentIntentWithSavedCard,\n};\n"],"names":["ENV_HOST","prod","demo","staging","qa","preview","dev","getGatewayUrl","env","STATIC_JS_URL","loadAirwallexJs","gatewayUrl","script","document","createElement","src","crossOrigin","headOrBody","head","body","Error","appendChild","loadAirwallex","async","options","window","Airwallex","RETRY_COUNT","tryToResolve","querySelector","Promise","resolve","reject","addEventListener","init","remove","error","setTimeout","console","redirectToCheckout","props","type","destroyElement","getElement","confirmPaymentIntent","data","err","confirmPaymentIntentWithSavedCard","createPaymentMethod","client_secret","getPaymentIntent","id","createPaymentConsent","getDeviceFingerprint"],"mappings":";uCAiBA,MAAMA,EAAW,CACfC,KAAM,yBACNC,KAAM,8BACNC,QAAS,iCAKTC,GAAI,uBACJC,QAAS,4BACTC,IAAK,kBAoBMC,EAAiBC,GAA8B,WAAWR,EAASQ,IAAQR,EAASC,OAE3FQ,EAAgB,+CAWTC,EAAmBC,IAC9B,MAAMC,EAASC,SAASC,cAAc,UACtCF,EAAOG,IAAM,GAAGJ,IAAaF,IAC7BG,EAAOI,YAAc,YAErB,MAAMC,EAAaJ,SAASK,MAAQL,SAASM,KAE7C,IAAKF,EACH,MAAM,IAAIG,MAAM,6FAKlB,OAFAH,EAAWI,YAAYT,GAEhBA,GAcIU,EAAwCC,MAAOC,IAC1D,GAAsB,oBAAXC,OACT,OAAO,KAGT,GAAIA,OAAOC,UACT,OAAOD,OAAOC,UAIhB,IAAIC,EAAc,EAClB,MAEMC,EAAeL,UACnB,MAAMX,EACJC,SAASgB,cAAc,eAAepB,oBAAgCA,SACtEC,EAAgBH,GAAciB,MAAAA,SAAAA,EAAShB,MAAO,SAEhD,OAAO,IAAIsB,SAAQ,CAACC,EAASC,KAC3BpB,EAAOqB,iBAAiB,QAAQ,KAC1BR,OAAOC,WACTD,OAAOC,UAAUQ,KAAKV,GACtBO,EAAQN,OAAOC,YAEfM,EAAO,IAAIZ,MAAM,8CAIrBR,EAAOqB,iBAAiB,SAAS,KAC/BD,EAAO,IAAIZ,MAAM,qCACjBR,EAAOuB,QAAUvB,EAAOuB,gBAK9B,KAAOR,EA1BiB,GA2BtB,IACE,aAAaC,IACb,MAAOQ,GACPT,UA5BgB,IAAIG,SAASC,GAAYN,OAAOY,WAAWN,EAAS,OAiCxE,OAAO,MAcIG,EAAuBV,I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,CACrB,MAAMC,EAAM,wDAEZ,MADAR,QAAQF,MAAMU,GACR,IAAI1B,MAAM0B,KAiBPO,EAAuDR,GAC3DpB,OAAOC,UAAU2B,qBAAqBR,SAGhC,CACbtC,cAAAA,EACAe,cAAAA,EACAZ,gBAAAA,EACAwB,KAAAA,EACAK,mBAAAA,EACAzB,cAAAA,EACA4B,eAAAA,EACAW,qBAAAA,EACAV,WAAAA,EACAO,iBAAAA,EACAF,oBAAAA,EACAI,qBAAAA,EACAR,qBAAAA,EACAG,kCAAAA"}
|
|
1
|
+
{"version":3,"file":"airwallex.iife.js","sources":["../../src/index.ts"],"sourcesContent":["import Airwallex, {\n init as initFn,\n redirectToCheckout as redirectToCheckoutFn,\n createElement as createElementFn,\n destroyElement as destroyElementFn,\n getElement as getElementFn,\n confirmPaymentIntent as confirmPaymentIntentFn,\n confirmPaymentIntentWithSavedCard as confirmPaymentIntentWithSavedCardFn,\n createPaymentMethod as createPaymentMethodFn,\n getPaymentIntent as getPaymentIntentFn,\n createPaymentConsent as createPaymentConsentFn,\n AirwallexEnv,\n} from '../types/airwallex';\nimport { getDeviceFingerprint as getDeviceFingerprintFn } from '../types/fraud';\nimport { loadAirwallex as loadAirwallexFn } from '../types/index';\nimport { version } from '../package.json';\n\nconst ENV_HOST = {\n prod: 'checkout.airwallex.com',\n demo: 'checkout-demo.airwallex.com',\n staging: 'checkout-staging.airwallex.com',\n /**\n * Below env only for the npm package development\n * Should not using them when integrate with Airwallex\n */\n qa: 'checkoutui.qa.awx.im',\n preview: 'checkoutui.preview.awx.im',\n dev: 'localhost:3000',\n};\n\ndeclare global {\n interface Window {\n Airwallex: Airwallex;\n ReactNativeWebView: {\n postMessage: (message: string) => void;\n };\n }\n}\n\n/**\n * @example\n * ```ts \nimport { gatewayUrl } from 'airwallex-payment-elements';\nconst gatewayUrl = getGatewayUrl('prod');\n```\n */\n\nexport const getGatewayUrl = (env: AirwallexEnv): string => `https://${ENV_HOST[env] || ENV_HOST.prod}`;\n\nconst STATIC_JS_URL = `/assets/elements.bundle.min.js?version=${version}`;\n\n/**\n * @example\n * ```ts \nimport { loadAirwallexJs } from 'airwallex-payment-elements';\nconst gatewayUrl = getGatewayUrl('prod');\nloadAirwallexJs(gatewayUrl);\n```\n */\n\nexport const loadAirwallexJs = (gatewayUrl: string): HTMLScriptElement => {\n const script = document.createElement('script');\n script.src = `${gatewayUrl}${STATIC_JS_URL}`;\n script.crossOrigin = 'anonymous';\n\n const headOrBody = document.head || document.body;\n\n if (!headOrBody) {\n throw new Error('Airwallex payment scripts requires a <head> or <body> html element in order to be loaded.');\n }\n\n headOrBody.appendChild(script);\n\n return script;\n};\n\n/**\n * @example\n * ```ts \nimport { loadAirwallex } from 'airwallex-payment-elements';\nloadAirwallex({\n env: 'prod',\n locale: 'en',\n});\n```\n */\n\nexport const loadAirwallex: typeof loadAirwallexFn = async (options) => {\n if (typeof window === 'undefined') {\n return null;\n }\n\n if (window.Airwallex) {\n return window.Airwallex;\n }\n\n const MAX_RETRY_COUNT = 3;\n let RETRY_COUNT = 0;\n const sleep = () => new Promise((resolve) => window.setTimeout(resolve, 500));\n\n const tryToResolve = async (): Promise<Airwallex> => {\n const script: HTMLScriptElement =\n document.querySelector(`script[src=\"${STATIC_JS_URL}\"], script[src=\"${STATIC_JS_URL}/\"]`) ||\n loadAirwallexJs(getGatewayUrl(options?.env || 'prod'));\n\n return new Promise((resolve, reject) => {\n script.addEventListener('load', () => {\n if (window.Airwallex) {\n window.Airwallex.init(options);\n resolve(window.Airwallex);\n } else {\n reject(new Error('Failed to load Airwallex on load event'));\n }\n });\n\n script.addEventListener('error', () => {\n reject(new Error('Failed to load Airwallex scripts'));\n script.remove && script.remove();\n });\n });\n };\n\n while (RETRY_COUNT < MAX_RETRY_COUNT) {\n try {\n return await tryToResolve();\n } catch (error) {\n RETRY_COUNT++;\n await sleep();\n }\n }\n\n return null;\n};\n\n/**\n * @example\n * ```ts \nimport { init } from 'airwallex-payment-elements';\ninit({\n env: 'prod',\n locale: 'en',\n});\n```\n */\n\nexport const init: typeof initFn = (options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before init();');\n } else {\n window.Airwallex.init(options);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { redirectToCheckout } from 'airwallex-payment-elements';\nredirectToCheckout({\n env: 'prod',\n intent_id: 'replace-with-your-intent_id',\n client_secret: 'replace-with-your-client-secret',,\n successUrl: `${window.location.origin}/checkout-success?isTesting=N`,\n locale: 'replace-with-your-language',\n showTermLink: true,\n theme: {\n variant: 'bootstrap',\n fonts: [\n {\n src: 'https://checkout.airwallex.com/fonts/CircularXXWeb/CircularXXSub-BoldSubset.woff2',\n family: 'AxLLCircular',\n weight: '700',\n },\n {\n src: 'https://checkout.airwallex.com/fonts/CircularXXWeb/CircularXXWeb-Regular.woff2',\n family: 'AxLLCircular',\n weight: '400',\n },\n ],\n popupWidth: 418,\n popupHeight: 549,\n },\n applePayRequestOptions: {\n countryCode: 'US',\n },\n googlePayRequestOptions: {\n countryCode: 'US',\n },\n requiredBillingContactFields: ['email', 'name'],\n currency: 'HKD',\n});\n```\n */\n\nexport const redirectToCheckout: typeof redirectToCheckoutFn = (props) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before redirectToCheckout();');\n } else {\n return window.Airwallex.redirectToCheckout(props);\n }\n};\n\n/**\n * We encourage to use `dropIn` element, since it's easy to scale new payment methods\n * We suggest to NOT use `applePayButton`, `googlePayButton`, `wechat`, `qrcode`, `redirect`, `fullFeaturedCard` and `directDebit` elements\n * \n * @example\n * ```ts \nimport { createElement } from 'airwallex-payment-elements';\nconst element = createElement('dropIn', {\n intent_id: 'replace-with-your-intent_id',\n client_secret: 'replace-with-your-client-secret',\n currency: 'replace-with-your-intent-currency',\n // if you want to use apple pay, please pass merchant country code in applePayRequestOptions\n applePayRequestOptions: {\n countryCode: 'replace-with-your-country-code',\n },\n // if you want to use google pay, please pass merchant country code in googlePayRequestOptions\n googlePayRequestOptions: {\n countryCode: 'replace-with-your-country-code',\n },\n});\n```\n */\n\nexport const createElement: typeof createElementFn = (type, options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before createElement();');\n return null;\n } else {\n return window.Airwallex.createElement(type, options);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { destroyElement } from 'airwallex-payment-elements';\ndestroyElement('dropIn');\n```\n */\n\nexport const destroyElement: typeof destroyElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before destroyElement();');\n return false;\n } else {\n return window.Airwallex.destroyElement(type);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { getElement } from 'airwallex-payment-elements';\ngetElement('dropIn');\n```\n */\n\nexport const getElement: typeof getElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before getElement();');\n return null;\n } else {\n return window.Airwallex.getElement(type);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { confirmPaymentIntent } from 'airwallex-payment-elements';\nconfirmPaymentIntent({\n element: card, // Provide Card element\n intent_id: 'replace-with-your-intent_id', // Payment Intent ID\n client_secret: 'replace-with-your-client-secret', // Client Secret\n payment_method_options: {\n card: {\n auto_capture: true,\n },\n },\n})\n```\n */\n\nexport const confirmPaymentIntent: typeof confirmPaymentIntentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntent(data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { confirmPaymentIntentWithSavedCard } from 'airwallex-payment-elements';\nconfirmPaymentIntentWithSavedCard({\n element: card, // Provide Card element\n customer_id: 'replace-with-your-customer-id',\n methodId: 'replace-with-your-method-id',\n intent_id: 'replace-with-your-intent_id', // Payment Intent ID\n client_secret: 'replace-with-your-client-secret', // Client Secret\n})\n```\n */\n\nexport const confirmPaymentIntentWithSavedCard: typeof confirmPaymentIntentWithSavedCardFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntentWithSavedCard();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntentWithSavedCard(data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { createPaymentMethod } from 'airwallex-payment-elements';\ncreatePaymentMethod('replace-with-your-client-secret', {\n element: card, // Provide Card element\n customer_id: 'replace-with-your-customer-id',\n})\n```\n */\n\nexport const createPaymentMethod: typeof createPaymentMethodFn = async (client_secret, data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentMethod();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentMethod(client_secret, data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { getPaymentIntent } from 'airwallex-payment-elements';\ngetPaymentIntent('replace-with-your-intent_id', 'replace-with-your-client_secret')\n```\n */\n\nexport const getPaymentIntent: typeof getPaymentIntentFn = async (id, client_secret) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before getPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.getPaymentIntent(id, client_secret);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { createPaymentConsent } from 'airwallex-payment-elements';\ncreatePaymentConsent({\n intent_id: 'replace-with-your-intent_id',\n customer_id: 'replace-with-your-customer_id',\n cardname: 'replace-with-your-card_name',\n client_secret: 'replace-with-your-client_secret',\n currency: 'HKD,\n element: cardNumberElement,\n next_triggered_by: 'customer',\n billing: {\n email: 'test@airwallex.com',\n first_name: 'TEST',\n last_name: 'TEST',\n date_of_birth: '2020-07-05',\n phone_number: '13333333333',\n address: {\n city: 'shanghai',\n country_code: 'CN',\n postcode: '200000',\n state: 'Shanghai',\n street: 'Street',\n },\n },\n})\n```\n */\n\nexport const createPaymentConsent: typeof createPaymentConsentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentConsent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentConsent(data);\n }\n};\n\n/**\n * @example\n * ```ts \nimport { getDeviceFingerprint } from 'airwallex-payment-elements';\ngetDeviceFingerprint({\n intent_id: 'replace-with-your-intent_id',\n env: 'prod',\n})\n```\n */\n\nexport const getDeviceFingerprint: typeof getDeviceFingerprintFn = (data) => {\n return window.Airwallex.getDeviceFingerprint(data);\n};\n\nexport default {\n getGatewayUrl,\n loadAirwallex,\n loadAirwallexJs,\n init,\n redirectToCheckout,\n createElement,\n destroyElement,\n getDeviceFingerprint,\n getElement,\n getPaymentIntent,\n createPaymentMethod,\n createPaymentConsent,\n confirmPaymentIntent,\n confirmPaymentIntentWithSavedCard,\n};\n"],"names":["ENV_HOST","prod","demo","staging","qa","preview","dev","getGatewayUrl","env","STATIC_JS_URL","loadAirwallexJs","gatewayUrl","script","document","createElement","src","crossOrigin","headOrBody","head","body","Error","appendChild","loadAirwallex","async","options","window","Airwallex","RETRY_COUNT","tryToResolve","querySelector","Promise","resolve","reject","addEventListener","init","remove","error","setTimeout","console","redirectToCheckout","props","type","destroyElement","getElement","confirmPaymentIntent","data","err","confirmPaymentIntentWithSavedCard","createPaymentMethod","client_secret","getPaymentIntent","id","createPaymentConsent","getDeviceFingerprint"],"mappings":";uCAiBA,MAAMA,EAAW,CACfC,KAAM,yBACNC,KAAM,8BACNC,QAAS,iCAKTC,GAAI,uBACJC,QAAS,4BACTC,IAAK,kBAoBMC,EAAiBC,GAA8B,WAAWR,EAASQ,IAAQR,EAASC,OAE3FQ,EAAgB,gDAWTC,EAAmBC,IAC9B,MAAMC,EAASC,SAASC,cAAc,UACtCF,EAAOG,IAAM,GAAGJ,IAAaF,IAC7BG,EAAOI,YAAc,YAErB,MAAMC,EAAaJ,SAASK,MAAQL,SAASM,KAE7C,IAAKF,EACH,MAAM,IAAIG,MAAM,6FAKlB,OAFAH,EAAWI,YAAYT,GAEhBA,GAcIU,EAAwCC,MAAOC,IAC1D,GAAsB,oBAAXC,OACT,OAAO,KAGT,GAAIA,OAAOC,UACT,OAAOD,OAAOC,UA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AAOC,UAAUqB,kCAAkCF,GALrC,CACrB,MAAMC,EAAM,qEAEZ,MADAR,QAAQF,MAAMU,GACR,IAAI1B,MAAM0B,KAiBPE,EAAoDzB,MAAO0B,EAAeJ,KACrF,GAAKpB,OAAOC,UAKV,OAAOD,OAAOC,UAAUsB,oBAAoBC,EAAeJ,GALtC,CACrB,MAAMC,EAAM,uDAEZ,MADAR,QAAQF,MAAMU,GACR,IAAI1B,MAAM0B,KAcPI,EAA8C3B,MAAO4B,EAAIF,KACpE,GAAKxB,OAAOC,UAKV,OAAOD,OAAOC,UAAUwB,iBAAiBC,EAAIF,GALxB,CACrB,MAAMH,EAAM,oDAEZ,MADAR,QAAQF,MAAMU,GACR,IAAI1B,MAAM0B,KAoCPM,EAAsD7B,MAAOsB,IACxE,GAAKpB,OAAOC,UAKV,OAAOD,OAAOC,UAAU0B,qBAAqBP,GALxB,CACrB,MAAMC,EAAM,wDAEZ,MADAR,QAAQF,MAAMU,GACR,IAAI1B,MAAM0B,KAiBPO,EAAuDR,GAC3DpB,OAAOC,UAAU2B,qBAAqBR,SAGhC,CACbtC,cAAAA,EACAe,cAAAA,EACAZ,gBAAAA,EACAwB,KAAAA,EACAK,mBAAAA,EACAzB,cAAAA,EACA4B,eAAAA,EACAW,qBAAAA,EACAV,WAAAA,EACAO,iBAAAA,EACAF,oBAAAA,EACAI,qBAAAA,EACAR,qBAAAA,EACAG,kCAAAA"}
|
package/package.json
CHANGED
package/types/airwallex.d.ts
CHANGED
|
@@ -69,6 +69,8 @@ export type AirwallexEnv = 'dev' | 'preview' | 'qa' | 'staging' | 'demo' | 'prod
|
|
|
69
69
|
|
|
70
70
|
export type Mode = 'payment' | 'recurring';
|
|
71
71
|
|
|
72
|
+
export type AuthorizationType = 'pre_auth' | 'final_auth';
|
|
73
|
+
|
|
72
74
|
/**
|
|
73
75
|
* Global init option config for Airwallex javascript SDK
|
|
74
76
|
*/
|
|
@@ -187,9 +189,15 @@ export interface HostPaymentPage {
|
|
|
187
189
|
*/
|
|
188
190
|
methods?: Array<PaymentMethodType>;
|
|
189
191
|
/**
|
|
190
|
-
*
|
|
192
|
+
* For card payment only. Indicate whether to capture immediately when authorization succeeds
|
|
193
|
+
* @defaultValue `true` if authorization type is `final_auth` and `false` for `pre_auth`.
|
|
191
194
|
*/
|
|
192
195
|
autoCapture?: boolean;
|
|
196
|
+
/**
|
|
197
|
+
* For card payment only. Indicate the authorization type.
|
|
198
|
+
* @defaultValue `final_auth`
|
|
199
|
+
*/
|
|
200
|
+
authorizationType?: AuthorizationType;
|
|
193
201
|
/**
|
|
194
202
|
* The success return url after shopper succeeded the payment
|
|
195
203
|
*/
|
|
@@ -379,9 +387,15 @@ export interface PaymentMethod {
|
|
|
379
387
|
*/
|
|
380
388
|
card?: {
|
|
381
389
|
/**
|
|
382
|
-
*
|
|
390
|
+
* Indicate whether to capture immediately when authorization succeeds
|
|
391
|
+
* @defaultValue `true` if authorization type is `final_auth` and `false` for `pre_auth`.
|
|
383
392
|
*/
|
|
384
393
|
auto_capture?: boolean;
|
|
394
|
+
/**
|
|
395
|
+
* The authorization type.
|
|
396
|
+
* @defaultValue `final_auth`
|
|
397
|
+
*/
|
|
398
|
+
authorization_type?: AuthorizationType;
|
|
385
399
|
};
|
|
386
400
|
};
|
|
387
401
|
/**
|
package/types/dropInElement.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ElementOptions, PaymentMethodType, BoxStyle } from './element';
|
|
2
|
-
import { Mode, RecurringOptions, Billing } from './airwallex';
|
|
2
|
+
import { Mode, RecurringOptions, Billing, AuthorizationType } from './airwallex';
|
|
3
3
|
import { ApplePayHppOrDropInRequestOptions, GooglePayRequestOptions, ContactField } from './element';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -30,9 +30,15 @@ export interface DropInElementOptions extends ElementOptions {
|
|
|
30
30
|
*/
|
|
31
31
|
methods?: Array<PaymentMethodType>;
|
|
32
32
|
/**
|
|
33
|
-
* Indicate whether to capture
|
|
33
|
+
* Indicate whether to capture immediately when authorization succeeds
|
|
34
|
+
* @defaultValue `true` if authorization type is `final_auth` and `false` for `pre_auth`.
|
|
34
35
|
*/
|
|
35
36
|
autoCapture?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* The authorization type.
|
|
39
|
+
* @defaultValue `final_auth`
|
|
40
|
+
*/
|
|
41
|
+
authorizationType?: AuthorizationType;
|
|
36
42
|
/**
|
|
37
43
|
* The options of apple pay
|
|
38
44
|
* If you want to integrate with apple pay, you need to provide the following options
|
package/types/element.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Intent, PaymentMethodBasicInfo } from './cardNumber';
|
|
2
2
|
import { Properties } from 'csstype';
|
|
3
3
|
import { PaymentMethodWithQrcode, QrcodeElementOptions } from './qrcodeElement';
|
|
4
|
-
import { RecurringOptions } from './airwallex';
|
|
4
|
+
import { AuthorizationType, RecurringOptions } from './airwallex';
|
|
5
5
|
import { DropInElementOptions } from './dropInElement';
|
|
6
6
|
import { RedirectElementOptions } from './redirectElement';
|
|
7
7
|
import { Mode, InitOptions } from './airwallex';
|
|
@@ -291,6 +291,7 @@ export type ExtendEventDetail = EventDetail & {
|
|
|
291
291
|
cardBin?: string;
|
|
292
292
|
status?: string;
|
|
293
293
|
auto_capture?: boolean;
|
|
294
|
+
authorization_type?: AuthorizationType;
|
|
294
295
|
paymentMethod?: PaymentMethodBasicInfo;
|
|
295
296
|
next_action?: NextAction;
|
|
296
297
|
testCard?: string;
|
|
@@ -404,9 +405,15 @@ export interface CardElementOptions extends ElementOptions {
|
|
|
404
405
|
*/
|
|
405
406
|
disabled?: boolean;
|
|
406
407
|
/**
|
|
407
|
-
* Indicate whether to capture
|
|
408
|
+
* Indicate whether to capture immediately when authorization succeeds.
|
|
409
|
+
* @defaultValue `true` if authorization type is `final_auth` and `false` for `pre_auth`.
|
|
408
410
|
*/
|
|
409
411
|
autoCapture?: boolean;
|
|
412
|
+
/**
|
|
413
|
+
* The authorization type.
|
|
414
|
+
* @defaultValue `final_auth`
|
|
415
|
+
*/
|
|
416
|
+
authorizationType?: AuthorizationType;
|
|
410
417
|
/**
|
|
411
418
|
* One or more card networks that you support.
|
|
412
419
|
*/
|
|
@@ -436,9 +443,15 @@ export interface CardNumberElementOptions extends ElementOptions {
|
|
|
436
443
|
*/
|
|
437
444
|
intent?: Intent;
|
|
438
445
|
/**
|
|
439
|
-
* Indicate whether to capture
|
|
446
|
+
* Indicate whether to capture immediately when authorization succeeds.
|
|
447
|
+
* @defaultValue `true` if authorization type is `final_auth` and `false` for `pre_auth`.
|
|
440
448
|
*/
|
|
441
449
|
autoCapture?: boolean;
|
|
450
|
+
/**
|
|
451
|
+
* The authorization type.
|
|
452
|
+
* @defaultValue `final_auth`
|
|
453
|
+
*/
|
|
454
|
+
authorizationType?: AuthorizationType;
|
|
442
455
|
/**
|
|
443
456
|
* One or more card networks that you support.
|
|
444
457
|
*/
|
|
@@ -525,9 +538,15 @@ export interface FullFeaturedCardElementOptions extends ElementOptions {
|
|
|
525
538
|
*/
|
|
526
539
|
intent?: Intent;
|
|
527
540
|
/**
|
|
528
|
-
* Indicate whether to capture
|
|
541
|
+
* Indicate whether to capture immediately when authorization succeeds. Apply when shopper uses card payment method.
|
|
542
|
+
* @defaultValue `true` if authorization type is `final_auth` and `false` for `pre_auth`.
|
|
529
543
|
*/
|
|
530
544
|
autoCapture?: boolean;
|
|
545
|
+
/**
|
|
546
|
+
* The authorization type.
|
|
547
|
+
* @defaultValue `final_auth`
|
|
548
|
+
*/
|
|
549
|
+
authorizationType?: AuthorizationType;
|
|
531
550
|
/**
|
|
532
551
|
* Indicate to improve 3DS experience, indicate if the payment form will collect billing info from shopper
|
|
533
552
|
*/
|
|
@@ -846,9 +865,15 @@ export interface GooglePayButtonOptions extends GooglePayRequestOptions, Element
|
|
|
846
865
|
};
|
|
847
866
|
|
|
848
867
|
/**
|
|
849
|
-
* Indicate whether to capture
|
|
868
|
+
* Indicate whether to capture immediately when authorization succeeds.
|
|
869
|
+
* @defaultValue `true` if authorization type is `final_auth` and `false` for `pre_auth`.
|
|
850
870
|
*/
|
|
851
871
|
autoCapture?: boolean;
|
|
872
|
+
/**
|
|
873
|
+
* The authorization type.
|
|
874
|
+
* @defaultValue `final_auth`
|
|
875
|
+
*/
|
|
876
|
+
authorizationType?: AuthorizationType;
|
|
852
877
|
/**
|
|
853
878
|
* Container for authentication form, it's an element id
|
|
854
879
|
*/
|
|
@@ -924,9 +949,15 @@ export interface ApplePayButtonOptions extends ElementOptions, ApplePayRequestOp
|
|
|
924
949
|
currency: string;
|
|
925
950
|
};
|
|
926
951
|
/**
|
|
927
|
-
* Indicate whether to capture
|
|
952
|
+
* Indicate whether to capture immediately when authorization succeeds.
|
|
953
|
+
* @defaultValue `true` if authorization type is `final_auth` and `false` for `pre_auth`.
|
|
928
954
|
*/
|
|
929
955
|
autoCapture?: boolean;
|
|
956
|
+
/**
|
|
957
|
+
* The authorization type.
|
|
958
|
+
* @defaultValue `final_auth`
|
|
959
|
+
*/
|
|
960
|
+
authorizationType?: AuthorizationType;
|
|
930
961
|
}
|
|
931
962
|
|
|
932
963
|
/**
|