From 493f279be26b4689bc81acda4cdd07a60e5b150e Mon Sep 17 00:00:00 2001 From: Polo Li <65737086+pololi-stripe@users.noreply.github.com> Date: Wed, 14 Aug 2024 13:25:10 -0700 Subject: [PATCH] Update EmbeddedCheckoutProvider prop types (#525) --- package.json | 2 +- .../EmbeddedCheckoutProvider.test.tsx | 32 +++++++++++++++++++ src/components/EmbeddedCheckoutProvider.tsx | 12 +++++++ yarn.lock | 8 ++--- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index c82aaba..ab01fbb 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "@rollup/plugin-replace": "^5.0.5", "@rollup/plugin-terser": "^0.4.4", "@storybook/react": "^6.5.0-beta.8", - "@stripe/stripe-js": "^4.0.0", + "@stripe/stripe-js": "^4.3.0", "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^13.1.1", "@testing-library/react-hooks": "^8.0.0", diff --git a/src/components/EmbeddedCheckoutProvider.test.tsx b/src/components/EmbeddedCheckoutProvider.test.tsx index ff1c731..1001719 100644 --- a/src/components/EmbeddedCheckoutProvider.test.tsx +++ b/src/components/EmbeddedCheckoutProvider.test.tsx @@ -382,6 +382,38 @@ describe('EmbeddedCheckoutProvider', () => { ); }); + it('does not allow changes to onShippingDetailsChange option', async () => { + const optionsProp1 = { + fetchClientSecret, + onShippingDetailsChange: () => Promise.resolve({type: 'accept' as const}), + }; + const optionsProp2 = { + fetchClientSecret, + onShippingDetailsChange: () => Promise.resolve({type: 'reject' as const}), + }; + // Silence console output so test output is less noisy + consoleWarn.mockImplementation(() => {}); + + const {rerender} = render( + + ); + await act(() => mockEmbeddedCheckoutPromise); + + rerender( + + ); + + expect(consoleWarn).toHaveBeenCalledWith( + 'Unsupported prop change on EmbeddedCheckoutProvider: You cannot change the onShippingDetailsChange option after setting it.' + ); + }); + it('destroys Embedded Checkout when the component unmounts', async () => { const {rerender} = render(
diff --git a/src/components/EmbeddedCheckoutProvider.tsx b/src/components/EmbeddedCheckoutProvider.tsx index b8af0c7..c33137b 100644 --- a/src/components/EmbeddedCheckoutProvider.tsx +++ b/src/components/EmbeddedCheckoutProvider.tsx @@ -54,6 +54,9 @@ interface EmbeddedCheckoutProviderProps { clientSecret?: string | null; fetchClientSecret?: (() => Promise) | null; onComplete?: () => void; + onShippingDetailsChange?: ( + event: stripeJs.StripeEmbeddedCheckoutShippingDetailsChangeEvent + ) => Promise; }; } @@ -208,6 +211,15 @@ export const EmbeddedCheckoutProvider: FunctionComponent