@amos.com/amos-js 0.3.5 → 0.3.6
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.js +1 -1
- package/dist/index.mjs +331 -396
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1 +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/google-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({paymentData:e}){return{paymentMethod:{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}})()}}}}function h(e,n={cardholderName:!1}){let r=Object.entries(n).filter(([,e])=>e).map(([e])=>e).join(`,`);return`${t(e)}/iframe/card?token=${e}&additionalFields=${r}`}function g(e){return`${t(e)}/iframe/bank?token=${e}`}function _(e={cardholderName:!1}){return e.cardholderName?`292px`:`212px`}function v(){return`400px`}function y(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 b(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 x={width:`calc(100% + 8px)`,transition:`opacity 150ms ease-in, height 200ms ease-in-out`,margin:`0 -4px`,opacity:`0`,border:`0`};function S({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,x,{height:r}),a}function C(e,t){let n=b(e),{renderToken:r,additionalFields:i={cardholderName:!1},...a}=t,o=S({src:h(r,i),title:`Secure credit card payment method form powered by Amos`,name:`amos-credit-card-payment-method-form`,height:_(i)});n.appendChild(o);let s=y(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 w(e,t){let n=b(e),{renderToken:r,...i}=t,a=S({src:g(r),title:`Secure bank account payment method form powered by Amos`,name:`amos-bank-account-payment-method-form`,height:v()});n.appendChild(a);let o=y(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 T(e,t){let n=b(e),{renderToken:r,...i}=t,a=S({src:d(r),title:`Secure Google Pay button powered by Amos`,name:`amos-google-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.attachGooglePayButtonListeners=p,exports.attachPaymentMethodFormListeners=y,exports.confirmPaymentIntent=c,exports.confirmSetupIntent=l,exports.createMessage=n,exports.decodeJwt=e,exports.formatGooglePayPaymentData=m,exports.getBankAccountFormInitialHeight=v,exports.getBankAccountFormSrc=g,exports.getCreditCardFormInitialHeight=_,exports.getCreditCardFormSrc=h,exports.getEmbedOrigin=t,exports.getGooglePayButtonInitialHeight=f,exports.getGooglePayButtonSrc=d,exports.mountAmosBankAccountPaymentMethodForm=w,exports.mountAmosCreditCardPaymentMethodForm=C,exports.mountAmosGooglePayButton=T,exports.sendConfirmationFailed=u,exports.sendParentReadyMessage=r,exports.updateAmount=a,exports.updateAppearance=i,exports.updateMerchantName=o,exports.validateForm=s;
|
package/dist/index.mjs
CHANGED
|
@@ -1,422 +1,357 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
1
|
+
//#region src/jwt.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
let [t = "", n = "", r = ""] = e?.split(".") ?? [], i = typeof atob == "function" ? atob : (e) => Buffer.from(e, "base64").toString("utf8");
|
|
4
|
+
return {
|
|
5
|
+
header: JSON.parse(i(t)),
|
|
6
|
+
payload: JSON.parse(i(n)),
|
|
7
|
+
signature: r
|
|
8
|
+
};
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return "https://embed-sandbox.amos.com";
|
|
19
|
-
default:
|
|
20
|
-
return "https://embed-sandbox.amos.com";
|
|
21
|
-
}
|
|
10
|
+
function t(t) {
|
|
11
|
+
let { env: n = "sandbox" } = e(t).payload;
|
|
12
|
+
switch (n) {
|
|
13
|
+
case "production": return "https://embed.amos.com";
|
|
14
|
+
case "sandbox": return "https://embed-sandbox.amos.com";
|
|
15
|
+
default: return "https://embed-sandbox.amos.com";
|
|
16
|
+
}
|
|
22
17
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/types.ts
|
|
20
|
+
function n(e) {
|
|
21
|
+
return e;
|
|
26
22
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"*"
|
|
32
|
-
);
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/messaging.ts
|
|
25
|
+
function r(e) {
|
|
26
|
+
e?.contentWindow?.postMessage(n({ type: "PARENT_ACKNOWLEDGED_IFRAME_READY" }), "*");
|
|
33
27
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
})
|
|
39
|
-
e?.contentWindow?.postMessage(
|
|
40
|
-
{ type: "UPDATE_APPEARANCE", appearance: n },
|
|
41
|
-
"*"
|
|
42
|
-
);
|
|
28
|
+
function i({ iframe: e, appearance: t = {} }) {
|
|
29
|
+
e?.contentWindow?.postMessage(n({
|
|
30
|
+
type: "UPDATE_APPEARANCE",
|
|
31
|
+
appearance: t
|
|
32
|
+
}), "*");
|
|
43
33
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
})
|
|
49
|
-
e?.contentWindow?.postMessage(
|
|
50
|
-
{ type: "UPDATE_AMOUNT", amount: n },
|
|
51
|
-
"*"
|
|
52
|
-
);
|
|
34
|
+
function a({ iframe: e, amount: t }) {
|
|
35
|
+
e?.contentWindow?.postMessage(n({
|
|
36
|
+
type: "UPDATE_AMOUNT",
|
|
37
|
+
amount: t
|
|
38
|
+
}), "*");
|
|
53
39
|
}
|
|
54
|
-
o(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
})
|
|
59
|
-
e?.contentWindow?.postMessage(
|
|
60
|
-
{ type: "UPDATE_MERCHANT_NAME", merchantName: n },
|
|
61
|
-
"*"
|
|
62
|
-
);
|
|
40
|
+
function o({ iframe: e, merchantName: t }) {
|
|
41
|
+
e?.contentWindow?.postMessage(n({
|
|
42
|
+
type: "UPDATE_MERCHANT_NAME",
|
|
43
|
+
merchantName: t
|
|
44
|
+
}), "*");
|
|
63
45
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
});
|
|
46
|
+
function s({ iframe: e }) {
|
|
47
|
+
let t = crypto.randomUUID();
|
|
48
|
+
return new Promise((r) => {
|
|
49
|
+
e?.contentWindow?.postMessage(n({
|
|
50
|
+
type: "VALIDATE_FORM",
|
|
51
|
+
requestId: t
|
|
52
|
+
}), "*");
|
|
53
|
+
let i = setTimeout(() => {
|
|
54
|
+
window.removeEventListener("message", a), r(!1);
|
|
55
|
+
}, 5e3);
|
|
56
|
+
function a(e) {
|
|
57
|
+
e.data.type === "VALIDATE_FORM" && e.data.requestId === t && (window.removeEventListener("message", a), clearTimeout(i), r(e.data.isValid ?? !1));
|
|
58
|
+
}
|
|
59
|
+
window.addEventListener("message", a);
|
|
60
|
+
});
|
|
80
61
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
{
|
|
89
|
-
type: "CONFIRM_PAYMENT_INTENT",
|
|
90
|
-
token: n,
|
|
91
|
-
id: t ?? void 0
|
|
92
|
-
},
|
|
93
|
-
"*"
|
|
94
|
-
);
|
|
62
|
+
function c({ iframe: t, token: r }) {
|
|
63
|
+
let { payment_intent_id: i } = e(r).payload;
|
|
64
|
+
t?.contentWindow?.postMessage(n({
|
|
65
|
+
type: "CONFIRM_PAYMENT_INTENT",
|
|
66
|
+
token: r,
|
|
67
|
+
id: i ?? void 0
|
|
68
|
+
}), "*");
|
|
95
69
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
{
|
|
104
|
-
type: "CONFIRM_SETUP_INTENT",
|
|
105
|
-
token: n,
|
|
106
|
-
id: t ?? void 0
|
|
107
|
-
},
|
|
108
|
-
"*"
|
|
109
|
-
);
|
|
70
|
+
function l({ iframe: t, token: r }) {
|
|
71
|
+
let { setup_intent_id: i } = e(r).payload;
|
|
72
|
+
t?.contentWindow?.postMessage(n({
|
|
73
|
+
type: "CONFIRM_SETUP_INTENT",
|
|
74
|
+
token: r,
|
|
75
|
+
id: i ?? void 0
|
|
76
|
+
}), "*");
|
|
110
77
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
})
|
|
116
|
-
e?.contentWindow?.postMessage(
|
|
117
|
-
{
|
|
118
|
-
type: "CONFIRMATION_FAILED",
|
|
119
|
-
errorMessage: n
|
|
120
|
-
},
|
|
121
|
-
"*"
|
|
122
|
-
);
|
|
78
|
+
function u({ iframe: e, errorMessage: t }) {
|
|
79
|
+
e?.contentWindow?.postMessage(n({
|
|
80
|
+
type: "CONFIRMATION_FAILED",
|
|
81
|
+
errorMessage: t
|
|
82
|
+
}), "*");
|
|
123
83
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/google-pay.ts
|
|
86
|
+
function d(e) {
|
|
87
|
+
return `${t(e)}/iframe/google-pay?token=${e}`;
|
|
127
88
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return "40px";
|
|
89
|
+
function f() {
|
|
90
|
+
return "40px";
|
|
131
91
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
92
|
+
function p(e, t) {
|
|
93
|
+
let n = { ...t };
|
|
94
|
+
function s() {
|
|
95
|
+
a({
|
|
96
|
+
iframe: e,
|
|
97
|
+
amount: n.amount
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function l() {
|
|
101
|
+
o({
|
|
102
|
+
iframe: e,
|
|
103
|
+
merchantName: n.merchantName
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function d(t) {
|
|
107
|
+
switch (t.data.type) {
|
|
108
|
+
case "IFRAME_READY":
|
|
109
|
+
r(e), i({
|
|
110
|
+
iframe: e,
|
|
111
|
+
appearance: n.appearance
|
|
112
|
+
}), s(), l();
|
|
113
|
+
break;
|
|
114
|
+
case "UPDATE_HEIGHT":
|
|
115
|
+
n.onHeightChange?.(t.data.height);
|
|
116
|
+
break;
|
|
117
|
+
case "UPDATE_APPEARANCE":
|
|
118
|
+
i({
|
|
119
|
+
iframe: e,
|
|
120
|
+
appearance: t.data.appearance
|
|
121
|
+
});
|
|
122
|
+
break;
|
|
123
|
+
case "UPDATED_APPEARANCE":
|
|
124
|
+
n.onAppearanceReady?.();
|
|
125
|
+
break;
|
|
126
|
+
case "CREATE_PAYMENT_INTENT":
|
|
127
|
+
n.onInitiatePaymentIntentRequest({
|
|
128
|
+
paymentIntentCreateAttributes: t.data.paymentIntentCreateAttributes,
|
|
129
|
+
customerCreateAttributes: t.data.customerCreateAttributes
|
|
130
|
+
}).then((t) => {
|
|
131
|
+
c({
|
|
132
|
+
iframe: e,
|
|
133
|
+
token: t
|
|
134
|
+
});
|
|
135
|
+
}).catch((t) => {
|
|
136
|
+
u({
|
|
137
|
+
iframe: e,
|
|
138
|
+
errorMessage: t instanceof Error ? t.message : "Unknown error"
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
break;
|
|
142
|
+
case "PAYMENT_INTENT_CONFIRMATION_SUCCEEDED":
|
|
143
|
+
n.onPaymentIntentConfirmationSucceeded(t.data.paymentIntent);
|
|
144
|
+
break;
|
|
145
|
+
case "CONFIRMATION_FAILED":
|
|
146
|
+
n.onConfirmationFailed(t.data.errorMessage);
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return window.addEventListener("message", d), {
|
|
151
|
+
update(t) {
|
|
152
|
+
let r = "appearance" in t, a = "amount" in t, o = "merchantName" in t;
|
|
153
|
+
n = {
|
|
154
|
+
...n,
|
|
155
|
+
...t
|
|
156
|
+
}, r && i({
|
|
157
|
+
iframe: e,
|
|
158
|
+
appearance: n.appearance
|
|
159
|
+
}), a && s(), o && l();
|
|
160
|
+
},
|
|
161
|
+
destroy() {
|
|
162
|
+
window.removeEventListener("message", d);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
187
165
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return "master";
|
|
217
|
-
case "DISCOVER":
|
|
218
|
-
return "discover";
|
|
219
|
-
default:
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
})()
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
};
|
|
166
|
+
function m({ paymentData: e }) {
|
|
167
|
+
return { paymentMethod: {
|
|
168
|
+
billing_address_attributes: {
|
|
169
|
+
name: e.shippingAddress?.name,
|
|
170
|
+
address_line1: e.shippingAddress?.address1,
|
|
171
|
+
address_line2: e.shippingAddress?.address2,
|
|
172
|
+
city: e.shippingAddress?.locality,
|
|
173
|
+
state: e.shippingAddress?.administrativeArea,
|
|
174
|
+
postal_code: e.shippingAddress?.postalCode,
|
|
175
|
+
country: e.shippingAddress?.countryCode,
|
|
176
|
+
email: e.email,
|
|
177
|
+
phone: e.shippingAddress?.phoneNumber
|
|
178
|
+
},
|
|
179
|
+
card_profile_attributes: {
|
|
180
|
+
wallet_provider: "googlepay",
|
|
181
|
+
wallet_payload: e.paymentMethodData.tokenizationData.token,
|
|
182
|
+
wallet_last4: e.paymentMethodData.info?.cardDetails,
|
|
183
|
+
wallet_brand: (() => {
|
|
184
|
+
switch (e.paymentMethodData.info?.cardNetwork) {
|
|
185
|
+
case "AMEX": return "american_express";
|
|
186
|
+
case "VISA": return "visa";
|
|
187
|
+
case "MASTERCARD": return "master";
|
|
188
|
+
case "DISCOVER": return "discover";
|
|
189
|
+
default: return;
|
|
190
|
+
}
|
|
191
|
+
})()
|
|
192
|
+
}
|
|
193
|
+
} };
|
|
226
194
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/payment-method-form.ts
|
|
197
|
+
function h(e, n = { cardholderName: !1 }) {
|
|
198
|
+
let r = Object.entries(n).filter(([, e]) => e).map(([e]) => e).join(",");
|
|
199
|
+
return `${t(e)}/iframe/card?token=${e}&additionalFields=${r}`;
|
|
231
200
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
return `${m(e)}/iframe/bank?token=${e}`;
|
|
201
|
+
function g(e) {
|
|
202
|
+
return `${t(e)}/iframe/bank?token=${e}`;
|
|
235
203
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return e.cardholderName ? "292px" : "212px";
|
|
204
|
+
function _(e = { cardholderName: !1 }) {
|
|
205
|
+
return e.cardholderName ? "292px" : "212px";
|
|
239
206
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
return "400px";
|
|
207
|
+
function v() {
|
|
208
|
+
return "400px";
|
|
243
209
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
210
|
+
function y(e, t) {
|
|
211
|
+
let n = { ...t };
|
|
212
|
+
function a(t) {
|
|
213
|
+
switch (t.data.type) {
|
|
214
|
+
case "IFRAME_READY":
|
|
215
|
+
r(e), i({
|
|
216
|
+
iframe: e,
|
|
217
|
+
appearance: n.appearance
|
|
218
|
+
});
|
|
219
|
+
break;
|
|
220
|
+
case "UPDATE_HEIGHT":
|
|
221
|
+
n.onHeightChange?.(t.data.height);
|
|
222
|
+
break;
|
|
223
|
+
case "UPDATE_APPEARANCE":
|
|
224
|
+
i({
|
|
225
|
+
iframe: e,
|
|
226
|
+
appearance: t.data.appearance
|
|
227
|
+
});
|
|
228
|
+
break;
|
|
229
|
+
case "UPDATED_APPEARANCE":
|
|
230
|
+
n.onAppearanceReady?.();
|
|
231
|
+
break;
|
|
232
|
+
case "PAYMENT_INTENT_CONFIRMATION_SUCCEEDED":
|
|
233
|
+
n.onPaymentIntentConfirmationSucceeded?.(t.data.paymentIntent);
|
|
234
|
+
break;
|
|
235
|
+
case "SETUP_INTENT_CONFIRMATION_SUCCEEDED":
|
|
236
|
+
n.onSetupIntentConfirmationSucceeded?.(t.data.setupIntent);
|
|
237
|
+
break;
|
|
238
|
+
case "CONFIRMATION_FAILED":
|
|
239
|
+
n.onConfirmationFailed(t.data.errorMessage);
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return window.addEventListener("message", a), {
|
|
244
|
+
update(t) {
|
|
245
|
+
let r = "appearance" in t;
|
|
246
|
+
n = {
|
|
247
|
+
...n,
|
|
248
|
+
...t
|
|
249
|
+
}, r && i({
|
|
250
|
+
iframe: e,
|
|
251
|
+
appearance: n.appearance
|
|
252
|
+
});
|
|
253
|
+
},
|
|
254
|
+
destroy() {
|
|
255
|
+
window.removeEventListener("message", a);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
283
258
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
return e;
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region src/mount.ts
|
|
261
|
+
function b(e) {
|
|
262
|
+
if (typeof e == "string") {
|
|
263
|
+
let t = document.querySelector(e);
|
|
264
|
+
if (!(t instanceof HTMLElement)) throw Error(`[amos-js] Container "${e}" did not match any HTMLElement.`);
|
|
265
|
+
return t;
|
|
266
|
+
}
|
|
267
|
+
return e;
|
|
295
268
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
border: "0"
|
|
269
|
+
var x = {
|
|
270
|
+
width: "calc(100% + 8px)",
|
|
271
|
+
transition: "opacity 150ms ease-in, height 200ms ease-in-out",
|
|
272
|
+
margin: "0 -4px",
|
|
273
|
+
opacity: "0",
|
|
274
|
+
border: "0"
|
|
303
275
|
};
|
|
304
|
-
function
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
name: t,
|
|
308
|
-
height: i,
|
|
309
|
-
allow: r
|
|
310
|
-
}) {
|
|
311
|
-
const a = document.createElement("iframe");
|
|
312
|
-
return a.src = e, a.title = n, a.name = t, a.setAttribute("role", "presentation"), a.scrolling = "no", r && (a.allow = r), Object.assign(a.style, F, { height: i }), a;
|
|
276
|
+
function S({ src: e, title: t, name: n, height: r, allow: i }) {
|
|
277
|
+
let a = document.createElement("iframe");
|
|
278
|
+
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, x, { height: r }), a;
|
|
313
279
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
update: d.update,
|
|
339
|
-
destroy() {
|
|
340
|
-
d.destroy(), s.remove();
|
|
341
|
-
}
|
|
342
|
-
};
|
|
280
|
+
function C(e, t) {
|
|
281
|
+
let n = b(e), { renderToken: r, additionalFields: i = { cardholderName: !1 }, ...a } = t, o = S({
|
|
282
|
+
src: h(r, i),
|
|
283
|
+
title: "Secure credit card payment method form powered by Amos",
|
|
284
|
+
name: "amos-credit-card-payment-method-form",
|
|
285
|
+
height: _(i)
|
|
286
|
+
});
|
|
287
|
+
n.appendChild(o);
|
|
288
|
+
let s = y(o, {
|
|
289
|
+
...a,
|
|
290
|
+
onHeightChange: (e) => {
|
|
291
|
+
o.style.height = e, a.onHeightChange?.(e);
|
|
292
|
+
},
|
|
293
|
+
onAppearanceReady: () => {
|
|
294
|
+
o.style.opacity = "1", a.onAppearanceReady?.();
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
return {
|
|
298
|
+
iframe: o,
|
|
299
|
+
update: s.update,
|
|
300
|
+
destroy() {
|
|
301
|
+
s.destroy(), o.remove();
|
|
302
|
+
}
|
|
303
|
+
};
|
|
343
304
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
};
|
|
305
|
+
function w(e, t) {
|
|
306
|
+
let n = b(e), { renderToken: r, ...i } = t, a = S({
|
|
307
|
+
src: g(r),
|
|
308
|
+
title: "Secure bank account payment method form powered by Amos",
|
|
309
|
+
name: "amos-bank-account-payment-method-form",
|
|
310
|
+
height: v()
|
|
311
|
+
});
|
|
312
|
+
n.appendChild(a);
|
|
313
|
+
let o = y(a, {
|
|
314
|
+
...i,
|
|
315
|
+
onHeightChange: (e) => {
|
|
316
|
+
a.style.height = e, i.onHeightChange?.(e);
|
|
317
|
+
},
|
|
318
|
+
onAppearanceReady: () => {
|
|
319
|
+
a.style.opacity = "1", i.onAppearanceReady?.();
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
return {
|
|
323
|
+
iframe: a,
|
|
324
|
+
update: o.update,
|
|
325
|
+
destroy() {
|
|
326
|
+
o.destroy(), a.remove();
|
|
327
|
+
}
|
|
328
|
+
};
|
|
369
329
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
};
|
|
330
|
+
function T(e, t) {
|
|
331
|
+
let n = b(e), { renderToken: r, ...i } = t, a = S({
|
|
332
|
+
src: d(r),
|
|
333
|
+
title: "Secure Google Pay button powered by Amos",
|
|
334
|
+
name: "amos-google-pay-button",
|
|
335
|
+
height: f(),
|
|
336
|
+
allow: "payment"
|
|
337
|
+
});
|
|
338
|
+
n.appendChild(a);
|
|
339
|
+
let o = p(a, {
|
|
340
|
+
...i,
|
|
341
|
+
onHeightChange: (e) => {
|
|
342
|
+
a.style.height = e, i.onHeightChange?.(e);
|
|
343
|
+
},
|
|
344
|
+
onAppearanceReady: () => {
|
|
345
|
+
a.style.opacity = "1", i.onAppearanceReady?.();
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
return {
|
|
349
|
+
iframe: a,
|
|
350
|
+
update: o.update,
|
|
351
|
+
destroy() {
|
|
352
|
+
o.destroy(), a.remove();
|
|
353
|
+
}
|
|
354
|
+
};
|
|
396
355
|
}
|
|
397
|
-
|
|
398
|
-
export {
|
|
399
|
-
b as attachGooglePayButtonListeners,
|
|
400
|
-
g as attachPaymentMethodFormListeners,
|
|
401
|
-
N as confirmPaymentIntent,
|
|
402
|
-
S as confirmSetupIntent,
|
|
403
|
-
D as createMessage,
|
|
404
|
-
u as decodeJwt,
|
|
405
|
-
H as formatGooglePayPaymentData,
|
|
406
|
-
R as getBankAccountFormInitialHeight,
|
|
407
|
-
P as getBankAccountFormSrc,
|
|
408
|
-
w as getCreditCardFormInitialHeight,
|
|
409
|
-
T as getCreditCardFormSrc,
|
|
410
|
-
m as getEmbedOrigin,
|
|
411
|
-
M as getGooglePayButtonInitialHeight,
|
|
412
|
-
_ as getGooglePayButtonSrc,
|
|
413
|
-
U as mountAmosBankAccountPaymentMethodForm,
|
|
414
|
-
L as mountAmosCreditCardPaymentMethodForm,
|
|
415
|
-
x as mountAmosGooglePayButton,
|
|
416
|
-
I as sendConfirmationFailed,
|
|
417
|
-
h as sendParentReadyMessage,
|
|
418
|
-
f as updateAmount,
|
|
419
|
-
c as updateAppearance,
|
|
420
|
-
C as updateMerchantName,
|
|
421
|
-
k as validateForm
|
|
422
|
-
};
|
|
356
|
+
//#endregion
|
|
357
|
+
export { p as attachGooglePayButtonListeners, y as attachPaymentMethodFormListeners, c as confirmPaymentIntent, l as confirmSetupIntent, n as createMessage, e as decodeJwt, m as formatGooglePayPaymentData, v as getBankAccountFormInitialHeight, g as getBankAccountFormSrc, _ as getCreditCardFormInitialHeight, h as getCreditCardFormSrc, t as getEmbedOrigin, f as getGooglePayButtonInitialHeight, d as getGooglePayButtonSrc, w as mountAmosBankAccountPaymentMethodForm, C as mountAmosCreditCardPaymentMethodForm, T as mountAmosGooglePayButton, u as sendConfirmationFailed, r as sendParentReadyMessage, a as updateAmount, i as updateAppearance, o as updateMerchantName, s as validateForm };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amos.com/amos-js",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,15 +34,15 @@
|
|
|
34
34
|
"author": "Amos",
|
|
35
35
|
"description": "Amos JavaScript SDK for embedding payment methods via iframes.",
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@changesets/cli": "2.31.0",
|
|
38
37
|
"@biomejs/biome": "2.4.15",
|
|
38
|
+
"@changesets/cli": "2.31.0",
|
|
39
39
|
"@types/node": "25.9.1",
|
|
40
40
|
"typescript": "6.0.3",
|
|
41
|
-
"vite": "
|
|
41
|
+
"vite": "^8.0.16",
|
|
42
42
|
"vite-plugin-dts": "4.5.4"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@amos.com/node": "0.1.
|
|
45
|
+
"@amos.com/node": "0.1.11",
|
|
46
46
|
"@types/googlepay": "0.7.10"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|