Whenever the initializePayment () is called, it expects the form object to be passed in as the first argument and a callback function as the second. With that, we are through with the initializePayment(). mycallback would be well defined to run after initializePayment runs whenever we call it.Īnd finally we call the request.post() which is request convenience method to initialize a POST request passing in the request options object and the request callback created just above. Request callback gets 3 arguments:Īll our call back does is return the callback function (mycallback) passed into the initializePayment passing in the error and body from the request. PASSING FUNCTION INTO PUG TEMPLATE FULLthe form object which will contain the full name, email, amount and other needed paramters for the actual transaction.If you look carefully, you’ll realize we have an options object with all the paramters for our request set: const mongoose = require (‘mongoose’) nnect(‘mongodb://localhost:27017/online_payment’, If our application is trying to persist some data to the database and it does not find it, it would create it first before inserting into it.Īt the end, we export it so it can be used in other JavaScript files within our project. Remember, with MongoDB we do not need to explicitly create a database. Next, we create a connection to the MongoDB database ‘online_payment’ on our local machine on the port 27017. PASSING FUNCTION INTO PUG TEMPLATE CODEIn the mongoose.js file, add the following code snippet to establish a connection our MongoDB database.įirstly, we import the mongoose module installed in our project and stored it to a constant name ‘mongoose’. PASSING FUNCTION INTO PUG TEMPLATE HOW TORead more on how to set up Node.js and MongoDB It would hold the connection to the database using the mongoose module: a MongoDB database driver. Go ahead and create a “mongoose.js” file in the config directory. Let’s set up our connection to the database. Setup the MongoDB database model using mongoose So, go ahead and create the “app.js” file in the root of the online_payment directory. We would also need an “app.js” file from which our webserver would be served. In the root of the online_payment directory create three directories We’ll set up our directory structure next. PASSING FUNCTION INTO PUG TEMPLATE INSTALLNpm install express request body-parser pug mongoose -save Don’t forget you’ll need internet connection to successfully install the packages. Just run this line on the CLI from the root of the project directory. Next let’s install the Node.js modules we’ll be using in this project: Next we’ll initialize node running npm init from the project directory on cli (Fill the desired details, but the defaults would do by just pressing “enter” each time and entering ‘yes’ for the final step) npm init Installing the needed packages for the project Run the following command to navigate to the “online_payment” directory created on the desktop: cd desktop cd online_payment Open your CLI by searching for “cmd” from the start menu. PASSING FUNCTION INTO PUG TEMPLATE WINDOWSTo do that we’ll create a directory for our donation platform on the desktop (I’m using a windows system). The only downside is that you wont be getting any real money. The unverified account is actually ok to follow up. You’ll also be required to have a Paystack account, its actually free. If you have issues setting up Node.js or MongoDB check out this article on Setting Up Node.js and MongoDB In the land of Node.js, and the time of online payments, the destiny of a Charity Company rests on the shoulders of a young programmer, named… YOU! What you need to know?īut at this point I assume you are familiar with the basics of Node.js and MongoDB that you have Node.js and MongoDB already installed. It’s just a simple 2-page system with a donation and success or failure. To fully comprehend this, we would be creating a donation payment system. Creating endpoints for payment and confirmation Building our own paystack payment moduleī. Setting up the MongoDB database model using mongoose Installing the needed Node.js packages for the project So we are going to start with baby steps: It starts with an initialization of a transaction and a redirect to the payment platform and finally back to your site with a response of success or failure. We would try to modularize the project structure to easily scale to incorporating other payment platforms.īasically, payment platforms use almost the same replica process for accepting payments online. In this article, we are going to take a trip to the world of online payment integration using Paystack API as a case study. Payment Integration With Node.Js: Express, Request and Paystack APIĪ good number of website owners today need channels for online payment especially as the sector has grown in lips and bounds.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |