# Invoice, PaymentIntent and Payment

> The three layers behind every TapPay payment: what to collect, one attempt to pay, and the money that moved.

Source: https://docs.tappay.mn/concepts/invoice-intent-payment/

## Overview {#overview}

Every [payment](https://docs.tappay.mn/glossary.md#payment) in TapPay goes through three objects: an [Invoice](https://docs.tappay.mn/glossary.md#invoice), a [PaymentIntent](https://docs.tappay.mn/glossary.md#payment-intent) and a [Payment](https://docs.tappay.mn/glossary.md#payment). Each one answers a different question. Your API calls return small objects that hold the `id` of the related ones.

## The three layers {#the-three-layers}

| Object | What it is | Question it answers |
| - | - | - |
| Invoice | The full amount and its lines | What do you collect? |
| PaymentIntent | One attempt to pay a share of the invoice | How is the [customer](https://docs.tappay.mn/glossary.md#customer) paying now? |
| Payment | The real transaction on a payment rail | What money moved? |

An invoice is what you ask the customer to pay. It has the amount, the order id and, if you send them, the [order lines](https://docs.tappay.mn/glossary.md#order-line). It does not hold a QR code.

A PaymentIntent is one share of the invoice. It carries the QR code and a stable [deeplink](https://docs.tappay.mn/glossary.md#deeplink), and it has its own expiry time. You can show it on one or more [channels](https://docs.tappay.mn/glossary.md#channel).

A Payment is the actual transaction. Every payment belongs to a PaymentIntent. A card, a QR scan and a wallet transfer all create a payment.

## How many of each {#how-many-of-each}

One invoice can have many intents. One intent can have many payments. A retry or an extra payment is a new payment under the same intent.

The open and paid shares together never exceed the invoice amount. One paid share does not close the invoice. The invoice closes when the full amount is paid.

## Partial payment {#partial-payment}

The `partialMode` of the invoice sets how a customer may [pay in parts](https://docs.tappay.mn/glossary.md#partial-payment). The modes are `NONE`, `AMOUNT` and `LINES`. A [terminal](https://docs.tappay.mn/glossary.md#terminal) can set the default.

With `AMOUNT`, each intent takes any amount. With `LINES`, each intent lists invoice lines and quantities, and its amount is the unit price times the quantity. An open intent locks those quantities. They are released when the intent expires or is cancelled.

One invoice cannot mix the two modes. An invoice without lines cannot use `LINES` and returns `422`.

## Expiry {#expiry}

An intent expires after the `intent_ttl` of the terminal. When an unpaid intent expires, its share returns to the invoice. If no other share was paid, the invoice expires too.

A paid share stays paid. The invoice then shows the status `PARTIALLY_PAID`. Once the invoice itself has expired, no new intent can be created. TapPay does not [refund](https://docs.tappay.mn/glossary.md#refund) the paid money, and you decide what to do with the rest.

## Overpaid {#overpaid}

Two payers can pay the same QR code at nearly the same time. The first payment holds the code. If the second one still succeeds, that payment has the status `OVERPAID`. TapPay refunds it automatically on the same rail, with no fee.

## Where checkout and payments fit {#where-checkout-and-payments-fit}

You rarely create these objects by hand. A [checkout session](https://docs.tappay.mn/glossary.md#checkout-session) creates the invoice and the intent together, and shows them on a hosted page. A payment without lines also creates one invoice and one intent, from a single call.

See [Create a checkout session](https://docs.tappay.mn/reference/checkout-sessions/create.md) and [Create a payment](https://docs.tappay.mn/reference/payments/create.md). The checkout flow is in the [checkout guide](https://docs.tappay.mn/guides/checkout.md).

## Related objects and expand {#related-objects-and-expand}

A response stays short. A related object appears as its `id`, such as the `intentId` in an invoice. To get the full object in the same call, send `expand[]` with the field name.

TapPay never shows the provider or acquirer behind a payment. You see only the fields in the [reference](https://docs.tappay.mn/reference.md).
