This is going to be a tutorial which consists of three parts: Initial setup, using the PayPal SDK for Node.js and UI plus deployment to Heroku. After following all three steps you should be able to create an experience similar to this.
Part 1 – Setup
For the first part of the tutorial I’ll be going into the initial setup & required packages that we’re going to use to build our Node.js web app.
Our application is going to leverage the Express framework which basically is a Node.js alternative to the popular Ruby framework Sinatra. Looking into most popular Node projects, there is nearly not a single one server-side application running that doesn’t also leverage the capabilities that Express offers – it can be considered the de facto standard for Node.js development.
To install Express globally use the following command:
npm install -g express.
Setting up the project
After this has been sucessfully installed we’re going to create a new folder & use Express to setup a “blank” Node.js project:
The two files we’re going to concentrate on in this tutorial are
app.js is basicaly the skeleton of your application and is responsible for different things like setting up the right requirements (like Express or the PayPal SDK) and your application’s routes.
package.json contains all requirements and is important for the
npm install command which automatically gets executed when deploying a Node.js app to services like Heroku. After creation it should look something like this:
You’ll see that next to Express another dependency got defined already. Jade is an amazing template engine for Node.js that allows to write very minimal HTML. The asterisk defines that any version of Jade will do (which usually either uses an existant global version or installs the newest stable version available).
Having a look at
app.js you’ll see that there are two lines that we can get rid off:
/routes/user.js as we are not going to need it for this project.
The reason for getting rid of these two lines and
user.js is that they are an plainly an auto generated example for creating an API endpoint that returns a resource (in this case your application’s registered users).
In this tutorial most of the payments implementation is going to happen in
routes/index.js. This is the place that allows you to define the functions that get executed when your application receives HTTP requests.
app.js file should look now like this:
Having executed with the
-s parameter adds session support to your project which we’re going to need later to store some information during the checkout process. The two lines adding support for this are:
Feel free to change the your secret here to anything else that suits your needs.
You can run the project by executing
node app.js in your project’s root folder and navigating over to
Having finished all required setup we’re going to concentrate on the PayPal SDK integration in the next part of this tutorial. If you want to have a look already: Feel free to go over to pprestnode.herokuapp.com or the GitHub repository!
- New REST API Feature: Setting a Receiver for Payments
- PayPal is Now Available Through WooCommerce 2.6 Onboarding Wizard
- Adaptive Payments is Moving to Limited Release – What you Need to Know
- Building the Next Step in Payment Tutorials with Stack Overflow Docs
Connect with us!
- January 2017
- December 2016
- October 2016
- September 2016
- July 2016
- May 2016
- March 2016
- November 2015
- September 2015
- August 2015
- June 2015
- April 2015
- March 2015
- November 2014
- October 2014
- August 2014
- July 2014
- March 2014
- February 2014
- January 2014
- December 2013
- October 2013
- September 2013
- August 2013
- July 2013
- June 2013
- May 2013
- April 2013
- March 2013