Reputation: 1634
I have a .Net Core 3 project and I want to integrate Paypal.
In past projects I was using Paypal
package, but now I was reading their documentation and they recommend to use version 2 of their API. (Previously I was using version 1 with Paypal
SDK). If I go to the nuget.com and check the Paypal
package I see that version 2 of this package is still rc
:
Version Downloads Last updated
2.0.0-rc2 143,570 2018-04-12T18:17:40Z
Now it has been almost 2 years in this, so it doesn't look promising. If I check their docs again I find that they recommend using following package: PayPalCheckoutSdk
. Link to their docs. If I try to copy-paste an exampe it doesn't even compile (mainly due to some properties renamed). This really doesn't give a lot of confidence in using this package at all. My last resort would be just to call paypal API directly without using their provided SDK.
What is the best way to integrate paypal with my server running on .Net Core 3.1?
Options:
paypal 2.0.0-rc2
PayPalCheckoutSdk
Upvotes: 4
Views: 8210
Reputation: 30379
Call the v2/orders API directly.
Server-side create: https://developer.paypal.com/docs/api/orders/v2/#orders_create
Server-side capture: https://developer.paypal.com/docs/api/orders/v2/#orders_capture
Follow the PayPal Checkout integration guide and make 2 routes on your server, one for the 'Create Order' and one for 'Capture Order' (see the optional step 5 in 'Add and modify the code'). Both of these routes should return only JSON data (no HTML or text). Inside the 2nd route, when the capture API is successful you should store its resulting payment details in your database (particularly purchase_units[0].payments.captures[0].id
, which is the PayPal transaction ID) and perform any necessary business logic (such as sending confirmation emails or reserving product) immediately before forwarding your return JSON to the frontend caller.
Pair those 2 routes with the frontend approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server
Upvotes: 7