@tokoinofficial/t-chain-payment

2.0.3 • Public • Published

t-chain-payment

Installation

Use NPM

$ npm install @tokoinofficial/t-chain-payment

Use Yarn

$ yarn add @tokoinofficial/t-chain-payment

Initialize

Sandbox mode (running on testnet)

import Payment from "@tokoinofficial/t-chain-payment";

Payment.init({ api_key: api-key, mode: 'sandbox' });

Production mode (running on mainnet)

import Payment from "@tokoinofficial/t-chain-payment";

Payment.init({ api_key: api-key });

api_key is the public key. It will be generated in the cms of t-chain.

Deposit

const params = {
	amount: 1000,
	notes: "order_id",
	currency: "IDR",
};
Payment.deposit(params, callbackFunc);

Notes:

  • currency : USD/IDR (default: USD)
  • Support for VND as currency is coming soon

Handle callback result

callbackFunc(res) {
    const tnxHash = res.hash;
}

Example for deposit

const params = {
	amount: 1000,
	notes: "order-123-456,
	currency: "IDR",
};
Payment.deposit(params, (res) => {
    this.transaction_hash = res.hash;
});

Generate QR

const params = {
    amount: 1000,
    notes: "order-123-456",
    currency: "IDR",
};

Payment.generateQrCode(params).then((res) => {
    this.qrCode = res;
});

Notes:

  • currency : USD/IDR (default: USD)
  • Support for VND as currency is coming soon

Next step:

  • User use T-Wallet app to scan the QR Code.
  • The merchant backend application will receive the transaction via HookURL when the payment is completed.

HookURL: the URL that the merchant provides to T-Chain. It is set when creating a project or updating the account management page of T-Chain for merchants.

Data structure sent via Hook URL :

{
	"tnx_hash": string,
	"deposit_address": string,
	"deposit_id": string,
	"offchain": string,
	"notes": string,
	"amount": string,
	"type": string, 
	"status": string,
	"deposited_at": string
}

status is Pending or Success type is Deposit or withdraw

Demo

Demo payment with t-chain

Package Sidebar

Install

npm i @tokoinofficial/t-chain-payment

Weekly Downloads

1

Version

2.0.3

License

Apache-2.0

Unpacked Size

1.31 MB

Total Files

24

Last publish

Collaborators

  • vu.truong_tokoin
  • quangdangtokoin
  • tokoin
  • trongdth