Reversals
Reverse Incoming Transactions
Initiate reversals for Incoming Transactions made within the last 30 days.
POST https://sandbox.kopokopo.com/api/api/v2/reversals
Content-Type: application/json
Accept: application/json
Authorization: Bearer <AccessToken>
User-Agent: "<product>/<product-version> <comment>"
- JSON
- Ruby
- Python
- JavaScript
- PHP
- Dart
{
"transaction_reference": "5d894b0f-b07e-4304-ab4a-d54b80bc7286",
"reason": "Testing Reversals",
"metadata": {
"name": "Test"
},
"_links": {
"callback_url": "https://callback_to_your_app.your_application.com"
}
}
reversal_params = {
transaction_reference: "Y7T2990R11",
reason: "Erroneous payment",
metadata: {
order_no: "ORD192832",
},
callback_url: "https://example.com/callback",
}
access_token = K2ConnectRuby::K2Entity::K2Token.new("client_id", "client_secret").request_token
k2_reversal = K2ConnectRuby::K2Entity::Reversal.new(access_token)
k2_reversal.initiate_reversal(reversal_params)
# initialize service
reversal_service = k2connect.Reversals(access_token=access_token)
# initiating a reversal request
request_payload = {
"transaction_reference": "CX83943KH",
"reason": "Wrong payment",
"callback_url": "https://webhook.site/52fd1913-778e-4ee1-bdc4-74517abb758d",
}
reversal_resource_location_url = reversal_service.initiate_reversal(request_payload)
# https://sandbox.kopokopo.com/api/v2/reversals/247b1bd8-f5a0-4b71-a898-f62f67b8ae1c
const ReversalService = K2.ReversalService
const reversalOpts = {
transactionReference: "transaction_reference",
reason: "reason",
callbackUrl: "https://8650bfeddc80.ngrok.io/reversals/result",
metadata: {
notes: "Sample Reversal transaction",
customId: "custom123"
},
accessToken: "access_token",
};
ReversalService
.initiateReversal(reversalOpts)
.then(response => {
console.log(response) // => 'https://sandbox.kopokopo.com/api/v2/reversals/cc438b3e-ecf0-4600-b9cc-edba32ae7019'
})
.catch(error => {
console.log(error)
})
// Using KopoKopoConnect - https://github.com/kopokopo/k2-connect-php (Recommended)
$reversalService = $K2->ReversalService();
$options = [
"transactionReference" => "transactionReference",
"reason" => "reason",
"callbackUrl" => "callbackUrl",
"accessToken" => $accessToken,
];
$response = $reversalService->initiateReversal($options);
if($response['status'] == 'success')
{
echo "The resource location is:" . json_encode($response['location']);
// => 'https://sandbox.kopokopo.com/api/v2/reversals/cc438b3e-ecf0-4600-b9cc-edba32ae7019'
}
// This feature is not currently available in the Flutter SDK.
// Please use one of the other SDKs (PHP, Ruby, Python, NodeJs) or the REST API.
HTTP Request
POST https://sandbox.kopokopo.com/api/api/v2/reversals
Request Parameters (JSON)
| Parameter | Required | Type | Description |
|---|---|---|---|
| transaction_reference | yes | String | The reference of the transaction to be reversed. |
| reason | yes | String | The reason for initiating the reversal. |
| metadata | No | String | A JSON object containing additional information. |
| _links | Yes | JSON | A JSON object containing the callback_url where the reversal result will be posted. |
HTTP Response
Successful Response
Upon a successful request a HTTP Status 201 will be returned and the location HTTP Header will contain the URL of the newly created Reversal Request.
HTTP/1.1 201 Created
Location: https://sandbox.kopokopo.com/api/v2/reversals/247b1bd8-f5a0-4b71-a898-f62f67b8ae1c
Error Response
This will have a HTTP Status code indicating the error and it might have a json that contains the error code and an error message specifying the error that occurred. Please note that the error response might not be present depending on the type of error that occurred.
If the error json response is present, it will look as follows:
HTTP/1.1 400 Bad Request
\{ "error_code": 400, "error_message": [ "You cannot reverse a transaction in Pending Reversal" ] \}
Process Reversal Request API Result
POST https://your-callback-url.com/api/v2/reversal_results
Content-Type: application/json
X-KopoKopo-Signature: 0Sn0W6kzNicvoWhDbQcVSKLRUpGjIdlPSEYyrHqrDDoRnQwE7Q
User-Agent: < product >/< product-version > < comment >
- JSON
- Ruby
- Python
- JavaScript
- PHP
- Dart
{
"data": {
"id": "67b1bb87-b89b-4366-93c9-a2bb6944ec99",
"type": "reversals",
"attributes": {
"status": "Processed",
"created_at": "2025-10-31T16:32:54.952+03:00",
"transaction_reference": "059278a2-8ffe-4f31-b3b4-d6c76770c72f",
"reason": "Testing Reversals",
"reversal_bulk_payment": {
"amount": "400.0",
"status": "Transferred",
"origination_time": "2025-10-31T12:55:18.000+03:00",
"transaction_reference": "ce430292-899b-4543-beb8-4195875dc063"
},
"errors":null,
"metadata": {
"name": "Test"
},
"_links": {
"callback_url": "https://your_callback_url.com/",
"self": "https://sandbox.kopokopo.com/api/v2/reversals/67b1bb87-b89b-4366-93c9-a2bb6944ec99"
}
}
}
}
{
"data": {
"id": "67b1bb87-b89b-4366-93c9-a2bb6944ec99",
"type": "reversals",
"attributes": {
"status": "Processed",
"created_at": "2025-10-31T16:32:54.952+03:00",
"transaction_reference": "059278a2-8ffe-4f31-b3b4-d6c76770c72f",
"reason": "Testing Reversals",
"reversal_bulk_payment": {
"amount": "400.0",
"status": "Transferred",
"origination_time": "2025-10-31T12:55:18.000+03:00",
"transaction_reference": "ce430292-899b-4543-beb8-4195875dc063"
},
"errors": nil,
"metadata": {
"name": "Test"
},
"_links": {
"callback_url": "https://your_callback_url.com/",
"self": "https://sandbox.kopokopo.com/api/v2/reversals/67b1bb87-b89b-4366-93c9-a2bb6944ec99"
}
}
}
}
{
"data": {
"id": "67b1bb87-b89b-4366-93c9-a2bb6944ec99",
"type": "reversals",
"attributes": {
"status": "Processed",
"created_at": "2025-10-31T16:32:54.952+03:00",
"transaction_reference": "059278a2-8ffe-4f31-b3b4-d6c76770c72f",
"reason": "Testing Reversals",
"reversal_bulk_payment": {
"amount": "400.0",
"status": "Transferred",
"origination_time": "2025-10-31T12:55:18.000+03:00",
"transaction_reference": "ce430292-899b-4543-beb8-4195875dc063"
},
"errors":null,
"metadata": {
"name": "Test"
},
"_links": {
"callback_url": "https://your_callback_url.com/",
"self": "https://sandbox.kopokopo.com/api/v2/reversals/67b1bb87-b89b-4366-93c9-a2bb6944ec99"
}
}
}
}
{
"data": {
"id": "67b1bb87-b89b-4366-93c9-a2bb6944ec99",
"type": "reversals",
"attributes": {
"status": "Processed",
"created_at": "2025-10-31T16:32:54.952+03:00",
"transaction_reference": "059278a2-8ffe-4f31-b3b4-d6c76770c72f",
"reason": "Testing Reversals",
"reversal_bulk_payment": {
"amount": "400.0",
"status": "Transferred",
"origination_time": "2025-10-31T12:55:18.000+03:00",
"transaction_reference": "ce430292-899b-4543-beb8-4195875dc063"
},
"errors":null,
"metadata": {
"name": "Test"
},
"_links": {
"callback_url": "https://your_callback_url.com/",
"self": "https://sandbox.kopokopo.com/api/v2/reversals/67b1bb87-b89b-4366-93c9-a2bb6944ec99"
}
}
}
}
<?
// The payload from the k2-connect-php SDK will look like this.
[
"data" => [
"id" => "67b1bb87-b89b-4366-93c9-a2bb6944ec99",
"type" => "reversals",
"attributes" => [
"status" => "Processed",
"created_at" => "2025-10-31T16:32:54.952+03:00",
"transaction_reference" => "059278a2-8ffe-4f31-b3b4-d6c76770c72f",
"reason" => "Testing Reversals",
"reversal_bulk_payment" => [
"amount" => "400.0",
"status" => "Transferred",
"origination_time" => "2025-10-31T12:55:18.000+03:00",
"transaction_reference" => "ce430292-899b-4543-beb8-4195875dc063"
],
"errors" => null,
"metadata" => [
"name" => "Test"
],
"_links" => [
"callback_url" => "https://your_callback_url.com/",
"self" => "https://sandbox.kopokopo.com/api/v2/reversals/67b1bb87-b89b-4366-93c9-a2bb6944ec99"
]
]
]
]
// This feature is not currently available in the Flutter SDK.
// Please use one of the other SDKs (PHP, Ruby, Python, NodeJs) or the REST API.
Unsuccessful Reversal
- JSON
- Ruby
- Python
- JavaScript
- PHP
- Dart
{
"data": {
"id": "c5486bd6-54c5-4d38-9e8a-e5a3597cd704",
"type": "reversals",
"attributes": {
"status": "Processed",
"created_at": "2025-11-24T13:11:13.255+03:00",
"transaction_reference": "8b275328-3b33-4144-9163-b2badbfb5de3",
"reason": "Testing Reversals",
"reversal_bulk_payment": {
"amount": "1300.0",
"status": "Cancelled",
"origination_time": "2025-11-24T13:01:18.000+03:00",
"transaction_reference":null
},
"errors": ["The balance is insufficient for the transaction"],
"metadata": {
"name": "Test"
},
"_links": {
"callback_url": "https://your_callback_url.com/",
"self": "https://sandbox.kopokopo.com/api/v2/reversals/c5486bd6-54c5-4d38-9e8a-e5a3597cd704"
}
}
}
}
{
"data": {
"id": "c5486bd6-54c5-4d38-9e8a-e5a3597cd704",
"type": "reversals",
"attributes": {
"status": "Processed",
"created_at": "2025-11-24T13:11:13.255+03:00",
"transaction_reference": "8b275328-3b33-4144-9163-b2badbfb5de3",
"reason": "Testing Reversals",
"reversal_bulk_payment": {
"amount": "1300.0",
"status": "Cancelled",
"origination_time": "2025-11-24T13:01:18.000+03:00",
"transaction_reference":nil
},
"errors": ["The balance is insufficient for the transaction"],
"metadata": {
"name": "Test"
},
"_links": {
"callback_url": "https://your_callback_url.com/",
"self": "https://sandbox.kopokopo.com/api/v2/reversals/c5486bd6-54c5-4d38-9e8a-e5a3597cd704"
}
}
}
}
{
"data": {
"id": "c5486bd6-54c5-4d38-9e8a-e5a3597cd704",
"type": "reversals",
"attributes": {
"status": "Processed",
"created_at": "2025-11-24T13:11:13.255+03:00",
"transaction_reference": "8b275328-3b33-4144-9163-b2badbfb5de3",
"reason": "Testing Reversals",
"reversal_bulk_payment": {
"amount": "1300.0",
"status": "Cancelled",
"origination_time": "2025-11-24T13:01:18.000+03:00",
"transaction_reference":null
},
"errors": ["The balance is insufficient for the transaction"],
"metadata": {
"name": "Test"
},
"_links": {
"callback_url": "https://your_callback_url.com/",
"self": "https://sandbox.kopokopo.com/api/v2/reversals/c5486bd6-54c5-4d38-9e8a-e5a3597cd704"
}
}
}
}
{
"data": {
"id": "c5486bd6-54c5-4d38-9e8a-e5a3597cd704",
"type": "reversals",
"attributes": {
"status": "Processed",
"created_at": "2025-11-24T13:11:13.255+03:00",
"transaction_reference": "8b275328-3b33-4144-9163-b2badbfb5de3",
"reason": "Testing Reversals",
"reversal_bulk_payment": {
"amount": "1300.0",
"status": "Cancelled",
"origination_time": "2025-11-24T13:01:18.000+03:00",
"transaction_reference":null
},
"errors": ["The balance is insufficient for the transaction"],
"metadata": {
"name": "Test"
},
"_links": {
"callback_url": "https://your_callback_url.com/",
"self": "https://sandbox.kopokopo.com/api/v2/reversals/c5486bd6-54c5-4d38-9e8a-e5a3597cd704"
}
}
}
}
[
"data" =>[
"id" =>"c5486bd6-54c5-4d38-9e8a-e5a3597cd704",
"type" =>"reversals",
"attributes" =>[
"status" =>"Processed",
"created_at" =>"2025-11-24T13:11:13.255+03:00",
"transaction_reference" =>"8b275328-3b33-4144-9163-b2badbfb5de3",
"reason" =>"Testing Reversals",
"reversal_bulk_payment" =>[
"amount" =>"1300.0",
"status" =>"Cancelled",
"origination_time" =>"2025-11-24T13:01:18.000+03:00",
"transaction_reference" =>null
],
"errors" => ["The balance is insufficient for the transaction"],
"metadata" =>[
"name" =>"Test"
],
"_links" =>[
"callback_url" =>"https://your_callback_url.com/",
"self" =>"https://sandbox.kopokopo.com/api/v2/reversals/c5486bd6-54c5-4d38-9e8a-e5a3597cd704"
]
]
]
]
// This feature is not currently available in the Flutter SDK.
// Please use one of the other SDKs (PHP, Ruby, Python, NodeJs) or the REST API.
After a Reversal Request is initiated, a Reversal API Result will be posted asynchronously to the call back URL specified in the Reversal Request.
Reversal Result Parameters (JSON)
Parameters contained in a successful Reversal result;
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | The ID of the reversal request |
| type | Yes | String | The type of the request (reversals) |
| status | Yes | String | Status of the reversal request |
| created_at | Yes | Date | Date and time the reversal request was created |
| transaction_reference | Yes | String | Transaction reference being reversed |
| reason | Yes | String | Reason for reversal |
| metadata | Yes | JSON | Metadata sent with the reversal request |
| _links | Yes | JSON | Object containing links to the reversal request |
| reversal_bulk_payment | Yes | JSON | Object containing the reversal transaction |
| errors | Yes | JSON | Object containing errors if any |
Reversal Bulk Payment JSON
| Parameter | Required | Type | Description |
|---|---|---|---|
| amount | Yes | Float | The amount reversed |
| status | Yes | String | The status of the bulk payment(Transfered means reversed, Cancelled is failed) |
| origination_time | Yes | String | The transaction timestamp |
| transaction_reference | Yes | String | The M-PESA reference |
Remember — if you are also subscribed to the buygoods_transaction_reversed and/or b2b_transaction_reversedwebhooks, the Request Reversal Result
will also be sent to that end point.
Query Reversal API Status
GET https://sandbox.kopokopo.com/api/v2/reversals/d79995cd-0111-e511-80da-0aa34a9b2388
Accept: application/json
Authorization: Bearer 0Sn0W6kzNicvoWhDbQcVSKLRUpGjIdlPSEYyrHqrDDoRnQwE7Q
Content-Type: application/json
User-Agent: < product >/< product-version > < comment >
- JSON
- Ruby
- Python
- JavaScript
- PHP
- Dart
{
"data": {
"id": "3a5ed056-988d-4ea6-824b-67f523939b92",
"type": "reversals",
"attributes": {
"status": "Scheduled",
"created_at": "2025-10-22T14:53:55.930+03:00",
"transaction_reference": "20251016125940",
"reason": "Testing Reversals",
"errors": null,
"metadata": {
"name": "Test"
},
"_links": {
"callback_url": "https://your.callback.url.com/",
"self": "https://sandbox.kopokopo.com/api/v2/reversals/3a5ed056-988d-4ea6-824b-67f523939b92"
}
}
}
}
access_token = K2ConnectRuby::K2Entity::K2Token.new("client_id", "client_secret").request_token
k2_reversal = K2ConnectRuby::K2Entity::Reversal.new(access_token)
location_url = k2_reversal.initiate_reversal(reversal_params)
# Get status of current reversal request
k2_reversal.query_status
# Get status of specific reversal request
k2_reversal.query_resource(location_url)
# initialize service
reversal_service = k2connect.Reversals(access_token=access_token)
reversal_resource_location_url = reversal_service.initiate_reversal(request_payload)
# https://sandbox.kopokopo.com/api/v2/reversals/247b1bd8-f5a0-4b71-a898-f62f67b8ae1c
# get reversal status
request_body = {
"reversal-reference": "247b1bd8-f5a0-4b71-a898-f62f67b8ae1c"
}
reversal_resource = reversal_service.get_status(request_body)
const ReversalService = K2.ReversalService
const reversalOpts = {
location: 'https://sandbox.kopokopo.com/api/v2/reversals/cc438b3e-ecf0-4600-b9cc-edba32ae7019',
accessToken: 'myRand0mAcc3ssT0k3n'
}
ReversalService.getStatus(reversalOpts)
// Using KopoKopoConnect - https://github.com/kopokopo/k2-connect-php (Recommended)
$reversalService = $K2->ReversalService();
$statusOptions = [
'location' => 'cc438b3e-ecf0-4600-b9cc-edba32ae7019',
'accessToken' => 'myRand0mAcc3ssT0k3n'
]
$response = $reversalService->getStatus($statusOptions);
echo $response;
// This feature is not currently available in the Flutter SDK.
// Please use one of the other SDKs (PHP, Ruby, Python, NodeJs) or the REST API.
With an Reversal location url, you can query what the status of the Reversal is. If a corresponding Reversal Result
exists, it will be bundled in the payload of the result.
HTTP Request
GET https://sandbox.kopokopo.com/api/v2/reversals/
Accept: application/json
Authorization: Bearer 0Sn0W6kzNicvoWhDbQcVSKLRUpGjIdlPSEYyrHqrDDoRnQwE7Q
User-Agent: < product >/< product-version > < comment >
Query Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
| ID | Yes | String | The reference / ID of the Reversal to retrieve |