<div id="integration-guide">

<div class="ig-section" id="bgateway-checkout">
<div class="ig-section-header">
<div class="ig-section-icon" style="background:#fef7f0;color:#ea580c;"><i class="fas fa-server"></i></div>
<h2>Migrating from B-Gateway to Embedded Components</h2>
</div>
<p class="ig-section-desc">For businesses whose systems send payments to <strong>B-Gateway</strong> directly: the Borgun payment gateway web service (SOAP/XML), also written BGateway and known in Iceland as Greiðslugátt or simply "the Borgun web service". The first half is for the business owner; the second half is for your developer.</p>

<!-- Who -->
<div class="ig-subsection">
<h3>Who this guide is for</h3>
<ul>
<li>Your systems send XML requests such as <code>getAuthorization</code> to <code>gateway01.borgun.is</code>, with a B-Gateway <strong>username and password</strong>.</li>
<li>Card numbers reach your own servers: your checkout form collects them, or your systems hold card numbers or virtual card numbers (<code>9910…</code>) and send them on to B-Gateway.</li>
<li>You use the same <code>getAuthorization</code> call for payments where a customer is checking out and for charges you run later without them (subscriptions, instalments, top-ups). You may also run 3D Secure through <code>get3DSAuthentication</code> or your own or a third-party MPI.</li>
</ul>

```admonition
icon: fas fa-map-signs
title: Not you?
content: Calls to <code>/api/payment</code> (the RPG payment API), redirects to <code>securepay.borgun.is</code>, and payment URLs created in advance each have their own guide.
link: /online-payments/migration/overview
```

</div>

<!-- Why -->
<div class="ig-subsection">
<h3>Why migrate, and what you gain</h3>
<p>B-Gateway runs on Teya's legacy platform, which is retiring in early 2027. The new platform is an upgrade, not a like-for-like swap: it removes the parts of a B-Gateway integration that cost the most to build and maintain.</p>
<div class="ig-features">
<div class="ig-feature"><i class="fas fa-check"></i> <span><strong>More completed payments</strong> — merchants on the new platform generally see higher conversion: modern 3D Secure with fewer challenges, less checkout drop-off, and card retries that keep the sale</span></div>
<div class="ig-feature"><i class="fas fa-check"></i> <span><strong>No 3D Secure to build</strong> — enrollment, challenge and validation run inside the component</span></div>
<div class="ig-feature"><i class="fas fa-check"></i> <span><strong>No card data on your systems</strong> — Teya-hosted fields inside your page, a smaller PCI scope</span></div>
<div class="ig-feature"><i class="fas fa-check"></i> <span><strong>Payment confirmations that can't get lost</strong> — a signed webhook for every successful payment</span></div>
<div class="ig-feature"><i class="fas fa-check"></i> <span><strong>Apple Pay and currency conversion</strong> without extra code</span></div>
<div class="ig-feature"><i class="fas fa-check"></i> <span><strong>Refunds without a developer</strong>, and partial captures on pre-authorisations</span></div>
</div>
</div>
</div>

<!-- Options -->
<div class="ig-subsection">
<h3>Your options</h3>
<p><strong>Checkout component</strong> <span class="ig-badge ig-badge-recommended">Recommended</span> — the closest match to a B-Gateway checkout with the least to maintain. The customer stays on your page; one block provides card fields, pay button, 3D Secure, Apple Pay and currency conversion. This guide follows it.</p>
<ul>
<li><strong>Card component</strong> — a single card field inside your own form with your own pay button. See <a href="/online-payments/embedded-components/overview">Embedded Components</a>.</li>
<li><strong>Hosted Checkout</strong> — the customer is redirected to a Teya page and back. Least code, different customer experience; the steps below apply, with one change at Step 3. See <a href="/online-payments/hosted-checkout/get-started">Hosted Checkout</a>.</li>
<li><strong>Direct API</strong> — your servers send card data to Teya, as with B-Gateway today. Card data stays on your systems, so the PCI DSS obligations that come with it (SAQ D) stay with you, and Teya runs 3D Secure on the transaction flow while you display the challenge. Check with Teya before choosing this path, and tell us if you run your own or a third-party MPI today. See the <a href="/online-payments/migration/bgateway">B-Gateway reference</a>.</li>
</ul>

```admonition
icon: fas fa-info-circle
title: Customer-initiated and merchant-initiated payments
content: The new platform supports both: payments where the customer is present, through a checkout session, and merchant-initiated payments on a card the customer saved with you, including card-on-file and tokenisation. Which of your B-Gateway calls is which is the first thing your developer sorts out (developer guide, step 1). See <a href="/online-payments/saved-payments/overview">Card on File</a>.
```

