Mitrahsoft
  • SERVICES
    • OUR SERVICES
      • SOFTWARE DEVELOPMENT
      • MOBILE DEVELOPMENT
      • BLOCKCHAIN DEVELOPMENT
      • SOFTWARE TESTING
      • CLOUD & DEVOPS SERVICES
      • PRODUCT DEVELOPMENT
      • OFFSHORE DEVELOPMENT
      • SOCIAL MEDIA MARKETING
      TECHNOLOGIES
      • COLDFUSION DEVELOPMENT
      • REACTJS DEVELOPMENT
      • VUEJS DEVELOPMENT
      • ANGULAR DEVELOPMENT
      • NODEJS DEVELOPMENT
      • PYTHON DEVELOPMENT
      • GOLANG DEVELOPMENT
      • GOLANG CORPORATE TRAINING
      COLDFUSION EXPERTISE
      • MURACMS EXPERTISE
      • COLDFUSION APP MIGRATION
      • COLDFUSION HOSTING & SUPPORT
      • CF LEGACY APP MAINTENANCE
      • COLDFUSION REST API
      • ECOMMERCE / SHOPPING CART SOLUTIONS
      • PRESIDECMS EXPERTISE
      MOBILE DEVELOPMENT
      • REACT NATIVE DEVELOPMENT
      • FLUTTER DEVELOPMENT
      • IONIC DEVELOPMENT
      • PHONEGAP DEVELOPMENT
  • ABOUT US
    • ABOUT MITRAHSOFT
    • OUR CLIENTS
    • TESTIMONIALS
    • PORTFOLIO
    • CAREERS
  • CONTACT US
  • BLOG
Adobe Solution PartnerLucee Solution Partner
Adobe Solution PartnerLucee Solution Partner
Adobe Solution PartnerLucee Solution Partner
  • OUR SERVICESSOFTWARE DEVELOPMENTMOBILE DEVELOPMENTBLOCKCHAIN DEVELOPMENTSOFTWARE TESTINGCLOUD & DEVOPS SERVICESPRODUCT DEVELOPMENTOFFSHORE DEVELOPMENTSOCIAL MEDIA MARKETING
    TECHNOLOGIESCOLDFUSION DEVELOPMENTREACTJS DEVELOPMENTVUEJS DEVELOPMENTANGULAR DEVELOPMENTNODEJS DEVELOPMENTPYTHON DEVELOPMENTGOLANG DEVELOPMENTGOLANG CORPORATE TRAINING
    COLDFUSION EXPERTISEMURACMS EXPERTISECOLDFUSION APP MIGRATIONCOLDFUSION HOSTING & SUPPORTCF LEGACY APP MAINTENANCECOLDFUSION REST API ECOMMERCE / SHOPPING CART SOLUTIONSPRESIDECMS EXPERTISE
    MOBILE DEVELOPMENTREACT NATIVE DEVELOPMENTFLUTTER DEVELOPMENTIONIC DEVELOPMENTPHONEGAP DEVELOPMENT
  • ABOUT MITRAHSOFTOUR CLIENTSTESTIMONIALSPORTFOLIOCAREERS
  • CONTACT US
  • BLOG

Stripe Payement Integration Using ReactJS & NodeJS

HomeBlogStripe Payement Integration Using ReactJS & NodeJS
Payment-gatewayNodeJSReactJS

Stripe Payement Integration Using ReactJS & NodeJS

M
Post by MitrahsoftPublished: Jan 4, 2019

Stripe is a payment platform with a well documented API for developers. Stripe is the alternative for Paypal. We used NodeJS as backend and ReactJS as frontend for stripe implementation in this blog.

Following points are covered in this blog:

  • Add a payment with a credit card.
  • How to create a customer(add card details)
  • How to Retrieve a customer(retrieve added card details)
  • How to update a customer(update added card details)
  • How to delete a customer(delete added card details)
  • Refund process to paid card.

Stripe Payment API Using Reactjs Nodejs

Stripe workflow

Stripe's workflow is super simple and it takes care of keeping the credit card data secure. Security is the main aspect when you are dealing with the credit card details. Our site can not run on HTTP if we accept credit cards even through stripe. We need to run our application in HTTPS.

Step 1: Add customer's credit card details with the webform.

