# mern_pay

> Help MERN developers to add payments to their app

Latest version **1.0.6** (published 2022-06-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install mern_pay
pnpm add mern_pay
yarn add mern_pay
bun add mern_pay
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2022-06-08 |
| First published | 2022-06-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.3 KB |
| Known vulnerabilities | 0 (+24 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Gaurav Bansal |
| Maintainers | gaurav_bansal |
| Keywords | payment, mern-payment, pay, payment-gateway, razorpay, payment-india |

## Links

- npm: https://www.npmjs.com/package/mern_pay
- Repository: https://github.com/GauravBansal29/mern_payment-npm-package
- Homepage: https://github.com/GauravBansal29/mern_payment-npm-package#readme
- Issues: https://github.com/GauravBansal29/mern_payment-npm-package/issues
- npm.io page: https://npm.io/package/mern_pay

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^0.27.2

## Recent versions

- 1.0.6 (latest) — 2022-06-08
- 1.0.5 — 2022-06-08
- 1.0.4 — 2022-06-08
- 1.0.3 — 2022-06-08
- 1.0.2 — 2022-06-08
- 1.0.1 — 2022-06-08
- 1.0.0 — 2022-06-08

## README

# What is this ?

Get payment gateway in your MERN app by using this package.

# Installation and Setup

1. Using `npm i mern_pay` ,add package in both your server and client side of app
2. Go to https://razorpay.com/ , Login and make a Razorpay account.
3. Go to Setting -> API keys -> Generate API keys
4. Store the _KEY_ID_ and _KEY_SECRET_ in the .env file by name **RAZORPAY_KEY_ID** and **RAZORPAY_KEY_SECRET** in your backend.

# Usage

## Client Side

`import {processPayment} from 'mern-pay'`

call `processPayment` function with following parameters:

    processPayment(
    server,
    amount,
    customer_name,
    description ,
    customer_email,
    customer_contact,
    color_theme,
    onSuccess,
    onFailure)

- server - Add url of location where your server for the project is running
- amount - Add amount you want to get from the customer
- customer_name - Add name of the customer
- description - Purpose of payment
- customer_email - Email id of customer
- customer_contacts - Contact number of customer
- color_theme - color of the gateway (give a hexadecimal string denoting the color)

*onSuccess* is a function which will be called on successful payment
It has 4 default parameters :

1. Amount
2. Razorpay Payment Id
3. Razorpay Order Id
4. Razorpay Payment Signature

*onFailure* is a function which will be called on payment failure

## Demo

```js
import {processPayment} from "mern_pay" `
 const getPayment= ()=>{ `

    const onSuccess=(a,b,c,d)=>{
        //a,b,c,d are amount, payment id, order id and razorpay signature
        // add something you want to execute on successfull payment 
        console.log("Got the payment");
    }
    const onFailure=()=>{
        //add something you want to execute on payment failure 
        console.log("Sorry its a decline");
    }

return
(<div className='btn btn-primary' onClick={()=>{processPayment(
'http://localhost:8000/api',
200,
'charles',
'payment for coffee' ,
'abc@xyz.com',
'9111111111',
'#0000FF',
onSuccess,
onFailure)}}>hello</div>);

}
export default getPayment;
```

**NOTE:** The ordering of the parameters is important and all the paramters are needed for the gateway to work properly.

## Server Side

`import {getKey, getOrder, paymentOrder} from "mern_pay"`

1. Make a get request to `/get-key` and pass getKey function to it
2. Make a post request to `/get-order` and pass getOrder function to it
3. Make a post request to `/payment-order` and pass paymentOrder function to it

## Demo

```js
import { getKey, getOrder, paymentOrder } from "mern_payment";

const router = require("express").Router();

router.get("/get-key", getKey);
router.post("/get-order", getOrder);
router.post("/payment-order", paymentOrder);

module.exports = router;
```

# Payment Gateway

<img width="691" alt="add payment pic" src="https://user-images.githubusercontent.com/77917141/172527183-c48e9c42-cb13-4018-b4cf-066070ad015f.png">
<img width="656" alt="pay2" src="https://user-images.githubusercontent.com/77917141/172527801-20f52216-0dc5-459b-a579-a8e357577c01.png">
<img width="680" alt="pay3" src="https://user-images.githubusercontent.com/77917141/172527813-27f253d7-fc3f-4612-91c4-168b4c46b886.png">

---
_Source: https://npm.io/package/mern_pay · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