<!-- Involves -->
<div class="ig-subsection">
<h3>What the migration involves</h3>
<div class="ig-flow-steps">
<div class="ig-flow-step"><span class="ig-flow-step-num">1</span> Get credentials</div>
<span class="ig-flow-arrow"><i class="fas fa-arrow-right"></i></span>
<div class="ig-flow-step"><span class="ig-flow-step-num">2</span> Build</div>
<span class="ig-flow-arrow"><i class="fas fa-arrow-right"></i></span>
<div class="ig-flow-step"><span class="ig-flow-step-num">3</span> Test in staging</div>
<span class="ig-flow-arrow"><i class="fas fa-arrow-right"></i></span>
<div class="ig-flow-step"><span class="ig-flow-step-num">4</span> Go live</div>
<span class="ig-flow-arrow"><i class="fas fa-arrow-right"></i></span>
<div class="ig-flow-step"><span class="ig-flow-step-num">5</span> Move saved cards</div>
<span class="ig-flow-arrow"><i class="fas fa-arrow-right"></i></span>
<div class="ig-flow-step"><span class="ig-flow-step-num">6</span> Retire B-Gateway</div>
</div>
<p>This is a small development project, and the result is less code than you have today: the SOAP client, the card form, any 3D Secure flow and batch handling are all removed. B-Gateway keeps working in parallel until you switch it off. If most of your payments are subscriptions or charges on cards you hold, step 5 and the charging of saved cards are the bulk of the work; the one-off checkout still comes first, because it is how new cards get saved from now on. Stored cards move on their own track, without any customer re-entering a card.</p>

```admonition
icon: fas fa-paper-plane
title: What to send your developer
content: (1) A link to this page, pointing at the developer guide below. (2) A development store from your Teya account manager, for staging credentials. Card saving (tokenization) is enabled by default, but enrolment can take up to 48 hours, so ask for the store early. (3) Questions to answer back: do you <strong>charge cards without the customer present</strong> (subscriptions, instalments, top-ups), and are those cards <strong>virtual card numbers</strong> from B-Gateway or <strong>card numbers you store yourself</strong>; do you use <strong>pre-authorisations</strong>; and do you use any <strong>other B-Gateway features</strong> (telephone or keyed orders, reports pulled from B-Gateway, Dynamic Descriptors, detail or itinerary data)? Each changes the plan.
```

</div>

</div>

<div class="ig-divider"></div>

<div class="ig-section" id="developer-guide">
<div class="ig-section-header">
<div class="ig-section-icon" style="background:#eff6ff;color:#2563eb;"><i class="fas fa-code"></i></div>
<h2>Developer guide</h2>
</div>
<p class="ig-section-desc">How a B-Gateway integration maps onto a checkout session, Hosted Checkout or the Checkout component, and token payments, with the one request you need at each step.</p>

<!-- Before / after -->
<div class="ig-subsection">
<h3>How it works: before and after</h3>
<p><strong>Today (B-Gateway)</strong></p>
<ol>
<li>Your checkout form collects the card number, expiry and security code; they reach your server.</li>
<li>If you run 3D Secure, your server calls <code>get3DSAuthentication</code> or your own MPI, sends the customer to the bank and gets <code>CAVV</code> / <code>UCAF</code> / <code>XID</code> back.</li>
<li>Your server sends <code>getAuthorization</code> (SOAP/XML, username and password, <code>Processor</code>, <code>MerchantID</code>, <code>TransType</code>, <code>RRN</code>) with the card or a virtual card number, plus 3D Secure values if you have them, and reads <code>ActionCode</code>. The same call is used whether or not the customer is present.</li>
<li>For subscriptions, you keep a virtual card number from <code>getVirtualCard</code> and later send <code>getAuthorization</code> with it, without the customer.</li>
<li>Refunds and cancellations reference the original <code>DateAndTime</code> + <code>RRN</code>; batches close at midnight GMT or on <code>newBatch</code>.</li>
</ol>
<p><strong>After (new platform)</strong></p>
<ol>
<li>Your server gets a short-lived access token and creates a <strong>checkout session</strong> for the amount. To save the card for later, it adds <code>save_payment_method: true</code>.</li>
<li>Your page mounts the <strong>Checkout component</strong> with the session token (or, with Hosted Checkout, redirects the customer to a Teya page). Teya collects the card and runs 3D Secure.</li>
<li>A signed <strong>webhook</strong> confirms the payment to your server. When the card was saved, it carries the <strong>token</strong>.</li>
<li>For subscriptions, your server charges the token later with <code>POST /v3/transactions/online</code>, marked as merchant-initiated.</li>
<li>Refunds reference the <code>transaction_id</code>. There are no batches.</li>
</ol>
<p><strong>The biggest change:</strong> card numbers no longer pass through your systems, and each payment is either a checkout session (customer present) or a charge on a saved card (merchant-initiated). The SOAP client, the card form, any 3D Secure flow, <code>getVirtualCard</code> and batch handling are all deleted.</p>
</div>

<!-- Before you start -->
<div class="ig-subsection">
<h3>Before you start</h3>

<h4>1. Sort your payments</h4>
<p>List every place your code calls <code>getAuthorization</code> and decide, for each one, whether a customer is present. On B-Gateway the same request serves both; on the new platform they are different calls:</p>
<ul>
<li><strong>A customer typing a card now</strong> (your checkout): a checkout session, then the Checkout component (Steps 2–3). 3D Secure runs for you.</li>
<li><strong>A charge on a stored card without the customer</strong> (subscription, instalment, top-up, pay-later): <code>POST /v3/transactions/online</code> on a saved token, declared merchant-initiated (Step 6). No 3D Secure, immediate result.</li>
<li><strong>Saving a card for later without charging it</strong>: a zero-amount <code>ACCOUNT_VERIFICATION</code> session with <code>save_payment_method</code> (Step 2).</li>
</ul>
<p>Every item on your list becomes either a session or a token charge. A charge without the customer is only possible on a card they saved with you, so if you hold card numbers that were never saved through Teya, see <a href="/online-payments/migration/stored-cards">Stored cards &amp; recurring</a> before you plan Step 6.</p>

<h4>2. Credentials</h4>
<p>Ask your Teya account manager for a development store. In the Staging Business Portal, select the store, go to <strong>Integrations</strong> and create ecommerce API credentials: a <strong>Client ID</strong>, a <strong>Client Secret</strong> (shown once) and your <strong>Store ID</strong>. Repeat at <code>business.teya.com</code> for production; never mix the two. This replaces your B-Gateway username, password, <code>Processor</code> and <code>MerchantID</code>. See <a href="/online-payments/authenticate">Authenticate</a>.</p>
<p>Card saving (tokenization) is enabled by default on every store, but enrolment can take up to 48 hours after the store is created. Until then, sessions with <code>save_payment_method</code> succeed but return no token. If that persists after 48 hours, contact support.</p>

<h4>3. Environments</h4>
<p>Staging is <code>api.teya.xyz</code> / <code>id.teya.xyz</code> / <code>business.teya.xyz</code>; production is the same hosts on <code>.com</code>. With Embedded Components, staging also needs <code>developmentMode: true</code> in the SDK. Full table on <a href="/online-payments/hosted-checkout/get-started">Hosted Checkout Get Started</a>.</p>

<h4>4. Webhook</h4>
<p>Teya sends a signed <code>payment.succeeded.v1</code> event to a public HTTPS endpoint with no authentication on it. Register the URL in the Business Portal next to your credentials; the portal issues a public key per webhook for verifying signatures. Only successful customer payments produce a webhook today; refunds, captures and token charges return their outcome in the API response. See <a href="/online-payments/webhooks">Webhooks</a>.</p>

<h4>5. Find the legacy code</h4>
<p>Search for <code>gateway01.borgun.is</code>, <code>borgun.is</code>, <code>getAuthorization</code>, <code>cancelAuthorization</code>, <code>get3DSAuthentication</code>, <code>getVirtualCard</code>, <code>newBatch</code>, <code>getTransactionList</code>, <code>TransType</code>, <code>TrAmount</code>, <code>TrCurrency</code>, <code>RRN</code>, <code>AuthCode</code>, <code>ActionCode</code>, <code>Processor</code>, <code>CAVV</code>, <code>UCAF</code>, <code>XID</code>, <code>SecurityLevelInd</code>, <code>lifecycleID</code>, the XML namespace <code>tempuri.org/getAuthorization.xsd</code>, and stored 16-digit values starting <code>9910</code>. Code based on the B-Gateway demo clients (<code>BGatewayDemoNet</code>, <code>BGatewayDemoPhp</code>, <code>BGatewayDemoPython</code>) follows the same pattern. Each hit is a line on the to-do list. If you send <code>TerminalID</code> 2 (ecommerce with 3D Secure) or <code>CAVV</code> / <code>UCAF</code> values, you run 3D Secure today: also check the MPI configuration behind it.</p>

<h4>6. Ground rules</h4>
<div class="ig-features">
<div class="ig-feature"><i class="fas fa-check"></i> <span>Complete a payment, webhook and refund end to end in staging before touching production code</span></div>
<div class="ig-feature"><i class="fas fa-check"></i> <span>Keep B-Gateway live behind a flag for a day or two after switching, so rollback is a config change</span></div>
<div class="ig-feature"><i class="fas fa-check"></i> <span>Never expose the Client Secret in browser code or repositories</span></div>
<div class="ig-feature"><i class="fas fa-check"></i> <span>Fulfil orders from the webhook, never from a browser redirect or callback alone</span></div>
<div class="ig-feature"><i class="fas fa-check"></i> <span>Move one-off payments first; saved cards follow on their own track</span></div>
</div>
</div>

<!-- Mapping -->
<div class="ig-subsection">
<h3>What replaces what</h3>
<p>The calls and fields a B-Gateway developer has to change. The <a href="/online-payments/migration/bgateway">B-Gateway reference</a> covers every operation, including reporting and the ones with no equivalent.</p>
<div style="overflow-x:auto;">
<table class="ig-comparison">
<thead>
<tr><th>B-Gateway today</th><th>New platform</th><th>What it means for you</th></tr>
</thead>
<tbody>
<tr><td>Username + password on every call</td><td><code>client_id</code> + <code>client_secret</code> → short-lived Bearer token</td><td>Cache and refresh from <code>expires_in</code> (currently 15 min in production, 24 h in staging).</td></tr>
<tr><td><code>Processor</code>, <code>MerchantID</code>, <code>TerminalID</code> (1 ecommerce, 2 ecommerce with 3D Secure, 3 recurring, 4 mail/telephone order)</td><td><code>store_id</code></td><td>One identifier per store, sent in the request body. What the terminal said about the payment is now said by the request itself: a session for customer-present payments, <code>initiator</code> + <code>recurring_payment_type</code> for the rest.</td></tr>
<tr><td><code>getAuthorization</code>, <code>TransType</code> 1</td><td><code>POST /v2/checkout/sessions</code>, <code>type: "SALE"</code> + the Checkout component</td><td>The server sends intent only: amount, currency, reference. No card data, no 3D Secure values.</td></tr>
<tr><td><code>getAuthorization</code>, <code>TransType</code> 5</td><td><code>type: "PRE_AUTHORISATION"</code> on the same endpoint</td><td>See Pre-authorisations below.</td></tr>
<tr><td><code>TransType</code> 1 with a pre-authorisation's <code>AuthCode</code></td><td><code>POST /v1/transactions/{id}/capture</code>, <code>{"amount": n}</code></td><td>Once per authorisation; the remainder is released.</td></tr>
<tr><td><code>TransType</code> 3 by <code>DateAndTime</code> + <code>RRN</code></td><td><code>POST /v3/refunds</code> with <code>transaction_id</code>, or the Business Portal</td><td>Same semantics: partial, multiple, total ≤ original.</td></tr>
<tr><td><code>TransType</code> 4, <code>cancelAuthorization</code></td><td><code>POST /v3/refunds</code> on the uncaptured payment</td><td>A refund before capture reverses the authorisation. No partial reversal; no open-batch rule.</td></tr>
<tr><td><code>get3DSAuthentication</code> / own MPI; <code>CAVV</code>, <code>UCAF</code>, <code>XID</code>, <code>SecurityLevelInd</code> (if you send them)</td><td>Gone: 3D Secure runs inside Hosted Checkout and the component</td><td>Delete the whole flow if you have one, including <code>MerchantReturnURL</code> handling. If you don't run 3D Secure today, there is nothing to delete.</td></tr>
<tr><td><code>PAN</code>, <code>ExpDate</code>, <code>CVC2</code>; your card form</td><td>Gone: entered on the Teya page or in Teya-hosted fields</td><td>Delete the card form and every place card data is logged or stored.</td></tr>
<tr><td><code>getVirtualCard</code></td><td><code>save_payment_method: true</code> on the session; <code>token_response.token_id</code> in the webhook</td><td>Saving happens inside the payment, or a zero-amount <code>ACCOUNT_VERIFICATION</code>.</td></tr>
<tr><td><code>getAuthorization</code> with a virtual card number (or a card number you store), customer absent</td><td><code>POST /v3/transactions/online</code>, <code>initiator: "MERCHANT"</code>, <code>payment_method.type: "TOKEN"</code></td><td>See Step 6. Virtual numbers you already hold move later; see <a href="/online-payments/migration/stored-cards">Stored cards &amp; recurring</a>. Card numbers you store yourself have no import: talk to your Teya account manager.</td></tr>
<tr><td><code>lifecycleID</code></td><td>Not sent</td><td>The platform links later charges to the first payment for you.</td></tr>
<tr><td><code>TrAmount</code>: 2 implied decimals, <strong>including ISK</strong> (100 ISK = <code>10000</code>)</td><td><code>amount.value</code>: minor units per ISO 4217; ISK has no subunit (100 ISK = <code>100</code>)</td><td>If you charge in ISK, divide B-Gateway amounts by 100: the most likely silent bug. Other currencies are unchanged (€49.90 is <code>4990</code> on both).</td></tr>
<tr><td><code>TrCurrency</code>: ISO numeric (<code>352</code>)</td><td><code>amount.currency</code>: ISO alphabetic (<code>"ISK"</code>)</td><td>Lookup change.</td></tr>
<tr><td><code>RRN</code> (12 characters), <code>DateAndTime</code></td><td><code>merchant_reference</code> (free-form) + optional <code>metadata</code>; no timestamp</td><td>Write the legacy RRN into <code>metadata</code> during the transition if it helps reconciliation.</td></tr>
<tr><td><code>ActionCode</code> (<code>000</code> = approved)</td><td><code>payment_status</code> (<code>SUCCESS</code> / <code>FAILED</code>) on the session</td><td>Declines show in the checkout and the customer retries in place.</td></tr>
<tr><td>Batches, <code>newBatch</code>, <code>Batch</code> / <code>Transaction</code> numbers</td><td>None</td><td>Delete. Key your records on <code>transaction_id</code>.</td></tr>
<tr><td><code>getTransactionList</code>, settlement and dispute lists</td><td><code>GET /v2/checkout/sessions/{session_id}</code> for one payment; the Business Portal for the rest</td><td>See <a href="/online-payments/migration/bgateway">the reference</a> for each report.</td></tr>
<tr><td>B-Online</td><td>Business Portal</td><td>Credentials, webhooks, refunds, transaction visibility.</td></tr>
</tbody>
</table>
</div>
</div>

