# Take your first online payment (/quickstart) > Create a test payment from a terminal, pay it on the MPS checkout and read it back in five minutes, with one test key. The developer quickstart. Create a payment with two API calls, pay it on the MPS checkout with a test card, and read it back. In test mode nothing is charged. Not a developer? A [payment link](/payment-links) or a [shop plugin](/connect-your-webshop) takes payments without code. [Start here](/) to choose. ## Five minutes, in a terminal - A test key (`mps_test_…`) from **Online › API keys** on the MPS platform. No test key yet? The merchant creates one; see [online payment setup](/set-up-your-account). - A terminal with `curl` and `uuidgen`, or your language's runtime, and a browser > **Server only.** The API cannot be called from a browser. The gateway answers no cross-origin (CORS) requests, and the API key must never reach a browser. Call it from your server. ### Set your key ```bash export MPS_API_KEY="mps_test_…" ``` Every call sends it as `Authorization: Bearer`. You do not exchange it for anything first. ### Create a payment Amounts are integers in **euro cents**. The `Idempotency-Key` makes a retry safe: send the same key again and you get the same payment back, never a second one. Pick your language. Each example runs as it is with the key from the step above; the choice is kept for the page. ```bash tab="curl" tab-group="lang" IDEMPOTENCY_KEY=$(uuidgen) # one per checkout attempt; reuse it to retry this create curl -sS --fail-with-body -X POST "https://gateway.mps-emi.com/api/payments/internet/create" \ -H "Authorization: Bearer $MPS_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $IDEMPOTENCY_KEY" \ -d '{ "amount": 1995, "reference": "order-42", "successUrl": "https://example.com/paid", "failureUrl": "https://example.com/failed" }' ``` ```csharp tab="C#" // dotnet new console, replace Program.cs, then: dotnet run using System.Net.Http.Json; using System.Text.Json; using var mps = new HttpClient { BaseAddress = new("https://gateway.mps-emi.com/api/payments/internet/") }; mps.DefaultRequestHeaders.Authorization = new("Bearer", Environment.GetEnvironmentVariable("MPS_API_KEY")); using var create = new HttpRequestMessage(HttpMethod.Post, "create") { Content = JsonContent.Create(new { amount = 1995, // cents reference = "order-42", successUrl = "https://example.com/paid", failureUrl = "https://example.com/failed", }), }; create.Headers.Add("Idempotency-Key", Guid.NewGuid().ToString()); // one per checkout attempt using var response = await mps.SendAsync(create); if (!response.IsSuccessStatusCode) { // 400 names the field, 401 and 403 the key: see Errors below. Console.Error.WriteLine($"MPS answered {(int)response.StatusCode}: {await response.Content.ReadAsStringAsync()}"); return 1; } var data = (await response.Content.ReadFromJsonAsync()).GetProperty("data"); Console.WriteLine($"paymentReference: {data.GetProperty("paymentReference")}"); // keep it for the read Console.WriteLine($"checkoutUrl: {data.GetProperty("checkoutUrl")}"); // open it in a browser return 0; ``` ```ts tab="TypeScript" // node create.ts (Node 23.6 or later) import { randomUUID } from 'node:crypto'; const response = await fetch('https://gateway.mps-emi.com/api/payments/internet/create', { method: 'POST', headers: { Authorization: `Bearer ${process.env.MPS_API_KEY}`, 'Content-Type': 'application/json', 'Idempotency-Key': randomUUID(), // one per checkout attempt }, body: JSON.stringify({ amount: 1995, // cents reference: 'order-42', successUrl: 'https://example.com/paid', failureUrl: 'https://example.com/failed', }), }); if (!response.ok) { // 400 names the field, 401 and 403 the key: see Errors below. throw new Error(`MPS answered ${response.status}: ${await response.text()}`); } const { data } = (await response.json()) as { data: { paymentReference: string; checkoutUrl: string } }; console.log('paymentReference:', data.paymentReference); // keep it for the read console.log('checkoutUrl:', data.checkoutUrl); // open it in a browser ``` ```python tab="Python" # pip install requests, then: python create.py import os import sys import uuid import requests response = requests.post( "https://gateway.mps-emi.com/api/payments/internet/create", headers={ "Authorization": f"Bearer {os.environ['MPS_API_KEY']}", "Idempotency-Key": str(uuid.uuid4()), # one per checkout attempt }, json={ "amount": 1995, # cents "reference": "order-42", "successUrl": "https://example.com/paid", "failureUrl": "https://example.com/failed", }, timeout=10, ) if response.status_code != 200: # 400 names the field, 401 and 403 the key: see Errors below. sys.exit(f"MPS answered {response.status_code}: {response.text}") data = response.json()["data"] print("paymentReference:", data["paymentReference"]) # keep it for the read print("checkoutUrl:", data["checkoutUrl"]) # open it in a browser ``` ```php tab="PHP" true, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . getenv('MPS_API_KEY'), 'Content-Type: application/json', 'Idempotency-Key: ' . bin2hex(random_bytes(16)), // one per checkout attempt ], CURLOPT_POSTFIELDS => json_encode([ 'amount' => 1995, // cents 'reference' => 'order-42', 'successUrl' => 'https://example.com/paid', 'failureUrl' => 'https://example.com/failed', ]), CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10, ]); $body = (string) curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); if ($status !== 200) { // 400 names the field, 401 and 403 the key: see Errors below. fwrite(STDERR, "MPS answered $status: $body\n"); exit(1); } $data = json_decode($body, true)['data']; echo "paymentReference: {$data['paymentReference']}\n"; // keep it for the read echo "checkoutUrl: {$data['checkoutUrl']}\n"; // open it in a browser ``` ```json title="200 OK" { "data": { "paymentReference": "test-…", "checkoutUrl": "https://pay.mps-emi.com/…" } } ``` ### Pay on the checkout Open `checkoutUrl` in a browser and pay with card `4111 1111 1111 1111`, any future expiry date and any security code. The checkout sends you on to your `successUrl`. > **Warning.** Landing on successUrl is not proof of payment. Verify the webhook signature, read the payment, and check its state, amount, currency, and reference before marking an order paid. ### Read it back Put the `paymentReference` from the create in `PAYMENT_REFERENCE`, then read the payment. ```bash tab="curl" tab-group="lang" export PAYMENT_REFERENCE="test-…" curl -sS --fail-with-body "https://gateway.mps-emi.com/api/payments/internet/$PAYMENT_REFERENCE" \ -H "Authorization: Bearer $MPS_API_KEY" ``` ```csharp tab="C#" // dotnet new console, replace Program.cs, then: PAYMENT_REFERENCE=test-… dotnet run using System.Net.Http.Json; using System.Text.Json; using var mps = new HttpClient { BaseAddress = new("https://gateway.mps-emi.com/api/payments/internet/") }; mps.DefaultRequestHeaders.Authorization = new("Bearer", Environment.GetEnvironmentVariable("MPS_API_KEY")); var reference = Environment.GetEnvironmentVariable("PAYMENT_REFERENCE")!; using var response = await mps.GetAsync(Uri.EscapeDataString(reference)); if (!response.IsSuccessStatusCode) { // 404: no such payment for this key. See Errors below. Console.Error.WriteLine($"MPS answered {(int)response.StatusCode}: {await response.Content.ReadAsStringAsync()}"); return 1; } var data = (await response.Content.ReadFromJsonAsync()).GetProperty("data"); Console.WriteLine($"state: {data.GetProperty("state")}, amount: {data.GetProperty("amount")}"); return 0; ``` ```ts tab="TypeScript" // PAYMENT_REFERENCE=test-… node read.ts (Node 23.6 or later) const reference = process.env.PAYMENT_REFERENCE!; const response = await fetch( `https://gateway.mps-emi.com/api/payments/internet/${encodeURIComponent(reference)}`, { headers: { Authorization: `Bearer ${process.env.MPS_API_KEY}` } }, ); if (!response.ok) { // 404: no such payment for this key. See Errors below. throw new Error(`MPS answered ${response.status}: ${await response.text()}`); } const { data } = (await response.json()) as { data: { state: string; amount: number } }; console.log(`state: ${data.state}, amount: ${data.amount}`); ``` ```python tab="Python" # PAYMENT_REFERENCE=test-… python read.py import os import sys from urllib.parse import quote import requests reference = os.environ["PAYMENT_REFERENCE"] response = requests.get( f"https://gateway.mps-emi.com/api/payments/internet/{quote(reference, safe='')}", headers={"Authorization": f"Bearer {os.environ['MPS_API_KEY']}"}, timeout=10, ) if response.status_code != 200: # 404: no such payment for this key. See Errors below. sys.exit(f"MPS answered {response.status_code}: {response.text}") data = response.json()["data"] print(f"state: {data['state']}, amount: {data['amount']}") ``` ```php tab="PHP" ['Authorization: Bearer ' . getenv('MPS_API_KEY')], CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10, ]); $body = (string) curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); if ($status !== 200) { // 404: no such payment for this key. See Errors below. fwrite(STDERR, "MPS answered $status: $body\n"); exit(1); } $data = json_decode($body, true)['data']; echo "state: {$data['state']}, amount: {$data['amount']}\n"; ``` ```json title="200 OK" { "data": { "paymentReference": "test-…", "state": "executed", "amount": 1995, "currency": "EUR", "reference": "order-42" } } ``` `executed` means paid. That is your first payment. Cards that decline or stay pending are under [Test mode](/online-payments#test-mode). ## Response The create answers `200` with: | Field | Type | Required | Description | |---|---|---|---| | `paymentReference` | string | Yes | The MPS reference of the payment. `test-…` in test mode. Store it with the order. | | `checkoutUrl` | string | Yes | The checkout address. Open it exactly as returned. | The read answers `200` with: | Field | Type | Required | Description | |---|---|---|---| | `paymentReference` | string | Yes | The payment you read. | | `state` | string | Yes | `pending`, `executed`, `failed` or `abandoned`. See [Payment lifecycle](/payment-lifecycle). | | `amount` | integer | Yes | The amount in euro cents. | | `currency` | string | Yes | `EUR`. | | `amountRefunded` | integer | Yes | What has been refunded so far, in euro cents. See [Refunds](/refunds). | | `amountRemaining` | integer | Yes | What can still be refunded, in euro cents. | | `reference` | string | Yes | Your order reference, as you sent it, or `null` if you sent none. | ## Errors | Status | Code | Cause | Resolution | |---|---|---|---| | `400` | — | A field is invalid, for example an `amount` of zero or a `successUrl` that is not `https://`. | Fix the field the body names. Do not retry unchanged. See [Validation errors](/errors-and-rate-limits#validation-errors). | | `401` | — | No API key, or a wrong or revoked one. | Check `MPS_API_KEY`. Do not retry. See [Authentication](/authentication). | | `403` | — | The key lacks the scope (`internet:create` or `internet:read`), or the merchant has no shop name registered yet. | Check the key's scopes, or contact MPS. See [Status codes](/errors-and-rate-limits#status-codes). | | `404` | — | The read found no such payment for the merchant the key acts for. | Check the `paymentReference` you stored. | | `409` | `idempotency_key_in_use` | A create with the same `Idempotency-Key` is still running. | Retry after a second with the same key and body. See [Conflicts](/errors-and-rate-limits#conflicts). | | `409` | `idempotency_key_expired` | The payment this key made can no longer be returned. | Create a new payment with a new key. | | `429` | — | The key's 100 requests a minute, shared by every endpoint. | Wait `Retry-After` seconds, then retry. See [Rate limits](/errors-and-rate-limits#rate-limits). | ## Then, in your backend The same calls, on your server. The API key never goes to a browser or an app. 1. **Create** the payment, store `paymentReference` with the order, and redirect the shopper to `checkoutUrl`. Pass a `callbackUrl` to receive a webhook when it is paid. 2. **Confirm** before you ship. In your [webhook](/webhooks) handler, verify the signature and timestamp, read the payment, and check its `state`, `amount`, `currency` and `reference` against the order. Mark the order paid with an update that only succeeds once, and only then answer `2xx`. On a failure answer `5xx` and MPS retries. This works as long as the handler finishes within 10 seconds. [The basic handler](/webhooks#the-simple-handler-process-then-answer) shows it, and [the production pattern](/webhooks#the-production-pattern-store-answer-process) covers the rest. 3. **Handle every state**: `executed` (check the amount), `failed`, `abandoned` after 24 hours, and `pending` until then. See [Payment lifecycle](/payment-lifecycle). [Integration examples](/integration-examples) has all of it as one runnable server in C#, TypeScript, Python and PHP. Partner key? Add `x-wallet-number` with the merchant's wallet. See [Choosing the merchant](/authentication#choosing-the-merchant). ## Related - [Payment lifecycle](/payment-lifecycle): what each state means and what to do with it - [Webhooks](/webhooks): receive and verify webhooks - [Integration examples](/integration-examples): one runnable server in four languages - [Production checklist](/production-checklist): the checks before you switch to a live key - [Switch to live payments](/take-live-payments#your-own-integration): what the merchant needs before a live key works