Skip to main content
This guide walks through creating a one-time payment session, launching the hosted checkout, and handling the completion webhook.

Prerequisites

  • A test API key. See Authentication.
  • A registered webhook endpoint. See Webhook Setup to register your URL and obtain your signing key.

Step 1: Create a payment session

Create a session server-side using your secret key. The minimum required fields are amount and currency.
curl -X POST https://api.momentpay.net/collect/payment_sessions \
  -H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 10000,
    "currency": "ZAR"
  }'
amount is always specified in minor units. See Monetary Amounts for details.
The response includes a session_url (the hosted checkout page your customer will use to complete payment) and an id you will use to match the subsequent webhook event.
{
  "id": "ps_kfAWZgfQIoeG0q",
  "status": "active",
  "payment_status": "unpaid",
  "amount": 10000,
  "currency": "ZAR",
  "session_url": "https://checkout.momentpay.net/ckt802zEb2P2uS4Ql",
  "created_at": "2025-03-18T14:06:51.149Z",
  "updated_at": "2025-03-18T14:06:51.149Z"
}

Step 2: Launch the checkout

Redirect your customer to the session_url, or embed it using the JavaScript SDK for an in-page modal or inline experience. The session remains active until the customer completes payment or the session expires. Do not poll for status. Use the webhook in the next step instead.

Step 3: Handle the completion webhook

When the customer completes payment, Moment sends a payment_session.completed event to your registered webhook endpoint.
{
  "id": "wh_e5cf73f1b3e4451c8c474fe56bfc688d",
  "type": "payment_session.completed",
  "data": {
    "id": "ps_kfAWZgfQIoeG0q",
    "status": "completed",
    "payment_status": "paid",
    "amount": 10000,
    "currency": "ZAR",
    "payment_id": "pay_87C7PAP35KcdpzAgckBvB"
  }
}
Match data.id in the event to the session you created in Step 1 to confirm which order was paid. Before processing, verify the event signature to confirm it originated from Moment. See Webhook Verification for the full verification steps and code samples. Respond with a 2xx status code to acknowledge receipt. If your endpoint does not respond in time, Moment will retry delivery.

Testing

Use test card 4242 4242 4242 4242 with any future expiry date and any 3-digit CVC to simulate a successful payment. See Integration Testing for the full list of test cards and error scenarios.

Next steps

Quickstart: Recurring Payments

Set up a mandate and collect future payments without customer interaction.

JavaScript SDK

Embed checkout directly in your page with the Moment JS SDK.