<!-- Steps -->
<div class="ig-subsection">
<h3>Step-by-step</h3>
<p>Steps 1–5 take one-off payments end to end; Step 6 adds charging a saved card. Samples are cURL and minimal JavaScript; other languages are on the <a href="/online-payments/embedded-components/checkout/get-started">Embedded Checkout</a> Get Started page.</p>

<h4>Step 1 — Fetch an access token (server)</h4>
<p>Exchange <code>client_id</code> + <code>client_secret</code> for a Bearer token. This replaces sending a username and password on every call: cache the token per environment and refresh it before <code>expires_in</code> runs out or on a <code>401</code>. Scopes for this guide: <code>checkout/sessions/create</code>, <code>checkout/sessions/id/get</code>, <code>refunds/create</code>. Add <code>captures/create</code> for pre-authorisations and <code>transactions/online/create</code> for charging saved cards.</p>

```bash
curl -X POST https://id.teya.xyz/oauth/v2/oauth-token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=client_credentials" \
  -d "client_id=$TEYA_CLIENT_ID" \
  -d "client_secret=$TEYA_CLIENT_SECRET" \
  -d "scope=checkout/sessions/create checkout/sessions/id/get refunds/create transactions/online/create"
```

```json
{ "access_token": "eyJhbGciOiJSUzI1NiJ9...", "token_type": "Bearer", "expires_in": 900 }
```

<p>Full reference: <a href="/online-payments/authenticate">Authenticate</a>.</p>

<h4>Step 2 — Create a checkout session (server)</h4>
<p>When the customer clicks Pay, your server describes the payment. This replaces <code>getAuthorization</code>, but the body carries no card data and no 3D Secure values; only the intent. For a subscription sign-up, add <code>save_payment_method: true</code> so the card is saved during this payment.</p>

```bash
curl -X POST https://api.teya.xyz/v2/checkout/sessions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "store_id": "123e4567-e89b-12d3-a456-426614174000",
    "type": "SALE",
    "amount": { "value": 4990, "currency": "ISK" },
    "merchant_reference": "INV-2026-00042",
    "save_payment_method": true,
    "success_url": "https://yourstore.com/order/success",
    "cancel_url": "https://yourstore.com/checkout",
    "metadata": { "legacy_rrn": "ACME00012345" }
  }'
```

```json
{
  "session_id": "14411456-79c8-4d8c-8498-f01907093b83",
  "session_token": "eyJhbGciOiJSUzI1NiJ9...",
  "session_status": "ACTIVE"
}
```

<p><strong>Things to get right</strong></p>
<ul>
<li><code>amount.value</code> is an integer in minor units per ISO 4217: 4,990 ISK is <code>4990</code>, not B-Gateway's <code>499000</code>; €49.90 is <code>4990</code> on both.</li>
<li><code>Idempotency-Key</code> is unique per order attempt; retries with the same key can't create duplicate sessions. This replaces looking up an unknown result with <code>getTransactionList</code>.</li>
<li>To save a card without charging it (a "add a card" or free-trial flow), send <code>type: "ACCOUNT_VERIFICATION"</code> with <code>amount.value: 0</code> and <code>save_payment_method: true</code>. This replaces the zero-amount pre-authorisation.</li>
<li>Record the customer's consent to store the card before you save it. See <a href="/online-payments/saved-payments/overview">Card on File</a>.</li>
<li>Create the session when the customer clicks Pay, not when the cart loads: sessions expire.</li>
<li>The <code>session_token</code> in the response is what your page needs for the component (Step 3). <code>success_url</code> and <code>cancel_url</code> are only used by Hosted Checkout.</li>
</ul>
<p>Full reference: <a href="/online-payments/embedded-components/checkout/get-started">Embedded Checkout</a>, <a href="/apis/online-payments/apis">API Reference</a>.</p>

<h4>Step 3 — Mount the Checkout component (frontend)</h4>
<p>Install <code>@teyaproduct/teya-blocks-js</code>, initialise the SDK with the <code>session_token</code> from your backend, and mount the component. It replaces your card form and your 3D Secure redirect: the fields are Teya-hosted, so card data never enters your page or your server.</p>

```javascript
import { initTeyaBlocks } from '@teyaproduct/teya-blocks-js';

// 1. Ask your backend for a session (Step 2)
const { session_token } = await (await fetch('/api/teya-session', { method: 'POST' })).json();

// 2. Initialise the SDK
const teya = await initTeyaBlocks(session_token, {
  locale: 'is',
  // Routes SDK calls to Teya staging. Remove for production.
  developmentMode: true,
});

// 3. Mount the checkout: card fields, pay button, 3D Secure, Apple Pay, DCC included
const checkout = teya.elements.create('checkout', {
  onSuccess: () => { window.location.href = '/order/confirmation'; },
  onError: (error) => console.error('Payment failed', error),
});

checkout.mount('#checkout-container');
```