Step 2: Stripe takes those details, encrypts the data(token) and send them to the Stripe server.

Step 3: Form the added customer id we can able to retrieve, update, delete the customers credit card details.

Step 4: Stripe provides an API to charge the card that the customer added their card in the site. By calling this Javascript API we make the payment for the customer. You need the keys (publishable & secret API key) to make call that is available in your Stripe Account.

Stripe

We need publishable & secret API key in our React application, so we need to create an account with the Stripe and our stripe dashboard looks like below image, In that we have our publishable API Key and secret API Key.

Stripe Dashboard

In Stripe dashboard,

Test Mode: Here we can able to see only the payments were done from your test application(For development use).
Live Mode: Here we you will see real payments(For production use).

Stripe API Keys:

Publishable API key: Used in React application to generate a token.
Secret API key: Used in server application to charge the money by accessing the Stripe API.

Stripe API Key

Stripe FrontEnd

For the front end React application we need to install the dependencies for stripe, react-stripe-elements or react-stripe-checkout. Both provides the stripe token which we later send to our backend and pretty component to capture credit card information.

Install dependencies

bash
npm i react-stripe-elements
import { Elements, StripeProvider, CardElement, injectStripe } from "react-stripe-elements";

StripeProvider

Component, which sets up the Stripe context for a component tree.This allows configuration like your API key to be provided at the root of a component tree.

Elements

Elements is used to wrap the component of our form and also pull data from groups of elements when tokenizing.

CardElement

It is UI for Elements, and it must be used within StripeProvider and Elements

InjectStripe

The injectStripe HOC(Higher Order Component) provides the this.props.stripe property that manages your Elements groups. You can call this.props.stripe.createToken or this.props.stripe.createSource within a component that has been injected to submit payment data to Stripe.

jsx
<StripeProvider apiKey='publishable_API_Key'>
	<Elements>
		<CardElement
			hidePostalCode={true}
			style={{ base: { fontSize: '18px' } }}
		/>
	</Elements>
</StripeProvider>

this.props.stripe.createToken({
	name: formProps.name,
	address_line1: formProps.address,
	address_city: formProps.city,
	address_state: formProps.state,
	address_zip: formProps.zipCode,
	address_country: formProps.country
}).then(({ token }) => {

	if (!token) return;

	// if token generated successfully,
	// then the token will send to BackEnd.

});

export default injectStripe(CardInfo);

Stripe Backend

Express server application, will receive the payment information from your React frontend and will pass it to the Stripe API. For this we need an Express serve

We need some node modules that are essential for our application to work:

  • express - this is our web server
  • cors - to enable cross origin resource sharing on our app
  • body-parser - used in parsing the contents of a request in a json format
  • stripe - to allow us to communicate with our stripe api

Following code is a basic setup for the server using nodejs,

javascript
const express = require("express");
const bodyParser = require("body-parser");
const config = require("./config");
const app = express();
const cors = require("cors");
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

const stripeRouter = require("./src/router");
app.use("/stripe", stripeRouter);

app.listen(config.app.port, () => {
	console.log(`😎 Server is listening on port ${config.app.port}`);
});

By using express node server we are going to discuss about the following API's,

  1. Create a Charge
  2. Create a Customer
  3. Retrieve a Customer
  4. Update a Customer
  5. Delete a Customer
  6. Create a Refund

Install Dependencies

bash
npm i react-stripe
const stripe = require('stripe')('Secret_API_Key');

Which collects the customer/card details as a token from the front-end and done the stripe related process.

Create a Charge:

It is used to charge a credit card or for payment purposes, where in test mode it doesn’t make a charge to the card but in live it make a charge to the card.

javascript
const chargeCustomer = stripe.charges.create({
	amount: 2000, // Required
	currency: "usd", // Required
	source: "tok_amex", // optional id of a card
	description: "Charge for aiden.wilson@example.com"
}, function(err, charge) {
	if (err) {
	} else {
		res.status(200).send({
			message: "charge success",
			id: charge.id
		});
	}

});

Create a Refund:

To make the refund we need to specify a charge on which to create it. Funds will be refunded to the credit / debit card which was charged previously and not refunded yet.

