Tonpay SDK
  • Home
  • Supported currencies
  • 🌐JavaScript
    • Getting started
    • Initialization
    • Interacting with Store
    • Interacting with Invoice
  • 🐍Python
    • Getting started
    • Initialization
    • Interacting with Store
    • Interacting with Invoice
Powered by GitBook
On this page
  • Edit an invoice
  • Manage active status
  • Paying the invoice
  • Get invoice info

Was this helpful?

  1. Python

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!

Invoice can't be edited once it's paid, or if it's inactive.

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!

When the invoice is deactivated, it won't accept any payments and it can't be edited.

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:

link = await invoice.get_payment_link() # "ton" by default

After retrieving the link, you can present it to your customer in any way you want (button, QR code, etc.)

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.is_paid() method!

Get invoice info

If you want to fetch the data about your invoice, you can use a set of methods for that:

get_store() # returns the store which issues the invoice
get_merchant() # returns the merchant of the store for this invoice
get_customer() # returns address of the customer to whom this invoice is issued, if any
has_customer() # returns true or false depending on the presense of the customer address
get_invoice_id() # returns invoice id
get_metadata() # returns invoice metadata
get_amount() # returns invoice amount in nanoTON
is_paid() # returns the payment status
is_active() # returns the active status
get_currency() # returns invoice currency
get_version() # returns the invoice contract version

get_data() # returns full invoice info, which includes all data above

It's recommended to just use the get_data() to save up on requests.

PreviousInteracting with Store

Last updated 1 year ago

Was this helpful?

As you may have noticed, we already had a payment link in the previous chapter. The difference is that this one will work only for the invoice that's already issued using the or the , and the previous one works without creating the invoice beforehand.

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:

🐍
😏
store.issue_invoice()
merchant portal