# Quickstart

> A sandbox payment from create to verified webhook, for an account that already has keys.

A sandbox payment in four steps: create it, send the customer to a page, verify the outcome from your
server, and let webhooks tell you what happens after the customer is gone.

> [!NOTE]
> **This page starts after setup**
>
> It assumes an account, sandbox keys and an installed SDK. If you have none of that yet, the
> [platform quickstart](https://docs.wajub.com/getting-started/quickstart) covers account creation, keys and install, then
> walks the same four steps from zero.

## 1. Create the payment

One request carries the whole intent: how much, in which currency, who is paying, and where that
person comes back. Wajub records it, keeps it `pending`, and answers with a page to send the
customer to. Nothing has reached an operator yet, and nobody has been charged.

Send it from your server with the secret key. The public key creates payments too, but it exists for
the one case where the call happens inside a browser.

Describe the payer in the `customer` object. A top-level `email` also works and lands on the same
customer record, but the object is what grows with you: it carries `name`, `phone`, `address` and
`metadata` as well.

`POST /payments`

**Create a payment**

```bash
curl https://api.wajub.com/payments \
  -H "Authorization: sk_test.xxxxxxxxxxxxxxxx…" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 5000,
    "currency": "XAF",
    "customer": { "email": "amina@example.com" },
    "reference": "order-4172",
    "callback": "https://shop.example.com/order/complete"
  }'
```

```javascript
import { Wajub } from '@wajub/node';

const wajub = new Wajub({ apiKey: process.env.WAJUB_API_KEY });

const payment = await wajub.payments.create({
  amount: 5000,
  currency: 'XAF',
  customer: { email: 'amina@example.com' },
  reference: 'order-4172',
  callback: 'https://shop.example.com/order/complete',
});

console.log(payment.id, payment.authorization_url);
```

```python
import os
from wajub import Wajub

wajub = Wajub(api_key=os.environ["WAJUB_API_KEY"])

payment = wajub.payments.create({
    "amount": 5000,
    "currency": "XAF",
    "customer": {"email": "amina@example.com"},
    "reference": "order-4172",
    "callback": "https://shop.example.com/order/complete",
})

print(payment.id, payment.authorization_url)
```

```php
<?php

use Wajub\Wajub;

$wajub = new Wajub(['api_key' => getenv('WAJUB_API_KEY')]);

$payment = $wajub->payments->create([
  'amount' => 5000,
  'currency' => 'XAF',
  'customer' => [
    'email' => 'amina@example.com',
  ],
  'reference' => 'order-4172',
  'callback' => 'https://shop.example.com/order/complete',
]);

echo $payment->authorization_url;
```

```go
client, err := wajub.New(wajub.Config{APIKey: os.Getenv("WAJUB_API_KEY")})

if err != nil {
	log.Fatal(err)
}

payment, err := client.Payments.Create(context.Background(), map[string]any{
	"amount": 5000,
	"currency": "XAF",
	"customer": map[string]any{"email": "amina@example.com"},
	"reference": "order-4172",
	"callback": "https://shop.example.com/order/complete",
}, nil)

if err != nil {
	log.Fatal(err)
}

log.Println(payment.ID, payment.AuthorizationURL)
```

Wajub answers `201 Created`. Two fields matter here: `transaction.id`, which you store against your
order, and `authorization_url`, which is where the customer goes next.

```json title="Response · 201 Created"
{
  "code": 201,
  "status": "Created",
  "message": "Payment initiated",
  "authorization_url": "https://pay.wajub.com/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "authorization_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "transaction": {
    "id": "trx_test_CSUGajfv9xh0XQ5wu2lx",
    "reference": "order-4172",
    "amount": 5000,
    "amount_paid": 0,
    "currency": "XAF",
    "status": "pending",
    "customer": {
      "id": "cus_test_sAaim5apjocIgtlhzJY3wQ8s",
      "email": "amina@example.com"
    },
    "callback": "https://shop.example.com/order/complete",
    "sandbox": true,
    "created_at": "2026-09-11T10:24:00+00:00"
  }
}
```

> [!NOTE]
> **Amounts are in the major unit, never in centimes**
>
> `"amount": 5000` is 5 000 XAF, not 50. Wajub has no subunits. A payment in XAF or XOF must fall
> between 25 and 2 000 000; outside that range the API answers `422` with the bound in
> `errors.amount`.

`reference` is yours: your order number, returned on every read and searchable in the Dashboard. It
carries no uniqueness constraint, so sending it twice creates two payments, and
`GET /payments?reference=order-4172` lists every payment that carries it. A payment is read by its
`id`.

What does protect you from a double charge is the `Idempotency-Key` header. Generate it yourself,
store it next to the order, and resend the same value on every retry: the API then returns the
original payment instead of opening a second one. Pass this key yourself on every call.
[Idempotency](https://docs.wajub.com/best-practices/idempotency) covers the strategies that work.

## 2. Send the customer to the page

Redirect to `authorization_url`. The customer picks an operator, types their number, confirms on
their handset and lands back on your `callback`.

That is Hosted Checkout, and it is the mode we recommend: Wajub renders the screen, so there is no
payment interface for you to maintain.

The session stays valid for 24 hours. Pass `expires.in` in minutes, anywhere from 5 to 43 200, to
close the window sooner.

In sandbox, the last six digits of the number decide the outcome, and `…000000` succeeds. The full
suffix table and a number per operator are in the [platform
quickstart](https://docs.wajub.com/getting-started/quickstart#4-pay-it-with-a-sandbox-number). Sandbox never asks for a
PIN.

## 3. Verify before you fulfil

The customer landing back on your `callback` proves nothing. Anyone can open that URL by hand, and a
customer who closes the tab never opens it at all. Ask the API what happened, from your server, with
the id you stored in step 1.

`GET /payments/{id}`

**Retrieve a payment**

```bash
curl https://api.wajub.com/payments/trx_test_CSUGajfv9xh0XQ5wu2lx \
  -H "Authorization: sk_test.xxxxxxxxxxxxxxxx…"
```

```javascript
const payment = await wajub.payments.retrieve('trx_test_CSUGajfv9xh0XQ5wu2lx');

console.log(payment.status, payment.amount, payment.currency);
```

```python
payment = wajub.payments.retrieve("trx_test_CSUGajfv9xh0XQ5wu2lx")

print(payment.status, payment.amount, payment.currency)
```

```php
$payment = $wajub->payments->retrieve('trx_test_CSUGajfv9xh0XQ5wu2lx');

echo $payment->status;
```

```go
payment, err := client.Payments.Retrieve(context.Background(), "trx_test_CSUGajfv9xh0XQ5wu2lx")

if err != nil {
	log.Fatal(err)
}

log.Println(payment.Status, payment.Amount, payment.Currency)
```

The answer is the payment as Wajub knows it, whatever the browser was told. `channel` names the
operator that was actually used, and `amount_paid` is what was really collected:

```json title="Response · 200 OK"
{
  "code": 200,
  "status": "OK",
  "message": "Payment retrieved",
  "transaction": {
    "id": "trx_test_CSUGajfv9xh0XQ5wu2lx",
    "reference": "order-4172",
    "amount": 5000,
    "amount_paid": 5000,
    "currency": "XAF",
    "status": "succeeded",
    "channel": "cm.mtn",
    "customer": {
      "id": "cus_test_sAaim5apjocIgtlhzJY3wQ8s",
      "email": "amina@example.com"
    },
    "sandbox": true,
    "created_at": "2026-09-11T10:24:00+00:00"
  }
}
```

Ship the order only when `status` is `succeeded`, and only once `amount` and `currency` match what
you charged for. A payment still `pending` is not a failure, it is a customer who has not finished
yet: leave the order open and let the next step close it.

## 4. Let the webhook close the loop

Verifying on return covers the customers who come back. Webhooks cover everyone else, and every
event that has no browser behind it at all: a confirmation the operator sends ten minutes late, a
refund issued from the Dashboard, a session that expires untouched.

Subscribe to the seven events a payment can produce, by name. A subscription matches exact names
only, so `payment.*` would receive nothing.

| Event                    | Fires when                                                                            |
| ------------------------ | ------------------------------------------------------------------------------------- |
| `payment.created`        | The payment was recorded and is `pending`                                             |
| `payment.processing`     | The request reached the operator, the customer is being prompted                      |
| `payment.succeeded`      | Funds captured. This is the one to fulfil on                                          |
| `payment.failed`         | The operator reported the attempt as failed after the prompt went out                 |
| `payment.attempt_failed` | A decline answered at once: the payment is `pending` again and the customer can retry |
| `payment.expired`        | The session ran out before the customer confirmed                                     |
| `payment.cancelled`      | Cancelled with `DELETE /payments/{id}`, or with the Cancel button of the hosted page  |

> [!NOTE]
> **Webhooks are documented once, not here**
>
> Endpoint registration, signature verification, retries and the full catalog live in
> [Webhooks](https://docs.wajub.com/developer-tools/webhooks). One rule belongs here though: deduplicate on the event
> `id`. A failed delivery is [retried](https://docs.wajub.com/developer-tools/webhooks/retries), and every attempt carries
> that same `id`, which is what keeps a retry from shipping the order twice.

## Then pick the mode you ship

What you just built is Hosted Checkout. The other three modes change exactly one thing, who renders
the screen in step 2. Creating, verifying and handling webhooks stay word for word what they are
above.

**Integration modes**

- [Hosted Checkout](https://docs.wajub.com/payments/hosted-checkout): What you just built. Wajub renders operator choice, prompt and result.
- [Embedded Components](https://docs.wajub.com/libraries/components): The same screen, mounted in your page with the session token.
- [Payment Links](https://docs.wajub.com/payments/link/quickstart): No integration at all. Production only, 25 links on the free plan.
- [Direct API](https://docs.wajub.com/payments/direct-api): You collect the number and charge it yourself with a second call.

## What's next?

- [Payment lifecycle](https://docs.wajub.com/payments/lifecycle): Every status a payment can hold, and the moves between them.
- [Payment methods & channels](https://docs.wajub.com/payments/payment-methods): Country and operator coverage, channel by channel.
- [Phone number formats](https://docs.wajub.com/payments/payment-methods/phone-numbers): What each operator accepts, before a payment can even start.
- [Refunds](https://docs.wajub.com/payments/refunds): Full or partial refunds on a succeeded payment.
- [Accept a payment, full guide](https://docs.wajub.com/guides/accept-a-payment): The same flow end to end, with the fulfilment logic around it.
- [Go Live](https://docs.wajub.com/getting-started/going-live): The checklist before you switch to production keys.
