@amos.com/amos-js 0.6.0 → 0.6.1
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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +83 -68
- package/dist/messaging.d.ts +13 -0
- package/dist/types.d.ts +8 -0
- package/package.json +2 -2
- package/src/apple-pay.ts +10 -0
- package/src/index.ts +2 -0
- package/src/messaging.ts +28 -0
- package/src/types.ts +9 -0
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { attachApplePayButtonListeners, getApplePayButtonInitialHeight, getApple
|
|
|
4
4
|
export type { FormattedGooglePayPaymentData, GooglePayButtonController, GooglePayButtonListenerOptions, } from './google-pay';
|
|
5
5
|
export { attachGooglePayButtonListeners, formatGooglePayPaymentData, getGooglePayButtonInitialHeight, getGooglePayButtonSrc, } from './google-pay';
|
|
6
6
|
export { decodeJwt, getEmbedOrigin } from './jwt';
|
|
7
|
-
export { confirmPaymentIntent, confirmSetupIntent, sendConfirmationFailed, sendParentReadyMessage, updateAmount, updateAppearance, updateMerchantName, validateForm, } from './messaging';
|
|
7
|
+
export { confirmPaymentIntent, confirmSetupIntent, hasNativeApplePaySession, sendConfirmationFailed, sendParentReadyMessage, updateAmount, updateAppearance, updateMerchantName, updateNativeApplePaySession, validateForm, } from './messaging';
|
|
8
8
|
export type { AmosApplePayButtonMountController, AmosApplePayButtonOptions, AmosBankAccountPaymentMethodFormOptions, AmosCreditCardPaymentMethodFormOptions, AmosGooglePayButtonMountController, AmosGooglePayButtonOptions, AmosPaymentMethodFormMountController, } from './mount';
|
|
9
9
|
export { mountAmosApplePayButton, mountAmosBankAccountPaymentMethodForm, mountAmosCreditCardPaymentMethodForm, mountAmosGooglePayButton, } from './mount';
|
|
10
10
|
export type { BillingAddressRequirement, CreditCardAdditionalFields, PaymentMethodFormController, PaymentMethodFormListenerOptions, } from './payment-method-form';
|
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(){return`ApplePaySession`in globalThis}function c({iframe:e,hasNativeApplePaySession:t}){e?.contentWindow?.postMessage(n({type:`UPDATE_NATIVE_APPLE_PAY_SESSION`,hasNativeApplePaySession:t}),`*`)}function l({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 u({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 d({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 f({iframe:e,errorMessage:t}){e?.contentWindow?.postMessage(n({type:`CONFIRMATION_FAILED`,errorMessage:t}),`*`)}function p(e){return`${t(e)}/iframe/apple-pay?token=${e}`}function m(){return`40px`}function h(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 g(e,t){t&&(document.body.style.overflow=t.bodyOverflow,e.style.cssText=t.cssText)}function _(e,t){let n={...t},l=null;function d(){a({iframe:e,amount:n.amount})}function p(){o({iframe:e,merchantName:n.merchantName})}function m(){c({iframe:e,hasNativeApplePaySession:s()})}function _(t){if(t.source===e.contentWindow)switch(t.data.type){case`IFRAME_READY`:r(e),i({iframe:e,appearance:n.appearance}),m(),d(),p();break;case`UPDATE_HEIGHT`:l||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`:l||=h(e);break;case`COLLAPSE_IFRAME`:g(e,l),l=null;break;case`CREATE_PAYMENT_INTENT`:n.onInitiatePaymentIntentRequest({paymentIntentCreateAttributes:t.data.paymentIntentCreateAttributes,customerCreateAttributes:t.data.customerCreateAttributes}).then(t=>{u({iframe:e,token:t})}).catch(t=>{f({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`,_),{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&&d(),o&&p()},destroy(){window.removeEventListener(`message`,_),g(e,l),l=null}}}function v(e){return`${t(e)}/iframe/google-pay?token=${e}`}function y(){return`40px`}function b(e,t){let n={...t};function s(){a({iframe:e,amount:n.amount})}function c(){o({iframe:e,merchantName:n.merchantName})}function l(t){switch(t.data.type){case`IFRAME_READY`:r(e),i({iframe:e,appearance:n.appearance}),s(),c();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=>{u({iframe:e,token:t})}).catch(t=>{f({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`,l),{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&&c()},destroy(){window.removeEventListener(`message`,l)}}}function x({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 S={country:212,full:452},C=80,w={country:400,full:640};function T(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 E(e,n=`country`){let r=new URLSearchParams({token:e,billingAddressRequirement:n});return`${t(e)}/iframe/bank?${r}`}function D(e={cardholderName:!1},t=`country`){return`${(S[t]??S.country)+(e.cardholderName?C:0)}px`}function O(e=`country`){return`${w[e]??w.country}px`}function k(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 A(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 j={width:`calc(100% + 8px)`,transition:`opacity 150ms ease-in, height 200ms ease-in-out`,margin:`0 -4px`,opacity:`0`,border:`0`};function M({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,j,{height:r}),a}function N(e,t){let n=A(e),{renderToken:r,additionalFields:i={cardholderName:!1},billingAddressRequirement:a=`country`,...o}=t,s=M({src:T(r,i,a),title:`Secure credit card payment method form powered by Amos`,name:`amos-credit-card-payment-method-form`,height:D(i,a)});n.appendChild(s);let c=k(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 P(e,t){let n=A(e),{renderToken:r,billingAddressRequirement:i=`country`,...a}=t,o=M({src:E(r,i),title:`Secure bank account payment method form powered by Amos`,name:`amos-bank-account-payment-method-form`,height:O(i)});n.appendChild(o);let s=k(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 F(e,t){let n=A(e),{renderToken:r,...i}=t,a=M({src:v(r),title:`Secure Google Pay button powered by Amos`,name:`amos-google-pay-button`,height:y(),allow:`payment`});n.appendChild(a);let o=b(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 I(e,t){let n=A(e),{renderToken:r,...i}=t,a=M({src:p(r),title:`Secure Apple Pay button powered by Amos`,name:`amos-apple-pay-button`,height:m(),allow:`payment`});n.appendChild(a);let o=_(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=_,exports.attachGooglePayButtonListeners=b,exports.attachPaymentMethodFormListeners=k,exports.confirmPaymentIntent=u,exports.confirmSetupIntent=d,exports.createMessage=n,exports.decodeJwt=e,exports.formatGooglePayPaymentData=x,exports.getApplePayButtonInitialHeight=m,exports.getApplePayButtonSrc=p,exports.getBankAccountFormInitialHeight=O,exports.getBankAccountFormSrc=E,exports.getCreditCardFormInitialHeight=D,exports.getCreditCardFormSrc=T,exports.getEmbedOrigin=t,exports.getGooglePayButtonInitialHeight=y,exports.getGooglePayButtonSrc=v,exports.hasNativeApplePaySession=s,exports.mountAmosApplePayButton=I,exports.mountAmosBankAccountPaymentMethodForm=P,exports.mountAmosCreditCardPaymentMethodForm=N,exports.mountAmosGooglePayButton=F,exports.sendConfirmationFailed=f,exports.sendParentReadyMessage=r,exports.updateAmount=a,exports.updateAppearance=i,exports.updateMerchantName=o,exports.updateNativeApplePaySession=c,exports.validateForm=l;
|
package/dist/index.mjs
CHANGED
|
@@ -43,7 +43,16 @@ function o({ iframe: e, merchantName: t }) {
|
|
|
43
43
|
merchantName: t
|
|
44
44
|
}), "*");
|
|
45
45
|
}
|
|
46
|
-
function s(
|
|
46
|
+
function s() {
|
|
47
|
+
return "ApplePaySession" in globalThis;
|
|
48
|
+
}
|
|
49
|
+
function c({ iframe: e, hasNativeApplePaySession: t }) {
|
|
50
|
+
e?.contentWindow?.postMessage(n({
|
|
51
|
+
type: "UPDATE_NATIVE_APPLE_PAY_SESSION",
|
|
52
|
+
hasNativeApplePaySession: t
|
|
53
|
+
}), "*");
|
|
54
|
+
}
|
|
55
|
+
function l({ iframe: e }) {
|
|
47
56
|
let t = crypto.randomUUID();
|
|
48
57
|
return new Promise((r) => {
|
|
49
58
|
e?.contentWindow?.postMessage(n({
|
|
@@ -59,7 +68,7 @@ function s({ iframe: e }) {
|
|
|
59
68
|
window.addEventListener("message", a);
|
|
60
69
|
});
|
|
61
70
|
}
|
|
62
|
-
function
|
|
71
|
+
function u({ iframe: t, token: r }) {
|
|
63
72
|
let { payment_intent_id: i } = e(r).payload;
|
|
64
73
|
t?.contentWindow?.postMessage(n({
|
|
65
74
|
type: "CONFIRM_PAYMENT_INTENT",
|
|
@@ -67,7 +76,7 @@ function c({ iframe: t, token: r }) {
|
|
|
67
76
|
id: i ?? void 0
|
|
68
77
|
}), "*");
|
|
69
78
|
}
|
|
70
|
-
function
|
|
79
|
+
function d({ iframe: t, token: r }) {
|
|
71
80
|
let { setup_intent_id: i } = e(r).payload;
|
|
72
81
|
t?.contentWindow?.postMessage(n({
|
|
73
82
|
type: "CONFIRM_SETUP_INTENT",
|
|
@@ -75,7 +84,7 @@ function l({ iframe: t, token: r }) {
|
|
|
75
84
|
id: i ?? void 0
|
|
76
85
|
}), "*");
|
|
77
86
|
}
|
|
78
|
-
function
|
|
87
|
+
function f({ iframe: e, errorMessage: t }) {
|
|
79
88
|
e?.contentWindow?.postMessage(n({
|
|
80
89
|
type: "CONFIRMATION_FAILED",
|
|
81
90
|
errorMessage: t
|
|
@@ -83,13 +92,13 @@ function u({ iframe: e, errorMessage: t }) {
|
|
|
83
92
|
}
|
|
84
93
|
//#endregion
|
|
85
94
|
//#region src/apple-pay.ts
|
|
86
|
-
function
|
|
95
|
+
function p(e) {
|
|
87
96
|
return `${t(e)}/iframe/apple-pay?token=${e}`;
|
|
88
97
|
}
|
|
89
|
-
function
|
|
98
|
+
function m() {
|
|
90
99
|
return "40px";
|
|
91
100
|
}
|
|
92
|
-
function
|
|
101
|
+
function h(e) {
|
|
93
102
|
let t = {
|
|
94
103
|
cssText: e.style.cssText,
|
|
95
104
|
bodyOverflow: document.body.style.overflow
|
|
@@ -108,33 +117,39 @@ function p(e) {
|
|
|
108
117
|
background: "#ffffff"
|
|
109
118
|
}), t;
|
|
110
119
|
}
|
|
111
|
-
function
|
|
120
|
+
function g(e, t) {
|
|
112
121
|
t && (document.body.style.overflow = t.bodyOverflow, e.style.cssText = t.cssText);
|
|
113
122
|
}
|
|
114
|
-
function
|
|
115
|
-
let n = { ...t },
|
|
116
|
-
function
|
|
123
|
+
function _(e, t) {
|
|
124
|
+
let n = { ...t }, l = null;
|
|
125
|
+
function d() {
|
|
117
126
|
a({
|
|
118
127
|
iframe: e,
|
|
119
128
|
amount: n.amount
|
|
120
129
|
});
|
|
121
130
|
}
|
|
122
|
-
function
|
|
131
|
+
function p() {
|
|
123
132
|
o({
|
|
124
133
|
iframe: e,
|
|
125
134
|
merchantName: n.merchantName
|
|
126
135
|
});
|
|
127
136
|
}
|
|
128
|
-
function
|
|
137
|
+
function m() {
|
|
138
|
+
c({
|
|
139
|
+
iframe: e,
|
|
140
|
+
hasNativeApplePaySession: s()
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function _(t) {
|
|
129
144
|
if (t.source === e.contentWindow) switch (t.data.type) {
|
|
130
145
|
case "IFRAME_READY":
|
|
131
146
|
r(e), i({
|
|
132
147
|
iframe: e,
|
|
133
148
|
appearance: n.appearance
|
|
134
|
-
}),
|
|
149
|
+
}), m(), d(), p();
|
|
135
150
|
break;
|
|
136
151
|
case "UPDATE_HEIGHT":
|
|
137
|
-
|
|
152
|
+
l || n.onHeightChange?.(t.data.height);
|
|
138
153
|
break;
|
|
139
154
|
case "UPDATE_APPEARANCE":
|
|
140
155
|
i({
|
|
@@ -146,22 +161,22 @@ function h(e, t) {
|
|
|
146
161
|
n.onAppearanceReady?.();
|
|
147
162
|
break;
|
|
148
163
|
case "EXPAND_IFRAME":
|
|
149
|
-
|
|
164
|
+
l ||= h(e);
|
|
150
165
|
break;
|
|
151
166
|
case "COLLAPSE_IFRAME":
|
|
152
|
-
|
|
167
|
+
g(e, l), l = null;
|
|
153
168
|
break;
|
|
154
169
|
case "CREATE_PAYMENT_INTENT":
|
|
155
170
|
n.onInitiatePaymentIntentRequest({
|
|
156
171
|
paymentIntentCreateAttributes: t.data.paymentIntentCreateAttributes,
|
|
157
172
|
customerCreateAttributes: t.data.customerCreateAttributes
|
|
158
173
|
}).then((t) => {
|
|
159
|
-
|
|
174
|
+
u({
|
|
160
175
|
iframe: e,
|
|
161
176
|
token: t
|
|
162
177
|
});
|
|
163
178
|
}).catch((t) => {
|
|
164
|
-
|
|
179
|
+
f({
|
|
165
180
|
iframe: e,
|
|
166
181
|
errorMessage: t instanceof Error ? t.message : "Unknown error"
|
|
167
182
|
});
|
|
@@ -175,7 +190,7 @@ function h(e, t) {
|
|
|
175
190
|
break;
|
|
176
191
|
}
|
|
177
192
|
}
|
|
178
|
-
return window.addEventListener("message",
|
|
193
|
+
return window.addEventListener("message", _), {
|
|
179
194
|
update(t) {
|
|
180
195
|
let r = "appearance" in t, a = "amount" in t, o = "merchantName" in t;
|
|
181
196
|
n = {
|
|
@@ -184,22 +199,22 @@ function h(e, t) {
|
|
|
184
199
|
}, r && i({
|
|
185
200
|
iframe: e,
|
|
186
201
|
appearance: n.appearance
|
|
187
|
-
}), a &&
|
|
202
|
+
}), a && d(), o && p();
|
|
188
203
|
},
|
|
189
204
|
destroy() {
|
|
190
|
-
window.removeEventListener("message",
|
|
205
|
+
window.removeEventListener("message", _), g(e, l), l = null;
|
|
191
206
|
}
|
|
192
207
|
};
|
|
193
208
|
}
|
|
194
209
|
//#endregion
|
|
195
210
|
//#region src/google-pay.ts
|
|
196
|
-
function
|
|
211
|
+
function v(e) {
|
|
197
212
|
return `${t(e)}/iframe/google-pay?token=${e}`;
|
|
198
213
|
}
|
|
199
|
-
function
|
|
214
|
+
function y() {
|
|
200
215
|
return "40px";
|
|
201
216
|
}
|
|
202
|
-
function
|
|
217
|
+
function b(e, t) {
|
|
203
218
|
let n = { ...t };
|
|
204
219
|
function s() {
|
|
205
220
|
a({
|
|
@@ -207,19 +222,19 @@ function v(e, t) {
|
|
|
207
222
|
amount: n.amount
|
|
208
223
|
});
|
|
209
224
|
}
|
|
210
|
-
function
|
|
225
|
+
function c() {
|
|
211
226
|
o({
|
|
212
227
|
iframe: e,
|
|
213
228
|
merchantName: n.merchantName
|
|
214
229
|
});
|
|
215
230
|
}
|
|
216
|
-
function
|
|
231
|
+
function l(t) {
|
|
217
232
|
switch (t.data.type) {
|
|
218
233
|
case "IFRAME_READY":
|
|
219
234
|
r(e), i({
|
|
220
235
|
iframe: e,
|
|
221
236
|
appearance: n.appearance
|
|
222
|
-
}), s(),
|
|
237
|
+
}), s(), c();
|
|
223
238
|
break;
|
|
224
239
|
case "UPDATE_HEIGHT":
|
|
225
240
|
n.onHeightChange?.(t.data.height);
|
|
@@ -238,12 +253,12 @@ function v(e, t) {
|
|
|
238
253
|
paymentIntentCreateAttributes: t.data.paymentIntentCreateAttributes,
|
|
239
254
|
customerCreateAttributes: t.data.customerCreateAttributes
|
|
240
255
|
}).then((t) => {
|
|
241
|
-
|
|
256
|
+
u({
|
|
242
257
|
iframe: e,
|
|
243
258
|
token: t
|
|
244
259
|
});
|
|
245
260
|
}).catch((t) => {
|
|
246
|
-
|
|
261
|
+
f({
|
|
247
262
|
iframe: e,
|
|
248
263
|
errorMessage: t instanceof Error ? t.message : "Unknown error"
|
|
249
264
|
});
|
|
@@ -257,7 +272,7 @@ function v(e, t) {
|
|
|
257
272
|
break;
|
|
258
273
|
}
|
|
259
274
|
}
|
|
260
|
-
return window.addEventListener("message",
|
|
275
|
+
return window.addEventListener("message", l), {
|
|
261
276
|
update(t) {
|
|
262
277
|
let r = "appearance" in t, a = "amount" in t, o = "merchantName" in t;
|
|
263
278
|
n = {
|
|
@@ -266,14 +281,14 @@ function v(e, t) {
|
|
|
266
281
|
}, r && i({
|
|
267
282
|
iframe: e,
|
|
268
283
|
appearance: n.appearance
|
|
269
|
-
}), a && s(), o &&
|
|
284
|
+
}), a && s(), o && c();
|
|
270
285
|
},
|
|
271
286
|
destroy() {
|
|
272
|
-
window.removeEventListener("message",
|
|
287
|
+
window.removeEventListener("message", l);
|
|
273
288
|
}
|
|
274
289
|
};
|
|
275
290
|
}
|
|
276
|
-
function
|
|
291
|
+
function x({ paymentData: e }) {
|
|
277
292
|
return { paymentMethod: {
|
|
278
293
|
type: "googlepay",
|
|
279
294
|
billing_address_attributes: {
|
|
@@ -305,14 +320,14 @@ function y({ paymentData: e }) {
|
|
|
305
320
|
}
|
|
306
321
|
//#endregion
|
|
307
322
|
//#region src/payment-method-form.ts
|
|
308
|
-
var
|
|
323
|
+
var S = {
|
|
309
324
|
country: 212,
|
|
310
325
|
full: 452
|
|
311
|
-
},
|
|
326
|
+
}, C = 80, w = {
|
|
312
327
|
country: 400,
|
|
313
328
|
full: 640
|
|
314
329
|
};
|
|
315
|
-
function
|
|
330
|
+
function T(e, n = { cardholderName: !1 }, r = "country") {
|
|
316
331
|
let i = Object.entries(n).filter(([, e]) => e).map(([e]) => e).join(","), a = new URLSearchParams({
|
|
317
332
|
token: e,
|
|
318
333
|
additionalFields: i,
|
|
@@ -320,20 +335,20 @@ function C(e, n = { cardholderName: !1 }, r = "country") {
|
|
|
320
335
|
});
|
|
321
336
|
return `${t(e)}/iframe/card?${a}`;
|
|
322
337
|
}
|
|
323
|
-
function
|
|
338
|
+
function E(e, n = "country") {
|
|
324
339
|
let r = new URLSearchParams({
|
|
325
340
|
token: e,
|
|
326
341
|
billingAddressRequirement: n
|
|
327
342
|
});
|
|
328
343
|
return `${t(e)}/iframe/bank?${r}`;
|
|
329
344
|
}
|
|
330
|
-
function
|
|
331
|
-
return `${(
|
|
345
|
+
function D(e = { cardholderName: !1 }, t = "country") {
|
|
346
|
+
return `${(S[t] ?? S.country) + (e.cardholderName ? C : 0)}px`;
|
|
332
347
|
}
|
|
333
|
-
function
|
|
334
|
-
return `${
|
|
348
|
+
function O(e = "country") {
|
|
349
|
+
return `${w[e] ?? w.country}px`;
|
|
335
350
|
}
|
|
336
|
-
function
|
|
351
|
+
function k(e, t) {
|
|
337
352
|
let n = { ...t };
|
|
338
353
|
function a(t) {
|
|
339
354
|
switch (t.data.type) {
|
|
@@ -384,7 +399,7 @@ function D(e, t) {
|
|
|
384
399
|
}
|
|
385
400
|
//#endregion
|
|
386
401
|
//#region src/mount.ts
|
|
387
|
-
function
|
|
402
|
+
function A(e) {
|
|
388
403
|
if (typeof e == "string") {
|
|
389
404
|
let t = document.querySelector(e);
|
|
390
405
|
if (!(t instanceof HTMLElement)) throw Error(`[amos-js] Container "${e}" did not match any HTMLElement.`);
|
|
@@ -392,26 +407,26 @@ function O(e) {
|
|
|
392
407
|
}
|
|
393
408
|
return e;
|
|
394
409
|
}
|
|
395
|
-
var
|
|
410
|
+
var j = {
|
|
396
411
|
width: "calc(100% + 8px)",
|
|
397
412
|
transition: "opacity 150ms ease-in, height 200ms ease-in-out",
|
|
398
413
|
margin: "0 -4px",
|
|
399
414
|
opacity: "0",
|
|
400
415
|
border: "0"
|
|
401
416
|
};
|
|
402
|
-
function
|
|
417
|
+
function M({ src: e, title: t, name: n, height: r, allow: i }) {
|
|
403
418
|
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,
|
|
419
|
+
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, j, { height: r }), a;
|
|
405
420
|
}
|
|
406
|
-
function
|
|
407
|
-
let n =
|
|
408
|
-
src:
|
|
421
|
+
function N(e, t) {
|
|
422
|
+
let n = A(e), { renderToken: r, additionalFields: i = { cardholderName: !1 }, billingAddressRequirement: a = "country", ...o } = t, s = M({
|
|
423
|
+
src: T(r, i, a),
|
|
409
424
|
title: "Secure credit card payment method form powered by Amos",
|
|
410
425
|
name: "amos-credit-card-payment-method-form",
|
|
411
|
-
height:
|
|
426
|
+
height: D(i, a)
|
|
412
427
|
});
|
|
413
428
|
n.appendChild(s);
|
|
414
|
-
let c =
|
|
429
|
+
let c = k(s, {
|
|
415
430
|
...o,
|
|
416
431
|
onHeightChange: (e) => {
|
|
417
432
|
s.style.height = e, o.onHeightChange?.(e);
|
|
@@ -428,15 +443,15 @@ function j(e, t) {
|
|
|
428
443
|
}
|
|
429
444
|
};
|
|
430
445
|
}
|
|
431
|
-
function
|
|
432
|
-
let n =
|
|
433
|
-
src:
|
|
446
|
+
function P(e, t) {
|
|
447
|
+
let n = A(e), { renderToken: r, billingAddressRequirement: i = "country", ...a } = t, o = M({
|
|
448
|
+
src: E(r, i),
|
|
434
449
|
title: "Secure bank account payment method form powered by Amos",
|
|
435
450
|
name: "amos-bank-account-payment-method-form",
|
|
436
|
-
height:
|
|
451
|
+
height: O(i)
|
|
437
452
|
});
|
|
438
453
|
n.appendChild(o);
|
|
439
|
-
let s =
|
|
454
|
+
let s = k(o, {
|
|
440
455
|
...a,
|
|
441
456
|
onHeightChange: (e) => {
|
|
442
457
|
o.style.height = e, a.onHeightChange?.(e);
|
|
@@ -453,16 +468,16 @@ function M(e, t) {
|
|
|
453
468
|
}
|
|
454
469
|
};
|
|
455
470
|
}
|
|
456
|
-
function
|
|
457
|
-
let n =
|
|
458
|
-
src:
|
|
471
|
+
function F(e, t) {
|
|
472
|
+
let n = A(e), { renderToken: r, ...i } = t, a = M({
|
|
473
|
+
src: v(r),
|
|
459
474
|
title: "Secure Google Pay button powered by Amos",
|
|
460
475
|
name: "amos-google-pay-button",
|
|
461
|
-
height:
|
|
476
|
+
height: y(),
|
|
462
477
|
allow: "payment"
|
|
463
478
|
});
|
|
464
479
|
n.appendChild(a);
|
|
465
|
-
let o =
|
|
480
|
+
let o = b(a, {
|
|
466
481
|
...i,
|
|
467
482
|
onHeightChange: (e) => {
|
|
468
483
|
a.style.height = e, i.onHeightChange?.(e);
|
|
@@ -479,16 +494,16 @@ function N(e, t) {
|
|
|
479
494
|
}
|
|
480
495
|
};
|
|
481
496
|
}
|
|
482
|
-
function
|
|
483
|
-
let n =
|
|
484
|
-
src:
|
|
497
|
+
function I(e, t) {
|
|
498
|
+
let n = A(e), { renderToken: r, ...i } = t, a = M({
|
|
499
|
+
src: p(r),
|
|
485
500
|
title: "Secure Apple Pay button powered by Amos",
|
|
486
501
|
name: "amos-apple-pay-button",
|
|
487
|
-
height:
|
|
502
|
+
height: m(),
|
|
488
503
|
allow: "payment"
|
|
489
504
|
});
|
|
490
505
|
n.appendChild(a);
|
|
491
|
-
let o =
|
|
506
|
+
let o = _(a, {
|
|
492
507
|
...i,
|
|
493
508
|
onHeightChange: (e) => {
|
|
494
509
|
a.style.height = e, i.onHeightChange?.(e);
|
|
@@ -506,4 +521,4 @@ function P(e, t) {
|
|
|
506
521
|
};
|
|
507
522
|
}
|
|
508
523
|
//#endregion
|
|
509
|
-
export {
|
|
524
|
+
export { _ as attachApplePayButtonListeners, b as attachGooglePayButtonListeners, k as attachPaymentMethodFormListeners, u as confirmPaymentIntent, d as confirmSetupIntent, n as createMessage, e as decodeJwt, x as formatGooglePayPaymentData, m as getApplePayButtonInitialHeight, p as getApplePayButtonSrc, O as getBankAccountFormInitialHeight, E as getBankAccountFormSrc, D as getCreditCardFormInitialHeight, T as getCreditCardFormSrc, t as getEmbedOrigin, y as getGooglePayButtonInitialHeight, v as getGooglePayButtonSrc, s as hasNativeApplePaySession, I as mountAmosApplePayButton, P as mountAmosBankAccountPaymentMethodForm, N as mountAmosCreditCardPaymentMethodForm, F as mountAmosGooglePayButton, f as sendConfirmationFailed, r as sendParentReadyMessage, a as updateAmount, i as updateAppearance, o as updateMerchantName, c as updateNativeApplePaySession, l as validateForm };
|
package/dist/messaging.d.ts
CHANGED
|
@@ -34,6 +34,19 @@ export declare function updateMerchantName({ iframe, merchantName, }: {
|
|
|
34
34
|
iframe: Iframe;
|
|
35
35
|
merchantName: string;
|
|
36
36
|
}): void;
|
|
37
|
+
/**
|
|
38
|
+
* Whether the host page exposes a native `ApplePaySession` (Safari).
|
|
39
|
+
* Non-Safari browsers load Apple's SDK inside the embed iframe instead.
|
|
40
|
+
*/
|
|
41
|
+
export declare function hasNativeApplePaySession(): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Tell the Apple Pay iframe whether the parent has a native
|
|
44
|
+
* `ApplePaySession`. Sent during the `IFRAME_READY` handshake.
|
|
45
|
+
*/
|
|
46
|
+
export declare function updateNativeApplePaySession({ iframe, hasNativeApplePaySession, }: {
|
|
47
|
+
iframe: Iframe;
|
|
48
|
+
hasNativeApplePaySession: boolean;
|
|
49
|
+
}): void;
|
|
37
50
|
/**
|
|
38
51
|
* Ask the embedded credit-card or bank-account iframe form to validate
|
|
39
52
|
* its inputs.
|
package/dist/types.d.ts
CHANGED
|
@@ -42,6 +42,14 @@ export type Message = {
|
|
|
42
42
|
} | {
|
|
43
43
|
type: "UPDATE_MERCHANT_NAME";
|
|
44
44
|
merchantName: string;
|
|
45
|
+
} | {
|
|
46
|
+
/**
|
|
47
|
+
* Parent → iframe: whether the host page has a native
|
|
48
|
+
* `ApplePaySession` (Safari). When `false`, the iframe should
|
|
49
|
+
* expand for Chrome's in-iframe QR handoff UI.
|
|
50
|
+
*/
|
|
51
|
+
type: "UPDATE_NATIVE_APPLE_PAY_SESSION";
|
|
52
|
+
hasNativeApplePaySession: boolean;
|
|
45
53
|
} | {
|
|
46
54
|
type: "UPDATE_APPEARANCE";
|
|
47
55
|
appearance: Appearance;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amos.com/amos-js",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
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.
|
|
47
|
+
"@amos.com/node": "0.1.32",
|
|
48
48
|
"@types/googlepay": "0.7.11"
|
|
49
49
|
}
|
|
50
50
|
}
|
package/src/apple-pay.ts
CHANGED
|
@@ -2,11 +2,13 @@ import type { components } from "@amos.com/node";
|
|
|
2
2
|
import { getEmbedOrigin } from "./jwt";
|
|
3
3
|
import {
|
|
4
4
|
confirmPaymentIntent,
|
|
5
|
+
hasNativeApplePaySession,
|
|
5
6
|
sendConfirmationFailed,
|
|
6
7
|
sendParentReadyMessage,
|
|
7
8
|
updateAmount as sendUpdateAmount,
|
|
8
9
|
updateAppearance as sendUpdateAppearance,
|
|
9
10
|
updateMerchantName as sendUpdateMerchantName,
|
|
11
|
+
updateNativeApplePaySession as sendUpdateNativeApplePaySession,
|
|
10
12
|
} from "./messaging";
|
|
11
13
|
import type { Appearance, Message } from "./types";
|
|
12
14
|
|
|
@@ -159,6 +161,13 @@ export function attachApplePayButtonListeners(
|
|
|
159
161
|
sendUpdateMerchantName({ iframe, merchantName: current.merchantName });
|
|
160
162
|
}
|
|
161
163
|
|
|
164
|
+
function pushNativeApplePaySession() {
|
|
165
|
+
sendUpdateNativeApplePaySession({
|
|
166
|
+
iframe,
|
|
167
|
+
hasNativeApplePaySession: hasNativeApplePaySession(),
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
162
171
|
function handleMessage(event: MessageEvent<Message>) {
|
|
163
172
|
// Ignore messages from other frames / windows.
|
|
164
173
|
if (event.source !== iframe.contentWindow) {
|
|
@@ -169,6 +178,7 @@ export function attachApplePayButtonListeners(
|
|
|
169
178
|
case "IFRAME_READY":
|
|
170
179
|
sendParentReadyMessage(iframe);
|
|
171
180
|
sendUpdateAppearance({ iframe, appearance: current.appearance });
|
|
181
|
+
pushNativeApplePaySession();
|
|
172
182
|
pushAmount();
|
|
173
183
|
pushMerchantName();
|
|
174
184
|
break;
|
package/src/index.ts
CHANGED
|
@@ -27,11 +27,13 @@ export { decodeJwt, getEmbedOrigin } from "./jwt";
|
|
|
27
27
|
export {
|
|
28
28
|
confirmPaymentIntent,
|
|
29
29
|
confirmSetupIntent,
|
|
30
|
+
hasNativeApplePaySession,
|
|
30
31
|
sendConfirmationFailed,
|
|
31
32
|
sendParentReadyMessage,
|
|
32
33
|
updateAmount,
|
|
33
34
|
updateAppearance,
|
|
34
35
|
updateMerchantName,
|
|
36
|
+
updateNativeApplePaySession,
|
|
35
37
|
validateForm,
|
|
36
38
|
} from "./messaging";
|
|
37
39
|
export type {
|
package/src/messaging.ts
CHANGED
|
@@ -70,6 +70,34 @@ export function updateMerchantName({
|
|
|
70
70
|
);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Whether the host page exposes a native `ApplePaySession` (Safari).
|
|
75
|
+
* Non-Safari browsers load Apple's SDK inside the embed iframe instead.
|
|
76
|
+
*/
|
|
77
|
+
export function hasNativeApplePaySession(): boolean {
|
|
78
|
+
return "ApplePaySession" in globalThis;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Tell the Apple Pay iframe whether the parent has a native
|
|
83
|
+
* `ApplePaySession`. Sent during the `IFRAME_READY` handshake.
|
|
84
|
+
*/
|
|
85
|
+
export function updateNativeApplePaySession({
|
|
86
|
+
iframe,
|
|
87
|
+
hasNativeApplePaySession,
|
|
88
|
+
}: {
|
|
89
|
+
iframe: Iframe;
|
|
90
|
+
hasNativeApplePaySession: boolean;
|
|
91
|
+
}): void {
|
|
92
|
+
iframe?.contentWindow?.postMessage(
|
|
93
|
+
createMessage({
|
|
94
|
+
type: "UPDATE_NATIVE_APPLE_PAY_SESSION",
|
|
95
|
+
hasNativeApplePaySession,
|
|
96
|
+
}),
|
|
97
|
+
"*",
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
73
101
|
/**
|
|
74
102
|
* Ask the embedded credit-card or bank-account iframe form to validate
|
|
75
103
|
* its inputs.
|
package/src/types.ts
CHANGED
|
@@ -155,6 +155,15 @@ export type Message =
|
|
|
155
155
|
type: "UPDATE_MERCHANT_NAME";
|
|
156
156
|
merchantName: string;
|
|
157
157
|
}
|
|
158
|
+
| {
|
|
159
|
+
/**
|
|
160
|
+
* Parent → iframe: whether the host page has a native
|
|
161
|
+
* `ApplePaySession` (Safari). When `false`, the iframe should
|
|
162
|
+
* expand for Chrome's in-iframe QR handoff UI.
|
|
163
|
+
*/
|
|
164
|
+
type: "UPDATE_NATIVE_APPLE_PAY_SESSION";
|
|
165
|
+
hasNativeApplePaySession: boolean;
|
|
166
|
+
}
|
|
158
167
|
| {
|
|
159
168
|
type: "UPDATE_APPEARANCE";
|
|
160
169
|
appearance: Appearance;
|