Skip to content

Instantly share code, notes, and snippets.

@phplaw
Last active June 5, 2019 07:59
Show Gist options
  • Select an option

  • Save phplaw/32d213d248d373f67fe4d91d584fc756 to your computer and use it in GitHub Desktop.

Select an option

Save phplaw/32d213d248d373f67fe4d91d584fc756 to your computer and use it in GitHub Desktop.
Paypal Intergrate
// 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
// 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
@phplaw
Copy link
Author

phplaw commented Jan 7, 2019

NodeJS N PACKAGE ISSUES

sudo chown -R $(whoami) /usr/local/n
# we may need to run this
# sudo chown -R $(whoami) /usr/local/lib/node_modules/

We may need to run this

sudo chown -R $(whoami) /usr/local/bin/npm
sudo chown -R $(whoami) /usr/local/bin/node
sudo chown -R $(whoami) /usr/local/bin/npx

This seemed to be good solution

# make cache folder (if missing) and take ownership
sudo mkdir -p /usr/local/n
sudo chown -R $(whoami) /usr/local/n
# take ownership of node install destination folders
sudo chown -R $(whoami) /usr/local/bin /usr/local/lib /usr/local/include /usr/local/share
# no longer need sudo as you own the folders
n lts

@phplaw
Copy link
Author

phplaw commented Jun 5, 2019

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