paypal-express-checkout-simple
PayPal Express Checkout implementation in Node.JS
If you got confused by PayPal instructions, If you are looking on how to charge your customers with paypal this is the simple solution. Whether you are using angularjs or any single page app or you just serve your html pages from node directly you can use this component.
Installation
npm install paypal-express-checkout-dt
Examples
Simplest example
- Set your paypal sandbox credentials runnning:
export API_USERNAME=your_username && export API_PASSWORD=your_password && export SIGNATURE=your_signature
- Run
cd example && npm i && npm start
and go to http://localhost:8893/index.html - you will see the full paypal flow
Tests
Run npm test to make sure everything works fine.
Usage
This is how we implement this component, any improvement is welcoming.
- SetExpressCheckout: the server gets POST request to setExpressCheckout
/** * Set the buy parameters. * * @param * @param * @param * @return */{ let paypal = PayPal paypal //TODO make a function for this //seting billing type as RecurringPayments paypalpayOptions"L_BILLINGTYPE0" = "RecurringPayments" paypalpayOptions"L_BILLINGAGREEMENTDESCRIPTION0" = reqbodyproductdescription let paypalItems = name: reqbodyproductname description: reqbodyproductdescription quantity: 1 amount: reqbodyproductamount days: reqbodyproductdays paypal; let paymentEnding = let order = uuid paypal}
- With the result from SetExpressCheckOut you can show the result or redirect to GetExpressCheckOutDetails like in this example.
/** * Charge and get the details. * * @param * @param * @param * @return */{ let paypal = PayPal paypal}
- How we manage the pending payments. We create a cronjob wich run every 4 hours.
/** * Check if the pending transaction are now completed * @param * @param * @param * @return */ { let last24hrs = let query = created_at: $gte: last24hrs $lte: status: 2 Payment}
- Additionally if you want the add some other pay options do it in this way.
for instance you can set the billing type.
//old way paypal //new feature to add pay options, you can combine the two var options = name: "L_BILLINGTYPE0" value: "RecurringPayments" name: "L_BILLINGAGREEMENTDESCRIPTION0" value: "Silly description" paypal;
Please feel free to comment and contribute.
License
MIT