@amos.com/amos-js 0.6.0 → 0.7.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.
@@ -75,7 +75,7 @@ export type ApplePayButtonController = {
75
75
  *
76
76
  * The Apple Pay button and `ApplePaySession` run inside the Amos embed
77
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.
78
+ * non-Safari browsers, the embed opens Apple's QR handoff in a popup
79
+ * (`pay.apple.com`) rather than expanding this iframe.
80
80
  */
81
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){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;
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){if(t.source===e.contentWindow)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;
package/dist/index.mjs CHANGED
@@ -89,52 +89,30 @@ function d(e) {
89
89
  function f() {
90
90
  return "40px";
91
91
  }
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() {
92
+ function p(e, t) {
93
+ let n = { ...t };
94
+ function s() {
117
95
  a({
118
96
  iframe: e,
119
97
  amount: n.amount
120
98
  });
121
99
  }
122
- function d() {
100
+ function l() {
123
101
  o({
124
102
  iframe: e,
125
103
  merchantName: n.merchantName
126
104
  });
127
105
  }
128
- function f(t) {
106
+ function d(t) {
129
107
  if (t.source === e.contentWindow) switch (t.data.type) {
130
108
  case "IFRAME_READY":
131
109
  r(e), i({
132
110
  iframe: e,
133
111
  appearance: n.appearance
134
- }), l(), d();
112
+ }), s(), l();
135
113
  break;
136
114
  case "UPDATE_HEIGHT":
137
- s || n.onHeightChange?.(t.data.height);
115
+ n.onHeightChange?.(t.data.height);
138
116
  break;
139
117
  case "UPDATE_APPEARANCE":
140
118
  i({
@@ -145,12 +123,6 @@ function h(e, t) {
145
123
  case "UPDATED_APPEARANCE":
146
124
  n.onAppearanceReady?.();
147
125
  break;
148
- case "EXPAND_IFRAME":
149
- s ||= p(e);
150
- break;
151
- case "COLLAPSE_IFRAME":
152
- m(e, s), s = null;
153
- break;
154
126
  case "CREATE_PAYMENT_INTENT":
155
127
  n.onInitiatePaymentIntentRequest({
156
128
  paymentIntentCreateAttributes: t.data.paymentIntentCreateAttributes,
@@ -175,7 +147,7 @@ function h(e, t) {
175
147
  break;
176
148
  }
177
149
  }
178
- return window.addEventListener("message", f), {
150
+ return window.addEventListener("message", d), {
179
151
  update(t) {
180
152
  let r = "appearance" in t, a = "amount" in t, o = "merchantName" in t;
181
153
  n = {
@@ -184,22 +156,22 @@ function h(e, t) {
184
156
  }, r && i({
185
157
  iframe: e,
186
158
  appearance: n.appearance
187
- }), a && l(), o && d();
159
+ }), a && s(), o && l();
188
160
  },
189
161
  destroy() {
190
- window.removeEventListener("message", f), m(e, s), s = null;
162
+ window.removeEventListener("message", d);
191
163
  }
192
164
  };
193
165
  }
194
166
  //#endregion
195
167
  //#region src/google-pay.ts
196
- function g(e) {
168
+ function m(e) {
197
169
  return `${t(e)}/iframe/google-pay?token=${e}`;
198
170
  }
199
- function _() {
171
+ function h() {
200
172
  return "40px";
201
173
  }
202
- function v(e, t) {
174
+ function g(e, t) {
203
175
  let n = { ...t };
204
176
  function s() {
205
177
  a({
@@ -273,7 +245,7 @@ function v(e, t) {
273
245
  }
274
246
  };
275
247
  }
276
- function y({ paymentData: e }) {
248
+ function _({ paymentData: e }) {
277
249
  return { paymentMethod: {
278
250
  type: "googlepay",
279
251
  billing_address_attributes: {
@@ -305,14 +277,14 @@ function y({ paymentData: e }) {
305
277
  }
306
278
  //#endregion
307
279
  //#region src/payment-method-form.ts
308
- var b = {
280
+ var v = {
309
281
  country: 212,
310
282
  full: 452
311
- }, x = 80, S = {
283
+ }, y = 80, b = {
312
284
  country: 400,
313
285
  full: 640
314
286
  };
315
- function C(e, n = { cardholderName: !1 }, r = "country") {
287
+ function x(e, n = { cardholderName: !1 }, r = "country") {
316
288
  let i = Object.entries(n).filter(([, e]) => e).map(([e]) => e).join(","), a = new URLSearchParams({
317
289
  token: e,
318
290
  additionalFields: i,
@@ -320,20 +292,20 @@ function C(e, n = { cardholderName: !1 }, r = "country") {
320
292
  });
321
293
  return `${t(e)}/iframe/card?${a}`;
322
294
  }
323
- function w(e, n = "country") {
295
+ function S(e, n = "country") {
324
296
  let r = new URLSearchParams({
325
297
  token: e,
326
298
  billingAddressRequirement: n
327
299
  });
328
300
  return `${t(e)}/iframe/bank?${r}`;
329
301
  }
330
- function T(e = { cardholderName: !1 }, t = "country") {
331
- return `${(b[t] ?? b.country) + (e.cardholderName ? x : 0)}px`;
302
+ function C(e = { cardholderName: !1 }, t = "country") {
303
+ return `${(v[t] ?? v.country) + (e.cardholderName ? y : 0)}px`;
332
304
  }
333
- function E(e = "country") {
334
- return `${S[e] ?? S.country}px`;
305
+ function w(e = "country") {
306
+ return `${b[e] ?? b.country}px`;
335
307
  }
336
- function D(e, t) {
308
+ function T(e, t) {
337
309
  let n = { ...t };
338
310
  function a(t) {
339
311
  switch (t.data.type) {
@@ -384,7 +356,7 @@ function D(e, t) {
384
356
  }
385
357
  //#endregion
386
358
  //#region src/mount.ts
387
- function O(e) {
359
+ function E(e) {
388
360
  if (typeof e == "string") {
389
361
  let t = document.querySelector(e);
390
362
  if (!(t instanceof HTMLElement)) throw Error(`[amos-js] Container "${e}" did not match any HTMLElement.`);
@@ -392,26 +364,26 @@ function O(e) {
392
364
  }
393
365
  return e;
394
366
  }
395
- var k = {
367
+ var D = {
396
368
  width: "calc(100% + 8px)",
397
369
  transition: "opacity 150ms ease-in, height 200ms ease-in-out",
398
370
  margin: "0 -4px",
399
371
  opacity: "0",
400
372
  border: "0"
401
373
  };
402
- function A({ src: e, title: t, name: n, height: r, allow: i }) {
374
+ function O({ src: e, title: t, name: n, height: r, allow: i }) {
403
375
  let a = document.createElement("iframe");
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;
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, D, { height: r }), a;
405
377
  }
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),
378
+ function k(e, t) {
379
+ let n = E(e), { renderToken: r, additionalFields: i = { cardholderName: !1 }, billingAddressRequirement: a = "country", ...o } = t, s = O({
380
+ src: x(r, i, a),
409
381
  title: "Secure credit card payment method form powered by Amos",
410
382
  name: "amos-credit-card-payment-method-form",
411
- height: T(i, a)
383
+ height: C(i, a)
412
384
  });
413
385
  n.appendChild(s);
414
- let c = D(s, {
386
+ let c = T(s, {
415
387
  ...o,
416
388
  onHeightChange: (e) => {
417
389
  s.style.height = e, o.onHeightChange?.(e);
@@ -428,15 +400,15 @@ function j(e, t) {
428
400
  }
429
401
  };
430
402
  }
431
- function M(e, t) {
432
- let n = O(e), { renderToken: r, billingAddressRequirement: i = "country", ...a } = t, o = A({
433
- src: w(r, i),
403
+ function A(e, t) {
404
+ let n = E(e), { renderToken: r, billingAddressRequirement: i = "country", ...a } = t, o = O({
405
+ src: S(r, i),
434
406
  title: "Secure bank account payment method form powered by Amos",
435
407
  name: "amos-bank-account-payment-method-form",
436
- height: E(i)
408
+ height: w(i)
437
409
  });
438
410
  n.appendChild(o);
439
- let s = D(o, {
411
+ let s = T(o, {
440
412
  ...a,
441
413
  onHeightChange: (e) => {
442
414
  o.style.height = e, a.onHeightChange?.(e);
@@ -453,16 +425,16 @@ function M(e, t) {
453
425
  }
454
426
  };
455
427
  }
456
- function N(e, t) {
457
- let n = O(e), { renderToken: r, ...i } = t, a = A({
458
- src: g(r),
428
+ function j(e, t) {
429
+ let n = E(e), { renderToken: r, ...i } = t, a = O({
430
+ src: m(r),
459
431
  title: "Secure Google Pay button powered by Amos",
460
432
  name: "amos-google-pay-button",
461
- height: _(),
433
+ height: h(),
462
434
  allow: "payment"
463
435
  });
464
436
  n.appendChild(a);
465
- let o = v(a, {
437
+ let o = g(a, {
466
438
  ...i,
467
439
  onHeightChange: (e) => {
468
440
  a.style.height = e, i.onHeightChange?.(e);
@@ -479,8 +451,8 @@ function N(e, t) {
479
451
  }
480
452
  };
481
453
  }
482
- function P(e, t) {
483
- let n = O(e), { renderToken: r, ...i } = t, a = A({
454
+ function M(e, t) {
455
+ let n = E(e), { renderToken: r, ...i } = t, a = O({
484
456
  src: d(r),
485
457
  title: "Secure Apple Pay button powered by Amos",
486
458
  name: "amos-apple-pay-button",
@@ -488,7 +460,7 @@ function P(e, t) {
488
460
  allow: "payment"
489
461
  });
490
462
  n.appendChild(a);
491
- let o = h(a, {
463
+ let o = p(a, {
492
464
  ...i,
493
465
  onHeightChange: (e) => {
494
466
  a.style.height = e, i.onHeightChange?.(e);
@@ -506,4 +478,4 @@ function P(e, t) {
506
478
  };
507
479
  }
508
480
  //#endregion
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 };
481
+ export { p as attachApplePayButtonListeners, g as attachGooglePayButtonListeners, T as attachPaymentMethodFormListeners, c as confirmPaymentIntent, l as confirmSetupIntent, n as createMessage, e as decodeJwt, _ as formatGooglePayPaymentData, f as getApplePayButtonInitialHeight, d as getApplePayButtonSrc, w as getBankAccountFormInitialHeight, S as getBankAccountFormSrc, C as getCreditCardFormInitialHeight, x as getCreditCardFormSrc, t as getEmbedOrigin, h as getGooglePayButtonInitialHeight, m as getGooglePayButtonSrc, M as mountAmosApplePayButton, A as mountAmosBankAccountPaymentMethodForm, k as mountAmosCreditCardPaymentMethodForm, j 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,16 +68,6 @@ 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";
81
71
  };
82
72
  /**
83
73
  * Identity helper that brands an object as a typed `Message`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amos.com/amos-js",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "main": "dist/index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -44,7 +44,7 @@
44
44
  "vite-plugin-dts": "5.0.3"
45
45
  },
46
46
  "dependencies": {
47
- "@amos.com/node": "0.1.31",
47
+ "@amos.com/node": "0.1.32",
48
48
  "@types/googlepay": "0.7.11"
49
49
  }
50
50
  }
package/src/apple-pay.ts CHANGED
@@ -88,49 +88,6 @@ 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
-
134
91
  /**
135
92
  * Wire up the host-page side of the Apple Pay iframe message protocol
136
93
  * on an existing `<iframe>` element. Returns a controller for updating
@@ -141,15 +98,14 @@ function collapseApplePayIframe(
141
98
  *
142
99
  * The Apple Pay button and `ApplePaySession` run inside the Amos embed
143
100
  * 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.
101
+ * non-Safari browsers, the embed opens Apple's QR handoff in a popup
102
+ * (`pay.apple.com`) rather than expanding this iframe.
146
103
  */
147
104
  export function attachApplePayButtonListeners(
148
105
  iframe: HTMLIFrameElement,
149
106
  options: ApplePayButtonListenerOptions,
150
107
  ): ApplePayButtonController {
151
108
  let current = { ...options };
152
- let savedLayout: SavedIframeLayout | null = null;
153
109
 
154
110
  function pushAmount() {
155
111
  sendUpdateAmount({ iframe, amount: current.amount });
@@ -174,10 +130,7 @@ export function attachApplePayButtonListeners(
174
130
  break;
175
131
 
176
132
  case "UPDATE_HEIGHT":
177
- // Ignore height updates while the session overlay is open.
178
- if (!savedLayout) {
179
- current.onHeightChange?.(event.data.height);
180
- }
133
+ current.onHeightChange?.(event.data.height);
181
134
  break;
182
135
 
183
136
  case "UPDATE_APPEARANCE":
@@ -188,17 +141,6 @@ export function attachApplePayButtonListeners(
188
141
  current.onAppearanceReady?.();
189
142
  break;
190
143
 
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
-
202
144
  case "CREATE_PAYMENT_INTENT":
203
145
  current
204
146
  .onInitiatePaymentIntentRequest({
@@ -248,8 +190,6 @@ export function attachApplePayButtonListeners(
248
190
  },
249
191
  destroy() {
250
192
  window.removeEventListener("message", handleMessage);
251
- collapseApplePayIframe(iframe, savedLayout);
252
- savedLayout = null;
253
193
  },
254
194
  };
255
195
  }
package/src/types.ts CHANGED
@@ -191,18 +191,6 @@ 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";
206
194
  };
207
195
 
208
196
  /**