We provide a separated npm package to generate and manipulate commit-chain invoices. Invoices are an easy way to integrate Liquidity Network payment solution for merchants and provide a better shopping experience for users.
npm install liquidity-invoice-generation
const invoice: Invoice = createInvoice({network: 4, // Network id// Public key of recipientpublicKey: '0xE6987CD613Dfda0995A95b3E6acBAbECecd41376',// Generate unique id for the invoice, payment by this invoice can be tracked by nonce.// If this is set to true, the invoice is payable only once. Otherwise the invoice is payable multiple-times.generateId: true,// Nocust contract address, if not defined, on-chain invoice will be generated.contractAddress: '0x4FED1fC4144c223aE3C1553be203cDFcbD38C581',// Token address of the payment, if not defined, Ether is used.tokenAddress: '0x4FED1fC4144c223aE3C1553be203cDFcbD38C581',// Optional. BigNumber or number also can be used.amount: '12000000000000',})// Encode the invoice as a compact string to displayed as QR code.const encodedInvoice: string = encodeInvoice(invoice)// Decode invoice after QR code scanningconst decodedInvoice: Invoice = decodeInvoice(encodedInvoice)// Note: Here, decodedInvoice equals invoice
Feed the output of encodeInvoice
into a QR code generator as plain text. (i.g: use https://www.the-qrcode-generator.com or a QR library) to be scanned by the user.
Feed to output of decodInvoice
into the sendTransfer
function of the NOCUSManager.
If no amount is specified invoice.amount
will be undefined, it needs to be set before making a transfer with the nocust manager.
If tokenAddress is not specified, Ether will be used.
To make an on-chain transactions invoice don't set a contract address.
The typical merchant needs to track the completion of payments by its customers. We usegenerateId
.
SERVER SIDE, generate an invoice with generateId
set to true
and save the nonce in the invoice object invoice.nonce
in the merchant server database. It is important this is done server side. Otherwise, the client can manipulate the value.
Encode the invoice with the encodeInvoice
function and send it to the client front-end to display the QR code that will have to be scanned by the developer's mobile wallet.
Wait for an incoming payment with the nocust-manager that has the correct nonce value AND amount.
It is possible to create deeplink invoices that will automatically open and fill the invoice details on the Liquidity Mobile Wallet on Android and iOS. Use the URL lqdnet://send
and set the query parameters identical to the fields outputted by createInvoice
Example:
lqdnet://send?network=4&publicKey=0x688...0E2&tokenAddress=0xA9F...717&amount=100000000