@amos.com/amos-js 0.4.0 → 0.4.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/README.md +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +10 -12
- package/dist/mount.d.ts +2 -2
- package/dist/payment-method-form.d.ts +3 -4
- package/package.json +1 -1
- package/src/mount.ts +4 -4
- package/src/payment-method-form.ts +11 -17
package/README.md
CHANGED
|
@@ -232,7 +232,7 @@ Mount the secure credit-card payment method form into a container element (an `H
|
|
|
232
232
|
|
|
233
233
|
- `appearance` (`{ themeVariables?: Partial<Record<ThemeVariable, string>>; labels?: "above" | "floating" | "placeholder" }`)
|
|
234
234
|
- `additionalFields` (`{ cardholderName: boolean }`, defaults to `{ cardholderName: false }`)
|
|
235
|
-
- `billingAddressRequirement` (`"
|
|
235
|
+
- `billingAddressRequirement` (`"country" | "full"`, defaults to `"country"`) — how much billing address the iframe collects. `country` collects country / region and, for CA / PR / GB / US, a postal code (labeled ZIP for the United States). `full` shows a full street address form with Smarty autocomplete.
|
|
236
236
|
- `onPaymentIntentConfirmationSucceeded` (`(paymentIntent: components["schemas"]["PaymentIntent"]) => void`)
|
|
237
237
|
- `onSetupIntentConfirmationSucceeded` (`(setupIntent: components["schemas"]["SetupIntent"]) => void`)
|
|
238
238
|
- `onHeightChange`, `onAppearanceReady` (advanced — override the default iframe styling logic)
|
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/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:{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 h={
|
|
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:{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 h={country:212,full:452},g=80,_={country:400,full:640};function v(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 y(e,n=`country`){let r=new URLSearchParams({token:e,billingAddressRequirement:n});return`${t(e)}/iframe/bank?${r}`}function b(e={cardholderName:!1},t=`country`){return`${(h[t]??h.country)+(e.cardholderName?g:0)}px`}function x(e=`country`){return`${_[e]??_.country}px`}function S(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 C(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 w={width:`calc(100% + 8px)`,transition:`opacity 150ms ease-in, height 200ms ease-in-out`,margin:`0 -4px`,opacity:`0`,border:`0`};function T({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,w,{height:r}),a}function E(e,t){let n=C(e),{renderToken:r,additionalFields:i={cardholderName:!1},billingAddressRequirement:a=`country`,...o}=t,s=T({src:v(r,i,a),title:`Secure credit card payment method form powered by Amos`,name:`amos-credit-card-payment-method-form`,height:b(i,a)});n.appendChild(s);let c=S(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 D(e,t){let n=C(e),{renderToken:r,billingAddressRequirement:i=`country`,...a}=t,o=T({src:y(r,i),title:`Secure bank account payment method form powered by Amos`,name:`amos-bank-account-payment-method-form`,height:x(i)});n.appendChild(o);let s=S(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 O(e,t){let n=C(e),{renderToken:r,...i}=t,a=T({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=S,exports.confirmPaymentIntent=c,exports.confirmSetupIntent=l,exports.createMessage=n,exports.decodeJwt=e,exports.formatGooglePayPaymentData=m,exports.getBankAccountFormInitialHeight=x,exports.getBankAccountFormSrc=y,exports.getCreditCardFormInitialHeight=b,exports.getCreditCardFormSrc=v,exports.getEmbedOrigin=t,exports.getGooglePayButtonInitialHeight=f,exports.getGooglePayButtonSrc=d,exports.mountAmosBankAccountPaymentMethodForm=D,exports.mountAmosCreditCardPaymentMethodForm=E,exports.mountAmosGooglePayButton=O,exports.sendConfirmationFailed=u,exports.sendParentReadyMessage=r,exports.updateAmount=a,exports.updateAppearance=i,exports.updateMerchantName=o,exports.validateForm=s;
|
package/dist/index.mjs
CHANGED
|
@@ -196,15 +196,13 @@ function m({ paymentData: e }) {
|
|
|
196
196
|
//#endregion
|
|
197
197
|
//#region src/payment-method-form.ts
|
|
198
198
|
var h = {
|
|
199
|
-
|
|
200
|
-
postalCodeAndCountry: 212,
|
|
199
|
+
country: 212,
|
|
201
200
|
full: 452
|
|
202
201
|
}, g = 80, _ = {
|
|
203
|
-
|
|
204
|
-
postalCodeAndCountry: 400,
|
|
202
|
+
country: 400,
|
|
205
203
|
full: 640
|
|
206
204
|
};
|
|
207
|
-
function v(e, n = { cardholderName: !1 }, r = "
|
|
205
|
+
function v(e, n = { cardholderName: !1 }, r = "country") {
|
|
208
206
|
let i = Object.entries(n).filter(([, e]) => e).map(([e]) => e).join(","), a = new URLSearchParams({
|
|
209
207
|
token: e,
|
|
210
208
|
additionalFields: i,
|
|
@@ -212,18 +210,18 @@ function v(e, n = { cardholderName: !1 }, r = "postalCode") {
|
|
|
212
210
|
});
|
|
213
211
|
return `${t(e)}/iframe/card?${a}`;
|
|
214
212
|
}
|
|
215
|
-
function y(e, n = "
|
|
213
|
+
function y(e, n = "country") {
|
|
216
214
|
let r = new URLSearchParams({
|
|
217
215
|
token: e,
|
|
218
216
|
billingAddressRequirement: n
|
|
219
217
|
});
|
|
220
218
|
return `${t(e)}/iframe/bank?${r}`;
|
|
221
219
|
}
|
|
222
|
-
function b(e = { cardholderName: !1 }, t = "
|
|
223
|
-
return `${(h[t] ?? h.
|
|
220
|
+
function b(e = { cardholderName: !1 }, t = "country") {
|
|
221
|
+
return `${(h[t] ?? h.country) + (e.cardholderName ? g : 0)}px`;
|
|
224
222
|
}
|
|
225
|
-
function x(e = "
|
|
226
|
-
return `${_[e] ?? _.
|
|
223
|
+
function x(e = "country") {
|
|
224
|
+
return `${_[e] ?? _.country}px`;
|
|
227
225
|
}
|
|
228
226
|
function S(e, t) {
|
|
229
227
|
let n = { ...t };
|
|
@@ -296,7 +294,7 @@ function T({ src: e, title: t, name: n, height: r, allow: i }) {
|
|
|
296
294
|
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, w, { height: r }), a;
|
|
297
295
|
}
|
|
298
296
|
function E(e, t) {
|
|
299
|
-
let n = C(e), { renderToken: r, additionalFields: i = { cardholderName: !1 }, billingAddressRequirement: a = "
|
|
297
|
+
let n = C(e), { renderToken: r, additionalFields: i = { cardholderName: !1 }, billingAddressRequirement: a = "country", ...o } = t, s = T({
|
|
300
298
|
src: v(r, i, a),
|
|
301
299
|
title: "Secure credit card payment method form powered by Amos",
|
|
302
300
|
name: "amos-credit-card-payment-method-form",
|
|
@@ -321,7 +319,7 @@ function E(e, t) {
|
|
|
321
319
|
};
|
|
322
320
|
}
|
|
323
321
|
function D(e, t) {
|
|
324
|
-
let n = C(e), { renderToken: r, billingAddressRequirement: i = "
|
|
322
|
+
let n = C(e), { renderToken: r, billingAddressRequirement: i = "country", ...a } = t, o = T({
|
|
325
323
|
src: y(r, i),
|
|
326
324
|
title: "Secure bank account payment method form powered by Amos",
|
|
327
325
|
name: "amos-bank-account-payment-method-form",
|
package/dist/mount.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export type AmosCreditCardPaymentMethodFormOptions = PaymentMethodFormListenerOp
|
|
|
23
23
|
/**
|
|
24
24
|
* How much billing address the form collects.
|
|
25
25
|
*
|
|
26
|
-
* @default "
|
|
26
|
+
* @default "country"
|
|
27
27
|
*/
|
|
28
28
|
billingAddressRequirement?: BillingAddressRequirement;
|
|
29
29
|
};
|
|
@@ -63,7 +63,7 @@ export type AmosBankAccountPaymentMethodFormOptions = PaymentMethodFormListenerO
|
|
|
63
63
|
/**
|
|
64
64
|
* How much billing address the form collects.
|
|
65
65
|
*
|
|
66
|
-
* @default "
|
|
66
|
+
* @default "country"
|
|
67
67
|
*/
|
|
68
68
|
billingAddressRequirement?: BillingAddressRequirement;
|
|
69
69
|
};
|
|
@@ -12,12 +12,11 @@ export type CreditCardAdditionalFields = {
|
|
|
12
12
|
* How much billing address the embedded credit-card or bank-account form
|
|
13
13
|
* collects.
|
|
14
14
|
*
|
|
15
|
-
* - `
|
|
16
|
-
*
|
|
17
|
-
* - `postalCodeAndCountry` — country and postal code, both required.
|
|
15
|
+
* - `country` — country / region, plus postal / ZIP when that selection
|
|
16
|
+
* collects one (CA, PR, GB, US). Default.
|
|
18
17
|
* - `full` — full street address (Smarty autocomplete on line 1).
|
|
19
18
|
*/
|
|
20
|
-
export type BillingAddressRequirement = "
|
|
19
|
+
export type BillingAddressRequirement = "country" | "full";
|
|
21
20
|
/**
|
|
22
21
|
* Build the iframe `src` URL for the embedded credit-card form.
|
|
23
22
|
*/
|
package/package.json
CHANGED
package/src/mount.ts
CHANGED
|
@@ -89,7 +89,7 @@ export type AmosCreditCardPaymentMethodFormOptions =
|
|
|
89
89
|
/**
|
|
90
90
|
* How much billing address the form collects.
|
|
91
91
|
*
|
|
92
|
-
* @default "
|
|
92
|
+
* @default "country"
|
|
93
93
|
*/
|
|
94
94
|
billingAddressRequirement?: BillingAddressRequirement;
|
|
95
95
|
};
|
|
@@ -125,7 +125,7 @@ export function mountAmosCreditCardPaymentMethodForm(
|
|
|
125
125
|
const {
|
|
126
126
|
renderToken,
|
|
127
127
|
additionalFields = { cardholderName: false },
|
|
128
|
-
billingAddressRequirement = "
|
|
128
|
+
billingAddressRequirement = "country",
|
|
129
129
|
...listenerOptions
|
|
130
130
|
} = options;
|
|
131
131
|
|
|
@@ -181,7 +181,7 @@ export type AmosBankAccountPaymentMethodFormOptions =
|
|
|
181
181
|
/**
|
|
182
182
|
* How much billing address the form collects.
|
|
183
183
|
*
|
|
184
|
-
* @default "
|
|
184
|
+
* @default "country"
|
|
185
185
|
*/
|
|
186
186
|
billingAddressRequirement?: BillingAddressRequirement;
|
|
187
187
|
};
|
|
@@ -202,7 +202,7 @@ export function mountAmosBankAccountPaymentMethodForm(
|
|
|
202
202
|
const host = resolveContainer(container);
|
|
203
203
|
const {
|
|
204
204
|
renderToken,
|
|
205
|
-
billingAddressRequirement = "
|
|
205
|
+
billingAddressRequirement = "country",
|
|
206
206
|
...listenerOptions
|
|
207
207
|
} = options;
|
|
208
208
|
|
|
@@ -19,28 +19,22 @@ export type CreditCardAdditionalFields = {
|
|
|
19
19
|
* How much billing address the embedded credit-card or bank-account form
|
|
20
20
|
* collects.
|
|
21
21
|
*
|
|
22
|
-
* - `
|
|
23
|
-
*
|
|
24
|
-
* - `postalCodeAndCountry` — country and postal code, both required.
|
|
22
|
+
* - `country` — country / region, plus postal / ZIP when that selection
|
|
23
|
+
* collects one (CA, PR, GB, US). Default.
|
|
25
24
|
* - `full` — full street address (Smarty autocomplete on line 1).
|
|
26
25
|
*/
|
|
27
|
-
export type BillingAddressRequirement =
|
|
28
|
-
| "postalCode"
|
|
29
|
-
| "postalCodeAndCountry"
|
|
30
|
-
| "full";
|
|
26
|
+
export type BillingAddressRequirement = "country" | "full";
|
|
31
27
|
|
|
32
28
|
const CREDIT_CARD_ADDRESS_HEIGHT_PX: Record<BillingAddressRequirement, number> =
|
|
33
29
|
{
|
|
34
|
-
|
|
35
|
-
postalCodeAndCountry: 212,
|
|
30
|
+
country: 212,
|
|
36
31
|
full: 452,
|
|
37
32
|
};
|
|
38
33
|
|
|
39
34
|
const CREDIT_CARD_CARDHOLDER_NAME_HEIGHT_PX = 80;
|
|
40
35
|
|
|
41
36
|
const BANK_ACCOUNT_HEIGHT_PX: Record<BillingAddressRequirement, number> = {
|
|
42
|
-
|
|
43
|
-
postalCodeAndCountry: 400,
|
|
37
|
+
country: 400,
|
|
44
38
|
full: 640,
|
|
45
39
|
};
|
|
46
40
|
|
|
@@ -50,7 +44,7 @@ const BANK_ACCOUNT_HEIGHT_PX: Record<BillingAddressRequirement, number> = {
|
|
|
50
44
|
export function getCreditCardFormSrc(
|
|
51
45
|
renderToken: string,
|
|
52
46
|
additionalFields: CreditCardAdditionalFields = { cardholderName: false },
|
|
53
|
-
billingAddressRequirement: BillingAddressRequirement = "
|
|
47
|
+
billingAddressRequirement: BillingAddressRequirement = "country",
|
|
54
48
|
): string {
|
|
55
49
|
const enabled = Object.entries(additionalFields)
|
|
56
50
|
.filter(([, value]) => value)
|
|
@@ -71,7 +65,7 @@ export function getCreditCardFormSrc(
|
|
|
71
65
|
*/
|
|
72
66
|
export function getBankAccountFormSrc(
|
|
73
67
|
renderToken: string,
|
|
74
|
-
billingAddressRequirement: BillingAddressRequirement = "
|
|
68
|
+
billingAddressRequirement: BillingAddressRequirement = "country",
|
|
75
69
|
): string {
|
|
76
70
|
const params = new URLSearchParams({
|
|
77
71
|
token: renderToken,
|
|
@@ -88,11 +82,11 @@ export function getBankAccountFormSrc(
|
|
|
88
82
|
*/
|
|
89
83
|
export function getCreditCardFormInitialHeight(
|
|
90
84
|
additionalFields: CreditCardAdditionalFields = { cardholderName: false },
|
|
91
|
-
billingAddressRequirement: BillingAddressRequirement = "
|
|
85
|
+
billingAddressRequirement: BillingAddressRequirement = "country",
|
|
92
86
|
): string {
|
|
93
87
|
const addressHeight =
|
|
94
88
|
CREDIT_CARD_ADDRESS_HEIGHT_PX[billingAddressRequirement] ??
|
|
95
|
-
CREDIT_CARD_ADDRESS_HEIGHT_PX.
|
|
89
|
+
CREDIT_CARD_ADDRESS_HEIGHT_PX.country;
|
|
96
90
|
const cardholderExtra = additionalFields.cardholderName
|
|
97
91
|
? CREDIT_CARD_CARDHOLDER_NAME_HEIGHT_PX
|
|
98
92
|
: 0;
|
|
@@ -104,9 +98,9 @@ export function getCreditCardFormInitialHeight(
|
|
|
104
98
|
* `billingAddressRequirement` into account.
|
|
105
99
|
*/
|
|
106
100
|
export function getBankAccountFormInitialHeight(
|
|
107
|
-
billingAddressRequirement: BillingAddressRequirement = "
|
|
101
|
+
billingAddressRequirement: BillingAddressRequirement = "country",
|
|
108
102
|
): string {
|
|
109
|
-
return `${BANK_ACCOUNT_HEIGHT_PX[billingAddressRequirement] ?? BANK_ACCOUNT_HEIGHT_PX.
|
|
103
|
+
return `${BANK_ACCOUNT_HEIGHT_PX[billingAddressRequirement] ?? BANK_ACCOUNT_HEIGHT_PX.country}px`;
|
|
110
104
|
}
|
|
111
105
|
|
|
112
106
|
/**
|