@amos.com/amos-js 0.9.14 → 0.9.16
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 +121 -114
- package/dist/apple-pay.d.ts +19 -10
- package/dist/google-pay.d.ts +21 -11
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.mjs +214 -237
- package/dist/messaging.d.ts +6 -3
- package/dist/mount.d.ts +14 -0
- package/dist/types.d.ts +28 -81
- package/package.json +1 -1
- package/src/apple-pay.ts +30 -24
- package/src/google-pay.ts +32 -28
- package/src/index.ts +1 -9
- package/src/messaging.ts +10 -5
- package/src/mount.ts +29 -4
- package/src/types.ts +31 -179
package/dist/messaging.d.ts
CHANGED
|
@@ -29,19 +29,22 @@ export declare function updateAppearance({ iframe, appearance, }: {
|
|
|
29
29
|
/**
|
|
30
30
|
* Push Apple Pay button visual options into the embedded iframe.
|
|
31
31
|
*/
|
|
32
|
-
export declare function updateApplePayButton({ iframe, props, }: {
|
|
32
|
+
export declare function updateApplePayButton({ iframe, props, height, }: {
|
|
33
33
|
iframe: Iframe;
|
|
34
34
|
props: ApplePayButtonElementProps;
|
|
35
|
+
height?: string;
|
|
35
36
|
}): void;
|
|
36
37
|
/**
|
|
37
38
|
* Push Google Pay button visual options into the embedded iframe.
|
|
38
39
|
*/
|
|
39
|
-
export declare function updateGooglePayButton({ iframe, props, }: {
|
|
40
|
+
export declare function updateGooglePayButton({ iframe, props, height, }: {
|
|
40
41
|
iframe: Iframe;
|
|
41
42
|
props: GooglePayButtonElementProps;
|
|
43
|
+
height?: string;
|
|
42
44
|
}): void;
|
|
43
45
|
/**
|
|
44
|
-
* Push the express-checkout amount into the embedded
|
|
46
|
+
* Push the express-checkout amount into the embedded wallet iframe.
|
|
47
|
+
* `amount` is a major-currency decimal string (e.g. `"50.00"` for $50.00).
|
|
45
48
|
*/
|
|
46
49
|
export declare function updateAmount({ iframe, amount, }: {
|
|
47
50
|
iframe: Iframe;
|
package/dist/mount.d.ts
CHANGED
|
@@ -95,6 +95,13 @@ export type AmosGooglePayButtonOptions = GooglePayButtonListenerOptions & {
|
|
|
95
95
|
* https://dashboard.amos.com.
|
|
96
96
|
*/
|
|
97
97
|
renderToken: string;
|
|
98
|
+
/** Class names applied to the host-page `<iframe>` element. */
|
|
99
|
+
iframeClassName?: string;
|
|
100
|
+
/**
|
|
101
|
+
* Inline style applied to the host-page `<iframe>` element. Use CSS
|
|
102
|
+
* lengths with units (`{ borderRadius: "8px" }`).
|
|
103
|
+
*/
|
|
104
|
+
iframeStyle?: Partial<CSSStyleDeclaration>;
|
|
98
105
|
};
|
|
99
106
|
/**
|
|
100
107
|
* Controller returned by {@link mountAmosGooglePayButton}.
|
|
@@ -122,6 +129,13 @@ export type AmosApplePayButtonOptions = ApplePayButtonListenerOptions & {
|
|
|
122
129
|
* https://dashboard.amos.com.
|
|
123
130
|
*/
|
|
124
131
|
renderToken: string;
|
|
132
|
+
/** Class names applied to the host-page `<iframe>` element. */
|
|
133
|
+
iframeClassName?: string;
|
|
134
|
+
/**
|
|
135
|
+
* Inline style applied to the host-page `<iframe>` element. Use CSS
|
|
136
|
+
* lengths with units (`{ borderRadius: "8px" }`).
|
|
137
|
+
*/
|
|
138
|
+
iframeStyle?: Partial<CSSStyleDeclaration>;
|
|
125
139
|
};
|
|
126
140
|
/**
|
|
127
141
|
* Controller returned by {@link mountAmosApplePayButton}.
|
package/dist/types.d.ts
CHANGED
|
@@ -78,53 +78,28 @@ export type Appearance = {
|
|
|
78
78
|
labels?: AppearanceLabels;
|
|
79
79
|
};
|
|
80
80
|
/**
|
|
81
|
-
*
|
|
81
|
+
* Apple's `<apple-pay-button>` attributes. `@types/applepayjs` only
|
|
82
|
+
* covers `ApplePaySession`, so this bag is the custom element's HTML
|
|
83
|
+
* attributes plus inner `style`. Posted as-is on `buttonProps`.
|
|
82
84
|
*
|
|
83
|
-
*
|
|
84
|
-
* `
|
|
85
|
-
* as `--apple-pay-button-height` are allowed.
|
|
86
|
-
*/
|
|
87
|
-
export type WalletButtonStyle = {
|
|
88
|
-
[property: string]: string | number | undefined;
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* `buttonstyle` attribute on Apple's `<apple-pay-button>`.
|
|
92
|
-
*
|
|
93
|
-
* @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple-pay-button
|
|
94
|
-
*/
|
|
95
|
-
export type ApplePayButtonStyle = "black" | "white" | "white-outline";
|
|
96
|
-
/**
|
|
97
|
-
* `type` attribute on Apple's `<apple-pay-button>`.
|
|
98
|
-
*
|
|
99
|
-
* @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple-pay-button
|
|
100
|
-
*/
|
|
101
|
-
export type ApplePayButtonType = "plain" | "buy" | "set-up" | "donate" | "check-out" | "book" | "subscribe" | "reload" | "add-money" | "top-up" | "order" | "rent" | "support" | "contribute" | "tip";
|
|
102
|
-
/**
|
|
103
|
-
* Visual props for Apple's `<apple-pay-button>`, using Apple's attribute
|
|
104
|
-
* names. Applied inside the Amos embed iframe.
|
|
85
|
+
* Omitted fields keep the painted button's defaults. Height belongs on
|
|
86
|
+
* the mount `height` option.
|
|
105
87
|
*
|
|
106
88
|
* @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple-pay-button
|
|
107
89
|
*/
|
|
108
90
|
export type ApplePayButtonElementProps = {
|
|
109
|
-
/**
|
|
110
|
-
* Stretch the button to the iframe width while preserving its default
|
|
111
|
-
* compact size when omitted.
|
|
112
|
-
*
|
|
113
|
-
* @default false
|
|
114
|
-
*/
|
|
115
|
-
fullWidth?: boolean;
|
|
116
91
|
/**
|
|
117
92
|
* Apple Pay button color.
|
|
118
93
|
*
|
|
119
94
|
* @default "black"
|
|
120
95
|
*/
|
|
121
|
-
buttonstyle?:
|
|
96
|
+
buttonstyle?: string;
|
|
122
97
|
/**
|
|
123
98
|
* Apple Pay button label / verb.
|
|
124
99
|
*
|
|
125
100
|
* @default "plain"
|
|
126
101
|
*/
|
|
127
|
-
type?:
|
|
102
|
+
type?: string;
|
|
128
103
|
/**
|
|
129
104
|
* BCP 47 locale for the button label (e.g. `"en-US"`).
|
|
130
105
|
*
|
|
@@ -132,58 +107,29 @@ export type ApplePayButtonElementProps = {
|
|
|
132
107
|
*/
|
|
133
108
|
locale?: string;
|
|
134
109
|
/**
|
|
135
|
-
* Inline style for the `<apple-pay-button>`.
|
|
136
|
-
* `--apple-pay-button-
|
|
137
|
-
* `--apple-pay-button-width` or CSS `width`.
|
|
110
|
+
* Inline style for the `<apple-pay-button>`. Omitted keys keep fill
|
|
111
|
+
* (`width: 100%` and `--apple-pay-button-width`).
|
|
138
112
|
*/
|
|
139
|
-
style?:
|
|
113
|
+
style?: Record<string, string | number | undefined>;
|
|
140
114
|
};
|
|
141
115
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
116
|
+
* Google Pay button visuals: {@link google.payments.api.ButtonOptions}
|
|
117
|
+
* without the fields that cannot go through `postMessage`, plus inner
|
|
118
|
+
* `style`. Posted as-is on `buttonProps`.
|
|
119
|
+
*
|
|
120
|
+
* Omitted fields keep the painted button's defaults (`buttonType:
|
|
121
|
+
* "plain"`, `buttonSizeMode: "fill"`). Height belongs on the mount
|
|
122
|
+
* `height` option.
|
|
144
123
|
*
|
|
145
124
|
* @see https://developers.google.com/pay/api/web/guides/resources/customize
|
|
146
125
|
*/
|
|
147
|
-
export type GooglePayButtonElementProps = {
|
|
126
|
+
export type GooglePayButtonElementProps = Omit<google.payments.api.ButtonOptions, "onClick" | "buttonRootNode" | "allowedPaymentMethods"> & {
|
|
148
127
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* @default false
|
|
153
|
-
*/
|
|
154
|
-
fullWidth?: boolean;
|
|
155
|
-
/**
|
|
156
|
-
* Button label / verb.
|
|
157
|
-
*
|
|
158
|
-
* @default "short"
|
|
159
|
-
*/
|
|
160
|
-
buttonType?: google.payments.api.ButtonType;
|
|
161
|
-
/** Button color. */
|
|
162
|
-
buttonColor?: google.payments.api.ButtonColor;
|
|
163
|
-
/** Corner radius in pixels (0–20). */
|
|
164
|
-
buttonRadius?: number;
|
|
165
|
-
/**
|
|
166
|
-
* `"fill"` stretches the button to the container width; `"static"`
|
|
167
|
-
* uses Google's default size.
|
|
168
|
-
*/
|
|
169
|
-
buttonSizeMode?: google.payments.api.ButtonSizeMode;
|
|
170
|
-
/** BCP 47 locale for the button label (e.g. `"en"`). */
|
|
171
|
-
buttonLocale?: string;
|
|
172
|
-
/** Whether the button draws a border. */
|
|
173
|
-
buttonBorderType?: google.payments.api.ButtonBorderType;
|
|
174
|
-
/**
|
|
175
|
-
* Inline style for the Google Pay button wrapper. Use `height` /
|
|
176
|
-
* `width` here (unlike Apple Pay, Google honors CSS `height`).
|
|
128
|
+
* Inline style for the Google Pay button wrapper. Omitted keys keep
|
|
129
|
+
* fill (`width: 100%`).
|
|
177
130
|
*/
|
|
178
|
-
style?:
|
|
131
|
+
style?: Record<string, string | number | undefined>;
|
|
179
132
|
};
|
|
180
|
-
/**
|
|
181
|
-
* Keep only JSON-cloneable string/number declarations from a style object
|
|
182
|
-
* before sending it through `postMessage`.
|
|
183
|
-
*/
|
|
184
|
-
export declare function serializeWalletButtonStyle(style: WalletButtonStyle | undefined): Record<string, string | number> | undefined;
|
|
185
|
-
export declare function pickApplePayButtonElementProps(options: ApplePayButtonElementProps): ApplePayButtonElementProps;
|
|
186
|
-
export declare function pickGooglePayButtonElementProps(options: GooglePayButtonElementProps): GooglePayButtonElementProps;
|
|
187
133
|
/**
|
|
188
134
|
* Typed `postMessage` payloads exchanged between the host page and the
|
|
189
135
|
* embedded Amos iframe.
|
|
@@ -199,7 +145,10 @@ export type Message = {
|
|
|
199
145
|
type: "UPDATE_HEIGHT";
|
|
200
146
|
height: string;
|
|
201
147
|
} | {
|
|
202
|
-
/**
|
|
148
|
+
/**
|
|
149
|
+
* Parent → embed: express-checkout amount changed. Major-currency
|
|
150
|
+
* decimal string (e.g. `"50.00"` for $50.00).
|
|
151
|
+
*/
|
|
203
152
|
type: "UPDATE_AMOUNT";
|
|
204
153
|
amount: string;
|
|
205
154
|
} | {
|
|
@@ -211,16 +160,14 @@ export type Message = {
|
|
|
211
160
|
type: "UPDATE_APPEARANCE";
|
|
212
161
|
appearance: Appearance;
|
|
213
162
|
} | {
|
|
214
|
-
/**
|
|
215
|
-
* Parent → embed: visual options for the Apple Pay button. Nested
|
|
216
|
-
* under `props` so Apple's `type` attribute does not collide with
|
|
217
|
-
* this message discriminant.
|
|
218
|
-
*/
|
|
163
|
+
/** Parent → embed: visual options for the Apple Pay button. */
|
|
219
164
|
type: "UPDATE_APPLE_PAY_BUTTON";
|
|
165
|
+
height?: string;
|
|
220
166
|
props: ApplePayButtonElementProps;
|
|
221
167
|
} | {
|
|
222
168
|
/** Parent → embed: visual options for the Google Pay button. */
|
|
223
169
|
type: "UPDATE_GOOGLE_PAY_BUTTON";
|
|
170
|
+
height?: string;
|
|
224
171
|
props: GooglePayButtonElementProps;
|
|
225
172
|
} | {
|
|
226
173
|
/**
|
package/package.json
CHANGED
package/src/apple-pay.ts
CHANGED
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
updateMerchantName as sendUpdateMerchantName,
|
|
15
15
|
} from "./messaging";
|
|
16
16
|
import {
|
|
17
|
-
type Appearance,
|
|
18
17
|
type ApplePayButtonElementProps,
|
|
19
18
|
type ConfirmationResult,
|
|
20
19
|
createMessage,
|
|
@@ -32,22 +31,32 @@ export function getApplePayButtonSrc(renderToken: string): string {
|
|
|
32
31
|
* Default iframe pixel height for the Apple Pay button.
|
|
33
32
|
*/
|
|
34
33
|
export function getApplePayButtonInitialHeight(): string {
|
|
35
|
-
return "
|
|
34
|
+
return "48px";
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
/**
|
|
39
38
|
* Options accepted by {@link attachApplePayButtonListeners}.
|
|
40
39
|
*/
|
|
41
|
-
export type ApplePayButtonListenerOptions =
|
|
42
|
-
/**
|
|
40
|
+
export type ApplePayButtonListenerOptions = {
|
|
41
|
+
/**
|
|
42
|
+
* Major-currency decimal string shown in the Apple Pay sheet
|
|
43
|
+
* (e.g. `"50.00"` for $50.00). Converted to cents in
|
|
44
|
+
* `paymentIntentCreateAttributes.amount`.
|
|
45
|
+
*/
|
|
43
46
|
amount: string;
|
|
44
47
|
/** A user-visible merchant name. */
|
|
45
48
|
merchantName: string;
|
|
46
49
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
50
|
+
* Painted Apple Pay button height. CSS length (e.g. `"48px"`).
|
|
51
|
+
* @default "48px"
|
|
52
|
+
*/
|
|
53
|
+
height?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Native `<apple-pay-button>` attributes and inner style. Omitted
|
|
56
|
+
* fields keep Apple's defaults (`black` / `plain` / `en-US`). The
|
|
57
|
+
* button fills the iframe — size the mount slot, not the button.
|
|
49
58
|
*/
|
|
50
|
-
|
|
59
|
+
buttonProps?: ApplePayButtonElementProps;
|
|
51
60
|
/**
|
|
52
61
|
* Called whenever the iframe asks the host page to resize it. Update
|
|
53
62
|
* the iframe's `height` style here.
|
|
@@ -85,9 +94,8 @@ export type ApplePayButtonController = {
|
|
|
85
94
|
/**
|
|
86
95
|
* Update one or more listener options without re-attaching the
|
|
87
96
|
* message listener. Pass `amount` or `merchantName` to push the new
|
|
88
|
-
* value into the iframe; pass `
|
|
89
|
-
*
|
|
90
|
-
* Apple Pay button.
|
|
97
|
+
* value into the iframe; pass `height` or `buttonProps` to restyle
|
|
98
|
+
* the Apple Pay button.
|
|
91
99
|
*/
|
|
92
100
|
update: (patch: Partial<ApplePayButtonListenerOptions>) => void;
|
|
93
101
|
/**
|
|
@@ -118,9 +126,12 @@ function sendApplePayCancel(iframe: HTMLIFrameElement): void {
|
|
|
118
126
|
*/
|
|
119
127
|
export function attachApplePayButtonListeners(
|
|
120
128
|
iframe: HTMLIFrameElement,
|
|
121
|
-
options: ApplePayButtonListenerOptions,
|
|
129
|
+
{ height = "48px", ...options }: ApplePayButtonListenerOptions,
|
|
122
130
|
): ApplePayButtonController {
|
|
123
|
-
let current = {
|
|
131
|
+
let current: ApplePayButtonListenerOptions = {
|
|
132
|
+
...options,
|
|
133
|
+
height,
|
|
134
|
+
};
|
|
124
135
|
|
|
125
136
|
function pushAmount() {
|
|
126
137
|
sendUpdateAmount({ iframe, amount: current.amount });
|
|
@@ -131,7 +142,11 @@ export function attachApplePayButtonListeners(
|
|
|
131
142
|
}
|
|
132
143
|
|
|
133
144
|
function pushButtonProps() {
|
|
134
|
-
sendUpdateApplePayButton({
|
|
145
|
+
sendUpdateApplePayButton({
|
|
146
|
+
iframe,
|
|
147
|
+
height: current.height ?? "48px",
|
|
148
|
+
props: current.buttonProps ?? {},
|
|
149
|
+
});
|
|
135
150
|
}
|
|
136
151
|
|
|
137
152
|
function handleMessage(event: MessageEvent<Message>) {
|
|
@@ -143,7 +158,7 @@ export function attachApplePayButtonListeners(
|
|
|
143
158
|
switch (event.data.type) {
|
|
144
159
|
case "IFRAME_READY":
|
|
145
160
|
sendParentReadyMessage(iframe);
|
|
146
|
-
sendUpdateAppearance({ iframe, appearance:
|
|
161
|
+
sendUpdateAppearance({ iframe, appearance: {} });
|
|
147
162
|
pushAmount();
|
|
148
163
|
pushMerchantName();
|
|
149
164
|
pushButtonProps();
|
|
@@ -205,19 +220,10 @@ export function attachApplePayButtonListeners(
|
|
|
205
220
|
|
|
206
221
|
return {
|
|
207
222
|
update(patch) {
|
|
208
|
-
const hadAppearance = "appearance" in patch;
|
|
209
223
|
const hadAmount = "amount" in patch;
|
|
210
224
|
const hadMerchantName = "merchantName" in patch;
|
|
211
|
-
const hadButtonProps =
|
|
212
|
-
"fullWidth" in patch ||
|
|
213
|
-
"buttonstyle" in patch ||
|
|
214
|
-
"type" in patch ||
|
|
215
|
-
"locale" in patch ||
|
|
216
|
-
"style" in patch;
|
|
225
|
+
const hadButtonProps = "height" in patch || "buttonProps" in patch;
|
|
217
226
|
current = { ...current, ...patch };
|
|
218
|
-
if (hadAppearance) {
|
|
219
|
-
sendUpdateAppearance({ iframe, appearance: current.appearance });
|
|
220
|
-
}
|
|
221
227
|
if (hadAmount) {
|
|
222
228
|
pushAmount();
|
|
223
229
|
}
|
package/src/google-pay.ts
CHANGED
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
updateMerchantName as sendUpdateMerchantName,
|
|
12
12
|
} from "./messaging";
|
|
13
13
|
import type {
|
|
14
|
-
Appearance,
|
|
15
14
|
ConfirmationResult,
|
|
16
15
|
GooglePayButtonElementProps,
|
|
17
16
|
Message,
|
|
@@ -28,22 +27,34 @@ export function getGooglePayButtonSrc(renderToken: string): string {
|
|
|
28
27
|
* Default iframe pixel height for the Google Pay button.
|
|
29
28
|
*/
|
|
30
29
|
export function getGooglePayButtonInitialHeight(): string {
|
|
31
|
-
return "
|
|
30
|
+
return "48px";
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
/**
|
|
35
34
|
* Options accepted by {@link attachGooglePayButtonListeners}.
|
|
36
35
|
*/
|
|
37
|
-
export type GooglePayButtonListenerOptions =
|
|
38
|
-
/**
|
|
36
|
+
export type GooglePayButtonListenerOptions = {
|
|
37
|
+
/**
|
|
38
|
+
* Major-currency decimal string shown in the Google Pay sheet
|
|
39
|
+
* (e.g. `"50.00"` for $50.00). Converted to cents in
|
|
40
|
+
* `paymentIntentCreateAttributes.amount`.
|
|
41
|
+
*/
|
|
39
42
|
amount: string;
|
|
40
43
|
/** A user-visible merchant name. */
|
|
41
44
|
merchantName: string;
|
|
42
45
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
46
|
+
* Painted Google Pay button height. CSS length (e.g. `"48px"`).
|
|
47
|
+
* @default "48px"
|
|
48
|
+
*/
|
|
49
|
+
height?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Native Google Pay button attributes and inner style. Omitted fields
|
|
52
|
+
* keep Amos paint defaults (`buttonType: "plain"`,
|
|
53
|
+
* `buttonSizeMode: "fill"`). The button fills the iframe — size the
|
|
54
|
+
* mount slot, not the button. Compact: `buttonSizeMode: "static"` and
|
|
55
|
+
* `style.width`.
|
|
45
56
|
*/
|
|
46
|
-
|
|
57
|
+
buttonProps?: GooglePayButtonElementProps;
|
|
47
58
|
/**
|
|
48
59
|
* Called whenever the iframe asks the host page to resize it. Update
|
|
49
60
|
* the iframe's `height` style here.
|
|
@@ -81,10 +92,8 @@ export type GooglePayButtonController = {
|
|
|
81
92
|
/**
|
|
82
93
|
* Update one or more listener options without re-attaching the
|
|
83
94
|
* message listener. Pass `amount` or `merchantName` to push the new
|
|
84
|
-
* value into the iframe; pass `
|
|
85
|
-
*
|
|
86
|
-
* `buttonLocale`, `buttonBorderType`, or `style` to restyle the
|
|
87
|
-
* Google Pay button.
|
|
95
|
+
* value into the iframe; pass `height` or `buttonProps` to restyle
|
|
96
|
+
* the Google Pay button.
|
|
88
97
|
*/
|
|
89
98
|
update: (patch: Partial<GooglePayButtonListenerOptions>) => void;
|
|
90
99
|
/**
|
|
@@ -103,9 +112,12 @@ export type GooglePayButtonController = {
|
|
|
103
112
|
*/
|
|
104
113
|
export function attachGooglePayButtonListeners(
|
|
105
114
|
iframe: HTMLIFrameElement,
|
|
106
|
-
options: GooglePayButtonListenerOptions,
|
|
115
|
+
{ height = "48px", ...options }: GooglePayButtonListenerOptions,
|
|
107
116
|
): GooglePayButtonController {
|
|
108
|
-
let current = {
|
|
117
|
+
let current: GooglePayButtonListenerOptions = {
|
|
118
|
+
...options,
|
|
119
|
+
height,
|
|
120
|
+
};
|
|
109
121
|
|
|
110
122
|
function pushAmount() {
|
|
111
123
|
sendUpdateAmount({ iframe, amount: current.amount });
|
|
@@ -116,7 +128,11 @@ export function attachGooglePayButtonListeners(
|
|
|
116
128
|
}
|
|
117
129
|
|
|
118
130
|
function pushButtonProps() {
|
|
119
|
-
sendUpdateGooglePayButton({
|
|
131
|
+
sendUpdateGooglePayButton({
|
|
132
|
+
iframe,
|
|
133
|
+
height: current.height ?? "48px",
|
|
134
|
+
props: current.buttonProps ?? {},
|
|
135
|
+
});
|
|
120
136
|
}
|
|
121
137
|
|
|
122
138
|
function handleMessage(event: MessageEvent<Message>) {
|
|
@@ -127,7 +143,7 @@ export function attachGooglePayButtonListeners(
|
|
|
127
143
|
switch (event.data.type) {
|
|
128
144
|
case "IFRAME_READY":
|
|
129
145
|
sendParentReadyMessage(iframe);
|
|
130
|
-
sendUpdateAppearance({ iframe, appearance:
|
|
146
|
+
sendUpdateAppearance({ iframe, appearance: {} });
|
|
131
147
|
pushAmount();
|
|
132
148
|
pushMerchantName();
|
|
133
149
|
pushButtonProps();
|
|
@@ -174,22 +190,10 @@ export function attachGooglePayButtonListeners(
|
|
|
174
190
|
|
|
175
191
|
return {
|
|
176
192
|
update(patch) {
|
|
177
|
-
const hadAppearance = "appearance" in patch;
|
|
178
193
|
const hadAmount = "amount" in patch;
|
|
179
194
|
const hadMerchantName = "merchantName" in patch;
|
|
180
|
-
const hadButtonProps =
|
|
181
|
-
"fullWidth" in patch ||
|
|
182
|
-
"buttonType" in patch ||
|
|
183
|
-
"buttonColor" in patch ||
|
|
184
|
-
"buttonRadius" in patch ||
|
|
185
|
-
"buttonSizeMode" in patch ||
|
|
186
|
-
"buttonLocale" in patch ||
|
|
187
|
-
"buttonBorderType" in patch ||
|
|
188
|
-
"style" in patch;
|
|
195
|
+
const hadButtonProps = "height" in patch || "buttonProps" in patch;
|
|
189
196
|
current = { ...current, ...patch };
|
|
190
|
-
if (hadAppearance) {
|
|
191
|
-
sendUpdateAppearance({ iframe, appearance: current.appearance });
|
|
192
|
-
}
|
|
193
197
|
if (hadAmount) {
|
|
194
198
|
pushAmount();
|
|
195
199
|
}
|
package/src/index.ts
CHANGED
|
@@ -69,19 +69,11 @@ export type {
|
|
|
69
69
|
Appearance,
|
|
70
70
|
AppearanceLabels,
|
|
71
71
|
ApplePayButtonElementProps,
|
|
72
|
-
ApplePayButtonStyle,
|
|
73
|
-
ApplePayButtonType,
|
|
74
72
|
ConfirmationIncompleteReason,
|
|
75
73
|
ConfirmationResult,
|
|
76
74
|
GooglePayButtonElementProps,
|
|
77
75
|
Message,
|
|
78
76
|
PaymentMethodFormValidityChangeEvent,
|
|
79
77
|
ThemeVariable,
|
|
80
|
-
WalletButtonStyle,
|
|
81
|
-
} from "./types";
|
|
82
|
-
export {
|
|
83
|
-
createMessage,
|
|
84
|
-
pickApplePayButtonElementProps,
|
|
85
|
-
pickGooglePayButtonElementProps,
|
|
86
|
-
serializeWalletButtonStyle,
|
|
87
78
|
} from "./types";
|
|
79
|
+
export { createMessage } from "./types";
|
package/src/messaging.ts
CHANGED
|
@@ -6,8 +6,6 @@ import {
|
|
|
6
6
|
createMessage,
|
|
7
7
|
type GooglePayButtonElementProps,
|
|
8
8
|
type Message,
|
|
9
|
-
pickApplePayButtonElementProps,
|
|
10
|
-
pickGooglePayButtonElementProps,
|
|
11
9
|
} from "./types";
|
|
12
10
|
|
|
13
11
|
type Iframe = HTMLIFrameElement | null | undefined;
|
|
@@ -69,9 +67,11 @@ export function updateAppearance({
|
|
|
69
67
|
export function updateApplePayButton({
|
|
70
68
|
iframe,
|
|
71
69
|
props,
|
|
70
|
+
height,
|
|
72
71
|
}: {
|
|
73
72
|
iframe: Iframe;
|
|
74
73
|
props: ApplePayButtonElementProps;
|
|
74
|
+
height?: string;
|
|
75
75
|
}): void {
|
|
76
76
|
if (!iframe?.contentWindow) {
|
|
77
77
|
return;
|
|
@@ -80,7 +80,8 @@ export function updateApplePayButton({
|
|
|
80
80
|
iframe.contentWindow.postMessage(
|
|
81
81
|
createMessage({
|
|
82
82
|
type: "UPDATE_APPLE_PAY_BUTTON",
|
|
83
|
-
|
|
83
|
+
height,
|
|
84
|
+
props,
|
|
84
85
|
}),
|
|
85
86
|
getIframeTargetOrigin(iframe),
|
|
86
87
|
);
|
|
@@ -92,9 +93,11 @@ export function updateApplePayButton({
|
|
|
92
93
|
export function updateGooglePayButton({
|
|
93
94
|
iframe,
|
|
94
95
|
props,
|
|
96
|
+
height,
|
|
95
97
|
}: {
|
|
96
98
|
iframe: Iframe;
|
|
97
99
|
props: GooglePayButtonElementProps;
|
|
100
|
+
height?: string;
|
|
98
101
|
}): void {
|
|
99
102
|
if (!iframe?.contentWindow) {
|
|
100
103
|
return;
|
|
@@ -103,14 +106,16 @@ export function updateGooglePayButton({
|
|
|
103
106
|
iframe.contentWindow.postMessage(
|
|
104
107
|
createMessage({
|
|
105
108
|
type: "UPDATE_GOOGLE_PAY_BUTTON",
|
|
106
|
-
|
|
109
|
+
height,
|
|
110
|
+
props,
|
|
107
111
|
}),
|
|
108
112
|
getIframeTargetOrigin(iframe),
|
|
109
113
|
);
|
|
110
114
|
}
|
|
111
115
|
|
|
112
116
|
/**
|
|
113
|
-
* Push the express-checkout amount into the embedded
|
|
117
|
+
* Push the express-checkout amount into the embedded wallet iframe.
|
|
118
|
+
* `amount` is a major-currency decimal string (e.g. `"50.00"` for $50.00).
|
|
114
119
|
*/
|
|
115
120
|
export function updateAmount({
|
|
116
121
|
iframe,
|
package/src/mount.ts
CHANGED
|
@@ -77,6 +77,7 @@ function createIframe({
|
|
|
77
77
|
name,
|
|
78
78
|
height,
|
|
79
79
|
allow,
|
|
80
|
+
className,
|
|
80
81
|
style = FORM_IFRAME_STYLE,
|
|
81
82
|
}: {
|
|
82
83
|
src: string;
|
|
@@ -84,6 +85,7 @@ function createIframe({
|
|
|
84
85
|
name: string;
|
|
85
86
|
height: string;
|
|
86
87
|
allow?: string;
|
|
88
|
+
className?: string;
|
|
87
89
|
style?: Partial<CSSStyleDeclaration>;
|
|
88
90
|
}): HTMLIFrameElement {
|
|
89
91
|
const iframe = document.createElement("iframe");
|
|
@@ -95,6 +97,9 @@ function createIframe({
|
|
|
95
97
|
if (allow) {
|
|
96
98
|
iframe.allow = allow;
|
|
97
99
|
}
|
|
100
|
+
if (className != null) {
|
|
101
|
+
iframe.className = className;
|
|
102
|
+
}
|
|
98
103
|
Object.assign(iframe.style, style, { height });
|
|
99
104
|
return iframe;
|
|
100
105
|
}
|
|
@@ -392,6 +397,13 @@ export type AmosGooglePayButtonOptions = GooglePayButtonListenerOptions & {
|
|
|
392
397
|
* https://dashboard.amos.com.
|
|
393
398
|
*/
|
|
394
399
|
renderToken: string;
|
|
400
|
+
/** Class names applied to the host-page `<iframe>` element. */
|
|
401
|
+
iframeClassName?: string;
|
|
402
|
+
/**
|
|
403
|
+
* Inline style applied to the host-page `<iframe>` element. Use CSS
|
|
404
|
+
* lengths with units (`{ borderRadius: "8px" }`).
|
|
405
|
+
*/
|
|
406
|
+
iframeStyle?: Partial<CSSStyleDeclaration>;
|
|
395
407
|
};
|
|
396
408
|
|
|
397
409
|
/**
|
|
@@ -414,16 +426,19 @@ export function mountAmosGooglePayButton(
|
|
|
414
426
|
options: AmosGooglePayButtonOptions,
|
|
415
427
|
): AmosGooglePayButtonMountController {
|
|
416
428
|
const host = resolveContainer(container);
|
|
417
|
-
const { renderToken, ...listenerOptions } =
|
|
429
|
+
const { renderToken, iframeClassName, iframeStyle, ...listenerOptions } =
|
|
430
|
+
options;
|
|
418
431
|
|
|
419
432
|
const iframe = createIframe({
|
|
420
433
|
src: getGooglePayButtonSrc(renderToken),
|
|
421
434
|
title: "Secure Google Pay button powered by Amos",
|
|
422
435
|
name: "amos-google-pay-button",
|
|
423
|
-
height: getGooglePayButtonInitialHeight(),
|
|
436
|
+
height: listenerOptions.height ?? getGooglePayButtonInitialHeight(),
|
|
424
437
|
allow: "payment",
|
|
438
|
+
className: iframeClassName,
|
|
425
439
|
style: WALLET_IFRAME_STYLE,
|
|
426
440
|
});
|
|
441
|
+
Object.assign(iframe.style, iframeStyle);
|
|
427
442
|
host.appendChild(iframe);
|
|
428
443
|
|
|
429
444
|
const controller = attachGooglePayButtonListeners(iframe, {
|
|
@@ -459,6 +474,13 @@ export type AmosApplePayButtonOptions = ApplePayButtonListenerOptions & {
|
|
|
459
474
|
* https://dashboard.amos.com.
|
|
460
475
|
*/
|
|
461
476
|
renderToken: string;
|
|
477
|
+
/** Class names applied to the host-page `<iframe>` element. */
|
|
478
|
+
iframeClassName?: string;
|
|
479
|
+
/**
|
|
480
|
+
* Inline style applied to the host-page `<iframe>` element. Use CSS
|
|
481
|
+
* lengths with units (`{ borderRadius: "8px" }`).
|
|
482
|
+
*/
|
|
483
|
+
iframeStyle?: Partial<CSSStyleDeclaration>;
|
|
462
484
|
};
|
|
463
485
|
|
|
464
486
|
/**
|
|
@@ -481,16 +503,19 @@ export function mountAmosApplePayButton(
|
|
|
481
503
|
options: AmosApplePayButtonOptions,
|
|
482
504
|
): AmosApplePayButtonMountController {
|
|
483
505
|
const host = resolveContainer(container);
|
|
484
|
-
const { renderToken, ...listenerOptions } =
|
|
506
|
+
const { renderToken, iframeClassName, iframeStyle, ...listenerOptions } =
|
|
507
|
+
options;
|
|
485
508
|
|
|
486
509
|
const iframe = createIframe({
|
|
487
510
|
src: getApplePayButtonSrc(renderToken),
|
|
488
511
|
title: "Secure Apple Pay button powered by Amos",
|
|
489
512
|
name: "amos-apple-pay-button",
|
|
490
|
-
height: getApplePayButtonInitialHeight(),
|
|
513
|
+
height: listenerOptions.height ?? getApplePayButtonInitialHeight(),
|
|
491
514
|
allow: "payment",
|
|
515
|
+
className: iframeClassName,
|
|
492
516
|
style: WALLET_IFRAME_STYLE,
|
|
493
517
|
});
|
|
518
|
+
Object.assign(iframe.style, iframeStyle);
|
|
494
519
|
host.appendChild(iframe);
|
|
495
520
|
|
|
496
521
|
const controller = attachApplePayButtonListeners(iframe, {
|