# 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:

```typescript
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.

{% hint style="warning" %}
Warning! Only the merchant can edit the invoice!
{% endhint %}

{% hint style="info" %}
Invoice can't be edited once it's paid, or if it's inactive.
{% endhint %}

### Manage active status

To activate or deactivate your invoice, call the respective methods like so:

```typescript
await store.activate();
// or
await store.deactivate();
```

After confirming the transaction, the invoice will be activated/deactivated.

{% hint style="warning" %}
Warning! Only the merchant can activate or deactivate the invoice!
{% endhint %}

{% hint style="info" %}
When the invoice is deactivated, it won't accept any payments and it can't be edited.
{% endhint %}

### 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

{% hint style="info" %}
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 [`store.issueInvoice()`](https://tonpay.gitbook.io/tonpay-sdk/javascript/interacting-with-store#issue-an-invoice) or the [merchant portal](https://business.thetonpay.app/invoices/create), and the previous one works without creating the invoice beforehand.
{% endhint %}

The easiest way is to provide a payment link like so:

```typescript
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 :smirk:) 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:

```typescript
await invoice.pay();
```

If the invoice's currency is other than TON, then you **must** specify the customer wallet address:

```typescript
await invoice.pay("EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N");
```

And that's it! When the user confirms the transaction, consider your invoice paid (assuming all data is correct).

{% hint style="success" %}
You can check the payment status easily by calling `invoice.isPaid()` method!
{% endhint %}

### Get invoice info

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

```typescript
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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tonpay.gitbook.io/tonpay-sdk/javascript/interacting-with-invoice.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
