How to Integrate Stripe Payment APIs Using Node.JS

Bigscal Technologies
4 min readJan 11, 2022

--

Types of payment method APIs

Stripe offers three different types of payment method APIs. And those are,

  1. Stripe Checkout
  2. Charges API
  3. Payment Intents API

Prerequisites

  • Install Node
  • Get Stripe API keys
  • Postman for API calling
  • Install stripe dependencies

Getting started with stripe payment APIs

1. Stripe Checkout

  • Here we’re going to see, An overview of stripe checkout, and how to build a simple checkout integration to accept one-time payments.
  • Stripe Checkout is a payment page that has already been constructed.
  • Accepting payments with stripe checkout consist of two steps.
  • Create a checkout session for what your customer intends to purchase.
  • Redirect your customer to a stripe-hosted payment form to complete their purchase.
  • ( Later you can optionally add a webhook handler to automate fulfillment of the purchase by sending an email.)
  • This is an example of creating the checkout session on the server. Here we are using the stripe node client library. First, we configure the library with our stripe secret key then make an API call to create the checkout session object. Once the response is returned from the API that session variable will contain the data including an id that’s used to redirect from the front end.

app.js

  • Define your route for API in the app.js file.
app.js

routes / index.js

  • Create a checkout session for what your customer intends to purchase.
routes / index.js

views / index.ejs

  • Redirect your customer to a stripe-hosted payment form to complete their purchase.
views / index.ejs

success.html

  • If the payment is successful, the customer will be redirected to the success page.
success.html

cancel.html

cancel.html

Output

After clicking on the Checkout button.

Success page:

2. Charges API

  • Using Charges and payment Intent APIs you can create your payment flow.
  • The Charges API is used to build basic payment flow without handling SCA or Strong customer authentication.

Steps to create stripe charges

app.js

app.js

routes / index.js

Define routes for creating customers, add a new card and create charges for customers.

routes / index.js
  • Create customer
  • Create or add a new card
  • Create charges
  • Using customer and card ID creates new charges.
  • Output

Payment Intents API

  • The Charges API has been replaced with the Payment Intent API.
  • Payment intent API provides Strong customer authentication or SCA.
  • The Payment Methods API has replaced tokens, which were previously used to securely transmit customer card information.
  • In this example, we will learn how to accept a one-time payment using payment intent.

index.js

index.js

Call API

Call API

Output

This is the fully functional code for handling payments and related data. It’ll work properly if you simply replace the sandbox key with your Stripe API key.

Stripe, on the other hand, makes it incredibly simple to develop payment sites without ever having to deal with sensitive data like credit card information, as you’ve seen.

Bigscal Technologies is India’s best to Hire NodeJs Developers & NodeJs Web Development Company. Where you can save up to 60% on costs and time, with no hiring fees.

This article was first published by @ Jayshree Sonar here.

Continue reading for more interesting articles by clicking here.

--

--

Bigscal Technologies

Bigscal is a custom software development services company with 150+ teams that successfully delivered 750+ projects covered clients in over 25 countries.