> **Description:** Generate dynamic QR codes for customer-facing screens that open the payment directly in the Vipps or MobilePay app.

# One-time payment QR codes

**TIP**

For a visual walkthrough of the one-time payment QR flow,
see [How the QR API works with one-time payment](https://developer.vippsmobilepay.com/docs/APIs/qr-api/how-it-works/qr-one-time-payment-api-howitworks.md).

You can use the QR API to generate QR codes that can be scanned by a customer in a physical store setting.
Once the QR code is scanned, the Vipps or MobilePay app will automatically open with the payment
ready for approval.
This avoids them needing to provide their phone number.

These QR codes are generated for each unique payment.

Flow diagram: One-time payment QR flow, showing the generation of a QR code linked to a payment, the customer scanning the QR code to open the Vipps or MobilePay app, and the payment completed in the app.

The QR code, when scanned from either the native camera or the Vipps or MobilePay app, will
automatically open an eCom or Recurring payment in the app, where the
payment can be completed.

Every payment needs a unique `orderId`. See
[Recommendations for `reference` and `orderId`](https://developer.vippsmobilepay.com/docs/knowledge-base/orderid.md).

The purchase will time out after 10 minutes, so it's not possible to print these
QR codes.

## One-Time Payment QR code with ePayment API

One-time payment QR is already included as a feature in the
[ePayment API](https://developer.vippsmobilepay.com/docs/APIs/epayment-api/api-guide/features/qr-payments.md).

## Basic flow for One-Time Payment QR code with eCom or Recurring payments

1. Initiate an eCom or Recurring payment
2. Receive the payment URL as response
3. Post the payment URL to the QR API
4. Receive a URL to a QR code in desired format (PNG or SVG)

See the [Quick start guide](https://developer.vippsmobilepay.com/docs/APIs/qr-api/qr-api-quick-start.md) for examples of generating QR codes.

### Initiate a payment with the eCom API

Before creating the QR code you must initiate a payment with the eCom API as is described in depth in the
[eCom API guide](https://developer.vippsmobilepay.com/docs/APIs/ecom-api/vipps-ecom-api.md#initiate).

The request to the eCom initiate endpoint
[`POST:/ecomm/v2/payments`](https://developer.vippsmobilepay.com/redocusaurus/ecom-swagger-id.yaml)
 will return a response like this (the `url` is truncated, but the format is correct):

```json
{
  "orderId": "acme-shop-123-order123abc",
  "url": "https://api.vipps.no/dwo-api-application/v1/deeplink/vippsgateway?v=2&token=eyJraWQiOiJqd3RrZXkiLC <snip>"
}
```

Be aware that the URL is only valid for 10 minutes.

### Creation of One-Time Payment QR code

Now that you have the `url` from the eCom API you can create a QR code
using the following endpoint:

[`POST:qr/v1/`](https://developer.vippsmobilepay.com/redocusaurus/qr-swagger-id.yaml)

Example of a request for a QR code image using `Accept: image/png`
(see [QR code formats](https://developer.vippsmobilepay.com/docs/APIs/qr-api/api-guide/code-formats.md) for more options):

Headers:

```json
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1Ni <snip>
Ocp-Apim-Subscription-Key: YOUR-SUBSCRIPTION-KEY
Accept: image/png
Merchant-Serial-Number: 123456
Vipps-System-Name: Acme Commerce
Vipps-System-Version: 3.1.2
Vipps-System-Plugin-Name: acme-pos
Vipps-System-Plugin-Version 4.5.6
```

Body:

```json
{
  "url": "https://api.vipps.no/dwo-api-application/v1/deeplink/vippsgateway?v=2&token=eyJraWQiOiJqd3RrZXkiLC <snip>"
}
```

The response will be similar to this, where the URL in the body of the response will be a link to the image as defined in the accept header:

```json
{
  "url":"https://qr-generator-prod-app-service.azurewebsites.net/qr-generator/v1?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9....",
  "expiresIn": 247
}
```

**Please note:** The `expiresIn` value is in seconds.

## Polling for payment status

**INFO**

One-time payment QR codes use polling to check payment status, not webhooks.
This is because the payment is initiated directly in the app when the QR is scanned.

You will need to get the result of the payment by polling with the
[`GET:/ecomm/v2/payments/{orderId}/details`](https://developer.vippsmobilepay.com/redocusaurus/ecom-swagger-id.yaml) request.

In a physical context, we recommend a polling interval of one second.
See [polling guidelines](https://developer.vippsmobilepay.com/docs/knowledge-base/polling-guidelines.md) for information.

Once the QR code has been opened in the app, the `transactionId`
field in `transactionLogHistory` will be set (it will not exist before the
QR code has been scanned). Once this field is set, you can safely show a
*waiting for user* message on your POS screen while the user finishes the payment.

### Body once the QR has been opened by a user

```json
{
    "orderId": "acme-shop-123-order123abc",
    "transactionLogHistory": [
      {
        "amount": 20000,
        "operation": "INITIATE",
        "operationSuccess": true,
        "timeStamp": "2018-11-14T15:21:04.697Z",
        "transactionId": "5001420062",
        "transactionText": "One pair of socks",
      }
    ]
}
```

> **Full site overview:** For every page in this documentation, read [https://developer.vippsmobilepay.com/llms.txt](https://developer.vippsmobilepay.com/llms.txt).
