Skip to content

Commit

Permalink
feat: updates PayPalButtons to add message option
Browse files Browse the repository at this point in the history
  • Loading branch information
danzhaaspaypal committed Jun 7, 2024
2 parents 672a48d + 8213385 commit ee7cf02
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 9 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"homepage": "https://paypal.github.io/react-paypal-js/",
"dependencies": {
"@paypal/paypal-js": "^8.0.5",
"@paypal/paypal-js": "^8.1.0",
"@paypal/sdk-constants": "^1.0.122"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions src/components/PayPalButtons.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ describe("<PayPalButtons />", () => {
<PayPalButtons
fundingSource={FUNDING.CREDIT}
style={{ layout: "horizontal" }}
message={{ amount: 100 }}
/>
</PayPalScriptProvider>
);

await waitFor(() =>
expect(window.paypal?.Buttons).toHaveBeenCalledWith({
style: { layout: "horizontal" },
message: { amount: 100 },
fundingSource: FUNDING.CREDIT,
onInit: expect.any(Function),
})
Expand Down
7 changes: 6 additions & 1 deletion src/components/PayPalButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ export const PayPalButtons: FunctionComponent<PayPalButtonsComponentProps> = ({

return closeButtonsComponent;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isResolved, ...forceReRender, buttonProps.fundingSource]);
}, [
isResolved,
...forceReRender,

Check warning on line 125 in src/components/PayPalButtons.tsx

View workflow job for this annotation

GitHub Actions / main

React Hook useEffect has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies

Check warning on line 125 in src/components/PayPalButtons.tsx

View workflow job for this annotation

GitHub Actions / main

React Hook useEffect has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies
buttonProps.fundingSource,
buttonProps.message,
]);

// useEffect hook for managing disabled state
useEffect(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/components/braintree/BraintreePayPalButtons.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ describe("render Braintree PayPal button component", () => {
>
<BraintreePayPalButtons
style={{ layout: "horizontal" }}
message={{ amount: 100 }}
fundingSource={FUNDING.CREDIT}
createOrder={jest.fn()}
onApprove={jest.fn()}
Expand All @@ -328,6 +329,7 @@ describe("render Braintree PayPal button component", () => {
window.paypal.Buttons) as jest.Mock;
expect(mockButtons).toBeCalledWith({
style: { layout: "horizontal" },
message: { amount: 100 },
fundingSource: FUNDING.CREDIT,
createOrder: expect.any(Function),
onApprove: expect.any(Function),
Expand Down
7 changes: 7 additions & 0 deletions src/stories/braintree/BraintreePayPalButtons.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import type {

type StoryProps = {
style: PayPalButtonsComponentOptions["style"];
message: PayPalButtonsComponentOptions["message"];
fundingSource: FUNDING_SOURCE;
disabled: boolean;
amount: string;
Expand Down Expand Up @@ -66,6 +67,10 @@ export default {
control: { type: "object", expanded: true },
...COMPONENT_PROPS_CATEGORY,
},
message: {
control: { type: "object" },
...COMPONENT_PROPS_CATEGORY,
},
disabled: {
options: [true, false],
control: { type: "select" },
Expand Down Expand Up @@ -149,6 +154,7 @@ export default {

export const Default: FC<StoryProps> = ({
style,
message,
fundingSource,
disabled,
amount,
Expand All @@ -158,6 +164,7 @@ export const Default: FC<StoryProps> = ({
return (
<BraintreePayPalButtons
style={style}
message={message}
disabled={disabled}
fundingSource={fundingSource}
forceReRender={[style, amount, currency]}
Expand Down
7 changes: 7 additions & 0 deletions src/stories/payPalButtons/PayPalButtons.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import type { DocsContextProps } from "@storybook/addon-docs";

type StoryProps = {
style: PayPalButtonsComponentOptions["style"];
message: PayPalButtonsComponentOptions["message"];
fundingSource: FUNDING_SOURCE;
disabled: boolean;
showSpinner: boolean;
Expand Down Expand Up @@ -75,6 +76,10 @@ export default {
control: { type: "object" },
...COMPONENT_PROPS_CATEGORY,
},
message: {
control: { type: "object" },
...COMPONENT_PROPS_CATEGORY,
},
disabled: {
options: [true, false],
control: { type: "select" },
Expand Down Expand Up @@ -136,6 +141,7 @@ export default {

export const Default: FC<StoryProps> = ({
style,
message,
fundingSource,
disabled,
showSpinner,
Expand All @@ -157,6 +163,7 @@ export const Default: FC<StoryProps> = ({
{showSpinner && <LoadingSpinner />}
<PayPalButtons
style={style}
message={message}
disabled={disabled}
fundingSource={fundingSource}
forceReRender={[style]}
Expand Down

0 comments on commit ee7cf02

Please sign in to comment.