<div id="integration-guide">

<div class="ig-section">
<div class="ig-section-header">
<div class="ig-section-icon" style="background:#eff6ff;color:#2563eb;"><i class="fas fa-exchange-alt"></i></div>
<h2>Migrate your RPG Credentials</h2>
</div>
<p class="ig-section-desc">This guide is for partners who process payments via RPG on their merchants' behalf. Individual merchants don't need this — they can generate fresh credentials in the Teya Business Portal. To transact on the new ecommerce platform you need new client credentials, issued per store. You can obtain them by implementing the <a href="/partners/online-payments/register-merchants">merchant registration flow</a>, which is ideal for newly onboarding merchants. But to avoid disrupting your existing merchants or asking them to re-onboard, we have built a credentials exchange API that accepts RPG credentials and issues new ones.</p>

<!-- How it works -->
<div class="ig-subsection">
<h3>1. How migration works</h3>
<div class="ig-flow-steps">
<div class="ig-flow-step"><span class="ig-flow-step-num">1</span> Call the <strong>credentials exchange endpoint</strong> with the merchant's RPG private key</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> Store the returned <strong>Client ID and Client Secret</strong> securely</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> Switch the merchant's integration to the <strong>new Teya APIs</strong></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> Verify payments and webhooks, then <strong>retire the RPG key</strong></div>
</div>
<p>Repeat the exchange once per merchant store. Each store gets its own pair of credentials.</p>

```admonition
icon: fas fa-info-circle
title: Production only
content: The exchange endpoint is available in production only, because it authenticates against live RPG credentials.
```
</div>

<!-- Exchange endpoint -->
<div class="ig-subsection">
<h3>2. Exchange RPG credentials</h3>
<p>Exchange a merchant's RPG private key for new ecommerce credentials:</p>

```text
POST https://ecom-gateway.teya.com/v1/ecommerce/legacy/credentials
```

<h4>Authentication</h4>
<p>HTTP Basic with the merchant's existing RPG <strong>private</strong> key — the same scheme you already use for payments on RPG. The username is the private key exactly as it was provided to you; the password field is ignored.</p>

<h4>Request</h4>
<p>The body is optional. Provide <code>webhook_url</code> to register a payments webhook for the store — an endpoint on your platform where Teya sends a real-time notification when a payment succeeds (see <a href="/partners/online-payments/webhooks">Webhooks</a>). It must be HTTPS with a publicly resolvable hostname, and it is what produces <code>payment_webhook_public_key</code> in the response.</p>
<p>Provide <code>plugin_metadata</code> if the merchant integrates through a plugin — it decides the application name recorded for the new credentials.</p>

```json
{
  "webhook_url": "https://partner.example.com/teya/payments",
  "plugin_metadata": {
    "plugin_type": "ACME_SHOP",
    "plugin_version": "1.0.0"
  }
}
```

<table class="ig-comparison">
<thead>
<tr><th>Field</th><th>Required</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><code>webhook_url</code></td><td>No</td><td>Payments webhook to register for the store. Must be HTTPS with a publicly resolvable hostname</td></tr>
<tr><td><code>plugin_metadata</code></td><td>No</td><td>The way for Teya to identify you as a partner. It helps us track partner usage, and debug and identify issues with your integration</td></tr>
<tr><td><code>plugin_metadata.plugin_type</code></td><td>Yes, when <code>plugin_metadata</code> is supplied</td><td>The plugin the merchant integrates through, for example <code>ACME_SHOP</code>. When you begin your integration, Teya will assign an ENUM for you</td></tr>
<tr><td><code>plugin_metadata.plugin_version</code></td><td>No</td><td>The version of the plugin</td></tr>
</tbody>
</table>

<h4>Example: Exchange credentials</h4>

```bash
curl -X POST 'https://ecom-gateway.teya.com/v1/ecommerce/legacy/credentials' \
  -u '<private_key>:' \
  -H 'Content-Type: application/json' \
  -d '{
    "webhook_url": "https://partner.example.com/teya/payments",
    "plugin_metadata": {"plugin_type": "ACME_SHOP", "plugin_version": "1.0.0"}
  }'
```

<h4>Response</h4>
<p><code>payment_webhook_public_key</code> is <code>null</code> when no <code>webhook_url</code> was supplied.</p>

```json
{
  "mid": "9256684",
  "store_id": "3f2b8c14-7d5e-4a91-b8c2-9e1f0a6d4b73",
  "client_id": "ecom_direct_8f41c9",
  "client_secret": "cs_live_2Hq9...redacted",
  "payment_webhook_public_key": "-----BEGIN PUBLIC KEY-----..."
}
```

