Exciting release!Introducing "safe npm". Learn more
Socket
Log inDemoInstall

vic-payment-js

Package Overview
Dependencies
9
Maintainers
1
Versions
31
Issues
File Explorer

Advanced tools

vic-payment-js

Payment for VIC coin

    1.1.5latest
    npm

Version published
Maintainers
1
Weekly downloads
130
decreased by-46.94%

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; vndtTokenAddress: string; paymentGatewayAddress: string; };

Keywords

FAQs

Last updated on 22 Mar 2023

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket
support@socket.devSocket SOC 2 Logo

Product

  • Package Issues
  • 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