@amos.com/amos-js 0.5.0 → 0.6.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/dist/apple-pay.d.ts +4 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +75 -47
- package/dist/types.d.ts +10 -0
- package/package.json +1 -1
- package/src/apple-pay.ts +70 -2
- package/src/types.ts +12 -0
package/dist/apple-pay.d.ts
CHANGED
|
@@ -73,6 +73,9 @@ export type ApplePayButtonController = {
|
|
|
73
73
|
* The iframe is expected to have already been added to the DOM with the
|
|
74
74
|
* correct `src` (see {@link getApplePayButtonSrc}).
|
|
75
75
|
*
|
|
76
|
-
*
|
|
76
|
+
* The Apple Pay button and `ApplePaySession` run inside the Amos embed
|
|
77
|
+
* iframe (so only Amos domains need Apple merchant registration). On
|
|
78
|
+
* `EXPAND_IFRAME`, the parent temporarily overlays that iframe
|
|
79
|
+
* full-viewport for Chrome's in-iframe QR handoff UI.
|
|
77
80
|
*/
|
|
78
81
|
export declare function attachApplePayButtonListeners(iframe: HTMLIFrameElement, options: ApplePayButtonListenerOptions): ApplePayButtonController;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){let[t=``,n=``,r=``]=e?.split(`.`)??[],i=typeof atob==`function`?atob:e=>Buffer.from(e,`base64`).toString(`utf8`);return{header:JSON.parse(i(t)),payload:JSON.parse(i(n)),signature:r}}function t(t){let{env:n=`sandbox`}=e(t).payload;switch(n){case`production`:return`https://embed.amos.com`;case`sandbox`:return`https://embed-sandbox.amos.com`;default:return`https://embed-sandbox.amos.com`}}function n(e){return e}function r(e){e?.contentWindow?.postMessage(n({type:`PARENT_ACKNOWLEDGED_IFRAME_READY`}),`*`)}function i({iframe:e,appearance:t={}}){e?.contentWindow?.postMessage(n({type:`UPDATE_APPEARANCE`,appearance:t}),`*`)}function a({iframe:e,amount:t}){e?.contentWindow?.postMessage(n({type:`UPDATE_AMOUNT`,amount:t}),`*`)}function o({iframe:e,merchantName:t}){e?.contentWindow?.postMessage(n({type:`UPDATE_MERCHANT_NAME`,merchantName:t}),`*`)}function s({iframe:e}){let t=crypto.randomUUID();return new Promise(r=>{e?.contentWindow?.postMessage(n({type:`VALIDATE_FORM`,requestId:t}),`*`);let i=setTimeout(()=>{window.removeEventListener(`message`,a),r(!1)},5e3);function a(e){e.data.type===`VALIDATE_FORM`&&e.data.requestId===t&&(window.removeEventListener(`message`,a),clearTimeout(i),r(e.data.isValid??!1))}window.addEventListener(`message`,a)})}function c({iframe:t,token:r}){let{payment_intent_id:i}=e(r).payload;t?.contentWindow?.postMessage(n({type:`CONFIRM_PAYMENT_INTENT`,token:r,id:i??void 0}),`*`)}function l({iframe:t,token:r}){let{setup_intent_id:i}=e(r).payload;t?.contentWindow?.postMessage(n({type:`CONFIRM_SETUP_INTENT`,token:r,id:i??void 0}),`*`)}function u({iframe:e,errorMessage:t}){e?.contentWindow?.postMessage(n({type:`CONFIRMATION_FAILED`,errorMessage:t}),`*`)}function d(e){return`${t(e)}/iframe/apple-pay?token=${e}`}function f(){return`40px`}function p(e,t){let n={...t};function s(){a({iframe:e,amount:n.amount})}function l(){o({iframe:e,merchantName:n.merchantName})}function d(t){switch(t.data.type){case`IFRAME_READY`:r(e),i({iframe:e,appearance:n.appearance}),s(),l();break;case`UPDATE_HEIGHT`:n.onHeightChange?.(t.data.height);break;case`UPDATE_APPEARANCE`:i({iframe:e,appearance:t.data.appearance});break;case`UPDATED_APPEARANCE`:n.onAppearanceReady?.();break;case`CREATE_PAYMENT_INTENT`:n.onInitiatePaymentIntentRequest({paymentIntentCreateAttributes:t.data.paymentIntentCreateAttributes,customerCreateAttributes:t.data.customerCreateAttributes}).then(t=>{c({iframe:e,token:t})}).catch(t=>{u({iframe:e,errorMessage:t instanceof Error?t.message:`Unknown error`})});break;case`PAYMENT_INTENT_CONFIRMATION_SUCCEEDED`:n.onPaymentIntentConfirmationSucceeded(t.data.paymentIntent);break;case`CONFIRMATION_FAILED`:n.onConfirmationFailed(t.data.errorMessage);break}}return window.addEventListener(`message`,d),{update(t){let r=`appearance`in t,a=`amount`in t,o=`merchantName`in t;n={...n,...t},r&&i({iframe:e,appearance:n.appearance}),a&&s(),o&&l()},destroy(){window.removeEventListener(`message`,d)}}}function m(e){return`${t(e)}/iframe/google-pay?token=${e}`}function h(){return`40px`}function g(e,t){let n={...t};function s(){a({iframe:e,amount:n.amount})}function l(){o({iframe:e,merchantName:n.merchantName})}function d(t){switch(t.data.type){case`IFRAME_READY`:r(e),i({iframe:e,appearance:n.appearance}),s(),l();break;case`UPDATE_HEIGHT`:n.onHeightChange?.(t.data.height);break;case`UPDATE_APPEARANCE`:i({iframe:e,appearance:t.data.appearance});break;case`UPDATED_APPEARANCE`:n.onAppearanceReady?.();break;case`CREATE_PAYMENT_INTENT`:n.onInitiatePaymentIntentRequest({paymentIntentCreateAttributes:t.data.paymentIntentCreateAttributes,customerCreateAttributes:t.data.customerCreateAttributes}).then(t=>{c({iframe:e,token:t})}).catch(t=>{u({iframe:e,errorMessage:t instanceof Error?t.message:`Unknown error`})});break;case`PAYMENT_INTENT_CONFIRMATION_SUCCEEDED`:n.onPaymentIntentConfirmationSucceeded(t.data.paymentIntent);break;case`CONFIRMATION_FAILED`:n.onConfirmationFailed(t.data.errorMessage);break}}return window.addEventListener(`message`,d),{update(t){let r=`appearance`in t,a=`amount`in t,o=`merchantName`in t;n={...n,...t},r&&i({iframe:e,appearance:n.appearance}),a&&s(),o&&l()},destroy(){window.removeEventListener(`message`,d)}}}function _({paymentData:e}){return{paymentMethod:{type:`googlepay`,billing_address_attributes:{name:e.shippingAddress?.name,address_line1:e.shippingAddress?.address1,address_line2:e.shippingAddress?.address2,city:e.shippingAddress?.locality,state:e.shippingAddress?.administrativeArea,postal_code:e.shippingAddress?.postalCode,country:e.shippingAddress?.countryCode,email:e.email,phone:e.shippingAddress?.phoneNumber},card_profile_attributes:{wallet_provider:`googlepay`,wallet_payload:e.paymentMethodData.tokenizationData.token,wallet_last4:e.paymentMethodData.info?.cardDetails,wallet_brand:(()=>{switch(e.paymentMethodData.info?.cardNetwork){case`AMEX`:return`american_express`;case`VISA`:return`visa`;case`MASTERCARD`:return`master`;case`DISCOVER`:return`discover`;default:return}})()}}}}var v={country:212,full:452},y=80,b={country:400,full:640};function x(e,n={cardholderName:!1},r=`country`){let i=Object.entries(n).filter(([,e])=>e).map(([e])=>e).join(`,`),a=new URLSearchParams({token:e,additionalFields:i,billingAddressRequirement:r});return`${t(e)}/iframe/card?${a}`}function S(e,n=`country`){let r=new URLSearchParams({token:e,billingAddressRequirement:n});return`${t(e)}/iframe/bank?${r}`}function C(e={cardholderName:!1},t=`country`){return`${(v[t]??v.country)+(e.cardholderName?y:0)}px`}function w(e=`country`){return`${b[e]??b.country}px`}function T(e,t){let n={...t};function a(t){switch(t.data.type){case`IFRAME_READY`:r(e),i({iframe:e,appearance:n.appearance});break;case`UPDATE_HEIGHT`:n.onHeightChange?.(t.data.height);break;case`UPDATE_APPEARANCE`:i({iframe:e,appearance:t.data.appearance});break;case`UPDATED_APPEARANCE`:n.onAppearanceReady?.();break;case`PAYMENT_INTENT_CONFIRMATION_SUCCEEDED`:n.onPaymentIntentConfirmationSucceeded?.(t.data.paymentIntent);break;case`SETUP_INTENT_CONFIRMATION_SUCCEEDED`:n.onSetupIntentConfirmationSucceeded?.(t.data.setupIntent);break;case`CONFIRMATION_FAILED`:n.onConfirmationFailed(t.data.errorMessage);break}}return window.addEventListener(`message`,a),{update(t){let r=`appearance`in t;n={...n,...t},r&&i({iframe:e,appearance:n.appearance})},destroy(){window.removeEventListener(`message`,a)}}}function E(e){if(typeof e==`string`){let t=document.querySelector(e);if(!(t instanceof HTMLElement))throw Error(`[amos-js] Container "${e}" did not match any HTMLElement.`);return t}return e}var D={width:`calc(100% + 8px)`,transition:`opacity 150ms ease-in, height 200ms ease-in-out`,margin:`0 -4px`,opacity:`0`,border:`0`};function O({src:e,title:t,name:n,height:r,allow:i}){let a=document.createElement(`iframe`);return a.src=e,a.title=t,a.name=n,a.setAttribute(`role`,`presentation`),a.scrolling=`no`,i&&(a.allow=i),Object.assign(a.style,D,{height:r}),a}function k(e,t){let n=E(e),{renderToken:r,additionalFields:i={cardholderName:!1},billingAddressRequirement:a=`country`,...o}=t,s=O({src:x(r,i,a),title:`Secure credit card payment method form powered by Amos`,name:`amos-credit-card-payment-method-form`,height:C(i,a)});n.appendChild(s);let c=T(s,{...o,onHeightChange:e=>{s.style.height=e,o.onHeightChange?.(e)},onAppearanceReady:()=>{s.style.opacity=`1`,o.onAppearanceReady?.()}});return{iframe:s,update:c.update,destroy(){c.destroy(),s.remove()}}}function A(e,t){let n=E(e),{renderToken:r,billingAddressRequirement:i=`country`,...a}=t,o=O({src:S(r,i),title:`Secure bank account payment method form powered by Amos`,name:`amos-bank-account-payment-method-form`,height:w(i)});n.appendChild(o);let s=T(o,{...a,onHeightChange:e=>{o.style.height=e,a.onHeightChange?.(e)},onAppearanceReady:()=>{o.style.opacity=`1`,a.onAppearanceReady?.()}});return{iframe:o,update:s.update,destroy(){s.destroy(),o.remove()}}}function j(e,t){let n=E(e),{renderToken:r,...i}=t,a=O({src:m(r),title:`Secure Google Pay button powered by Amos`,name:`amos-google-pay-button`,height:h(),allow:`payment`});n.appendChild(a);let o=g(a,{...i,onHeightChange:e=>{a.style.height=e,i.onHeightChange?.(e)},onAppearanceReady:()=>{a.style.opacity=`1`,i.onAppearanceReady?.()}});return{iframe:a,update:o.update,destroy(){o.destroy(),a.remove()}}}function M(e,t){let n=E(e),{renderToken:r,...i}=t,a=O({src:d(r),title:`Secure Apple Pay button powered by Amos`,name:`amos-apple-pay-button`,height:f(),allow:`payment`});n.appendChild(a);let o=p(a,{...i,onHeightChange:e=>{a.style.height=e,i.onHeightChange?.(e)},onAppearanceReady:()=>{a.style.opacity=`1`,i.onAppearanceReady?.()}});return{iframe:a,update:o.update,destroy(){o.destroy(),a.remove()}}}exports.attachApplePayButtonListeners=p,exports.attachGooglePayButtonListeners=g,exports.attachPaymentMethodFormListeners=T,exports.confirmPaymentIntent=c,exports.confirmSetupIntent=l,exports.createMessage=n,exports.decodeJwt=e,exports.formatGooglePayPaymentData=_,exports.getApplePayButtonInitialHeight=f,exports.getApplePayButtonSrc=d,exports.getBankAccountFormInitialHeight=w,exports.getBankAccountFormSrc=S,exports.getCreditCardFormInitialHeight=C,exports.getCreditCardFormSrc=x,exports.getEmbedOrigin=t,exports.getGooglePayButtonInitialHeight=h,exports.getGooglePayButtonSrc=m,exports.mountAmosApplePayButton=M,exports.mountAmosBankAccountPaymentMethodForm=A,exports.mountAmosCreditCardPaymentMethodForm=k,exports.mountAmosGooglePayButton=j,exports.sendConfirmationFailed=u,exports.sendParentReadyMessage=r,exports.updateAmount=a,exports.updateAppearance=i,exports.updateMerchantName=o,exports.validateForm=s;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){let[t=``,n=``,r=``]=e?.split(`.`)??[],i=typeof atob==`function`?atob:e=>Buffer.from(e,`base64`).toString(`utf8`);return{header:JSON.parse(i(t)),payload:JSON.parse(i(n)),signature:r}}function t(t){let{env:n=`sandbox`}=e(t).payload;switch(n){case`production`:return`https://embed.amos.com`;case`sandbox`:return`https://embed-sandbox.amos.com`;default:return`https://embed-sandbox.amos.com`}}function n(e){return e}function r(e){e?.contentWindow?.postMessage(n({type:`PARENT_ACKNOWLEDGED_IFRAME_READY`}),`*`)}function i({iframe:e,appearance:t={}}){e?.contentWindow?.postMessage(n({type:`UPDATE_APPEARANCE`,appearance:t}),`*`)}function a({iframe:e,amount:t}){e?.contentWindow?.postMessage(n({type:`UPDATE_AMOUNT`,amount:t}),`*`)}function o({iframe:e,merchantName:t}){e?.contentWindow?.postMessage(n({type:`UPDATE_MERCHANT_NAME`,merchantName:t}),`*`)}function s({iframe:e}){let t=crypto.randomUUID();return new Promise(r=>{e?.contentWindow?.postMessage(n({type:`VALIDATE_FORM`,requestId:t}),`*`);let i=setTimeout(()=>{window.removeEventListener(`message`,a),r(!1)},5e3);function a(e){e.data.type===`VALIDATE_FORM`&&e.data.requestId===t&&(window.removeEventListener(`message`,a),clearTimeout(i),r(e.data.isValid??!1))}window.addEventListener(`message`,a)})}function c({iframe:t,token:r}){let{payment_intent_id:i}=e(r).payload;t?.contentWindow?.postMessage(n({type:`CONFIRM_PAYMENT_INTENT`,token:r,id:i??void 0}),`*`)}function l({iframe:t,token:r}){let{setup_intent_id:i}=e(r).payload;t?.contentWindow?.postMessage(n({type:`CONFIRM_SETUP_INTENT`,token:r,id:i??void 0}),`*`)}function u({iframe:e,errorMessage:t}){e?.contentWindow?.postMessage(n({type:`CONFIRMATION_FAILED`,errorMessage:t}),`*`)}function d(e){return`${t(e)}/iframe/apple-pay?token=${e}`}function f(){return`40px`}function p(e){let t={cssText:e.style.cssText,bodyOverflow:document.body.style.overflow};return document.body.style.overflow=`hidden`,Object.assign(e.style,{position:`fixed`,inset:`0px`,width:`100vw`,height:`100vh`,maxWidth:`none`,maxHeight:`none`,margin:`0`,border:`0`,zIndex:`2147483647`,opacity:`1`,background:`#ffffff`}),t}function m(e,t){t&&(document.body.style.overflow=t.bodyOverflow,e.style.cssText=t.cssText)}function h(e,t){let n={...t},s=null;function l(){a({iframe:e,amount:n.amount})}function d(){o({iframe:e,merchantName:n.merchantName})}function f(t){if(t.source===e.contentWindow)switch(t.data.type){case`IFRAME_READY`:r(e),i({iframe:e,appearance:n.appearance}),l(),d();break;case`UPDATE_HEIGHT`:s||n.onHeightChange?.(t.data.height);break;case`UPDATE_APPEARANCE`:i({iframe:e,appearance:t.data.appearance});break;case`UPDATED_APPEARANCE`:n.onAppearanceReady?.();break;case`EXPAND_IFRAME`:s||=p(e);break;case`COLLAPSE_IFRAME`:m(e,s),s=null;break;case`CREATE_PAYMENT_INTENT`:n.onInitiatePaymentIntentRequest({paymentIntentCreateAttributes:t.data.paymentIntentCreateAttributes,customerCreateAttributes:t.data.customerCreateAttributes}).then(t=>{c({iframe:e,token:t})}).catch(t=>{u({iframe:e,errorMessage:t instanceof Error?t.message:`Unknown error`})});break;case`PAYMENT_INTENT_CONFIRMATION_SUCCEEDED`:n.onPaymentIntentConfirmationSucceeded(t.data.paymentIntent);break;case`CONFIRMATION_FAILED`:n.onConfirmationFailed(t.data.errorMessage);break}}return window.addEventListener(`message`,f),{update(t){let r=`appearance`in t,a=`amount`in t,o=`merchantName`in t;n={...n,...t},r&&i({iframe:e,appearance:n.appearance}),a&&l(),o&&d()},destroy(){window.removeEventListener(`message`,f),m(e,s),s=null}}}function g(e){return`${t(e)}/iframe/google-pay?token=${e}`}function _(){return`40px`}function v(e,t){let n={...t};function s(){a({iframe:e,amount:n.amount})}function l(){o({iframe:e,merchantName:n.merchantName})}function d(t){switch(t.data.type){case`IFRAME_READY`:r(e),i({iframe:e,appearance:n.appearance}),s(),l();break;case`UPDATE_HEIGHT`:n.onHeightChange?.(t.data.height);break;case`UPDATE_APPEARANCE`:i({iframe:e,appearance:t.data.appearance});break;case`UPDATED_APPEARANCE`:n.onAppearanceReady?.();break;case`CREATE_PAYMENT_INTENT`:n.onInitiatePaymentIntentRequest({paymentIntentCreateAttributes:t.data.paymentIntentCreateAttributes,customerCreateAttributes:t.data.customerCreateAttributes}).then(t=>{c({iframe:e,token:t})}).catch(t=>{u({iframe:e,errorMessage:t instanceof Error?t.message:`Unknown error`})});break;case`PAYMENT_INTENT_CONFIRMATION_SUCCEEDED`:n.onPaymentIntentConfirmationSucceeded(t.data.paymentIntent);break;case`CONFIRMATION_FAILED`:n.onConfirmationFailed(t.data.errorMessage);break}}return window.addEventListener(`message`,d),{update(t){let r=`appearance`in t,a=`amount`in t,o=`merchantName`in t;n={...n,...t},r&&i({iframe:e,appearance:n.appearance}),a&&s(),o&&l()},destroy(){window.removeEventListener(`message`,d)}}}function y({paymentData:e}){return{paymentMethod:{type:`googlepay`,billing_address_attributes:{name:e.shippingAddress?.name,address_line1:e.shippingAddress?.address1,address_line2:e.shippingAddress?.address2,city:e.shippingAddress?.locality,state:e.shippingAddress?.administrativeArea,postal_code:e.shippingAddress?.postalCode,country:e.shippingAddress?.countryCode,email:e.email,phone:e.shippingAddress?.phoneNumber},card_profile_attributes:{wallet_provider:`googlepay`,wallet_payload:e.paymentMethodData.tokenizationData.token,wallet_last4:e.paymentMethodData.info?.cardDetails,wallet_brand:(()=>{switch(e.paymentMethodData.info?.cardNetwork){case`AMEX`:return`american_express`;case`VISA`:return`visa`;case`MASTERCARD`:return`master`;case`DISCOVER`:return`discover`;default:return}})()}}}}var b={country:212,full:452},x=80,S={country:400,full:640};function C(e,n={cardholderName:!1},r=`country`){let i=Object.entries(n).filter(([,e])=>e).map(([e])=>e).join(`,`),a=new URLSearchParams({token:e,additionalFields:i,billingAddressRequirement:r});return`${t(e)}/iframe/card?${a}`}function w(e,n=`country`){let r=new URLSearchParams({token:e,billingAddressRequirement:n});return`${t(e)}/iframe/bank?${r}`}function T(e={cardholderName:!1},t=`country`){return`${(b[t]??b.country)+(e.cardholderName?x:0)}px`}function E(e=`country`){return`${S[e]??S.country}px`}function D(e,t){let n={...t};function a(t){switch(t.data.type){case`IFRAME_READY`:r(e),i({iframe:e,appearance:n.appearance});break;case`UPDATE_HEIGHT`:n.onHeightChange?.(t.data.height);break;case`UPDATE_APPEARANCE`:i({iframe:e,appearance:t.data.appearance});break;case`UPDATED_APPEARANCE`:n.onAppearanceReady?.();break;case`PAYMENT_INTENT_CONFIRMATION_SUCCEEDED`:n.onPaymentIntentConfirmationSucceeded?.(t.data.paymentIntent);break;case`SETUP_INTENT_CONFIRMATION_SUCCEEDED`:n.onSetupIntentConfirmationSucceeded?.(t.data.setupIntent);break;case`CONFIRMATION_FAILED`:n.onConfirmationFailed(t.data.errorMessage);break}}return window.addEventListener(`message`,a),{update(t){let r=`appearance`in t;n={...n,...t},r&&i({iframe:e,appearance:n.appearance})},destroy(){window.removeEventListener(`message`,a)}}}function O(e){if(typeof e==`string`){let t=document.querySelector(e);if(!(t instanceof HTMLElement))throw Error(`[amos-js] Container "${e}" did not match any HTMLElement.`);return t}return e}var k={width:`calc(100% + 8px)`,transition:`opacity 150ms ease-in, height 200ms ease-in-out`,margin:`0 -4px`,opacity:`0`,border:`0`};function A({src:e,title:t,name:n,height:r,allow:i}){let a=document.createElement(`iframe`);return a.src=e,a.title=t,a.name=n,a.setAttribute(`role`,`presentation`),a.scrolling=`no`,i&&(a.allow=i),Object.assign(a.style,k,{height:r}),a}function j(e,t){let n=O(e),{renderToken:r,additionalFields:i={cardholderName:!1},billingAddressRequirement:a=`country`,...o}=t,s=A({src:C(r,i,a),title:`Secure credit card payment method form powered by Amos`,name:`amos-credit-card-payment-method-form`,height:T(i,a)});n.appendChild(s);let c=D(s,{...o,onHeightChange:e=>{s.style.height=e,o.onHeightChange?.(e)},onAppearanceReady:()=>{s.style.opacity=`1`,o.onAppearanceReady?.()}});return{iframe:s,update:c.update,destroy(){c.destroy(),s.remove()}}}function M(e,t){let n=O(e),{renderToken:r,billingAddressRequirement:i=`country`,...a}=t,o=A({src:w(r,i),title:`Secure bank account payment method form powered by Amos`,name:`amos-bank-account-payment-method-form`,height:E(i)});n.appendChild(o);let s=D(o,{...a,onHeightChange:e=>{o.style.height=e,a.onHeightChange?.(e)},onAppearanceReady:()=>{o.style.opacity=`1`,a.onAppearanceReady?.()}});return{iframe:o,update:s.update,destroy(){s.destroy(),o.remove()}}}function N(e,t){let n=O(e),{renderToken:r,...i}=t,a=A({src:g(r),title:`Secure Google Pay button powered by Amos`,name:`amos-google-pay-button`,height:_(),allow:`payment`});n.appendChild(a);let o=v(a,{...i,onHeightChange:e=>{a.style.height=e,i.onHeightChange?.(e)},onAppearanceReady:()=>{a.style.opacity=`1`,i.onAppearanceReady?.()}});return{iframe:a,update:o.update,destroy(){o.destroy(),a.remove()}}}function P(e,t){let n=O(e),{renderToken:r,...i}=t,a=A({src:d(r),title:`Secure Apple Pay button powered by Amos`,name:`amos-apple-pay-button`,height:f(),allow:`payment`});n.appendChild(a);let o=h(a,{...i,onHeightChange:e=>{a.style.height=e,i.onHeightChange?.(e)},onAppearanceReady:()=>{a.style.opacity=`1`,i.onAppearanceReady?.()}});return{iframe:a,update:o.update,destroy(){o.destroy(),a.remove()}}}exports.attachApplePayButtonListeners=h,exports.attachGooglePayButtonListeners=v,exports.attachPaymentMethodFormListeners=D,exports.confirmPaymentIntent=c,exports.confirmSetupIntent=l,exports.createMessage=n,exports.decodeJwt=e,exports.formatGooglePayPaymentData=y,exports.getApplePayButtonInitialHeight=f,exports.getApplePayButtonSrc=d,exports.getBankAccountFormInitialHeight=E,exports.getBankAccountFormSrc=w,exports.getCreditCardFormInitialHeight=T,exports.getCreditCardFormSrc=C,exports.getEmbedOrigin=t,exports.getGooglePayButtonInitialHeight=_,exports.getGooglePayButtonSrc=g,exports.mountAmosApplePayButton=P,exports.mountAmosBankAccountPaymentMethodForm=M,exports.mountAmosCreditCardPaymentMethodForm=j,exports.mountAmosGooglePayButton=N,exports.sendConfirmationFailed=u,exports.sendParentReadyMessage=r,exports.updateAmount=a,exports.updateAppearance=i,exports.updateMerchantName=o,exports.validateForm=s;
|
package/dist/index.mjs
CHANGED
|
@@ -89,30 +89,52 @@ function d(e) {
|
|
|
89
89
|
function f() {
|
|
90
90
|
return "40px";
|
|
91
91
|
}
|
|
92
|
-
function p(e
|
|
93
|
-
let
|
|
94
|
-
|
|
92
|
+
function p(e) {
|
|
93
|
+
let t = {
|
|
94
|
+
cssText: e.style.cssText,
|
|
95
|
+
bodyOverflow: document.body.style.overflow
|
|
96
|
+
};
|
|
97
|
+
return document.body.style.overflow = "hidden", Object.assign(e.style, {
|
|
98
|
+
position: "fixed",
|
|
99
|
+
inset: "0px",
|
|
100
|
+
width: "100vw",
|
|
101
|
+
height: "100vh",
|
|
102
|
+
maxWidth: "none",
|
|
103
|
+
maxHeight: "none",
|
|
104
|
+
margin: "0",
|
|
105
|
+
border: "0",
|
|
106
|
+
zIndex: "2147483647",
|
|
107
|
+
opacity: "1",
|
|
108
|
+
background: "#ffffff"
|
|
109
|
+
}), t;
|
|
110
|
+
}
|
|
111
|
+
function m(e, t) {
|
|
112
|
+
t && (document.body.style.overflow = t.bodyOverflow, e.style.cssText = t.cssText);
|
|
113
|
+
}
|
|
114
|
+
function h(e, t) {
|
|
115
|
+
let n = { ...t }, s = null;
|
|
116
|
+
function l() {
|
|
95
117
|
a({
|
|
96
118
|
iframe: e,
|
|
97
119
|
amount: n.amount
|
|
98
120
|
});
|
|
99
121
|
}
|
|
100
|
-
function
|
|
122
|
+
function d() {
|
|
101
123
|
o({
|
|
102
124
|
iframe: e,
|
|
103
125
|
merchantName: n.merchantName
|
|
104
126
|
});
|
|
105
127
|
}
|
|
106
|
-
function
|
|
107
|
-
switch (t.data.type) {
|
|
128
|
+
function f(t) {
|
|
129
|
+
if (t.source === e.contentWindow) switch (t.data.type) {
|
|
108
130
|
case "IFRAME_READY":
|
|
109
131
|
r(e), i({
|
|
110
132
|
iframe: e,
|
|
111
133
|
appearance: n.appearance
|
|
112
|
-
}),
|
|
134
|
+
}), l(), d();
|
|
113
135
|
break;
|
|
114
136
|
case "UPDATE_HEIGHT":
|
|
115
|
-
n.onHeightChange?.(t.data.height);
|
|
137
|
+
s || n.onHeightChange?.(t.data.height);
|
|
116
138
|
break;
|
|
117
139
|
case "UPDATE_APPEARANCE":
|
|
118
140
|
i({
|
|
@@ -123,6 +145,12 @@ function p(e, t) {
|
|
|
123
145
|
case "UPDATED_APPEARANCE":
|
|
124
146
|
n.onAppearanceReady?.();
|
|
125
147
|
break;
|
|
148
|
+
case "EXPAND_IFRAME":
|
|
149
|
+
s ||= p(e);
|
|
150
|
+
break;
|
|
151
|
+
case "COLLAPSE_IFRAME":
|
|
152
|
+
m(e, s), s = null;
|
|
153
|
+
break;
|
|
126
154
|
case "CREATE_PAYMENT_INTENT":
|
|
127
155
|
n.onInitiatePaymentIntentRequest({
|
|
128
156
|
paymentIntentCreateAttributes: t.data.paymentIntentCreateAttributes,
|
|
@@ -147,7 +175,7 @@ function p(e, t) {
|
|
|
147
175
|
break;
|
|
148
176
|
}
|
|
149
177
|
}
|
|
150
|
-
return window.addEventListener("message",
|
|
178
|
+
return window.addEventListener("message", f), {
|
|
151
179
|
update(t) {
|
|
152
180
|
let r = "appearance" in t, a = "amount" in t, o = "merchantName" in t;
|
|
153
181
|
n = {
|
|
@@ -156,22 +184,22 @@ function p(e, t) {
|
|
|
156
184
|
}, r && i({
|
|
157
185
|
iframe: e,
|
|
158
186
|
appearance: n.appearance
|
|
159
|
-
}), a &&
|
|
187
|
+
}), a && l(), o && d();
|
|
160
188
|
},
|
|
161
189
|
destroy() {
|
|
162
|
-
window.removeEventListener("message",
|
|
190
|
+
window.removeEventListener("message", f), m(e, s), s = null;
|
|
163
191
|
}
|
|
164
192
|
};
|
|
165
193
|
}
|
|
166
194
|
//#endregion
|
|
167
195
|
//#region src/google-pay.ts
|
|
168
|
-
function
|
|
196
|
+
function g(e) {
|
|
169
197
|
return `${t(e)}/iframe/google-pay?token=${e}`;
|
|
170
198
|
}
|
|
171
|
-
function
|
|
199
|
+
function _() {
|
|
172
200
|
return "40px";
|
|
173
201
|
}
|
|
174
|
-
function
|
|
202
|
+
function v(e, t) {
|
|
175
203
|
let n = { ...t };
|
|
176
204
|
function s() {
|
|
177
205
|
a({
|
|
@@ -245,7 +273,7 @@ function g(e, t) {
|
|
|
245
273
|
}
|
|
246
274
|
};
|
|
247
275
|
}
|
|
248
|
-
function
|
|
276
|
+
function y({ paymentData: e }) {
|
|
249
277
|
return { paymentMethod: {
|
|
250
278
|
type: "googlepay",
|
|
251
279
|
billing_address_attributes: {
|
|
@@ -277,14 +305,14 @@ function _({ paymentData: e }) {
|
|
|
277
305
|
}
|
|
278
306
|
//#endregion
|
|
279
307
|
//#region src/payment-method-form.ts
|
|
280
|
-
var
|
|
308
|
+
var b = {
|
|
281
309
|
country: 212,
|
|
282
310
|
full: 452
|
|
283
|
-
},
|
|
311
|
+
}, x = 80, S = {
|
|
284
312
|
country: 400,
|
|
285
313
|
full: 640
|
|
286
314
|
};
|
|
287
|
-
function
|
|
315
|
+
function C(e, n = { cardholderName: !1 }, r = "country") {
|
|
288
316
|
let i = Object.entries(n).filter(([, e]) => e).map(([e]) => e).join(","), a = new URLSearchParams({
|
|
289
317
|
token: e,
|
|
290
318
|
additionalFields: i,
|
|
@@ -292,20 +320,20 @@ function x(e, n = { cardholderName: !1 }, r = "country") {
|
|
|
292
320
|
});
|
|
293
321
|
return `${t(e)}/iframe/card?${a}`;
|
|
294
322
|
}
|
|
295
|
-
function
|
|
323
|
+
function w(e, n = "country") {
|
|
296
324
|
let r = new URLSearchParams({
|
|
297
325
|
token: e,
|
|
298
326
|
billingAddressRequirement: n
|
|
299
327
|
});
|
|
300
328
|
return `${t(e)}/iframe/bank?${r}`;
|
|
301
329
|
}
|
|
302
|
-
function
|
|
303
|
-
return `${(
|
|
330
|
+
function T(e = { cardholderName: !1 }, t = "country") {
|
|
331
|
+
return `${(b[t] ?? b.country) + (e.cardholderName ? x : 0)}px`;
|
|
304
332
|
}
|
|
305
|
-
function
|
|
306
|
-
return `${
|
|
333
|
+
function E(e = "country") {
|
|
334
|
+
return `${S[e] ?? S.country}px`;
|
|
307
335
|
}
|
|
308
|
-
function
|
|
336
|
+
function D(e, t) {
|
|
309
337
|
let n = { ...t };
|
|
310
338
|
function a(t) {
|
|
311
339
|
switch (t.data.type) {
|
|
@@ -356,7 +384,7 @@ function T(e, t) {
|
|
|
356
384
|
}
|
|
357
385
|
//#endregion
|
|
358
386
|
//#region src/mount.ts
|
|
359
|
-
function
|
|
387
|
+
function O(e) {
|
|
360
388
|
if (typeof e == "string") {
|
|
361
389
|
let t = document.querySelector(e);
|
|
362
390
|
if (!(t instanceof HTMLElement)) throw Error(`[amos-js] Container "${e}" did not match any HTMLElement.`);
|
|
@@ -364,26 +392,26 @@ function E(e) {
|
|
|
364
392
|
}
|
|
365
393
|
return e;
|
|
366
394
|
}
|
|
367
|
-
var
|
|
395
|
+
var k = {
|
|
368
396
|
width: "calc(100% + 8px)",
|
|
369
397
|
transition: "opacity 150ms ease-in, height 200ms ease-in-out",
|
|
370
398
|
margin: "0 -4px",
|
|
371
399
|
opacity: "0",
|
|
372
400
|
border: "0"
|
|
373
401
|
};
|
|
374
|
-
function
|
|
402
|
+
function A({ src: e, title: t, name: n, height: r, allow: i }) {
|
|
375
403
|
let a = document.createElement("iframe");
|
|
376
|
-
return a.src = e, a.title = t, a.name = n, a.setAttribute("role", "presentation"), a.scrolling = "no", i && (a.allow = i), Object.assign(a.style,
|
|
404
|
+
return a.src = e, a.title = t, a.name = n, a.setAttribute("role", "presentation"), a.scrolling = "no", i && (a.allow = i), Object.assign(a.style, k, { height: r }), a;
|
|
377
405
|
}
|
|
378
|
-
function
|
|
379
|
-
let n =
|
|
380
|
-
src:
|
|
406
|
+
function j(e, t) {
|
|
407
|
+
let n = O(e), { renderToken: r, additionalFields: i = { cardholderName: !1 }, billingAddressRequirement: a = "country", ...o } = t, s = A({
|
|
408
|
+
src: C(r, i, a),
|
|
381
409
|
title: "Secure credit card payment method form powered by Amos",
|
|
382
410
|
name: "amos-credit-card-payment-method-form",
|
|
383
|
-
height:
|
|
411
|
+
height: T(i, a)
|
|
384
412
|
});
|
|
385
413
|
n.appendChild(s);
|
|
386
|
-
let c =
|
|
414
|
+
let c = D(s, {
|
|
387
415
|
...o,
|
|
388
416
|
onHeightChange: (e) => {
|
|
389
417
|
s.style.height = e, o.onHeightChange?.(e);
|
|
@@ -400,15 +428,15 @@ function k(e, t) {
|
|
|
400
428
|
}
|
|
401
429
|
};
|
|
402
430
|
}
|
|
403
|
-
function
|
|
404
|
-
let n =
|
|
405
|
-
src:
|
|
431
|
+
function M(e, t) {
|
|
432
|
+
let n = O(e), { renderToken: r, billingAddressRequirement: i = "country", ...a } = t, o = A({
|
|
433
|
+
src: w(r, i),
|
|
406
434
|
title: "Secure bank account payment method form powered by Amos",
|
|
407
435
|
name: "amos-bank-account-payment-method-form",
|
|
408
|
-
height:
|
|
436
|
+
height: E(i)
|
|
409
437
|
});
|
|
410
438
|
n.appendChild(o);
|
|
411
|
-
let s =
|
|
439
|
+
let s = D(o, {
|
|
412
440
|
...a,
|
|
413
441
|
onHeightChange: (e) => {
|
|
414
442
|
o.style.height = e, a.onHeightChange?.(e);
|
|
@@ -425,16 +453,16 @@ function A(e, t) {
|
|
|
425
453
|
}
|
|
426
454
|
};
|
|
427
455
|
}
|
|
428
|
-
function
|
|
429
|
-
let n =
|
|
430
|
-
src:
|
|
456
|
+
function N(e, t) {
|
|
457
|
+
let n = O(e), { renderToken: r, ...i } = t, a = A({
|
|
458
|
+
src: g(r),
|
|
431
459
|
title: "Secure Google Pay button powered by Amos",
|
|
432
460
|
name: "amos-google-pay-button",
|
|
433
|
-
height:
|
|
461
|
+
height: _(),
|
|
434
462
|
allow: "payment"
|
|
435
463
|
});
|
|
436
464
|
n.appendChild(a);
|
|
437
|
-
let o =
|
|
465
|
+
let o = v(a, {
|
|
438
466
|
...i,
|
|
439
467
|
onHeightChange: (e) => {
|
|
440
468
|
a.style.height = e, i.onHeightChange?.(e);
|
|
@@ -451,8 +479,8 @@ function j(e, t) {
|
|
|
451
479
|
}
|
|
452
480
|
};
|
|
453
481
|
}
|
|
454
|
-
function
|
|
455
|
-
let n =
|
|
482
|
+
function P(e, t) {
|
|
483
|
+
let n = O(e), { renderToken: r, ...i } = t, a = A({
|
|
456
484
|
src: d(r),
|
|
457
485
|
title: "Secure Apple Pay button powered by Amos",
|
|
458
486
|
name: "amos-apple-pay-button",
|
|
@@ -460,7 +488,7 @@ function M(e, t) {
|
|
|
460
488
|
allow: "payment"
|
|
461
489
|
});
|
|
462
490
|
n.appendChild(a);
|
|
463
|
-
let o =
|
|
491
|
+
let o = h(a, {
|
|
464
492
|
...i,
|
|
465
493
|
onHeightChange: (e) => {
|
|
466
494
|
a.style.height = e, i.onHeightChange?.(e);
|
|
@@ -478,4 +506,4 @@ function M(e, t) {
|
|
|
478
506
|
};
|
|
479
507
|
}
|
|
480
508
|
//#endregion
|
|
481
|
-
export {
|
|
509
|
+
export { h as attachApplePayButtonListeners, v as attachGooglePayButtonListeners, D as attachPaymentMethodFormListeners, c as confirmPaymentIntent, l as confirmSetupIntent, n as createMessage, e as decodeJwt, y as formatGooglePayPaymentData, f as getApplePayButtonInitialHeight, d as getApplePayButtonSrc, E as getBankAccountFormInitialHeight, w as getBankAccountFormSrc, T as getCreditCardFormInitialHeight, C as getCreditCardFormSrc, t as getEmbedOrigin, _ as getGooglePayButtonInitialHeight, g as getGooglePayButtonSrc, P as mountAmosApplePayButton, M as mountAmosBankAccountPaymentMethodForm, j as mountAmosCreditCardPaymentMethodForm, N as mountAmosGooglePayButton, u as sendConfirmationFailed, r as sendParentReadyMessage, a as updateAmount, i as updateAppearance, o as updateMerchantName, s as validateForm };
|
package/dist/types.d.ts
CHANGED
|
@@ -68,6 +68,16 @@ export type Message = {
|
|
|
68
68
|
errorMessage: string;
|
|
69
69
|
} | {
|
|
70
70
|
type: "UPDATED_APPEARANCE";
|
|
71
|
+
} | {
|
|
72
|
+
/**
|
|
73
|
+
* Iframe → parent: expand the Apple Pay iframe to a full-viewport
|
|
74
|
+
* overlay so Chrome's QR handoff UI is not clipped by the button
|
|
75
|
+
* height. The Apple Pay session stays on the Amos embed origin.
|
|
76
|
+
*/
|
|
77
|
+
type: "EXPAND_IFRAME";
|
|
78
|
+
} | {
|
|
79
|
+
/** Iframe → parent: restore the Apple Pay iframe to its button size. */
|
|
80
|
+
type: "COLLAPSE_IFRAME";
|
|
71
81
|
};
|
|
72
82
|
/**
|
|
73
83
|
* Identity helper that brands an object as a typed `Message`.
|
package/package.json
CHANGED
package/src/apple-pay.ts
CHANGED
|
@@ -88,6 +88,49 @@ export type ApplePayButtonController = {
|
|
|
88
88
|
destroy: () => void;
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
+
type SavedIframeLayout = {
|
|
92
|
+
cssText: string;
|
|
93
|
+
bodyOverflow: string;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Expand the Apple Pay iframe to a full-viewport overlay so Chrome's QR
|
|
98
|
+
* handoff UI (rendered inside the iframe) is not clipped to the button
|
|
99
|
+
* height. Safari's native sheet is OS-level and unaffected.
|
|
100
|
+
*/
|
|
101
|
+
function expandApplePayIframe(iframe: HTMLIFrameElement): SavedIframeLayout {
|
|
102
|
+
const saved: SavedIframeLayout = {
|
|
103
|
+
cssText: iframe.style.cssText,
|
|
104
|
+
bodyOverflow: document.body.style.overflow,
|
|
105
|
+
};
|
|
106
|
+
document.body.style.overflow = "hidden";
|
|
107
|
+
Object.assign(iframe.style, {
|
|
108
|
+
position: "fixed",
|
|
109
|
+
inset: "0px",
|
|
110
|
+
width: "100vw",
|
|
111
|
+
height: "100vh",
|
|
112
|
+
maxWidth: "none",
|
|
113
|
+
maxHeight: "none",
|
|
114
|
+
margin: "0",
|
|
115
|
+
border: "0",
|
|
116
|
+
zIndex: "2147483647",
|
|
117
|
+
opacity: "1",
|
|
118
|
+
background: "#ffffff",
|
|
119
|
+
});
|
|
120
|
+
return saved;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function collapseApplePayIframe(
|
|
124
|
+
iframe: HTMLIFrameElement,
|
|
125
|
+
saved: SavedIframeLayout | null,
|
|
126
|
+
): void {
|
|
127
|
+
if (!saved) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
document.body.style.overflow = saved.bodyOverflow;
|
|
131
|
+
iframe.style.cssText = saved.cssText;
|
|
132
|
+
}
|
|
133
|
+
|
|
91
134
|
/**
|
|
92
135
|
* Wire up the host-page side of the Apple Pay iframe message protocol
|
|
93
136
|
* on an existing `<iframe>` element. Returns a controller for updating
|
|
@@ -96,13 +139,17 @@ export type ApplePayButtonController = {
|
|
|
96
139
|
* The iframe is expected to have already been added to the DOM with the
|
|
97
140
|
* correct `src` (see {@link getApplePayButtonSrc}).
|
|
98
141
|
*
|
|
99
|
-
*
|
|
142
|
+
* The Apple Pay button and `ApplePaySession` run inside the Amos embed
|
|
143
|
+
* iframe (so only Amos domains need Apple merchant registration). On
|
|
144
|
+
* `EXPAND_IFRAME`, the parent temporarily overlays that iframe
|
|
145
|
+
* full-viewport for Chrome's in-iframe QR handoff UI.
|
|
100
146
|
*/
|
|
101
147
|
export function attachApplePayButtonListeners(
|
|
102
148
|
iframe: HTMLIFrameElement,
|
|
103
149
|
options: ApplePayButtonListenerOptions,
|
|
104
150
|
): ApplePayButtonController {
|
|
105
151
|
let current = { ...options };
|
|
152
|
+
let savedLayout: SavedIframeLayout | null = null;
|
|
106
153
|
|
|
107
154
|
function pushAmount() {
|
|
108
155
|
sendUpdateAmount({ iframe, amount: current.amount });
|
|
@@ -113,6 +160,11 @@ export function attachApplePayButtonListeners(
|
|
|
113
160
|
}
|
|
114
161
|
|
|
115
162
|
function handleMessage(event: MessageEvent<Message>) {
|
|
163
|
+
// Ignore messages from other frames / windows.
|
|
164
|
+
if (event.source !== iframe.contentWindow) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
116
168
|
switch (event.data.type) {
|
|
117
169
|
case "IFRAME_READY":
|
|
118
170
|
sendParentReadyMessage(iframe);
|
|
@@ -122,7 +174,10 @@ export function attachApplePayButtonListeners(
|
|
|
122
174
|
break;
|
|
123
175
|
|
|
124
176
|
case "UPDATE_HEIGHT":
|
|
125
|
-
|
|
177
|
+
// Ignore height updates while the session overlay is open.
|
|
178
|
+
if (!savedLayout) {
|
|
179
|
+
current.onHeightChange?.(event.data.height);
|
|
180
|
+
}
|
|
126
181
|
break;
|
|
127
182
|
|
|
128
183
|
case "UPDATE_APPEARANCE":
|
|
@@ -133,6 +188,17 @@ export function attachApplePayButtonListeners(
|
|
|
133
188
|
current.onAppearanceReady?.();
|
|
134
189
|
break;
|
|
135
190
|
|
|
191
|
+
case "EXPAND_IFRAME":
|
|
192
|
+
if (!savedLayout) {
|
|
193
|
+
savedLayout = expandApplePayIframe(iframe);
|
|
194
|
+
}
|
|
195
|
+
break;
|
|
196
|
+
|
|
197
|
+
case "COLLAPSE_IFRAME":
|
|
198
|
+
collapseApplePayIframe(iframe, savedLayout);
|
|
199
|
+
savedLayout = null;
|
|
200
|
+
break;
|
|
201
|
+
|
|
136
202
|
case "CREATE_PAYMENT_INTENT":
|
|
137
203
|
current
|
|
138
204
|
.onInitiatePaymentIntentRequest({
|
|
@@ -182,6 +248,8 @@ export function attachApplePayButtonListeners(
|
|
|
182
248
|
},
|
|
183
249
|
destroy() {
|
|
184
250
|
window.removeEventListener("message", handleMessage);
|
|
251
|
+
collapseApplePayIframe(iframe, savedLayout);
|
|
252
|
+
savedLayout = null;
|
|
185
253
|
},
|
|
186
254
|
};
|
|
187
255
|
}
|
package/src/types.ts
CHANGED
|
@@ -191,6 +191,18 @@ export type Message =
|
|
|
191
191
|
}
|
|
192
192
|
| {
|
|
193
193
|
type: "UPDATED_APPEARANCE";
|
|
194
|
+
}
|
|
195
|
+
| {
|
|
196
|
+
/**
|
|
197
|
+
* Iframe → parent: expand the Apple Pay iframe to a full-viewport
|
|
198
|
+
* overlay so Chrome's QR handoff UI is not clipped by the button
|
|
199
|
+
* height. The Apple Pay session stays on the Amos embed origin.
|
|
200
|
+
*/
|
|
201
|
+
type: "EXPAND_IFRAME";
|
|
202
|
+
}
|
|
203
|
+
| {
|
|
204
|
+
/** Iframe → parent: restore the Apple Pay iframe to its button size. */
|
|
205
|
+
type: "COLLAPSE_IFRAME";
|
|
194
206
|
};
|
|
195
207
|
|
|
196
208
|
/**
|