Socket
Socket
Sign inDemoInstall

vic-payment-js

Package Overview
Dependencies
8
Maintainers
1
Versions
94
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vic-payment-js

VIC Pay SDK


Version published
Weekly downloads
5
Maintainers
1
Created
Weekly downloads
 

Readme

Source

VIC Payment

TypeScript library to interact with VIC PaymentGateway

Overview

This library provide functions for both frontend and backend to interact with PaymentGateway

For Frontend

Provide functions for:

  • User connect with web3 wallet
  • User switch chain
  • User execute pay on smart contract

For Backend

Provide functions for:

  • BE Merchant send request to create payment session
  • BE Merchant verify payment event received on webhook
  • BE Merchant query payments information

Install package

We can directly install from npm:

npm install vic-payment-js
yarn add vic-payment-js

Usage

All modules packaged in vic-payment-js, however the usage for frontend and backend is completely different. The key different is on frontend we don't require any apiKey to initialized library, but on backend we require apiKey to interact with PaymentGateway.

For Frontend

On Frontend, we use the Client module from vic-payment-js

Import Client into project:

import { Client } from "vic-payment-js";

Client module provide static method to directly handle PaymentSession returned from BE Merchant, ex:

// Ask User to pay for Order
const session = /*...from BE Merchant ...*/;
 Client.userPay(session);

For Backend

On Backend, we use the Session, Event module from vic-payment-js

Session module

Import Session into project:

import { Session } from "vic-payment-js/lib/session";

// Initialize session with apiKey
const session = Session.init({ apiKey });

Session module provide methods to send request to PaymentGateway to create PaymentSession, ex:

const paymentSession = await session.ofUserPay({
  paymentId: nanoid(12),
  amount: 50000,
  chainName: "BINANCE",
  metadata: {
    orderId: req.params.id,
  },
});

Event module

Import Event into project:

import { Event } from "vic-payment-js/lib/session";

// Initialize event with apiKey
const event = Event.init({ apiKey });

Event module provide methods to verify PaymentEvent sent from PaymentGateway, ex:

router.post("/api/test/webhook", async (req, res) => {
  const webhookEvent = req.body;

  try {
    const paymentEvent = event.verifySignature(webhookEvent);
    console.log("paymentEvent", paymentEvent);
    return res.json({ message: "Received" });
  } catch (err) {
    console.log("Fail to verify event", err.message);
    return res.json({ message: err.message });
  }
});

PaymentEvent has base schema:

type PaymentEvent = {
  paymentId: string;
  chainName: string;
  metadata?: Record<string, unknown>;
  merchantAddress: string;
  vicTokenAddress: string;
  paymentGatewayAddress: string;
};

Keywords

FAQs

Last updated on 02 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc