Last active
June 5, 2019 07:59
-
-
Save phplaw/32d213d248d373f67fe4d91d584fc756 to your computer and use it in GitHub Desktop.
Paypal Intergrate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // return_url | |
| // credit_card || paypal | |
| //approval_url | |
| // paymentId | |
| // https://github.com/paypal/paypal-checkout/blob/master/docs/button.md | |
| // Build PayPal payment request | |
| // DEFINE PAYPMENT DATA | |
| var payReq = JSON.stringify({ | |
| intent:'sale', | |
| payer:{ | |
| payment_method:'paypal' | |
| }, | |
| redirect_urls:{ | |
| return_url:'http://localhost:3000/process', | |
| cancel_url:'http://localhost:3000/cancel' | |
| }, | |
| transactions:[{ | |
| amount:{ | |
| total:'10', | |
| currency:'USD' | |
| }, | |
| description:'This is the payment transaction description.' | |
| }] | |
| }); | |
| // EXECUTE PAYMENT | |
| paypal.payment.create(payReq, function(error, payment){ | |
| var links = {}; | |
| if(error){ | |
| console.error(JSON.stringify(error)); | |
| } else { | |
| // Capture HATEOAS links | |
| payment.links.forEach(function(linkObj){ | |
| links[linkObj.rel] = { | |
| href: linkObj.href, | |
| method: linkObj.method | |
| }; | |
| }) | |
| // If the redirect URL is present, redirect the customer to that URL | |
| if (links.hasOwnProperty('approval_url')){ | |
| // Redirect the customer to links['approval_url'].href | |
| } else { | |
| console.error('no redirect URI present'); | |
| } | |
| } | |
| }); | |
| // After the customer accepts the payment, | |
| // your app redirects the customer to the return_url or cancel_url that you defined in the payment object in | |
| var paymentId = req.query.paymentId; | |
| var payerId = { payer_id: req.query.PayerID }; | |
| paypal.payment.execute(paymentId, payerId, function(error, payment){ | |
| if(error){ | |
| console.error(JSON.stringify(error)); | |
| } else { | |
| if (payment.state == 'approved'){ | |
| console.log('payment completed successfully'); | |
| } else { | |
| console.log('payment not successful'); | |
| } | |
| } | |
| }); | |
| // DONE | |
| // https://developer.paypal.com/demo/checkout/#/pattern/validation // validate paypment | |
| // https://developer.paypal.com/docs/api/quickstart/payments/#execute-payment | |
| // https://developer.paypal.com/docs/checkout/integrate | |
| // https://developer.paypal.com/docs/checkout/how-to/customize-button/#customization-example |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://www.npmjs.com/package/paypal-express-checkout-simple | |
| // https://github.com/paypal/paypal-checkout-demo | |
| //https://github.com/Arfius/paypal-fast-checkout | |
| //https://github.com/visla/paypal-express-checkout |
Author
Author
What the point of using RegExp here?
Express patterns is simpler, yet almost as powerful as regular expressions:
app.get('/blog(?:/p/:page([0-9]+)?)?', blog.list);This route will match all of the following urls:
/blog
/blog/
/blog/p
/blog/p/
/blog/p/123
In blog.list controller req.params.page will contain page number or will be undefined if it wasn't supplied.
Source: https://stackoverflow.com/questions/17807825/regex-in-expressjs-route
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NodeJS N PACKAGE ISSUES
We may need to run this
This seemed to be good solution