Skip to content
commitius

How do you connect a virtual POS to your site? The PayTR iFrame API step by step

Payment token, payment form and notification URL. Fields, signature, testing and going live from PayTR's own docs, plus a checklist before you launch.

Can DemirFounder & author · 5 min read
The blue PayTR logo on a white background

It connects in two parts. First your server gets a payment token from PayTR and opens the payment form on your site. When the payment is done, PayTR sends the result to your notification URL, and that is where you confirm the order. Bank virtual POS systems work the same way. We use PayTR, one of the most widely used payment providers in Turkey, as the example because its docs are public.

What do you need before you start?

  • An approved PayTR merchant account.
  • Three values from the panel: the store number (merchant_id), the store password (merchant_key) and the secret key (merchant_salt). In the panel they are under Destek & Kurulum > Entegrasyon Bilgileri, and only the main user and the technical user can see that screen.
  • The password and the secret key live on the server only. They never go to the browser, the site's JavaScript or Git.

Step 1: getting the payment token

When the customer goes to checkout, your server sends a POST request to https://www.paytr.com/odeme/api/get-token. According to PayTR's docs, these are the fields to watch:

  • The amount is sent in kuruş. 34.56 TL is sent as 3456. Round carefully when you multiply a decimal.
  • The order number (merchant_oid) must be unique and contain only letters and digits. Many platforms use dashes or underscores in order IDs (order_01J...). Strip them before you send.
  • The customer's IP must be their real IP. If the site sits behind Cloudflare or another proxy, the address your server sees is the proxy's. Take the real one from the request header.
  • The email must not contain Turkish characters.
  • The basket is a list of product name, unit price and quantity. It is turned into JSON and then base64 encoded.
  • paytr_token signs the request. These fields are joined in this order: merchant_id, user_ip, merchant_oid, email, payment_amount, user_basket, no_installment, max_installment, currency, test_mode. merchant_salt is appended, an HMAC-SHA256 is taken with merchant_key, and the result is base64 encoded.
import { createHmac } from "node:crypto"
 
const hashInput =
  [merchantId, userIp, merchantOid, email, paymentAmount, basketBase64,
    noInstallment, maxInstallment, currency, testMode].join("") + merchantSalt
const paytrToken = createHmac("sha256", merchantKey).update(hashInput).digest("base64")

Send debug_on=1 while you develop. If a field is missing or wrong, PayTR tells you why.

Step 2: showing the payment form

The token in the response opens the form inside an iframe on your site. Its source is https://www.paytr.com/odeme/guvenli/{token}, and PayTR's iframeResizer script sets its height. If your site has a Content Security Policy, allow paytr.com for frames and scripts. Without it the form does not open, and the browser blocks it silently.

Step 3: the notification URL, where the real work happens

When the payment ends, PayTR sends a server-to-server POST to your notification URL. It carries the order number, the result (success or failed), the amount collected and a verification value (hash). The docs set these rules:

  • Verify the signature first. Join merchant_oid + merchant_salt + status + total_amount, take an HMAC-SHA256 with merchant_key, base64 encode it and compare it with the incoming hash. If it doesn't match, reject the request. Skipping this means shipping goods on a fake "paid" notification.
  • The response must be plain text, just OK. Any HTML before or after it and PayTR treats the notification as failed, and the order shows as "Devam Ediyor" (in progress) in the panel.
  • The same notification can arrive more than once. If the order is already confirmed, don't process it again. Just return OK.
  • No session or login check on this page. PayTR's server calls it, not the customer.
  • Use total_amount in your books. If the customer chose instalments with interest, the amount collected is higher than the order amount.
  • The URL is set in the panel under Destek & Kurulum > Ayarlar > Bildirim URL Ayarları. If your site runs on HTTPS, choose HTTPS there too.
const expected = createHmac("sha256", merchantKey)
  .update(merchantOid + merchantSalt + status + totalAmount)
  .digest("base64")
if (expected !== hash) return new Response("bad hash", { status: 400 })
// If the order was already handled, leave it. Otherwise confirm or cancel it.
return new Response("OK")

Why doesn't the "payment successful" page confirm the order?

Because PayTR sends no data to that page. The success and failure pages only inform the customer. If the customer closes the tab after paying, they never reach it. The order is confirmed only at the notification URL. Most "the payment went through but no order was created" complaints come from this. On custom-built platforms we set up the notification URL and the order confirmation as part of PayTR integration.

How do testing and going live work?

PayTR describes this order:

  1. In test mode the card details come pre-filled in the payment form. You start the payment and approve it on PayTR's 3D test page.
  2. Find the test payment by email on the İşlemler (transactions) page in the panel and check its status. If you see "Devam Ediyor", your notification URL is not returning OK. The "Detay" link on the row shows what it returned.
  3. In Destek & Kurulum > Canlı Mod, click "Evet, Entegrasyonu Tamamladım", then "Canlı Moda Geçiş Talebi Gönder".
  4. PayTR checks it and lets you know by SMS and email once it is approved. Real payments start from then on.

Save this: a checklist before you go live

  • The password and the secret key are on the server only, not in Git.
  • The amount is sent in kuruş and rounded correctly.
  • The order number is unique, letters and digits only.
  • The real customer IP is sent.
  • The CSP allows paytr.com.
  • The notification URL verifies the signature.
  • The notification URL returns a plain OK.
  • A repeated notification does not process the order twice.
  • The order is confirmed at the notification URL, not on the "successful" page.
  • total_amount goes to your books.
  • debug_on is off in production.

If you use WooCommerce, PayTR's plugin does most of this, as we explain in a separate note. We compare commissions and fees in our note on free virtual POS.

Share

Working on something similar?

Tell us in a few sentences what you want to do, and we will work out the right way together.