Lädt...


🔧 Getting Started with Hyperswitch, Nodejs, and Express for Payment Processing


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

Introduction

Welcome to this step-by-step tutorial on using the Hyperswitch API with Express and Node.js! In this first part, we'll walk you through creating a basic app using Node.js and Express. Later, in part two, we’ll integrate multiple payment gateways with the help of Hyperswitch.

Why Hyperswitch?

Hyperswitch allows you to connect to various payment processors and payment methods, making it easier to manage transactions. Meanwhile, Node.js enables you to run JavaScript on the server side, and Express simplifies the process of building web applications and APIs.

Requirements

Before we start, make sure you have the following:

  • Node.js installed on your system
  • Hyperswitch API keys
  • A text editor (I’ll be using Vim on Termux, but feel free to use your favorite editor like VS Code)

Step 1: Create a "Hello World" Application

  1. Open your terminal.

    new terminal

  2. Create a new folder for the project:

    mkdir hyperswitch
    
  3. Navigate to the folder:

    cd hyperswitch
    
  4. Initialize a Node.js project by running:

    npm init -y
    

    package json

    This will generate a package.json file that manages your project’s dependencies and configurations.

  5. Create a server file.
    You can create it using your text editor’s UI or in the terminal:

    touch app.js
    

    Since I’m using Vim, I’ll run:

    vim app.js
    

    and paste the "Hello World" code from the Express documentation:

    const express = require('express');
    const app = express();
    const port = 3000;
    
    app.get('/', (req, res) => {
    res.send('Hello World!');
    });
    
    app.listen(port, () => {
    console.log(`Example app listening on port ${port}`);
    });
    
  6. Save and exit the editor (in Vim, this would be :wq).

    vim in termux

  7. Install Express by running:

    npm i express
    
  8. Run the app and open your browser at http://localhost:3000/. You should see "Hello World!" displayed.

    app in browser

Step 2: Connecting to Hyperswitch

Now that you have a basic app running, let’s connect it to Hyperswitch.

  1. Sign up for Hyperswitch.
    For a smoother experience, it’s best to complete the sign-up process on a desktop or laptop.

  2. Get your API key from the settings. This key will allow your app to interact with the Hyperswitch API.

    Note: For this tutorial, we’ll paste the API key directly into our code. However, this is not recommended for production environments. We’ll cover a more secure method later.

  3. Update your code to create a customer through Hyperswitch. Replace the previous code in app.js with the following:

    const express = require('express');
    const app = express();
    const port = 3000;
    
    app.get('/', (req, res) => 
    {
    /* Fetching the API key from 
    Hyperswitch to create a 
    customer */
      const options = {
      method: 'POST',
      headers: {
      'api-key': '<api-key>', 
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      email: '[email protected]',
      name: 'John Doe'
    })
    }; 
    fetch('https://sandbox.hyperswitch.io/customers', options)
    .then(response => response.json())
    .then(response => console.log(response))
    .catch(err => console.error(err));
    res.send('Customer creation initiated.');
    });
    
    app.listen(port, () => {
    console.log(`App listening on port ${port}`);
    });
    
  4. Insert your API key by replacing with the actual key from Hyperswitch:

    headers: { 'api-key': 'snd_xxxxxxxxxxxxx', 'Content-Type': 'application/json' }
    
  5. Save the changes to app.js and run the server:

    node app.js
    
  6. Refresh your browser and check the terminal. You should see your first customer entry logged!

    first entry

That’s it for part one! Now you’ve created a basic Express app and connected it to Hyperswitch to create customers. In the next part, we’ll dive deeper into handling payments and managing multiple gateways.

Stay tuned!

...

🔧 Getting Started with Hyperswitch, Nodejs, and Express for Payment Processing


📈 87.02 Punkte
🔧 Programmierung

🔧 Securing Digital Transactions: How Hyperswitch makes Payment Protection a Priority


📈 38.05 Punkte
🔧 Programmierung

🔧 🚀 Hyperswitch Plugin Development Hackathon: Build, Compete, and Win Big! 🚀