<p><strong>Things to get right</strong></p>
<ul>
<li>A staging session token only works with <code>developmentMode: true</code>; a production token only works without it.</li>
<li>Return only <code>session_token</code> to the browser through a small endpoint of your own; never the access token or the Client Secret.</li>
<li>For your own form layout and pay button, use the <a href="/online-payments/embedded-components/card/get-started">Card component</a> instead; everything else is the same.</li>
</ul>
<p><strong>Using Hosted Checkout instead?</strong> Skip the SDK: send the browser to the <code>session_url</code> returned with the session, exactly as returned. The customer pays on Teya's page and lands on your <code>success_url</code> or <code>cancel_url</code>; the redirect carries no payment data, so Steps 4 and 5 are unchanged. See <a href="/online-payments/hosted-checkout/get-started">Hosted Checkout Get Started</a>.</p>
<p>Full reference: <a href="/online-payments/embedded-components/sdk-initialization">SDK Initialization</a> and <a href="/online-payments/embedded-components/checkout/get-started">Embedded Checkout</a>.</p>

<h4>Step 4 — Look up the session (server)</h4>
<p>The webhook (Step 5) is the source of truth for fulfilment. As a fallback (customer closed the browser, webhook delayed, payment failed), look the session up by ID. This replaces reading <code>ActionCode</code> and polling <code>getTransactionList</code>.</p>

```bash
curl https://api.teya.xyz/v2/checkout/sessions/$SESSION_ID \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

```json
{
  "session_id": "14411456-79c8-4d8c-8498-f01907093b83",
  "session_status": "COMPLETED",
  "payment_status": "SUCCESS",
  "type": "SALE",
  "amount": { "value": 4990, "currency": "ISK" },
  "merchant_reference": "INV-2026-00042",
  "transaction_id": "tr_72302a4d-b2f9-4663-93f8-d9260e5370c8"
}
```

<p><strong>Things to get right:</strong> <code>session_status</code> runs <code>ACTIVE</code> → <code>PROCESSING</code> → <code>COMPLETED</code> or <code>EXPIRED</code>; trust <code>payment_status</code> only once <code>COMPLETED</code>. Store the <code>transaction_id</code>: it is the key for refunds, replacing <code>DateAndTime</code> + <code>RRN</code>. Full reference: <a href="/apis/online-payments/apis">API Reference</a>.</p>

<h4>Step 5 — Receive and verify the webhook (server)</h4>
<p>Teya POSTs a signed <code>payment.succeeded.v1</code> event to your registered URL when a payment succeeds, whether or not the customer comes back to your site. Verify <code>x-teya-signature</code> (SHA256withRSA, Base64) over the <strong>raw request body</strong> with the public key issued for this webhook, before parsing anything. When the card was saved, the event carries the token.</p>

```json
{
  "event": "payment.succeeded.v1",
  "timestamp": "2026-10-05T12:04:22Z",
  "data": {
    "transaction_id": "tr_72302a4d-b2f9-4663-93f8-d9260e5370c8",
    "session_id": "14411456-79c8-4d8c-8498-f01907093b83",
    "merchant_reference": "INV-2026-00042",
    "amount": { "value": 4990, "currency": "ISK" },
    "status": "SUCCESS",
    "token_response": { "token_id": "1e2d4f80-9c3e-4f5b-83aa-9e8d2b6a6c49", "token_status": "SUCCESS" }
  }
}
```

<p><strong>Things to get right</strong></p>
<ul>
<li>Store <code>data.token_response.token_id</code> against the customer. It replaces the virtual card number in your subscription records. <code>token_response</code> is <code>null</code> when no card was saved.</li>
<li>Be idempotent: the same event can arrive more than once. Return <code>200</code> promptly and do slow work asynchronously.</li>
<li>Register the route before any JSON body parser so you verify the raw bytes; check your handler with the <a href="/online-payments/webhook-signature-validator">Webhook Signature Validator</a>.</li>
</ul>
<p>Full reference: <a href="/online-payments/webhooks">Webhooks</a>.</p>

<h4>Step 6 — Charge a saved card later (server)</h4>
<p>For each subscription or instalment due, charge the token without the customer present. This replaces <code>getAuthorization</code> with a virtual card number and no 3D Secure values. Declare it as merchant-initiated: there is no 3D Secure and the result is immediate and final.</p>

```bash
curl -X POST https://api.teya.xyz/v3/transactions/online \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Idempotency-Key: sub-8812-2026-11" \
  -d '{
    "store_id": "123e4567-e89b-12d3-a456-426614174000",
    "type": "SALE",
    "initiator": "MERCHANT",
    "amount": { "value": 4990, "currency": "ISK" },
    "payment_method": {
      "type": "TOKEN",
      "token": {
        "token_id": "1e2d4f80-9c3e-4f5b-83aa-9e8d2b6a6c49",
        "recurring_payment_type": "RECURRING"
      }
    }
  }'
