Transaction API

Create, retrieve, search, and manage transactions

The Transaction API allows you to create and manage transactions programmatically. All transaction endpoints require the X-API-Key header for authentication.

📝 Transaction Status Lifecycle:

Transactions in the BessaPay API follow this lifecycle:

  1. PENDING - Initial state when transaction is created
  2. PROCESSING - Payment is being processed
  3. COMPLETED - Payment was successful
  4. FAILED - Payment failed or was rejected
  5. CANCELLED - Transaction was cancelled by merchant or user
  6. EXPIRED - Transaction expired due to inactivity

Available Endpoints

POST/api/v1/integration/transactions/create

Create a new transaction via API integration.

Authentication

API Key required in X-API-Key header

Query Parameters

ParameterTypeRequiredDescription
environmentstringOptionalOptional environment to use (TEST or LIVE). If not specified, the system will resolve the environment based on other factors.

Request Body

Request Body
1{
2  "merchantId": "mer_12345abcde",
3  "amount": 1000,
4  "currency": "KES",
5  "reference": "order-123456",
6  "customer": {
7    "name": "John Doe",
8    "email": "john@example.com",
9    "phone": "+254712345678"
10  },
11  "callbackUrl": "https://your-app.com/callbacks/bessapay",
12  "returnUrl": "https://your-app.com/return",
13  "cancelUrl": "https://your-app.com/cancel",
14  "timeoutUrl": "https://your-app.com/timeout"
15}

Response

Response
1{
2  "transaction": {
3    "id": "txn_1J3F9KHGKm7Zf",
4    "merchantId": "mer_12345abcde",
5    "amount": 1000,
6    "currency": "KES",
7    "reference": "order-123456",
8    "transactionStatus": "PENDING",
9    "paymentStatus": "PENDING",
10    "paymentUrl": "https://pay.bessapay.com/checkout/txn_1J3F9KHGKm7Zf",
11    "createdAt": "2023-06-01T12:00:00Z",
12    "environment": "TEST"
13  }
14}

Notes

  • Authentication requires a valid API key in the X-API-Key header
  • The merchant must have the appropriate permissions
  • The environment can be specified via query parameter, header, or domain
  • All transactions created will inherit the environment setting
GET/api/v1/integration/transactions/{transactionId}

Retrieve details of an existing transaction.

Authentication

API Key required in X-API-Key header

Path Parameters

ParameterTypeRequiredDescription
transactionIdstringRequiredThe ID of the transaction to retrieve

Query Parameters

ParameterTypeRequiredDescription
merchantIdstringRequiredThe ID of the merchant who owns the transaction
environmentstringOptionalOptional environment to filter by (TEST or LIVE)

Response

Response
1{
2  "transaction": {
3    "id": "txn_1J3F9KHGKm7Zf",
4    "merchantId": "mer_12345abcde",
5    "amount": 1000,
6    "currency": "KES",
7    "reference": "order-123456",
8    "transactionStatus": "COMPLETED",
9    "paymentStatus": "COMPLETED",
10    "createdAt": "2023-06-01T12:00:00Z",
11    "updatedAt": "2023-06-01T12:05:00Z",
12    "environment": "TEST"
13  }
14}

Notes

  • Authentication requires a valid API key in the X-API-Key header
  • The API key must belong to the specified merchant
  • The transaction must be in the specified environment
  • If no transaction is found in the specified environment, a 400 error is returned
POST/api/v1/integration/transactions/{transactionId}/cancel

Cancel a pending transaction.

Authentication

API Key required in X-API-Key header

Path Parameters

ParameterTypeRequiredDescription
transactionIdstringRequiredThe ID of the transaction to cancel

Query Parameters

ParameterTypeRequiredDescription
merchantIdstringRequiredThe ID of the merchant who owns the transaction
environmentstringOptionalOptional environment to filter by (TEST or LIVE)

Response

Response
1{
2  "transaction": {
3    "id": "txn_1J3F9KHGKm7Zf",
4    "merchantId": "mer_12345abcde",
5    "amount": 1000,
6    "currency": "KES",
7    "reference": "order-123456",
8    "transactionStatus": "FAILED",
9    "paymentStatus": "FAILED",
10    "createdAt": "2023-06-01T12:00:00Z",
11    "updatedAt": "2023-06-01T12:10:00Z",
12    "environment": "TEST"
13  }
14}

Notes

  • Authentication requires a valid API key in the X-API-Key header
  • The API key must belong to the specified merchant
  • Only transactions with PENDING status can be cancelled
  • The transaction must be in the specified environment
  • After cancellation, the transaction status will be set to FAILED