PaySwitcher
  • About PaySwitcher
    • 🛒For Online Businesses
    • 🪜For Small & Medium Enterprises
    • 🏢For Enterprises
    • 🖥️For SaaS Providers
    • 🛍️For E-Commerce Businesses
    • 📦For Marketplace/Platforms
    • 🏦For Banks & Financial Institutions
  • PaySwitcher Cloud
    • ⚡Quickstart
      • 📥Migrate from Stripe
        • Web
        • Android
        • iOS
        • React Native
      • 🥗Payment Recipes
        • Use PayPal With Stripe
    • ⚙️Control Centre Account setup
    • 📦Integration guide
      • 🌐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 (Beta)
        • Card Widget (Beta)
        • Customization
      • ⏺️Flutter
        • Flutter with Node Backend
        • Customization
      • Headless SDK
      • Payment Methods Management
    • 💳Payment methods setup
      • 💳Cards
      • 📱Wallets
        • Apple Pay
          • Web Domain
          • iOS Application
        • Google Pay
        • PayPal
      • 📆Pay Later
      • 🏦Banks
        • Bank Debits
        • Bank Redirects
        • Bank Transfers
      • 🪙Crypto
      • 🔑Test Credentials
    • 🔌Connectors
      • 🖲️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
      • Activate connector on PaySwitcher
      • Test a Payment with connector
    • 🪝Webhooks
  • Features
    • 🔀Payment flows
      • 🔁Saving payment methods & recurring payments
      • 💵Payouts
        • ➕Get started with payouts!
        • 🔗Process payouts using saved payment methods
        • 🛣️Route your payout transactions using Smart Router
        • ♻️Smart Retries in Payout
        • 🔗Payout links
      • 0️ 0️ 0️ Zero Amount Authorization
      • 🔓Tokenization & saved cards
      • 🔗Payment links
      • ⏭️External Authentication for 3DS
      • 💰Manual Capture
      • 🛑Fraud Blocklist
      • 🔁Subscriptions
      • 🔃PG Agnostic Recurring Payments
    • 🕹️Merchant controls
      • 🛣️Smart Router
        • Rule Based Routing
        • Volume Based Routing
        • Default Fallback Routing
      • 🛡️Fraud & risk management
      • 🔃Smart retries
      • 🎛️Analytics & operations
      • 📋3DS decision manager
        • Setup guide
      • 📋Surcharge
        • Surcharge Setup guide
      • 🔼3DS Step-up retries
      • 🚩Disputes/Chargebacks Management
      • 🤝Reconciliation
        • Getting Started with Recon
    • 🔑Account management
      • 🔢Exporting payments data
      • 🤹Multiple accounts & profiles
      • 🛂Manage your team
    • 🛍️E-commerce platform plugins
      • WooCommerce Plugin
        • Setup
        • Compatibility
        • FAQs
  • SECURITY AND COMPLIANCE
    • 🔏Overview
    • 💳PCI Compliance
    • 🔐Data Security
    • 💽GDPR compliance
    • 🕵️Identity and Access Management
  • Learn more
    • 🍡SDK Reference
      • Node
      • React
      • JS
    • 📐PaySwitcher Architecture
      • Router
      • Storage
      • A Payments Switch with virtually zero overhead
    • 🌊Payment flows
Powered by GitBook
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 PaySwitcher Node SDK
  1. Learn more
  2. SDK Reference

Node

Node to access the PaySwitcher 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 @payswitcher/payswitcher-node --save
# or
yarn add @payswitcher/payswitcher-node

Usage

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

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

payswitcher.paymentIntents.create(
  {
    // Refer the request body of payments from this API https://app.swaggerhub.com/apis-docs/bernard-eugine/PaySwitcherAPI/0.0.1#/Payments/Create%20a%20Payment
    amount: 10000,
    currency: "USD",
    capture_method: "automatic",
    amount_to_capture: 10000,
    customer_id: "payswitcherCustomer",
    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.payswitcher.com",
    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 PaySwitcher from 'payswitcher';
const payswitcher = new PaySwitcher('snd_efe...');

const payments_response = await payswitcher.paymentIntents.create(
  {
    // Refer the request body of payments from this API https://app.swaggerhub.com/apis-docs/bernard-eugine/PaySwitcherAPI/0.0.1#/Payments/Create%20a%20Payment
    amount: 10000,
    currency: "USD",
    capture_method: "automatic",
    amount_to_capture: 10000,
    customer_id: "payswitcherCustomer",
    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.payswitcher.com",
    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 PaySwitcher 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 payswitcher = require('@payswitcher/payswitcher-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/PaySwitcherAPI/0.0.1

// Customer API

app.get("/customer_create", async (req, res) => { // Api Endpoint that the merchant has 
  try {
    const resp = await payswitcher.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 payswitcher.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 payswitcher.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 payswitcher.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 payswitcher.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 payswitcher.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 payswitcher.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 payswitcher.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 payswitcher.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 payswitcher.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 payswitcher.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 payswitcher.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 payswitcher.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!"));
PreviousSDK ReferenceNextReact

Last updated 11 months ago

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

🍡
API reference