Skip to main content
POST
/
api
/
v1
/
payments
/
test
/
checkout
Test Payment
curl --request POST \
  --url https://api.example.com/api/v1/payments/test/checkout
{
  "status": "<string>",
  "phone_number": "<string>",
  "amount": 123,
  "response": {
    "status": "<string>",
    "description": "<string>",
    "transactionId": "<string>"
  }
}

Overview

Initiate a test mobile money checkout to verify that the Africa’s Talking payment integration is working correctly. This endpoint is useful for development and testing.

Query Parameters

phone_number
string
required
Phone number to send the checkout prompt to (e.g., +254712345678)
amount
number
default:"100.0"
Test amount in KES (defaults to 100.0)

Response

status
string
Status of the test (always “test_initiated”)
phone_number
string
The phone number used for testing
amount
number
The test amount requested
response
object
Response from Africa’s Talking payment service

Example Request

# Test with specific phone and amount
curl -X POST "http://localhost:8000/api/v1/payments/test/checkout?phone_number=%2B254712345678&amount=50"

# Test with default amount (100 KES)
curl -X POST "http://localhost:8000/api/v1/payments/test/checkout?phone_number=%2B254712345678"

Example Response (Success)

{
  "status": "test_initiated",
  "phone_number": "+254712345678",
  "amount": 100.0,
  "response": {
    "status": "PendingConfirmation",
    "description": "Waiting for user to confirm payment",
    "transactionId": "ATPid_test123abc456"
  }
}

Example Response (Failure)

{
  "detail": "Payment test failed: Invalid phone number"
}

Status Codes

  • 200 - Test payment initiated successfully
  • 500 - Test payment failed

Test Payment Flow

1

API Call

Send POST request to test endpoint with phone number and amount
2

STK Push

User receives M-Pesa/Airtel Money prompt on their phone
3

User Confirmation

User enters PIN to approve or decline the payment
4

Webhook Callback

Africa’s Talking sends webhook to /api/v1/payments/webhook with result

Sandbox Testing

When using Africa’s Talking sandbox credentials:
  • No real money is transferred
  • Simulated STK push (won’t appear on real phone)
  • Test using sandbox phone numbers
  • Webhook callbacks are still sent

Sandbox Test Values

# Sandbox phone numbers (Kenya)
+254711XXXYYY  # Replace XXX and YYY with any digits

# Test amounts that trigger specific responses
# 10-100 KES: Success
# 101-500 KES: User cancellation
# 501+ KES: Insufficient funds

Metadata

The test includes metadata {"test": "true"} to mark the transaction as a test. This helps identify test transactions in your database and Africa’s Talking dashboard.

Use Cases

  • Integration Testing: Verify payment API is configured correctly
  • Flow Testing: Test the complete checkout → webhook → database flow
  • Sandbox Validation: Confirm sandbox credentials work before production
  • Development: Test payment UX during local development

Implementation

This endpoint calls the mobile_checkout method with test metadata. Source: payments.py:203-227

Troubleshooting

Problem: Phone number format is incorrectSolution: Use international format with country code:
  • Correct: +254712345678
  • Incorrect: 0712345678
Problem: Using sandbox credentials or wrong phone numberSolution:
  • Sandbox mode doesn’t send real STK push
  • Verify phone number is correct
  • Check if phone supports M-Pesa/Airtel Money
Problem: Africa’s Talking credentials invalidSolution:
  • Verify AT_API_KEY is set correctly
  • Check API key has payment permissions
  • Ensure sufficient wallet balance (production only)

Next Steps

Mobile Checkout

Production payment endpoint

Payment Webhook

Handle payment callbacks

Wallet Balance

Check available balance

Payment Integration

Complete integration guide

Build docs developers (and LLMs) love