<table class="ig-comparison">
<thead>
<tr><th>Field</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><code>mid</code></td><td>The RPG merchant ID the key authenticated as</td></tr>
<tr><td><code>store_id</code></td><td>The Teya store mapped to that merchant ID</td></tr>
<tr><td><code>client_id</code></td><td>OAuth client ID for the new ecommerce APIs</td></tr>
<tr><td><code>client_secret</code></td><td>OAuth client secret for the new ecommerce APIs. Returned once and never stored — this is the only time it is available</td></tr>
<tr><td><code>payment_webhook_public_key</code></td><td>Public key for verifying payment webhook signatures; <code>null</code> if no <code>webhook_url</code> was supplied</td></tr>
</tbody>
</table>

<table class="ig-comparison">
<thead>
<tr><th>Response</th><th>Meaning</th></tr>
</thead>
<tbody>
<tr><td><code>200</code></td><td>Credentials issued, and webhook registered when <code>webhook_url</code> was supplied</td></tr>
<tr><td><code>400</code></td><td>The supplied <code>webhook_url</code> or <code>plugin_metadata</code> cannot be used</td></tr>
<tr><td><code>401</code></td><td>The credentials are missing, malformed, or were rejected</td></tr>
<tr><td><code>422</code></td><td>The credentials are valid but the merchant is not eligible for migration</td></tr>
<tr><td><code>500</code></td><td>A service the flow depends on could not be reached</td></tr>
</tbody>
</table>

<h4>Error codes</h4>
<p>Error responses carry a JSON body with a <code>code</code> and a human-readable <code>description</code>:</p>

```json
{
  "code": "MERCHANT_NOT_MAPPED",
  "description": "Not yet available for this merchant."
}
```

<table class="ig-comparison">
<thead>
<tr><th>Code</th><th>Status</th><th>Meaning</th></tr>
</thead>
<tbody>
<tr><td><code>INVALID_WEBHOOK</code></td><td><code>400</code></td><td>The <code>webhook_url</code> is not HTTPS or not publicly resolvable</td></tr>
<tr><td><code>BAD_REQUEST</code></td><td><code>400</code></td><td>The <code>plugin_metadata</code> is invalid — for example, <code>plugin_type</code> is missing or not a supported value</td></tr>
<tr><td><code>UNAUTHORISED</code></td><td><code>401</code></td><td>The RPG key is missing, malformed, unknown or disabled</td></tr>
<tr><td><code>MERCHANT_NOT_MAPPED</code></td><td><code>422</code></td><td>The merchant ID is not yet mapped to a Teya store — migration is not yet available for this merchant</td></tr>
<tr><td><code>SUBSCRIPTION_NOT_FOUND</code></td><td><code>422</code></td><td>The store does not have an active ecommerce subscription</td></tr>
<tr><td><code>INTERNAL_SERVER_ERROR</code></td><td><code>500</code></td><td>Credential verification is temporarily unavailable — retry later</td></tr>
</tbody>
</table>

```admonition
icon: fas fa-exclamation-triangle
title: Keep credentials secure
content: Store <code>client_secret</code> and <code>payment_webhook_public_key</code> in encrypted configuration or a secrets store. Never expose them in client-side code.
```

</div>

<!-- Use the new credentials -->
<div class="ig-subsection">
<h3>3. Use your new credentials</h3>
<p>Exchange the <code>client_id</code> and <code>client_secret</code> for an access token, then call the Online Payments API on the merchant's behalf:</p>

```bash
curl -X POST 'https://id.teya.com/oauth/v2/oauth-token' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'grant_type=client_credentials' \
  -d 'client_id=<client_id>' \
  -d 'client_secret=<client_secret>' \
  -d 'scope=<scopes for your products>'
```

<p>The scopes you need depend on the products you integrate — see <a href="/partners/online-payments/register-merchants">Required scopes by product</a>.</p>
</div>

<!-- Next steps -->
<div class="ig-subsection">
<h3>Next steps</h3>
<ul>
<li><a href="/partners/online-payments/migration/overview">Migration overview</a> - The three-stage plan for migrating a merchant base</li>
<li><a href="/partners/online-payments/migration/rpg">Migrating from RPG</a> - Map each RPG capability to its replacement</li>
<li><a href="/partners/online-payments/webhooks">Webhooks</a> - Receive and verify payment notifications</li>
<li><a href="/partners/online-payments/embedded-components/overview">Embedded Components</a> - Embed payment fields in your own UI</li>
<li><a href="/partners/online-payments/testing">Testing</a> - Test cards and integration checklist</li>
<li><a href="/apis/online-payments/apis">API Reference</a> - Full API endpoint documentation</li>
</ul>
</div>

</div>
</div>
