Sample Node.js app built on the Express.js framework that masks payment details using the ChargeIO.js tokenization library and submits charge requests to the AffiniPay Payment Gateway
This is a simple node app for accepting credit card payments on a website. Here's what it does:
- Provides a form for collecting credit card details and a payment amount.
- Exchanges credit card details for a one-time token without passing sensitive data through the local web server.
- Posts the one-time token and payment amount to an endpoint on the local web server using a callback (public/javascripts/event-handler.js).
- Submits a charge request to the AffiniPay Payment Gateway using the one-time token and payment amount.
This app requires AffiniPay Payment Gateway API keys, which include a public and test- or live-mode secret key.
-
Public key: The ChargeIO.js tokenization library needs to know your merchant identity to create payment tokens. You identify yourself by providing your public key, which is safe to expose in web pages (as opposed to your secret key, which must be safeguarded).
-
Secret key: Used to authenticate requests from your web server to the AffiniPay Payment Gateway when running charges and performing other operations.
Your secret keys provide access to sensitive operations affecting payments and therefore must be closely guarded. Never expose these keys in any publicly-accessible web pages, JavaScript, etc.
This app is written in Node.js, which must be installed prior to use. Node.js includes the Node Package Manager (NPM), which is used for installing dependencies.
-
Clone the repository:
$ git clone git@github.com:jeff-matthews/payment-page.git
-
Open a terminal and navigate to the new directory:
$ cd payment-page
-
Install dependencies:
$ npm install
-
Log in to the AffiniPay web app.
-
Obtain your AffiniPay Payment Gateway API keys.
-
Enter your public key in the
views/layout.pug
template to initialize the ChargeIO.js library:script. ChargeIO.init({public_key: '<add-your-key-here>'});
-
Add your live- or test-mode secret key to your web server. [TODO]
-
Start the server:
$ npm start
Use
DEBUG=app.js:* npm start
to launch the app in debug mode. -
Open a web browser and go to http://localhost:3000.
-
Enter payment details in the form.
-
Click Submit.
Contributions in the form of GitHub pull requests are welcome. Please adhere to the following guidelines:
- Before embarking on a significant change, please create an issue to discuss the proposed change and ensure that it is likely to be merged.
- Follow the coding conventions used throughout the project, including 2-space indentation and no unnecessary semicolons. Many conventions are enforced using eslint.
- Any contributions must be licensed under the MIT license.
MIT © Jeff Matthews