Interacting with Invoice
When working with the store, you had a chance to get the invoice. Here you'll learn what you can do with it.
Edit an invoice
To edit your invoice, just call the edit() on the invoice object like so:
await invoice.edit(
true, // has customer or not
"EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N", // customer address or ZERO_ADDRESS
"in_abcderf654321", // invoice id
"some metadata", // invoice metadata
6.9, // invoice amount
Currencies.TON // currency of the invoice from the supported currencies set
);
After confirming the transaction, the invoice will be updated in a couple of seconds. Note that this operation requires you to provide functional sender to the SDK.
Warning! Only the merchant can edit the invoice!
Manage active status
To activate or deactivate your invoice, call the respective methods like so:
await store.activate();
// or
await store.deactivate();
After confirming the transaction, the invoice will be activated/deactivated.
Warning! Only the merchant can activate or deactivate the invoice!
Paying the invoice
After the invoice is issued, the customer needs to pay for it. This can be handled in 2 ways:
providing customer with the payment link (not the same one as for the store!)
send a payment to the invoice programmatically
The easiest way is to provide a payment link like so:
const link = await invoice.getPaymentLink(); // "ton" by default
After retrieving the link, you can present it to your customer in any way you want (button, QR code, etc.)
If you use TON Connect 2.0 in your app (to have your store inside user's wallet for example π) and provided a sender
to the SDK, you can directly call the corresponding method which will prompt the payment in the user's wallet, like so:
await invoice.pay();
If the invoice's currency is other than TON, then you must specify the customer wallet address:
await invoice.pay("EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N");
And that's it! When the user confirms the transaction, consider your invoice paid (assuming all data is correct).
You can check the payment status easily by calling invoice.isPaid()
method!
Get invoice info
If you want to fetch the data about your invoice, you can use a set of methods for that:
getStore(); // returns the store which issues the invoice
getMerchant(); // returns the merchant of the store for this invoice
getCustomer(); // returns address of the customer to whom this invoice is issued, if any
hasCustomer(); // returns true or false depending on the presense of the customer address
getInvoiceId(); // returns invoice id
getMetadata(); // returns invoice metadata
getAmount(); // returns invoice amount in nanoTON
isPaid(); // returns the payment status
isActive(); // returns the active status
getCurrency(); // returns invoice currency
getVersion(); // returns the invoice contract version
getData(); // returns full invoice info, which includes all data above
It's recommended to just use the getData()
to save up on requests.
Last updated
Was this helpful?