Finally, I found a solution, and I thought I should post it here so that it can be useful to others.
So, there are basically 4 next steps, and you need to use the PayPal Node SDK
- Create payment.
- Redirect user to PayPal.
- Make an authorized payment.
- Authorized Payment Capture.
To create a payment, you can use the payment.create method for PayPal Node sdk here .
The .Create Method will return the URL links to "href" to redirect the user to the PayPal page, to redirect the user to the PayPal page.
After returning from the PayPal page, you should run the .execute method for the PayPal Node SDK here , using payer_id and paymentId received from PayPal.
and finally, when you need to record the amount of the allowed transaction, you should .authorization.capture use the PayPal Node SDK method here , indicating the amount and 17 authorization identifiers received in response to the authorization.
An example code and response is provided below if links in the future do not work.
.create Code
var create_payment_json = { "intent": "authorize", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": "http://return.url", "cancel_url": "http://cancel.url" }, "transactions": [{ "item_list": { "items": [{ "name": "item", "sku": "item", "price": "1.00", "currency": "USD", "quantity": 1 }] }, "amount": { "currency": "USD", "total": "1.00" }, "description": "This is the payment description." }] }; paypal.payment.create(create_payment_json, function (error, payment) { if (error) { console.log(error.response); throw error; } else { for (var index = 0; index < payment.links.length; index++) { //Redirect user to this endpoint for redirect url if (payment.links[index].rel === 'approval_url') { console.log(payment.links[index].href); } } console.log(payment); } });
Response Sample
{ "id": "PAY-17S8410768582940NKEE66EQ", "create_time": "2013-01-31T04:12:02Z", "update_time": "2013-01-31T04:12:04Z", "state": "approved", "intent": "authorize", "payer": { "payment_method": "credit_card", "funding_instruments": [ { "credit_card": { "type": "visa", "number": "xxxxxxxxxxxx0331", "expire_month": "11", "expire_year": "2018", "first_name": "Betsy", "last_name": "Buyer", "billing_address": { "line1": "111 First Street", "city": "Saratoga", "state": "CA", "postal_code": "95070", "country_code": "US" } } } ] }, "transactions": [ { "amount": { "total": "7.47", "currency": "USD", "details": { "tax": "0.03", "shipping": "0.03" } }, "description": "This is the payment transaction description.", "related_resources": [ { "sale": { "id": "4RR959492F879224U", "create_time": "2013-01-31T04:12:02Z", "update_time": "2013-01-31T04:12:04Z", "state": "completed", "amount": { "total": "7.47", "currency": "USD" }, "parent_payment": "PAY-17S8410768582940NKEE66EQ", "links": [ { "href": "https://api.sandbox.paypal.com/v1/payments/sale/4RR959492F879224U", "rel": "self", "method": "GET" }, { "href": "https://api.sandbox.paypal.com/v1/payments/sale/4RR959492F879224U/refund", "rel": "refund", "method": "POST" }, { "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-17S8410768582940NKEE66EQ", "rel": "parent_payment", "method": "GET" } ] } } ] } ], "links": [ { "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-17S8410768582940NKEE66EQ", "rel": "self", "method": "GET" } ] }
.execute Code
var paymentId = 'PAYMENT id created in previous step'; paypal.payment.execute(paymentId, execute_payment_json, function (error, payment) { if (error) { console.log(error.response); throw error; } else { console.log("Get Payment Response"); console.log(JSON.stringify(payment)); } });
Response Sample
{ "id": "PAY-34629814WL663112AKEE3AWQ", "create_time": "2013-01-30T23:44:26Z", "update_time": "2013-01-30T23:44:28Z", "state": "approved", "intent": "aurthorize", "payer": { "payment_method": "paypal", "payer_info": { "email": " bbuyer@example.com ", "first_name": "Betsy", "last_name": "Buyer", "payer_id": "CR87QHB7JTRSC" } }, "transactions": [ { "amount": { "total": "7.47", "currency": "USD", "details": { "tax": "0.04", "shipping": "0.06" } }, "description": "This is the payment transaction description.", "related_resources": [ { "sale": { "id": "1KE4800207592173L", "create_time": "2013-01-30T23:44:26Z", "update_time": "2013-01-30T23:44:28Z", "state": "completed", "amount": { "currency": "USD", "total": "7.47" }, "transaction_fee": { "value": "0.50", "currency": "USD" }, "parent_payment": "PAY-34629814WL663112AKEE3AWQ", "links": [ { "href": "https://api.sandbox.paypal.com/v1/payments/sale/1KE4800207592173L", "rel": "self", "method": "GET" }, { "href": "https://api.sandbox.paypal.com/v1/payments/sale/1KE4800207592173L/refund", "rel": "refund", "method": "POST" }, { "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-34629814WL663112AKEE3AWQ", "rel": "parent_payment", "method": "GET" } ] } } ] } ], "links": [ { "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-34629814WL663112AKEE3AWQ", "rel": "self", "method": "GET" } ] }
.authorization.capture Code
var capture_details = { "amount": { "currency": "USD", "total": "4.54" }, "is_final_capture": true }; paypal.authorization.capture("5RA45624N3531924N", capture_details, function (error, capture) { if (error) { console.error(error); } else { console.log(capture); } });
Response Sample
{ "id": "6BA17599X0950293U", "create_time": "2013-05-06T22:32:24Z", "update_time": "2013-05-06T22:32:25Z", "amount": { "total": "4.54", "currency": "USD" }, "is_final_capture": true, "state": "completed", "parent_payment": "PAY-44664305570317015KGEC5DI", "links": [ { "href": "https://api.sandbox.paypal.com/v1/payments/capture/6BA17599X0950293U", "rel": "self", "method": "GET" }, { "href": "https://api.sandbox.paypal.com/v1/payments/capture/6BA17599X0950293U/refund", "rel": "refund", "method": "POST" }, { "href": "https://api.sandbox.paypal.com/v1/payments/authorization/5RA45624N3531924N", "rel": "authorization", "method": "GET" }, { "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-44664305570317015KGEC5DI", "rel": "parent_payment", "method": "GET" } ] }
You can get more information from the REST API Reference and PayPal-node-SDK .
Forgive me if the sample response has changed a bit, because I copied it from the PayPal network.
Thanks.