问题
For my users to be able to send money to each other on my website I figured the following flow:
- User is authenticated with paypal connect
- "Clicks on a pay button" calling my api
- In the api Create an order calling /v2/checkout/orders what returns HATEOAS links, order id. And, I need the user to follow the authorize order link from the HATEOAS links to authorize the order.
- User follows the link.
- I capture the order calling /v2/checkout/orders/{id}/capture
And, here is a question: how do I know when users follow the authorize order link to call the capture api? If that is not possible, is there a way to authorize orders calling the paypal api directly without making users following some links?
回答1:
First of all, what you are actually talking about is user "approval", not authorizing.
The best approval flow to use is this one: https://developer.paypal.com/demo/checkout/#/pattern/server
This way, they don't follow a link and are not redirected away from your site. Your site stays loaded, but is just greyed out while they are presented with an in-context approval flow, and return to your site's JS, which will do a fetch call to your server, which can then do the capture.
An alternative legacy flow is to provide a return_url in your initial create call, where the payer will be redirected back to after approval. This is not recommended, the above solution (that uses no redirects at all) is much more modern and preferred.
来源:https://stackoverflow.com/questions/65161718/is-there-a-way-to-authorize-orders-calling-the-paypal-api-directly