javascript
const refundAmount = stripe.refunds.create({
	charge: req.body.chargeId,
}, (err, refund) => {
	if (refund) {
		res.status(200).send({
			message: 'Refund successful',
			refundObj: refund
		});
	} else {
		res.status(200).send({
			message: 'Refund failed',
			refundObj: {}
		});
	}
});

Create a Customer:

Create a customer with needed details like card details, address etc.,

javascript
const customer = await stripe.customers.create({
           description: 'Customer for ' + id, //is just for reference
           source: token_id //created by the front end createToken()
       });
 // customer.id is used for the further purposes

Retrieve a Customer:

Retrieves the details of an existing customer. We need to pass the unique customer id which was created while the customer creation.

javascript
const customer = await stripe.customers.retrieve(customer_id);
//customer_id which is generated while creating the customer

Update a Customer:

Update customer by the created customer id by setting the updated token to its source.

javascript
const customer = await stripe.customers.update(
           customerDetails, // updated details of the customer like card number, address, name etc..,
           { 'source': token_id }, // latest token to update the older one
           function (err, customer) {
               if (err) {
                   console.log("StripeError: (update)", err);
               }
           }
);

Delete a Customer:

It permanently deletes the customer and stops all subscriptions.

javascript
const customer = await stripe.customers.del(customer_id, 
//customer_id which is generated while creating the customer
           function (err, customer) {
               if (err) {
                   console.log('StripeError: (delete)', err);               
}
});

Stripe Benefits:

It is incredibly easy to use and everything is built-in like card storage, subscriptions, and bank payouts.

Using Stripe.js you can make your own payment forms and still avoid PCI requirements.

Reasonable rates, no extra fees and awesome customer service.

Added card details in stripe dashboard :Stripe Customer Details

Stripe Demo:Stripe

Tags

ADYENAMAZON-SESANDROIDAPACHEAPACHE-JMETERAWSBARCODE-SCANNERCOLDBOXCOLDFUSIONCOLDFUSION-API-INTEGRATIONCOLDFUSIONBUILDERECHARTSEVENT-GATEWAYFFMPEGFW1JQUERYJSOUPLUCEEMURACMSMURACMS-THEMENODEJSONESIGNALOSSPAYFLOW-PROPAYMENT-GATEWAYPAYPALPRESIDECMSPUPPETEERRAILORAZUNAREACTJSREACTNATIVERESTSASS-COMPILATIONSEMANTIC-UISUBLIMETEXTTINYMCETWILIOYUI-LIBRARY

Archives

JAN 20DEC 19AUG 19JUL 19JUN 19MAY 19APR 19MAR 19FEB 19JAN 19DEC 18NOV 18OCT 18MAR 16NOV 15SEP 15MAY 15MAY 14OCT 13JUN 13MAY 13APR 13MAR 13FEB 13JAN 13

Follow us

Mitrahsoft
United StatesUnited States

Hurst, Texas, United States

+1 (817) 606-8684usa-sales@mitrahsoft.com

IndiaIndia

Head Office

126G2/5, Thiru malai nagaram,
Kovilpatti - 628 501

Madurai

1/B, 2nd & 3rd floor, GV Complex,

Bye Pass Road, SS Colony,

Madurai - 625 016

Coimbatore

2nd Floor, Sri Narmadha Towers,

Murugan Nagar Rd, Thoppampatti Pirivu,

 K. Vadamadurai, Coimbatore - 641 017

+91 9092480924

business@mitrahsoft.com

ColdFusion
  • eCommerce / Shopping Cart Solutions
  • Payment Gateway Integrations
  • Shipping API Integrations
  • ColdFusion Development Services
  • REST API Development
  • MuraCMS Plugin Creation & Personalization
Technology Services
  • ReactJS Development
  • VueJS Development
  • AngularJS Development
  • NodeJS API Development
  • Python Development
  • Golang Development
  • React Native Development
  • D3.JS data Visualization
Other Services
  • Software Development
  • Mobile Development
  • Blockchain Development
  • Cloud & Devops Services

Connect with MitrahSoft

Please fill out this field
Please fill out this field
Please fill out this field
Please fill out this field
Please fill out this field
Please fill out this field

© 2026 All Rights Reserved. MitrahSoft Solutions Pvt Ltd

Home|About Us|Careers