📈 29.89 Punkte
🔧 Programmierung

📰 SoftIron HyperSwitch: Built to maximize the flexibility of an open source network OS


📈 28.58 Punkte
📰 IT Security Nachrichten

🍏 HyperSwitch 0.2.594 - Keyboard-focused window switcher (beta).


📈 28.58 Punkte
🍏 iOS / Mac OS

🔧 Hyperswitch by Juspay


📈 28.58 Punkte
🔧 Programmierung

🔧 Hacktoberfest 2024 with Hyperswitch


📈 28.58 Punkte
🔧 Programmierung

🔧 Getting Started with NodeJS in 2019


📈 28.29 Punkte
🔧 Programmierung

🔧 Getting Started with Nodejs


📈 28.29 Punkte
🔧 Programmierung

🔧 Getting Started with Express.js and Node.js: A Beginner's Guide


📈 26.64 Punkte
🔧 Programmierung

🔧 Getting Started with Prisma, SQLite, and Express


📈 26.64 Punkte
🔧 Programmierung

🎥 Getting started with Natural Language Processing - ML on Android with MediaPipe


📈 25.91 Punkte
🎥 Videos

🔧 Getting Started with Express.js: Build Your First Web Server in Minutes!


📈 25.33 Punkte
🔧 Programmierung

🔧 Aligning NodeJS with the Web: Should NodeJS Implement The Same APIs as the Web Browser?


📈 24.71 Punkte
🔧 Programmierung

🔧 How to use open source nodejs project's build or bundle in another nodejs project by importing?


📈 24.71 Punkte
🔧 Programmierung

🔧 Practical Guide to Send Emails from NodeJS/Express App using Gmail and Nodemailer (Screenshots and Code)


📈 24.37 Punkte
🔧 Programmierung

🕵️ Flaw in popular NodeJS ‘express-fileupload’ module allows DoS attacks and code injection


📈 23.06 Punkte
🕵️ Hacking

🔧 Build A News Website With NodeJS, Express, EJS and WP Rest API


📈 23.06 Punkte
🔧 Programmierung

🔧 Dockerizing NodeJS, Express, and MongoDB App with NGINX as a Reverse Proxy


📈 23.06 Punkte
🔧 Programmierung

🔧 Why should we use Typescript with NodeJs and Express?


📈 23.06 Punkte
🔧 Programmierung

🔧 How to Create a CRUD API – NodeJS and Express Project for Beginners


📈 23.06 Punkte
🔧 Programmierung

🔧 Deepening NodeJS Knowledge: URLs, HTTP Methods, Express Framework, and Versioning


📈 23.06 Punkte
🔧 Programmierung

🔧 Deploying a NodeJS - Express API to AWS Lambda


📈 21.75 Punkte
🔧 Programmierung

🔧 Build a CRUD Rest API in JavaScript using Nodejs, Express, Postgres, Docker


📈 21.75 Punkte
🔧 Programmierung

🔧 How to handle CORS issues when deploying a nodeJS express app on vercel??


📈 21.75 Punkte
🔧 Programmierung

🔧 Introduction to the principles of clean architecture in a NodeJs API (Express)


📈 21.75 Punkte
🔧 Programmierung

🔧 Why Laravel is better then NodeJs/Express?


📈 21.75 Punkte
🔧 Programmierung

🔧 Execute function after response sent to client - express nodejs


📈 21.75 Punkte
🔧 Programmierung

🔧 Execute function after response sent to client - express nodejs


📈 21.75 Punkte
🔧 Programmierung

🔧 Batch Processing vs. Stream Processing: Why Batch Is Dying and Streaming Takes Over


📈 21.26 Punkte
🔧 Programmierung

🔧 How to Get Started with Docker using NodeJS


📈 21.16 Punkte
🔧 Programmierung

🔧 Get Started Building an API Server with NodeJS


📈 21.16 Punkte
🔧 Programmierung

🔧 Day 2 of NodeJS || Get Started


📈 21.16 Punkte
🔧 Programmierung

matomo