1.2.33 • Published 4 months ago

vic-payment-js v1.2.33

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

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;
};
1.2.33

4 months ago

1.2.31

5 months ago

1.2.32

5 months ago

1.2.30

5 months ago

1.2.17

7 months ago

1.2.18

7 months ago

1.2.19

6 months ago

1.2.20

6 months ago

1.2.23

6 months ago

1.2.24

6 months ago

1.2.21

6 months ago

1.2.22

6 months ago

1.2.27

5 months ago

1.2.28

5 months ago

1.2.25

5 months ago

1.2.26

5 months ago

1.2.29

5 months ago

1.2.0

8 months ago

1.1.29

9 months ago

1.1.28

9 months ago

1.2.8

7 months ago

1.2.7

7 months ago

1.2.6

7 months ago

1.2.5

8 months ago

1.2.4

8 months ago

1.2.3

8 months ago

1.2.1

8 months ago

1.1.30

9 months ago

1.1.34

9 months ago

1.1.33

9 months ago

1.1.32

9 months ago

1.1.31

9 months ago

1.1.36

8 months ago

1.1.35

8 months ago

1.2.12

7 months ago

1.2.13

7 months ago

1.2.10

7 months ago

1.2.11

7 months ago

1.2.16

7 months ago

1.2.14

7 months ago

1.2.15

7 months ago

1.1.9

11 months ago

1.1.8

11 months ago

1.1.12

11 months ago

1.1.11

11 months ago

1.1.10

11 months ago

1.1.15

11 months ago

1.1.14

11 months ago

1.1.13

11 months ago

1.1.19

11 months ago

1.1.18

11 months ago

1.1.17

11 months ago

1.2.9

7 months ago

1.1.23

10 months ago

1.1.22

10 months ago

1.1.21

10 months ago

1.1.20

10 months ago

1.1.27

9 months ago

1.1.26

9 months ago

1.1.25

10 months ago

1.1.24

10 months ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

0.1.26

1 year ago

0.1.25

1 year ago

0.1.24

1 year ago

0.1.23

1 year ago

0.1.22

1 year ago

0.1.21

1 year ago

0.1.20

1 year ago

0.1.19

1 year ago

0.1.18

1 year ago

0.1.17

1 year ago

0.1.16

1 year ago

0.1.15

1 year ago

0.1.14

1 year ago

0.1.13

1 year ago

0.1.12

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago