-
Notifications
You must be signed in to change notification settings - Fork 142
Feature: useBraintreePayPalOneTimePaymentSession hook #889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0140f8e
16eb36d
6086bb1
820bae6
92cf64b
34b89dc
dead06f
21c1a94
388847f
8945074
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@paypal/react-paypal-js": minor | ||
| --- | ||
|
|
||
| Adds Braintree PayPal One Time Payment Session hook. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /** | ||
| * Creates a Braintree payment session with error handling and retry prevention. | ||
| * | ||
| * @param sessionCreator - Function that creates the payment session | ||
| * @param failedInstanceRef - Ref tracking which checkout instance failed | ||
| * @param checkoutInstance - Current Braintree checkout instance | ||
| * @param setError - Error state setter | ||
| * @returns The payment session or null if creation fails | ||
| */ | ||
| export function createBraintreePaymentSession<T>( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this function is very similar to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea I went back and forth on this. Mostly b/c I thought it meant updating every usage of the new util with an error message. Let me investigate further.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We decided to take this up in a follow up, in order to keep the scope smaller. |
||
| sessionCreator: () => T, | ||
| failedInstanceRef: { current: unknown }, | ||
| checkoutInstance: unknown, | ||
| setError: (error: Error | null) => void, | ||
| ): T | null { | ||
| // Skip retry if this checkout instance already failed | ||
| if (failedInstanceRef.current === checkoutInstance) { | ||
| return null; | ||
| } | ||
|
|
||
| try { | ||
| return sessionCreator(); | ||
| } catch (err) { | ||
| failedInstanceRef.current = checkoutInstance; | ||
|
|
||
| const detailedError = new Error( | ||
| "Failed to create Braintree payment session. Ensure the BraintreePayPalProvider is properly initialized with a valid client token and namespace.", | ||
| { cause: err }, | ||
| ); | ||
|
|
||
| setError(detailedError); | ||
| return null; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pulled changes from main and ran
npm installthis updated a handful of packages to include apeerboolean.