```

```json
{
  "type": "ONLINE_TRANSACTION",
  "online_transaction": {
    "transaction_id": "tr_9f2c1a70-4d88-4b3e-91ad-6c7e2f5b8d40",
    "status": "SUCCESS",
    "status_reason": null
  }
}
```

<p><strong>Things to get right</strong></p>
<ul>
<li><code>recurring_payment_type</code>: <code>RECURRING</code> for a fixed schedule, <code>INSTALLMENT</code> for a fixed number of payments, <code>CARD_ON_FILE</code> for unscheduled charges.</li>
<li>Use one <code>Idempotency-Key</code> per customer per billing period, so a re-run of your billing job can't charge twice.</li>
<li>Retry declines only for temporary reasons (<code>status_reason</code> such as <code>INSUFFICIENT_FUNDS</code> or <code>TEMPORARY_ISSUE_RETRY</code>); the full list is on Charge a Saved Payment Method.</li>
<li>Virtual card numbers you already hold are charged on B-Gateway, unchanged, until your stored cards are moved. See <a href="/online-payments/migration/stored-cards">Stored cards &amp; recurring</a>.</li>
<li>If your systems hold real card numbers rather than virtual card numbers, there is no import for them: talk to your Teya account manager before planning this step.</li>
</ul>
<p>Full reference: <a href="/online-payments/saved-payments/charge">Charge a Saved Payment Method</a>.</p>
</div>

<!-- After the payment -->
<div class="ig-subsection">
<h3>After the payment</h3>
<p>Each operation returns its outcome in the synchronous API response; there is no webhook for refunds or captures today, so record the response.</p>

<h4>Refunds</h4>
<p>Replaces <code>TransType</code> 3 and <code>cancelAuthorization</code>: partial and multiple refunds, total ≤ original, referenced by <code>transaction_id</code> instead of <code>DateAndTime</code> + <code>RRN</code>. <code>201</code> is processed; <code>202</code> is still processing: retry with the same <code>Idempotency-Key</code>. Staff can also refund from the Business Portal. Payments taken on B-Gateway before you switch stay refundable in B-Online.</p>

```bash
curl -X POST https://api.teya.xyz/v3/refunds \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{ "transaction_id": "tr_72302a4d-b2f9-4663-93f8-d9260e5370c8", "amount": 1000 }'
```

<p>See <a href="/online-payments/payment-actions">Payment Actions</a>.</p>

<h4>Pre-authorisations</h4>
<p>Skip this if you only send <code>TransType</code> 1 without an <code>AuthCode</code>. Create the session with <code>type: "PRE_AUTHORISATION"</code>; the checkout is unchanged and the funds are held (no currency conversion on pre-authorisations). Capture with <code>POST /v1/transactions/{id}/capture</code> and <code>{"amount": n}</code>: any amount up to the authorised total, but <strong>exactly once</strong>. The remainder is released, so capture the final amount; this also replaces the partial reversal (<code>TransType</code> 4). To cancel, refund the uncaptured payment; untouched holds expire on their own. See <a href="/online-payments/payment-actions">Payment Actions</a>.</p>

<h4>Using other features</h4>
<p>Batches, transaction and settlement reports, telephone or keyed orders, Dynamic Descriptors and detail or itinerary data each have their own answer on the new platform, and some depend on your set-up. If you use any of them, contact <a href="/support">Teya support</a> with your specific case before you migrate, so we can check it with you. The <a href="/online-payments/migration/bgateway">B-Gateway reference</a> lists every operation and where it lives now.</p>
</div>

<!-- Testing -->
<div class="ig-subsection">
<h3>Testing and going live</h3>
<p>Test in staging with the cards on the <a href="/online-payments/testing">Testing</a> page; frictionless, challenge and declined scenarios are all there. If your development machine isn't publicly reachable, tunnel it so staging webhooks can reach you.</p>

<p><strong>Definition of done</strong></p>
<div class="ig-features">
<div class="ig-feature"><i class="fas fa-check"></i> <span>Frictionless card: payment completes, webhook received and verified, session <code>COMPLETED</code> / <code>SUCCESS</code></span></div>
<div class="ig-feature"><i class="fas fa-check"></i> <span>Challenge card: the 3D Secure challenge shows in the component, and the payment completes</span></div>
<div class="ig-feature"><i class="fas fa-check"></i> <span>Declined card: error shown, customer can retry, order not marked paid</span></div>
<div class="ig-feature"><i class="fas fa-check"></i> <span>Abandoned or expired session: no webhook, nothing fulfilled, your code creates a fresh session</span></div>
<div class="ig-feature"><i class="fas fa-check"></i> <span>Amounts: an ISK (and, if relevant, EUR) payment charges exactly the right amount in the Business Portal</span></div>
<div class="ig-feature"><i class="fas fa-check"></i> <span>Full refund, then two partial refunds; a third exceeding the original fails</span></div>
<div class="ig-feature"><i class="fas fa-check"></i> <span>Replaying the same webhook doesn't double-fulfil</span></div>
<div class="ig-feature"><i class="fas fa-check"></i> <span>Integration recovers from a <code>401</code> by refreshing the token</span></div>
<div class="ig-feature"><i class="fas fa-check"></i> <span>Saved cards: a sale with <code>save_payment_method</code> and an <code>ACCOUNT_VERIFICATION</code> both return a <code>token_id</code> in the webhook; a merchant-initiated charge on that token succeeds</span></div>
<div class="ig-feature"><i class="fas fa-check"></i> <span>Pre-auth users: authorise, capture a partial amount, remainder released</span></div>
</div>

<p><strong>Go live</strong></p>
<ol>
<li>Create production credentials and register the production webhook in the Business Portal at <code>business.teya.com</code>; store the new public key. If you save cards, create the production store early: card saving is on by default but enrolment can take up to 48 hours.</li>
<li>Swap hosts by config (<code>.xyz</code> → <code>.com</code>) and, for Embedded Components, remove <code>developmentMode</code>.</li>
<li>Process one small real payment end to end: payment → webhook → refund.</li>
<li>Run B-Gateway in parallel for a day or two behind a flag; watch logs, webhook deliveries and the Business Portal. New cards are now saved on the new platform; existing virtual card numbers keep being charged on B-Gateway until they are moved.</li>
<li>Move your saved cards with <a href="/online-payments/migration/stored-cards">Stored cards &amp; recurring</a>.</li>
<li>Retire the legacy integration: delete the SOAP client, card form, 3D Secure flow, <code>getVirtualCard</code> and batch code. Remove stored card numbers and card data from your systems and logs. Teya retires the B-Gateway usernames and passwords for you; there is nothing to request.</li>
</ol>
</div>

<!-- Common errors -->
<div class="ig-subsection">
<h3>Common errors</h3>
<div style="overflow-x:auto;">
<table class="ig-comparison">
<thead>
<tr><th>Symptom</th><th>Likely cause</th><th>Fix</th></tr>
</thead>
<tbody>
<tr><td>Charged amount is 100× too big (ISK)</td><td>B-Gateway's two-implied-decimals convention carried over</td><td>Divide legacy ISK amounts by 100</td></tr>
<tr><td><code>422</code> creating a session</td><td>Numeric currency code (<code>352</code>) or a non-integer amount</td><td>Alphabetic <code>currency</code>; integer <code>amount.value</code> in minor units</td></tr>
<tr><td><code>401</code> on API calls</td><td>Access token expired; unlike a B-Gateway password it is short-lived</td><td>Refresh from <code>expires_in</code>; retry once on <code>401</code></td></tr>
<tr><td><code>403</code></td><td>Missing scope, e.g. <code>transactions/online/create</code> for saved-card charges</td><td>Add the scope to the token request (Step 1)</td></tr>
<tr><td><code>409</code></td><td>Same <code>Idempotency-Key</code>, different body</td><td>Unique key per order attempt or billing period; reuse only for retries of the identical request</td></tr>
<tr><td>Payment succeeds but no <code>token_id</code> in the webhook</td><td><code>save_payment_method</code> missing, or the store was created less than 48 hours ago and tokenization enrolment is still pending</td><td>Send <code>save_payment_method: true</code>; wait for enrolment, then contact support if it persists</td></tr>
<tr><td><code>400</code> charging a <code>9910…</code> value as <code>TOKEN</code></td><td>A legacy virtual card number sent as a Teya token</td><td>Keep charging it on B-Gateway until your stored cards are moved, then use <code>LEGACY_TOKEN</code>. See <a href="/online-payments/migration/stored-cards">Stored cards</a></td></tr>
<tr><td>A refund can't find the payment</td><td>Legacy <code>DateAndTime</code> + <code>RRN</code> used as the reference</td><td>Refund by <code>transaction_id</code>; refund B-Gateway payments in B-Online</td></tr>
<tr><td>Webhook never arrives</td><td>URL not public, no valid certificate, auth on the endpoint, or non-<code>200</code> responses</td><td>Public HTTPS, no auth, return <code>200</code> after processing</td></tr>
<tr><td>Signature verification fails</td><td>Parsed body re-serialised, or the wrong key</td><td>Verify the raw body; use the key issued for this webhook in this environment</td></tr>
<tr><td>Payment succeeded but not in the Business Portal</td><td>Wrong environment</td><td>Staging payments are in <code>business.teya.xyz</code>, production in <code>business.teya.com</code></td></tr>
</tbody>
</table>
</div>

```admonition
icon: fas fa-life-ring
title: Need help?
content: Your Teya account manager can provide a development store and plan the move of your saved cards. For integration questions and anything under "Using other features", see <a href="/support">Support</a>.
```

</div>

<!-- Next steps -->
<div class="ig-subsection">
<h3>Next steps</h3>
<ul>
<li><a href="/online-payments/migration/bgateway">B-Gateway reference</a> - Every B-Gateway operation and its replacement</li>
<li><a href="/online-payments/migration/stored-cards">Stored cards &amp; recurring</a> - Move your virtual card numbers once one-off payments are live</li>
<li><a href="/online-payments/embedded-components/checkout/get-started">Embedded Checkout</a> / <a href="/online-payments/hosted-checkout/get-started">Hosted Checkout</a> - Quickstarts in your language</li>
<li><a href="/online-payments/saved-payments/charge">Charge a Saved Payment Method</a> - Token payments and decline handling</li>
<li><a href="/online-payments/testing">Testing</a> - Test cards and integration checklist</li>
</ul>
</div>

</div>
</div>
