> **Description:** Implementation guide for generating and processing one-time payment QR codes with ePayment.

> **AI agent:** Read [https://developer.vippsmobilepay.com/docs/knowledge-base/ai-tools.md](https://developer.vippsmobilepay.com/docs/knowledge-base/ai-tools.md) first. It covers keeping API keys and secrets out of generated code.

> **Full site overview:** For an overview of the entire site, read [https://developer.vippsmobilepay.com/llms.txt](https://developer.vippsmobilepay.com/llms.txt).

# How to make one-time payment QRs

This flow uses a one-time payment QR (i.e., a dynamic QR) that is shown on a screen.

Flow diagram: A one-time payment QR code displayed on a screen. The customer scans the QR code with the Vipps or MobilePay app to authorize the payment.

The QR directs the customer to the Vipps or MobilePay app, where they authorize the payment.

## Details

A [one-time payment QR code](https://developer.vippsmobilepay.com/docs/APIs/qr-api/api-guide/one-time-payment.md) is presented on the vending machine
or screen. The QR code is a dynamic representation of the payment URL, and the customer needs to scan it and pay
within 10 minutes.

### 1. The customer selects their products

The customer either scans their own products or hands them to an attendant.

### 2. The merchant's system requests a payment and dynamic QR code

When the customer selects a product, the system generates the payment request with a dynamic QR code by sending a
[`POST:/epayment/v1/payments`](https://developer.vippsmobilepay.com/redocusaurus/epayment-swagger-id.yaml) request with:

* `userFlow` set to `QR` (optionally specify `qrFormat` and `size` for the QR)
* `"customerInteraction": "CUSTOMER_PRESENT"` (required by regulation)

Since the customer scans the QR from their own phone, you don't need their phone number.

For a full example, see
[ePayment Features: One-time payment QR](https://developer.vippsmobilepay.com/docs/APIs/epayment-api/api-guide/features/qr-payments.md).

### 3. Vipps MobilePay returns the QR code

Vipps MobilePay returns the one-time payment QR in the create payment response.

### 4. The merchant's system displays the QR on the screen

The merchant's system displays the one-time payment QR on a screen facing the customer.

### 5. The customer scans the QR and confirms the payment

The customer scans the QR code and is directed to the Vipps or MobilePay app, where the payment screen is
presented and they click *Pay*. They have 10 minutes from when the QR is created.

### 6. The merchant learns the outcome from webhooks and polling

The merchant's system has no visibility into what happens in the app, so it must subscribe to webhooks to be
notified when the customer acts on the payment. Register the webhook with the
[Webhooks API](https://developer.vippsmobilepay.com/docs/APIs/webhooks-api/api-guide.md) before the QR is displayed, so that no event is missed while
the customer is paying, and subscribe to all three outcomes:

* `epayments.payment.authorized.v1`: the customer approved the payment in the app.
* `epayments.payment.aborted.v1`: the customer canceled the payment in the app.
* `epayments.payment.expired.v1`: the customer did not confirm the payment in time, 10 minutes by default.

Webhooks can be delayed or missed, so do not rely on them alone. Back them up by polling
[`GET:/epayment/v1/payments/{reference}`](https://developer.vippsmobilepay.com/redocusaurus/epayment-swagger-id.yaml)
for the payment state, following the [polling guidelines](https://developer.vippsmobilepay.com/docs/knowledge-base/polling-guidelines.md):
start after 5 seconds, then check every 2 seconds.

Once the payment is approved, the merchant updates the status in their system.

### 7. The merchant captures the payment

Authorization only reserves the amount. Capturing the payment is what transfers the funds, so the merchant
captures once the customer has received the goods, using
[`POST:/epayment/v1/payments/{reference}/capture`](https://developer.vippsmobilepay.com/redocusaurus/epayment-swagger-id.yaml),
and confirms that the capture succeeded.

The funds are then transferred to the merchant's account. This may take 2 or 3 days, depending on the bank.

## Sequence diagram

Dynamic QR directing to the app

```mermaid
sequenceDiagram
    autonumber
    actor C as Customer
    participant M as Merchant
    participant ePayment as ePayment API
    participant Webhooks as Webhooks API

    C->>M: Select the products
    M->>ePayment: Request a payment with userFlow QR
    ePayment-->>M: Return the one-time payment QR
    M->>C: Display the one-time QR on a screen facing the customer
    C->>ePayment: Scan the QR, select a card, and confirm the payment
    Webhooks-->>M: Webhook: the payment was authorized, aborted, or expired
    M->>ePayment: Poll for payment info, as a backup if the webhook is delayed or missed
    ePayment-->>M: Current state of the payment
    alt The payment was aborted or expired
        M->>M: Remove the QR and return the customer to the checkout screen
    else The payment was authorized
        M->>ePayment: Capture payment
        ePayment-->>M: Status of capture
        M->>M: Verify status of POS matches capture
    end
```

  Customer selects the products.
  Merchant requests a payment with a QR user flow via the ePayment API.
  ePayment API returns the one-time payment QR to the merchant.
  Merchant displays the one-time QR on a screen facing the customer.
  Customer scans the QR, selects a card, and confirms the payment.
  Webhooks API sends the merchant an authorized, aborted, or expired event.
  Merchant gets the payment from the ePayment API, as a backup if the webhook is delayed or missed.
  ePayment API returns the current state of the payment.
  If the payment was aborted or expired, the merchant removes the QR and returns the customer to the checkout screen, and
  the flow ends.
  If the payment was authorized, the merchant captures the payment via the ePayment API.
  ePayment API returns the status of the capture.
  Merchant verifies that the POS status matches the capture.

## More details

For more details, see [ePayment Features: Payment through a QR](https://developer.vippsmobilepay.com/docs/APIs/epayment-api/api-guide/features/qr-payments.md).
