# Static QR Code

## Create a Static QR Code - Gastro Case

You can create a Static QR Code with our Merchant API.\
For simplicity, we will explain it with the example of the QR Code creation.

### **Step 1: Create a QR Code**

Create a QR Code with the mandatory parameters:

* [Create a QR Code](https://developers.payrexx.com/reference/create-a-qr-code)

The **webshopUrl** is a mandatory field.

Your QR Code can be scanned using any QR Code scanner.

### **Step 2: Display the QR Code**

After Step 1, you will get a QR Code string in the response of your request.\
Use this string as src attribute in HTML image tag. Now your QR Code can be displayed as image.

### **Step 3: Scan the QR Code**

If the buyer scans the QR Code using TWINT app, they will be redirected to your webshop URL with the following parameters.

* qr\_code\_session\_id
* returnAppScheme (iOS)
* returnAppPackage (Android)

#### Example Redirects

Scanned using a TWINT app

* **iOS**: `https://{{webshopUrl}}?qr_code_session_id={{session}}&returnAppScheme={{appName}}`
* **Android**: `https://{{webshopUrl}}?qr_code_session_id={{session}}&returnAppPackage={{appName}}`

Scanned using a regular QR code scanner app

* `https://{{webshopUrl}}`

### Step 4: Gateway

Once the buyer has selected their products on your webshop and is ready to pay, you have to [Create a Gateway](/developer/guides/gateway.md) with the corresponding amount and currency (optional: basket).

In Gateway creation you need to pass the QR Code session ID and the "return app" parameter:

```php
$gateway->setQrCodeSessionId($_GET['qr_code_session_id']);
if ($_GET['returnAppScheme']) {
    $returnApp = 'returnAppScheme=' . $_GET['returnAppScheme']; // iOS
} else if ($_GET['returnAppPackage']) {
    $returnApp = 'returnAppPackage=' . $_GET['returnAppPackage']; // Android
}
$gateway->setReturnApp($returnApp);
```

In the Gateway response you will get the TWINT app link:

```json
{
  "status": "success",
  "data": [
    {
      "transactionId": "100",
      "appLink": "intent://payment#Intent;action=ch.twint.action.TWINT_PAYMENT;scheme=twint;S.code=12345;S.startingOrigin=EXTERNAL_WEB_BROWSER;S.browser_fallback_url=;end", // Android
      // "appLink": 'twint-issuer1://applinks/?al_applink_data={"app_action_type": "TWINT_PAYMENT","extras": {"code": "12345",},"referer_app_link": {"target_url": "", "url": "", "app_name": "EXTERNAL_WEB_BROWSER"}, "version": "6.0" }' // iOS
    }
  ]
}
```

Once you received the **appLink** in the response, you need to open it. So the TWINT app will be automatically opened for the buyer.

Parallel to this you have to start a **transaction polling** using the **transactionId** in the response and the [Retrieve a transaction](https://developers.payrexx.com/reference/retrieve-a-transaction) endpoint. You can perform the GET request every second until the transaction status changes from `initiated` to `confirmed` or `cancelled`. Once the status has changed, you can show the corresponding result page on your webshop.

#### Scan the QR Code (Other App / Camera)

If the customer scans the QR Code other than TWINT app, they will also be redirected to your webshop url. But without special parameters. When the buyer is ready to pay in your webshop, you have to [Create a Gateway](https://developers.payrexx.com/reference/create-a-gateway).

Other as in the TWINT app case you have to create the Gateway with the following redirect URLs.

```php
$gateway->setSuccessRedirectUrl('https://www.merchant-website.com/success');
$gateway->setFailedRedirectUrl('https://www.merchant-website.com/failed');
$gateway->setCancelRedirectUrl('https://www.merchant-website.com/cancel');
```

You will receive a link in the Gateway response as mentioned [here](https://developers.payrexx.com/reference/create-a-gateway). You just need to open the link. The buyer will be redirected to Payrexx Gateway page. There the buyer can choose their preferred payment method and do the payment. Once the payment is done, they will be redirected to the URL which is set in the Gateway creation.

### **Delete a QR Code**

You can delete the QR Code using [Delete a QR Code](https://developers.payrexx.com/reference/delete-a-qr-code) endpoint.

When cancelling the order process in your webshop you also have to destroy the session to prevent possible payments after cancellation. You can delete the QR Code Scan using [Delete a QR Code Scan](https://developers.payrexx.com/reference/delete-a-qr-code-scan) endpoint by setting the session ID (see [#step-3-scan-the-qr-code](#step-3-scan-the-qr-code "mention")).


---

# 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://docs.payrexx.com/developer/general-info/payment-method/static-qr-code.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.
