npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mern_pay

v1.0.6

Published

Help MERN developers to add payments to their app

Downloads

10

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

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' ,
'[email protected]',
'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

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