Checkout: Fetch PayPal configuration directly in calypso #97487
Merged
+57
−13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed Changes
When the
@automattic/calypso-paypal
package was made, I decided to use thewpcom-proxy-request
package directly to call the/me/paypal-configuration
endpoint. This seemed to be a simpler way to make a network call without needing to inject the fetching function from the call-site. However, it's possible that there are some cases where it fails. We've seen some intermittent fatals in thepaypal-js
submit button that appear to originate at this API call.In this PR, I return to the way of making an API call inside an external package that I'm used to: injecting the call as an argument, or in this case a prop, to
PayPalProvider
. The call can then be made withwp.req.get()
directly inside the calypso app.This PR also modifies the provider so that if there is an error calling the endpoint, it will call a custom error handler function which is also injected, rather than throwing at runtime. This should allow us to log such failures without causing fatal errors.
Testing Instructions
To verify that the happy path still works: add a product to your cart and visit checkout. Then verify that PayPal is an option in the list of payment methods and that there are no errors related to the payment method in the console.
To test the failure state, you'll need to modify something. Either you need to modify the paypal configuration endpoint to fail, or modify the new injected function (
fetchPayPalConfiguration
) to throw. Verify that when you load checkout you see an error logged in the console but that checkout itself should be unaffected. The only difference is that PayPal should not show up as a payment method option.Here's an example of how to break the configuration: