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

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

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

Last updated

Was this helpful?