Code Monkey home page Code Monkey logo

paymob-payment-gateway's Introduction

GIF

PayMob Integration for Node.js Application

This project provides integration with the PayMob payment gateway in a Node.js application, allowing you to process payments, retrieve transactions, and perform void and refund operations.

Features

  • Process payments securely using PayMob payment gateway
  • Retrieve transaction details for analysis and reporting
  • Perform void and refund operations on transactions
  • Easy integration into Node.js applications with clean and readable code

Installation

  1. Clone the repository or download the source code.
  2. Install the required dependencies by running the following command:
npm install
  1. Create a .env file in the root directory of the project and add the following environment variables:
PAY_API
HMAC_KEY
PASSWORD
USERNAME
MONGO_URI
PORT
  1. Run the application using the following command:
npm start

Project flow

src/utils/authenticate.js

This file contains the authenticate function, which is used to authenticate the application with the PayMob payment gateway. It takes the following parameters:

  • username: The username of the PayMob account
  • password: The password of the PayMob account
  • api_key: The API key of the PayMob account

The function returns a promise that resolves to an object containing the following properties:

  • token: The token to be used for authentication aka access token

src/utils/checkout.js

This file contains the checkout function, which is used to register an order to Accept's database and obtain payment_key token for this order, think of it as a wrapper around the payment flow found in paymob documentation It takes the following parameters:

  • order_cart: An array of objects containing the items to be purchased
  • amount_cents: The total amount to be paid in cents
  • billing_data: An object containing the billing details of the customer

and returns a promise that resolves to an object containing the following properties:

  • id: The ID of the order

the function then proceeds to create the payment key token for this order and returns a promise that resolves to an object containing the following properties:

  • token: The payment key token

this token is then used in the iframe to redirect the user to the payment page

void, get_transaction, refund

These functions are used to perform void, get transaction details, and refund operations respectively. all of them need to be authenticated first using the authenticate function then continue with the operation.

Rest Examples

in the rest folder you can find examples of how to use the routes in the project, take a look at them to get a better understanding of how to use the project but in general the flow is as follows:

  • create an order using the checkout
  • Do any the following operations:
    • get the transaction details using get_transaction
    • get the order status using orders
  • if the payment is not captured yet, you can void it using void
  • if the payment is captured, you can refund it using refund

Acknowledgements

This project was inspired by the need to integrate PayMob payment gateway into Node.js applications, making it easier to handle payments and related operations especially in Egypt.

Special thanks to the PayMob team for providing the support for integrating with their payment gateway.

License

This project is licensed under the MIT License. You are free to use, modify, and distribute the code.

paymob-payment-gateway's People

Contributors

rafa763 avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.