@paypercut/checkout-js 1.2.4 → 1.2.5
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 +115 -4
- package/dist/index.cjs +49 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +34 -9
- package/dist/index.mjs +49 -3
- package/dist/index.mjs.map +1 -1
- package/dist/paypercut-checkout.iife.min.js +1 -1
- package/dist/paypercut-checkout.iife.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -57,6 +57,31 @@ declare enum WalletOption {
|
|
|
57
57
|
/** Google Pay */
|
|
58
58
|
GOOGLE_PAY = "google_pay"
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Appearance variables for customising the hosted checkout visual style.
|
|
62
|
+
* All fields are optional — only override what you need.
|
|
63
|
+
*/
|
|
64
|
+
interface AppearanceVariables {
|
|
65
|
+
/** Primary button / CTA background colour (hex, e.g. '#0066ff') */
|
|
66
|
+
brandColor?: `#${string}`;
|
|
67
|
+
/** Font family for the checkout UI (must be available in the iframe context) */
|
|
68
|
+
fontFamily?: string;
|
|
69
|
+
/** Merchant logo URL shown in the checkout header (https only) */
|
|
70
|
+
logoUrl?: string;
|
|
71
|
+
/** Border radius for checkout panels and payment method selector (e.g. '8px', '0.5rem') */
|
|
72
|
+
borderRadius?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Appearance options for the hosted checkout UI.
|
|
76
|
+
*/
|
|
77
|
+
interface Appearance {
|
|
78
|
+
/** Layout preset */
|
|
79
|
+
preset?: 'inline' | 'modal';
|
|
80
|
+
/** Colour theme */
|
|
81
|
+
theme?: 'light' | 'dark';
|
|
82
|
+
/** Fine-grained visual variable overrides */
|
|
83
|
+
variables?: AppearanceVariables;
|
|
84
|
+
}
|
|
60
85
|
/**
|
|
61
86
|
* Configuration options for PaypercutCheckout
|
|
62
87
|
*/
|
|
@@ -101,15 +126,9 @@ interface PaypercutCheckoutOptions {
|
|
|
101
126
|
*/
|
|
102
127
|
form_only?: boolean;
|
|
103
128
|
/**
|
|
104
|
-
* Optional: Appearance options
|
|
129
|
+
* Optional: Appearance options for theming the checkout UI
|
|
105
130
|
*/
|
|
106
|
-
appearance?:
|
|
107
|
-
preset?: 'inline' | 'modal';
|
|
108
|
-
theme?: 'light' | 'dark' | 'none' | 'flat';
|
|
109
|
-
variables: {};
|
|
110
|
-
rules: {};
|
|
111
|
-
labels: 'floating' | 'above' | 'none';
|
|
112
|
-
};
|
|
131
|
+
appearance?: Appearance;
|
|
113
132
|
/**
|
|
114
133
|
* Optional: Require form validation before wallet payment (Google Pay / Apple Pay)
|
|
115
134
|
* @default false
|
|
@@ -186,6 +205,12 @@ interface CheckoutInstance {
|
|
|
186
205
|
* @param errors - Optional array of validation errors to pass back
|
|
187
206
|
*/
|
|
188
207
|
failFormValidation(wallet: WalletType, errors?: FormValidationError[]): void;
|
|
208
|
+
/**
|
|
209
|
+
* Dynamically update the checkout appearance after it has been rendered.
|
|
210
|
+
* Useful for syncing the checkout theme with the merchant page (e.g. dark mode toggle).
|
|
211
|
+
* @param appearance - Partial appearance options to merge into the current appearance
|
|
212
|
+
*/
|
|
213
|
+
updateAppearance(appearance: Appearance): void;
|
|
189
214
|
}
|
|
190
215
|
/**
|
|
191
216
|
* PaypercutCheckout static interface (callable and constructable)
|
|
@@ -464,4 +489,4 @@ declare const PaypercutExpressCheckout: ExpressCheckoutStatic;
|
|
|
464
489
|
declare const PaypercutCheckout: PaypercutCheckoutStatic;
|
|
465
490
|
|
|
466
491
|
export { ExpressSdkEvent, LOCALES, PaymentMethod, PaypercutCheckout, PaypercutExpressCheckout, SdkEvent, UIMode, WalletOption, PaypercutCheckout as default };
|
|
467
|
-
export type { ApplePayButtonStyle, CancelPayload, CheckoutInstance, EventName, ExpressBillingDetails, ExpressButtonOptions, ExpressButtonType, ExpressCheckoutInstance, ExpressCheckoutOptions, ExpressCheckoutShippingOption, ExpressCheckoutUpdateOptions, ExpressEventName, ExpressPaymentMethodCreatedEvent, ExpressPaymentMethodFailedEvent, ExpressSessionStartEvent, ExpressShippingAddress, ExpressShippingDetails, ExpressTokenPayload, FormValidationError, GooglePayButtonColor, LineItem, Locale, PaypercutCheckoutOptions, PaypercutCheckoutStatic, ShippingAddressChangeEvent, ShippingOptionChangeEvent, WalletType };
|
|
492
|
+
export type { Appearance, AppearanceVariables, ApplePayButtonStyle, CancelPayload, CheckoutInstance, EventName, ExpressBillingDetails, ExpressButtonOptions, ExpressButtonType, ExpressCheckoutInstance, ExpressCheckoutOptions, ExpressCheckoutShippingOption, ExpressCheckoutUpdateOptions, ExpressEventName, ExpressPaymentMethodCreatedEvent, ExpressPaymentMethodFailedEvent, ExpressSessionStartEvent, ExpressShippingAddress, ExpressShippingDetails, ExpressTokenPayload, FormValidationError, GooglePayButtonColor, LineItem, Locale, PaypercutCheckoutOptions, PaypercutCheckoutStatic, ShippingAddressChangeEvent, ShippingOptionChangeEvent, WalletType };
|
package/dist/index.mjs
CHANGED
|
@@ -87,7 +87,7 @@ class Emitter {
|
|
|
87
87
|
* Production configuration (for merchants)
|
|
88
88
|
*/
|
|
89
89
|
const productionConfig = {
|
|
90
|
-
version: "1.2.
|
|
90
|
+
version: "1.2.5",
|
|
91
91
|
defaultCheckoutOrigin: 'https://buy.paypercut.io',
|
|
92
92
|
defaultApiOrigin: 'https://api.paypercut.io',
|
|
93
93
|
defaultVaultApiUrl: 'https://api.basistheory.com',
|
|
@@ -965,8 +965,8 @@ class ExpressCheckoutImpl {
|
|
|
965
965
|
: [WalletOption.APPLE_PAY, WalletOption.GOOGLE_PAY];
|
|
966
966
|
const showApplePay = requestedWallets.includes(WalletOption.APPLE_PAY);
|
|
967
967
|
const showGooglePay = requestedWallets.includes(WalletOption.GOOGLE_PAY);
|
|
968
|
-
// Wrapper —
|
|
969
|
-
const layoutOption = this.options.layout ?? '
|
|
968
|
+
// Wrapper — auto (default), row, or column layout; 'auto' uses ResizeObserver
|
|
969
|
+
const layoutOption = this.options.layout ?? 'auto';
|
|
970
970
|
this.preferredLayout = layoutOption === 'auto' ? 'row' : layoutOption;
|
|
971
971
|
const wrapper = document.createElement('div');
|
|
972
972
|
this.wrapper = wrapper;
|
|
@@ -2009,6 +2009,30 @@ const PaypercutExpressCheckout = function (options) {
|
|
|
2009
2009
|
return new ExpressCheckoutImpl(options);
|
|
2010
2010
|
};
|
|
2011
2011
|
|
|
2012
|
+
// ── Appearance validation ─────────────────────────────────────────────────────
|
|
2013
|
+
const _HEX_RE = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
|
2014
|
+
const _CSS_LEN_RE = /^(0|(\d+(\.\d+)?(px|rem|em)))$/;
|
|
2015
|
+
function warnInvalidAppearanceVariables(variables) {
|
|
2016
|
+
if (!variables)
|
|
2017
|
+
return;
|
|
2018
|
+
if (variables.brandColor !== undefined && !_HEX_RE.test(variables.brandColor)) {
|
|
2019
|
+
console.warn(`[PaypercutCheckout] Invalid appearance.variables.brandColor: "${variables.brandColor}". ` +
|
|
2020
|
+
`Expected a hex color (#RGB or #RRGGBB). Value ignored.`);
|
|
2021
|
+
}
|
|
2022
|
+
if (variables.fontFamily !== undefined && !variables.fontFamily.trim()) {
|
|
2023
|
+
console.warn(`[PaypercutCheckout] Invalid appearance.variables.fontFamily: value is empty. Value ignored.`);
|
|
2024
|
+
}
|
|
2025
|
+
if (variables.logoUrl !== undefined && !/^https:\/\//.test(variables.logoUrl)) {
|
|
2026
|
+
console.warn(`[PaypercutCheckout] Invalid appearance.variables.logoUrl: "${variables.logoUrl}". ` +
|
|
2027
|
+
`Must start with https://. Value ignored.`);
|
|
2028
|
+
}
|
|
2029
|
+
if (variables.borderRadius !== undefined &&
|
|
2030
|
+
!_CSS_LEN_RE.test(variables.borderRadius.trim())) {
|
|
2031
|
+
console.warn(`[PaypercutCheckout] Invalid appearance.variables.borderRadius: "${variables.borderRadius}". ` +
|
|
2032
|
+
`Expected a CSS length like "8px", "0.5rem", or "0". Value ignored.`);
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
// ── Checkout implementation ───────────────────────────────────────────────────
|
|
2012
2036
|
/**
|
|
2013
2037
|
* Internal implementation of CheckoutInstance
|
|
2014
2038
|
*/
|
|
@@ -2076,6 +2100,13 @@ class CheckoutImpl {
|
|
|
2076
2100
|
if (this.options.appearance?.preset) {
|
|
2077
2101
|
url.searchParams.set('preset', this.options.appearance.preset);
|
|
2078
2102
|
}
|
|
2103
|
+
if (this.options.appearance?.theme) {
|
|
2104
|
+
url.searchParams.set('theme', this.options.appearance.theme);
|
|
2105
|
+
}
|
|
2106
|
+
if (this.options.appearance?.variables && Object.keys(this.options.appearance.variables).length > 0) {
|
|
2107
|
+
warnInvalidAppearanceVariables(this.options.appearance.variables);
|
|
2108
|
+
url.searchParams.set('appearance_vars', JSON.stringify(this.options.appearance.variables));
|
|
2109
|
+
}
|
|
2079
2110
|
if (this.options.form_only !== undefined) {
|
|
2080
2111
|
url.searchParams.set('form_only', String(this.options.form_only));
|
|
2081
2112
|
}
|
|
@@ -2369,6 +2400,21 @@ class CheckoutImpl {
|
|
|
2369
2400
|
status: 'success',
|
|
2370
2401
|
});
|
|
2371
2402
|
}
|
|
2403
|
+
/**
|
|
2404
|
+
* Dynamically update the checkout appearance after it has been rendered.
|
|
2405
|
+
*/
|
|
2406
|
+
updateAppearance(appearance) {
|
|
2407
|
+
if (!this.mounted) {
|
|
2408
|
+
console.warn('[PaypercutCheckout] Cannot update appearance: not mounted');
|
|
2409
|
+
return;
|
|
2410
|
+
}
|
|
2411
|
+
warnInvalidAppearanceVariables(appearance.variables);
|
|
2412
|
+
this.postToIframe({
|
|
2413
|
+
type: 'UPDATE_APPEARANCE',
|
|
2414
|
+
checkoutId: this.options.id,
|
|
2415
|
+
appearance,
|
|
2416
|
+
});
|
|
2417
|
+
}
|
|
2372
2418
|
/**
|
|
2373
2419
|
* Fail form validation - prevents wallet payment from starting.
|
|
2374
2420
|
* Call this in response to 'form_validation' event when merchant form has errors.
|