> **Description:** A step-by-step guide to quickly implement the QR API, including authentication setup, QR code generation, handling redirects, and testing the integration in various scenarios.

# Quick start

This guide takes you through all the QR API requests.

## Before you begin

Sign up as an organization with Vipps MobilePay and get your API keys.

You will need the [sales unit API keys](https://developer.vippsmobilepay.com/docs/knowledge-base/api-keys.md) for a *test* sales unit:

* `client_id` - Client ID for the sales unit.
* `client_secret` - Client secret for the sales unit.
* `Ocp-Apim-Subscription-Key` - Subscription key for the sales unit.
* `merchantSerialNumber` - The unique ID (MSN) for the sales unit.

[Partner keys](https://developer.vippsmobilepay.com/docs/partner/partner-keys.md#partner-keys) only work in the production environment.
To follow this guide in the test environment, use the test sales unit API keys provided in your welcome email.

In production, partner keys are used exactly like sales unit API keys, with one difference:
the `Merchant-Serial-Number` header is *required*, not just recommended.

If you're new to the platform, see
[Getting started](https://developer.vippsmobilepay.com/docs/getting-started.md)
for information about API keys, product activation, and the test environment.

The example values in this guide must be replaced with the values for your sales unit and user.
This applies to API keys, HTTP headers, references, phone numbers, and similar values.

## Create QR codes

### Step 1 - Setup

If using Postman, download the following files and import them into Postman.
Select the global environment as your active environment and update with your own values for the API keys and mobile numbers (both with and without country code). *Don't store production keys in the cloud.*

* [Download QR API Postman collection](https://developer.vippsmobilepay.com/tools/qr-api-postman-collection.json)
* [Download Global Postman environment](https://developer.vippsmobilepay.com/tools/global-postman-environment.json)

### Step 2 - Get an access token

Get an `access_token` from the
[Access Token API](https://developer.vippsmobilepay.com/docs/APIs/access-token-api/README.md):
[`POST:/accesstoken/get`](https://developer.vippsmobilepay.com/redocusaurus/access-token-swagger-id.yaml).

```text
Send request "Get Access Token"
```

```bash
curl -X POST 'https://apitest.vipps.no/accesstoken/get' \
-H "Content-Type: application/json" \
-H 'client_id: YOUR-CLIENT-ID' \
-H 'client_secret: YOUR-CLIENT-SECRET' \
-H 'Ocp-Apim-Subscription-Key: YOUR-SUBSCRIPTION-KEY' \
-H 'Merchant-Serial-Number: YOUR-MSN' \
--data ''
```

In production, include all `Vipps-System` headers to aid debugging.
See [HTTP headers](https://developer.vippsmobilepay.com/docs/knowledge-base/http-headers.md) for details.

The property `access_token` should be used as the Bearer token in the `Authorization` header of all the following API requests.

### Step 3 - Create a Merchant Redirect QR

A merchant redirect QR contains a link to your webshop. When the user scans this with their phone, your website will open.

Image: A sample merchant redirect QR code branded for Vipps, linking to a demo webshop.

Generate a merchant redirect QR with:
[`POST:/qr/v1/merchant-redirect`](https://developer.vippsmobilepay.com/redocusaurus/qr-swagger-id.yaml).

```text
Send request "Merchant Redirect QR > Generate QR"
```

The `qr-id` variable is now set in the environment for use with subsequent calls.

*Ctrl+click* the link to see the QR code. Scanning the QR should open the specified URL on your phone.

The result from this request provides a URL with its own JWT token, which will expire.
Get a new token by calling `Get QR by id`.

```bash
curl -X POST https://apitest.vipps.no/qr/v1/merchant-redirect \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR-ACCESS-TOKEN" \
-H "Ocp-Apim-Subscription-Key: YOUR-SUBSCRIPTION-KEY" \
-H "Merchant-Serial-Number: YOUR-MSN" \
-H 'Idempotency-Key: YOUR-IDEMPOTENCY-KEY' \
-H "Vipps-System-Name: acme" \
-H "Vipps-System-Version: 3.1.2" \
-H "Vipps-System-Plugin-Name: acme-webshop" \
-H "Vipps-System-Plugin-Version: 4.5.6" \
-d '{
    "redirectUrl": "https://example.com/mywebshop",
    "id": "UNIQUE-QR-ID"
}'
```

Enter the returned link into a browser. It will show the QR code. Scanning the QR should open the specified URL on your phone.

The result from this request provides a URL with its own JWT token, which will expire.
Get a new token by calling
[`GET:/qr/v1/merchant-redirect/{qr-id}`](https://developer.vippsmobilepay.com/redocusaurus/qr-swagger-id.yaml).

Relevant examples:

* [QR to site (payment only)](https://developer.vippsmobilepay.com/docs/recommended-flows/vending-machines/qr-to-merchant-site-payment-only.md)
* [QR to site (product selection)](https://developer.vippsmobilepay.com/docs/recommended-flows/vending-machines/qr-to-merchant-site-product-selection.md)

### Step 3 - Create a one-time payment QR

A one-time payment QR (also called dynamic QR) is connected to a payment. When the user scans this QR with their phone,
the Vipps app will open and present them with the payment request.

If you are using the ePayment API in your solution, you do not need to use the QR API.
See
[Dynamic QR directing to the app for payment](https://developer.vippsmobilepay.com/docs/recommended-flows/vending-machines/one-time-payment.md) for an example.

Legacy method for eCom API

Create a payment and get the unique payment reference.

```text
Send request "Initiate Payment"
```

The `orderId` and `vippsLandingPageUrl` variables are now in the environment of this Postman example.

```bash
curl -X POST 'https://apitest.vipps.no/ecomm/v2/payments/' \
-H "Authorization: Bearer YOUR-ACCESS-TOKEN" \
-H "Ocp-Apim-Subscription-Key: YOUR-SUBSCRIPTION-KEY" \
-H "Merchant-Serial-Number: YOUR-MSN" \
-H 'Idempotency-Key: YOUR-IDEMPOTENCY-KEY' \
-H "Vipps-System-Name: acme" \
-H "Vipps-System-Version: 3.1.2" \
-H "Vipps-System-Plugin-Name: acme-webshop" \
-H "Vipps-System-Plugin-Version: 4.5.6" \
-d '{
  "customerInfo": {
    "mobileNumber": "12345678"
  },
  "merchantInfo": {
    "merchantSerialNumber": "123456",
    "callbackPrefix":"https://example.com/vipps/callbacks-for-payment-update-from-vipps",
    "fallBack": "https://example.com/vipps/fallback-result-page-for-both-success-and-failure/acme-shop-123-order123abc",
  },
  "transaction": {
    "amount": 49900,
    "orderId": "UNIQUE-PAYMENT-REFERENCE",
    "transactionText": "One pair of socks.",
}
}'
```

Note that `orderId` must be unique for each payment you create.

Take note of the URL that is returned in the response body and provide it in the
[`POST:/qr/v1`](https://developer.vippsmobilepay.com/redocusaurus/qr-swagger-id.yaml)
request to generate the one-time payment QR.

```text
Send request "Generate OTP QR"
```

This supplies `vippsLandingPageUrl` to
[`POST:/qr/v1`](https://developer.vippsmobilepay.com/redocusaurus/qr-swagger-id.yaml)
to provide a URL that can be used to show a QR code.

*Ctrl+click* the link to see the QR code. Scanning the QR should open the test app on your phone and allow you to complete the one-time purchase.

```bash
curl -X POST 'https://apitest.vipps.no/qr/v1' \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR-ACCESS-TOKEN" \
-H "Ocp-Apim-Subscription-Key: YOUR-SUBSCRIPTION-KEY" \
-H "Merchant-Serial-Number: YOUR-MSN" \
-H "Vipps-System-Name: acme" \
-H "Vipps-System-Version: 3.1.2" \
-H "Vipps-System-Plugin-Name: acme-webshop" \
-H "Vipps-System-Plugin-Version: 4.5.6" \
-d '{
    "url": "https://apitest.vipps.no/dwo-api-application/v1/deeplink/vippsgateway?v=2&token=eyJraWQiOiJqd3RrZXkiLCJhbGciOiJSUzI1NiJ<truncated>"
}'
```

## Next steps

See the [QR API guide](https://developer.vippsmobilepay.com/docs/APIs/qr-api/api-guide/README.md) to read about the concepts and details.

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