Skip to content

Commit a83971e

Browse files
Allows button message amount type to be string (#545)
1 parent 5bd68be commit a83971e

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

.changeset/smooth-pets-scream.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@paypal/react-paypal-js": minor
3+
"@paypal/paypal-js": patch
4+
---
5+
6+
Allows button message amount type to be string

packages/paypal-js/types/components/buttons.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ export type PayPalButtonStyle = {
273273
};
274274
export type PayPalButtonDisplayOnly = DisplayOnlyOptions[];
275275
export type PayPalButtonMessage = {
276-
amount?: number;
276+
amount?: number | string;
277277
align?: "center" | "left" | "right";
278278
color?: "black" | "white";
279279
position?: "top" | "bottom";

packages/react-paypal-js/src/components/PayPalButtons.test.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,4 +446,21 @@ describe("<PayPalButtons />", () => {
446446
).toBeFalsy();
447447
spyConsoleError.mockRestore();
448448
});
449+
450+
test("should accept button message amount as a string", async () => {
451+
render(
452+
<PayPalScriptProvider options={{ clientId: "test" }}>
453+
<PayPalButtons
454+
message={{ amount: "100" }}
455+
/>
456+
</PayPalScriptProvider>
457+
);
458+
459+
await waitFor(() =>
460+
expect(window.paypal?.Buttons).toHaveBeenCalledWith({
461+
message: { amount: "100" },
462+
onInit: expect.any(Function),
463+
})
464+
);
465+
});
449466
});

packages/react-paypal-js/src/components/braintree/BraintreePayPalButtons.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,27 @@ describe("render Braintree PayPal button component", () => {
365365
});
366366
});
367367
});
368+
369+
test("should accept button message amount as a string", async () => {
370+
const options = {
371+
clientId: "test",
372+
dataClientToken: CLIENT_TOKEN,
373+
};
374+
render(
375+
<PayPalScriptProvider options={ options }>
376+
<BraintreePayPalButtons
377+
message={{ amount: "100" }}
378+
/>
379+
</PayPalScriptProvider>
380+
);
381+
382+
await waitFor(() => {
383+
const mockButtons = (window.paypal &&
384+
window.paypal.Buttons) as jest.Mock;
385+
expect(mockButtons).toBeCalledWith({
386+
message: { amount: "100" },
387+
onInit: expect.any(Function),
388+
})
389+
});
390+
});
368391
});

0 commit comments

Comments
 (0)