How to integrate Paypal with node js into REST way - node.js

I need to integrate paypal with node js ( first time ). But node js working as REST server with frontend built on mobile ( Android and iOS ). I think purpose of using return url and cancel url for web based frontend not for mobile.
Previously I implemented Stripe payment gateway which have simple system which generate a auth token on mobile and mobile sent this token to Node Js Rest API. So not node js application have buyer auth token and it process the required payment.
But I am very much confused how Paypal achieve same scenario.
UPDATE : I am using paypal official node js package https://github.com/paypal/PayPal-node-SDK
UPDATE : After more search, I see some steps in payment flow
User paypal payment create API into my REST API to get "payment id" and links.
Hit on approval_url link which used for fullfill buyer information on paypal site. After completion, Paypal hit automatically described return url in first API, along with payment id and payer id params.
In Return API, use payment id and payer id params to paypal payment execute API.
If all above is actual process to generate payment, Then I am assuming that Backend API only needed third Step which API url could be shared with mobile developer in their integration of paypal.
So Mobile will
create payment
Fill Buyer information
While Paypal automatically hit return url where backend API will execute payment.
If this is the recommended ( or only ) way to paypal integration with mobile and rest apis ?

The purpose of return and cancel url is to notify the client(mobile or web) for potential user action, if user completes payment then via return url and if user cancels payments via cancel Url
You can use rest or nvp PayPal will support both, they have rest endpoints which you can use to complete the transaction.
https://github.com/santhoshlfms/Android_PayPal_EC_NodeJs_Server_Sample (Node server)
https://github.com/santhoshlfms/Android_PayPal_EC_CustomTab_Demo (Mobile Front end)
you can follow these repo to figure out how to proceed.

Related

How to get details of an express checkout - PayPal / Postman

I'm trying to get the details of payment after test an express checkout.
When I go to
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-0CS36485JR5738828
It shows the checkout and I click on confirm.
After that, I'm being redirected to http://return.url/?paymentId=PAYID-MHKJM6A3W026542BR076654N&token=EC-0CS36485JR5738828&PayerID=HUGNJ49ZGF8CU
Here I have the paymentID, but I can't find an endpoint to see the details of that payment.
And I have a Webhook too with the event Checkout checkout buyer-approved, if I simulate an event, the webhook responds and sends the data to my backend, but it doesn't do it when I do an express checkout.
Now I'm trying almost everything with Servistate (Postman-like), but the idea is to make an express checkout, and confirm that payment on the backend.
Note: On my backend, I'm using paypal-rest-sdk package to generate the payment and with that, the checkout url
The PAYID token was created using the v1/payments API.
Use that API to get the status of the payment.
Note that the v1/payments API is deprecated, you should use the v2/checkout/orders API for payment processing instead. See the current PayPal Checkout documentation, and be sure to read through the 5th bullet in 'Add and modify the code' which discusses a server integration.

How can I make payment using credit/debit cards using PayPal payment gateway in Node.js?

I am currently using paypal-rest-sdk and want to accept payment using the cards.
In both sdk's (paypal rest and paypal checkout), when I create an order, in response there is an approve URL:
{
"href":"https://www.sandbox.paypal.com/checkoutnowtoken=token",
"rel":"approve",
"method":"GET"
}
Which will take you to this page:
The payment with PayPal account (logging in) is working, it correctly redirects to the return URL.
However, the "Pay with Credit or Debit card" option is not working.
After filling the card information when I click on continue button a loading screen appears and nothing happens after that.
I have seen solutions using PayPal smart-buttons, but can it work using "Pay with Credit or Debit card" option?
What do you mean by "paypal-rest-sdk" ? The PayPal-Node-SDK is deprecated, do not use it for anything. Use the current Checkout-NodeJS-SDK.
Follow the Set up standard payments guide and make 2 routes on your server, one for 'Create Order' and one for 'Capture Order', documented here. Both 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

Test stripe api payment using google pay token

I have set up a Google Pay button on the front end of my website and have tested communicating with the Google Pay API and have successfully received a response.
I have a Laravel project (PHP) so the front end sends this data to the server to be processed.
Once I have this response however I am not sure how to pass the required information to stripe api. From my understanding I need to pass the token received in the response to stripe's api but not sure how to formulate the request to stripe using this token.
Any assistance would be greatly appreciated
On your PHP side, you need to create a Charge on Stripe: https://stripe.com/docs/api/charges/create , using stripe-php library.
The Stripe Token you got from Google Pay, you would pass that under the source: tok_123 parameter.
(recommended) If you are using PaymentIntent/PaymentMethod objects, you would create a PaymentIntent (https://stripe.com/docs/api/payment_intents/create) using the API and pass payment_method: pm_123.

Stripe integration - best approach for front end and back end

I'd like to ask about best approach for integrating Stripe payment for FrontEnd and Backend.
As far as I understand from webpage https://stripe.com/docs/payments/integration-builder we should use following flow:
FrontEnd asks Backend for clientSecret to continue payment. That means that Backend doesn't have to know about credit card and other secured information, but can securely build request from payment and calculate amount to be paid.
Once Stripe payment is finished FrontEnd gets the result of payment and then can send paymentId to the
Backend and Backed receives details from Stripe based on paymentId.
Is it the best and most secured way of payment? What should happend in case of issues with FrontEnd - payment is successfully processed, but because of some issue paymentId was not send to the Backend?

Paypal integration with Paypal IPN

Need some help for Paypal integration. I did all the configuration what is mentioned in the documentation like: Paypal gateway URL, Return URL (Success), and Notification url (~/CMSModules/Ecommerce/CMSPages/PayPalIPN.aspx). But my order status is not updating even after the successful payment.
Using sandbox account for testing
Able to redirect to Paypal page (Sandbox account) and on completion of payment, successfully redirected back to site (thank you page) configured as Return URL in settings
Below is the sample return URL from after succesfult payment
/ConfirmPaypalPayment.aspx?amt=5.00&cc=USD&cm=en-US&item_name=Order%20ID%3A%201177&st=Completed&tx=83L5281177755044V
How can I make sure PaypalIPN is executed properly,
what else I need to do/check other than what I mentioned above.
Can we debug the the code PaypalIPN.asps.cs
Is there any webpart I need to add on the thank you page(ConfirmPaypalPayment)
I am testing this in my local site with Sandbox account
Please suggest.
Thanks,
Sharath
Documentation says: The default Kentico PayPal provider does not utilize payment notifications – Webhooks or Instant Payment Notification (IPN). If you require payment notifications for any custom functionality or integrations, you need to configure the related options for your PayPal Business account and implement the required handlers (either within the Kentico web project or a custom project).
The return page(thank you page) must contain the PayPal payment execution web part, which processes the payment URL parameters provided by PayPal and completes transactions.
So there is no IPN in the default payment flow, if you want to use IPN take a look at Creating a custom payment gateway. There is there an explanation and a code sample.

Resources