LogoLogo
Explore with DeepWikiJoin Slack CommunityContact Us
  • About Hyperswitch
    • Exploration Guide
    • Overview
    • Payments Suite
    • Payments Modules
      • Cost Observability
      • Revenue Recovery
      • Vault
        • Server to Server Vault tokenization
        • Vault SDK Integration
        • Hyperswitch Vault: Pass Through Proxy Payments
      • Intelligent Routing
        • Auth Rate Based Routing
        • Self-Deployment Guide
      • Reconciliation
        • Getting Started with Recon
      • Alternate Payment Method Widgets
        • Hyperwidget Integration Guide
    • Roadmap - Q2 2025
      • Previous Roadmap - Q1 2025
      • Previous Roadmap - Q4 2024
      • Previous Roadmap - Q3 2024
      • Previous Roadmap - Q2 2024
      • Previous roadmap - Q1 2024
      • Previous roadmap - Q4 2023
  • Use-Cases
    • For SaaS Businesses
    • For B2B SaaS Businesses
    • For E-Commerce Businesses
    • For Marketplace/Platforms
  • Explore Hyperswitch
    • Payment Orchestration
      • Accept Payments
        • Connectors
          • Activate Connector on Hyperswitch
          • Try a Payment
          • Available Connectors
            • ACI
            • Adyen
            • Airwallex
            • Authorizedotnet
            • Bambora
            • Bank of America
            • Billwerk
            • Bluesnap
            • Braintree
            • Checkout
            • Coinbase
            • Cybersource
              • Apple Pay
              • Google Pay
            • dLocal
            • Fiserv
            • GlobalPayments
            • GoCardless
            • Klarna
            • Mollie
            • MultiSafepay
            • Nuvei
            • OpenNode
            • Paypal
            • PayU
            • Prophetpay
            • Rapyd
            • Shift4
            • Stripe
            • TrustPay
            • Volt
            • Worldline
            • Worldpay
            • Zen
            • Netcetera
              • Authenticating Payments via Netcetera Through HyperSwitch SDK
        • Setup Payment Methods
          • Cards
          • Wallets
            • Apple Pay
              • Web Domain
              • iOS Application
            • Google Pay
            • PayPal
          • Pay Later
          • Banks
            • Bank Debits
            • Bank Redirects
            • Bank Transfers
            • Open Banking
          • Crypto
          • Test Credentials
        • Payment Links
          • Configurations
          • Create Payment Links
          • Secure Payment Links
          • Setup Custom Domain
        • Save a Payment Method
        • Manual Capture
        • Incremental Authorization
        • Tokenization & Card Vault
          • Network Tokenisation
        • Supported Payment Workflows
        • Co-badged Cards
        • Webhooks
      • Process Payouts
        • Getting Started with Payouts
        • Using Saved Payment Methods
        • Smart Router for Payouts
        • Smart Retries in Payout
        • Payout Links
      • Smart Routing
        • Rule Based Routing
        • Volume Based Routing
        • Default Fallback Routing
      • Smart Retries
        • 3DS Step-up Retries
      • 3DS / Strong Customer Authentication
        • Setting up 3DS Decision Manager
        • Native 3DS Authentication
        • External Authentication for 3DS
      • Fraud & Risk Management
        • Activating FRM in Hyperswitch
        • Fraud Blocklist
      • Subscriptions
        • PG Agnostic Card Forwarding
        • Zero Amount Authorization
      • Split Payments
        • Stripe Split Payments
        • Adyen Split Payments
        • Xendit Split Payments
    • Checkout Experience
      • Customizable and Native Integrations
        • Web
          • Node And React
          • Customization
          • Error Codes
          • Node and HTML
          • Vanilla JS and REST API Integration
        • Android
          • Kotlin with Node Backend
          • Customization
          • Features
        • iOS
          • Swift with Node Backend
          • Customization
          • Features
        • React Native
          • React Native with Node Backend
          • Card Widget
          • Customization
        • Flutter
          • Flutter with Node Backend
          • Customization
        • Headless SDK
        • Server Setup
      • Click To Pay
        • Visa Click to Pay: V1 to V2 Migration
      • Payment Methods Management
    • Payment Operations
      • Managing Accounts and Profiles
        • ⚙️Control Centre Account setup
        • Hyperswitch Account Structure
      • Manage Your Team
      • Analytics & operations
        • Exporting payments data
      • Disputes / Chargebacks
      • Surcharge
        • Surcharge Setup guide
      • Multi-Tenancy
      • Data migration
        • Import data to Hyperswitch
        • Export data from Hyperswitch
    • Security and Compliance
      • PCI Compliance
      • Data Security
      • GDPR compliance
      • Identity and Access Management
    • E-commerce Platform Plugins by Hyperswitch
      • 🔌WooCommerce Plugin
        • Setup
        • Roadmap
        • Compatibility
        • FAQs
      • Saleor App
        • Setup
      • Automatic Tax calculation for Express Checkout wallets
  • Hyperswitch open source
    • Overview
      • Run Hyperswitch Locally Using Docker
        • Run Additional Services
      • Development Environment Setup
        • Backend
          • Configure and Run the Application
          • Try out APIs
        • SDK (Frontend)
        • Control Center
    • Deploy on AWS
      • Deploy on AWS using CloudFormation
      • Component-wise Deployment
        • Deploy app server
        • Deploy Control Center
        • Deploy web client
          • Production ready deployment
          • Integrate web client on your web app
          • Playground deployment for prototyping (optional)
        • Deploy Card Vault
          • Production ready deployment on AWS
          • Cloud setup guide
    • Deploy on Kubernetes
      • Deploy on GCP Using Helm Charts
      • Deploy on Azure Using Helm Charts
    • Account setup
      • Using Hyperswitch Control Center
      • Test a payment
      • Using postman
    • Troubleshooting
  • Testing Payments
  • Check list for Production
    • Going live
      • For SaaS Setup
      • For On-Prem Setup
        • Monitoring
        • PCI compliance
          • Get started
          • Completing the SAQ
        • Data Security
        • Updates
  • Learn more
    • API Reference
    • Connectors Supported
    • SDK Reference
      • React
      • JS
      • Custom Events
    • Hyperswitch architecture
      • Router
      • Storage
      • A Payments Switch with virtually zero overhead
    • Payment flows
    • Blog
  • Community Guidelines
Powered by GitBook

Compliance

  • Vulnerability Disclosure
  • PCI DSS 4.0
  • ISO 27001:2022

Community

  • Slack
  • Discord
  • GitHub Discussion
On this page
  • Using Node SDK for app server is OPTIONAL. You can use our REST APIs for the
  • Requirements
  • Installation
  • Usage
  • Sample server code using Hyperswitch Node SDK

Was this helpful?

  1. Learn more
  2. SDK Reference

Node

Node to access the Hyperswitch API

In this section, we will cover the steps to do an easy integration of your Node Backend server

Using Node SDK for app server is OPTIONAL. You can use our REST APIs for the

Requirements

Node 12 or higher.

Installation

Install the package with:

npm install @juspay-tech/hyperswitch-node --save
# or
yarn add @juspay-tech/hyperswitch-node

Usage

The package needs to be configured with your account's secret key, which is available in the Hyperswitch Dashboard. Require it with the key's value:

const hyperswitch = require('hyperswitch')('snd_efe...');

hyperswitch.paymentIntents.create(
  {
    // Refer the request body of payments from this API https://app.swaggerhub.com/apis-docs/bernard-eugine/HyperswitchAPI/0.0.1#/Payments/Create%20a%20Payment
    amount: 10000,
    currency: "USD",
    capture_method: "automatic",
    amount_to_capture: 10000,
    customer_id: "hyperswitchCustomer",
    email: "guest@example.com",
    name: "John Doe",
    phone: "999999999",
    phone_country_code: "+65",
    description: "Its my first payment request",
    authentication_type: "no_three_ds",
    return_url: "https://app.hyperswitch.io",
    shipping: {
      address: {
        line1: "1467",
        line2: "Harrison Street",
        line3: "Harrison Street",
        city: "San Fransico",
        state: "California",
        zip: "94122",
        country: "US",
        first_name: "John",
        last_name: "Doe"
      },
      phone: {
        number: "123456789",
        country_code: "+1"
      }
    },
    billing: {
      address: {
        line1: "1467",
        line2: "Harrison Street",
        line3: "Harrison Street",
        city: "San Fransico",
        state: "California",
        zip: "94122",
        country: "US",
        first_name: "John",
        last_name: "Doe"
      },
      phone: {
        number: "123456789",
        country_code: "+1"
      }
    },
    metadata: {
      order_details: {
        product_name: "Apple iphone 15",
        quantity: 1
      },
    }
  }
)
  .then(customer => console.log(customer.id))
  .catch(error => console.error(error));

If you are using ES modules and async/await,

import Hyperswitch from 'hyperswitch';
const hyperswitch = new Hyperswitch('snd_efe...');

const payments_response = await hyperswitch.paymentIntents.create(
  {
    // Refer the request body of payments from this API https://app.swaggerhub.com/apis-docs/bernard-eugine/HyperswitchAPI/0.0.1#/Payments/Create%20a%20Payment
    amount: 10000,
    currency: "USD",
    capture_method: "automatic",
    amount_to_capture: 10000,
    customer_id: "hyperswitchCustomer",
    email: "guest@example.com",
    name: "John Doe",
    phone: "999999999",
    phone_country_code: "+65",
    description: "Its my first payment request",
    authentication_type: "no_three_ds",
    return_url: "https://app.hyperswitch.io",
    shipping: {
      address: {
        line1: "1467",
        line2: "Harrison Street",
        line3: "Harrison Street",
        city: "San Fransico",
        state: "California",
        zip: "94122",
        country: "US",
        first_name: "John",
        last_name: "Doe"
      },
      phone: {
        number: "123456789",
        country_code: "+1"
      }
    },
    billing: {
      address: {
        line1: "1467",
        line2: "Harrison Street",
        line3: "Harrison Street",
        city: "San Fransico",
        state: "California",
        zip: "94122",
        country: "US",
        first_name: "John",
        last_name: "Doe"
      },
      phone: {
        number: "123456789",
        country_code: "+1"
      }
    },
    metadata: {
      order_details: {
        product_name: "Apple iphone 15",
        quantity: 1
      },
    }
  }
);
console.log(customer.id);

Sample server code using Hyperswitch Node SDK

There is a sample server code that uses the node sdk. Below are the available functions that work with the current latest node sdk version.

Payments

  • Create a payment

  • Retrieve a payment

  • Confirm a payment

  • Capture a payment

  • Cancel a payment

Refunds

  • Create a refund

  • Retrieve a refund

Customers

  • Create a customer

  • Retrieve a customer

  • Delete a customer

Payment Methods

  • Create a payment method

  • List customer's payment methods

  • List merchant's payment methods

const express = require("express");
const app = express();
// This is a public sample test API key.
// Don't submit any personally identifiable information in requests made with this key.
// Sign in to see your own test API key embedded in code samples.

const hyperswitch = require('@juspay-tech/hyperswitch-node')('snd_b8df3xxx......');

app.use(express.static("public"));
app.use(express.json());

// The request body(req.body) for all API's below can be referred from https://app.swaggerhub.com/apis-docs/bernard-eugine/HyperswitchAPI/0.0.1

// Customer API

app.get("/customer_create", async (req, res) => { // Api Endpoint that the merchant has 
  try {
    const resp = await hyperswitch.customers.create(
      req.body // send the customer request body as it is in openapi spec
    );
    res.send(resp);
  } catch (e) {
    // handle error here 
    res.send(e);
  }
});

app.get("/customer_retrieve/:customer_id", async (req, res) => { // Api endpoint that customer has
  try {
    const resp = await hyperswitch.customers.retrieve(
      req.params.customer_id,
    );
    res.send(resp);
  } catch (e) {
    // handle error here 
    res.send(e);
  }
});

app.get("/customer_delete/:customer_id", async (req, res) => {
  try {
    const resp = await hyperswitch.customers.del(
      req.params.customer_id,
    );
    res.send(resp);
  } catch (e) {
    // handle error here 
    res.send(e);
  }
});


// Payments API

app.get("/payment_create", async (req, res) => {
  try {
    const resp = await hyperswitch.paymentIntents.create(
      req.body
    );
    res.send(resp);
  } catch (e) {
    // handle error here 
    res.send(e);
  }
});

app.get("/payment_confirm/:payment_id", async (req, res) => {
  try {
    const resp = await hyperswitch.paymentIntents.confirm(
      req.params.payment_id,
      req.body
    );
    res.send(resp);
  } catch (e) {
    // handle error here 
    res.send(e);
  }
});

app.get("/payment_retrieve/:payment_id", async (req, res) => {
  try {
    const resp = await hyperswitch.paymentIntents.retrieve(
      req.params.payment_id,
    );
    res.send(resp);
  } catch (e) {
    // handle error here 
    res.send(e);
  }
});

app.get("/payment_capture/:payment_id", async (req, res) => {
  try {
    const resp = await hyperswitch.paymentIntents.capture(
      req.params.payid,
      req.body
    );
    res.send(resp);
  } catch (e) {
    // handle error here 
    res.send(e);
  }
});

app.get("/payment_cancel/:payment_id", async (req, res) => {
  try {
    const resp = await hyperswitch.paymentIntents.cancel(
      req.params.payment_id,
      req.body
    );
    res.send(resp);
  } catch (e) {
    // handle error here 
    res.send(e);
  }
});


// Refunds API 

app.get("/refunds_create", async (req, res) => {
  try {
    const resp = await hyperswitch.refunds.create(
      req.body
    );
    res.send(resp);
  } catch (e) {
    // handle error here 
    res.send(e);
  }
});

app.get("/refunds_retrieve/:refund_id", async (req, res) => {
  try {
    const resp = await hyperswitch.refunds.retrieve(
      req.params.refund_id,
      req.body
    );
    res.send(resp);
  } catch (e) {
    // handle error here 
    res.send(e);
  }
});

// Payment Methods API

app.get("/payment_method_create", async (req, res) => {
  try {
    const resp = await hyperswitch.paymentMethods.create(
      req.body
    );
    res.send(resp);
  } catch (e) {
    // handle error here 
    res.send(e);
  }
});

app.get("/payment_method_list", async (req, res) => {
  try {
    const resp = await hyperswitch.paymentMethods.list(
    );
    res.send(resp);
  } catch (e) {
    // handle error here 
    res.send(e);
  }
});

app.get("/payment_method_list_by_customer/:customer_id", async (req, res) => {
  try {
    const resp = await hyperswitch.customers.listPaymentMethods(
      req.params.customer_id,
    );
    res.send(resp);
  } catch (e) {
    // handle error here 
    res.send(e);
  }
});

app.listen(4242, () => console.log("Node server listening on port 4242!"));

Last updated 6 months ago

Was this helpful?

The request body(req.body) for all API's below can be referred from

API reference