Receive M-PESA payments
Receive payments from M-PESA users via STK Push.
POST https://sandbox.kopokopo.com/api/v2/incoming_payments
Content-Type: application/json
Accept: application/json
Authorization: Bearer 0Sn0W6kzNicvoWhDbQcVSKLRUpGjIdlPSEYyrHqrDDoRnQwE7Q
User-Agent: "< product >/< product-version > < comment >"
- JSON
- Ruby
- Python
- JavaScript
- PHP
- Dart
{
"payment_channel": "M-PESA STK Push",
"till_number": "K000000 || 000000",
"subscriber": {
"first_name": "Joe",
"last_name": "Buyer",
"phone_number": "+254999999999",
"email": "jbuyer@mail.net"
},
"amount": {
"currency": "KES",
"value": 20000
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"_links": {
"callback_url": "https://callback_to_your_app.your_application.com"
}
}
# Using K2Connect - https://github.com/kopokopo/k2-connect-ruby (Recommended)
your_input =
{
payment_channel: 'M-PESA STK Push',
till_number: 'K000000 || 000000',
first_name: 'Joe',
last_name: 'Buyer',
phone_number: '+254999999999',
email: 'jbuyer@mail.net',
currency: 'KES',
value: 20000,
metadata: {
customer_id: '123456789',
reference: '123456',
notes: 'Payment for invoice 12345'
},
callback_url: 'https://call_back_to_your_app.your_application.com'
}
k2_stk = K2Stk.new("your_access_token")
k2_stk.receive_mpesa_payments(your_input)
k2_stk.location_url # => "https://sandbox.kopokopo.com/api/v2/incoming_payments/247b1bd8-f5a0-4b71-a898-f62f67b8ae1c"
request_body =
{
"access_token": ACCESS_TOKEN,
"callback_url": "https://webhook.site/52fd1913-778e-4ee1-bdc4-74517abb758d",
"first_name": "python_first_name",
"last_name": "python_last_name",
"email": "john.doe@gmail.com",
"payment_channel": "MPESA",
"phone_number": "+254911222536",
"till_number": "K000000 || 000000",
"amount": "10"
}
# Using K2Connect - https://github.com/kopokopo/k2-connect-python (Recommended)
k2connect.initialize(environ.get('CLIENT_ID'), environ.get('CLIENT_SECRET'), 'sandbox.kopokopo.com')
stk_service = k2connect.ReceivePayments
stk_push_location = stk_service.create_payment_request(request_body)
stk_push_location # => 'https://sandbox.kopokopo.com/api/v2/incoming_payments/247b1bd8-f5a0-4b71-a898-f62f67b8ae1c'
const StkService = K2.StkService;
var stkOptions = {
paymentChannel: "M-PESA STK Push",
tillNumber: "K000000 || 000000",
firstName: "Jane",
lastName: "Doe",
phoneNumber: "+254999999999",
email: "example@example.com",
currency: "KES",
// A maximum of 5 key value pairs
metadata: {
customerId: "123456789",
reference: "123456",
notes: "Payment for invoice 123456",
},
// This is where once the request is completed kopokopo will post the response
callbackUrl: "https://callback_to_your_app.your_application.com/endpoint",
accessToken: "myRand0mAcc3ssT0k3n",
};
StkService.initiateIncomingPayment(stkOptions)
.then((response) => {
console.log(response);
// => 'https://sandbox.kopokopo.com/api/v2/incoming_payments/247b1bd8-f5a0-4b71-a898-f62f67b8ae1c'
})
.catch((error) => {
console.log(error);
});
<?
$stk = $K2->StkService();
$response = $stk->initiateIncomingPayment([
'paymentChannel' => 'M-PESA STK Push',
'tillNumber' => 'K000000 || 000000',
'firstName' => 'Jane',
'lastName' => 'Doe',
'phoneNumber' => '+254999999999',
'amount' => 3455,
'currency' => 'KES',
'email' => 'example@example.com',
'callbackUrl' => 'https://callback_to_your_app.your_application.com/endpoint',
'metadata' => [
'customerId' => '123456789',
'reference' => '123456',
'notes' => 'Payment for invoice 12345'
],
'accessToken' => 'myRand0mAcc3ssT0k3n',
]);
if($response['status'] == 'success')
{
echo "The resource location is:" . json_encode($response['location']);
// => 'https://sandbox.kopokopo.com/api/v2/incoming_payments/247b1bd8-f5a0-4b71-a898-f62f67b8ae1c'
}
final TokenService tokenService = K2ConnectFlutter.tokenService();
final tokenResponse = await tokenService.requestAccessToken();
# For bottom sheet payment request UI
final request = StkPushRequest(
companyName: 'Test Company',
tillNumber: 'K12345',
amount: Amount(
currency: 'KES', value: '1.00'),
callbackUrl:
'https://webhook.site/your-callback-url',
metadata: {'source': 'flutter-app'},
onSuccess: () =>
print('Payment success'),
onError: (error) =>
print('Payment error: $error'),
accessToken: tokenResponse.accessToken,
);
final stkService =
K2ConnectFlutter.stkService();
await stkService
.requestPaymentBottomSheet(
context,
request: request,
);
# To make a request without UI
final stkRequest = StkPushRequest(
tillNumber: 'K12345',
subscriber: Subscriber(phoneNumber: '0712345678'),
amount: Amount(value: '10.00', currency: 'KES'),
callbackUrl: 'https://webhook.site/your-callback-url',
accessToken: tokenResponse.accessToken,
);
final service = StkService(baseUrl: 'base_url');
final result = await service.requestPayment(stkRequest);
HTTP Request
POST https://sandbox.kopokopo.com/api/v2/incoming_payments
Request Parameters (JSON)
| Parameter | Required | Type | Description |
|---|---|---|---|
| payment_channel | Yes | String | The payment channel to be used eg. M-PESA |
| till_number | Yes | String | Your M-PESA till number or online payments account number from the Kopo Kopo dashboard to which the payment will be made. |
| subscriber | Yes | Subscriber | A Subscriber JSON object see below |
| amount | Yes | Amount | An Amount JSON object containing currency and amount |
| metadata | No | Metadata | An optional JSON object containing a maximum of 5 key value pairs |
| links | Yes | _links | A JSON object containing the call back URL where the result of the Incoming Payment will be posted |
Subscriber (JSON)
| Parameter | Required | Type | Description |
|---|---|---|---|
| first_name | No | String | First name of the subscriber |
| last_name | No | String | Last name of the subscriber |
| phone_number | Yes | String | The phone number of the subscriber from which the payment will be made |
| No | String | E-mail address of the subscriber - optional |
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 Incoming Payment
HTTP/1.1 201 Created
Location: https://sandbox.kopokopo.com/api/v2/incoming_payments/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 occured. Please note that the error response might not be present depending on the type of error that occured.
If the error json response is present, it will look as follows:
HTTP/1.1 400 Bad Request
{ "error_code": 400, "error_message": "Till number can't be blank" }
Process Incoming Payment Result
POST https://your-callback-url.com/api/v2/payment_request_result
Content-Type: application/json
User-Agent: < product >/< product-version > < comment >
X-KopoKopo-Signature: 0Sn0W6kzNicvoWhDbQcVSKLRUpGjIdlPSEYyrHqrDDoRnQwE7Q
- JSON
- Ruby
- Python
- JavaScript
- PHP
- Dart
{
"data": {
"id": "a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"type": "incoming_payment",
"attributes": {
"initiation_time": "2020-10-19T09:24:48.622+03:00",
"status": "Success",
"event": {
"type": "Incoming Payment Request",
"resource": {
"id": "52f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"reference": "OJJ1MPU40Z",
"origination_time": "2020-10-19T09:24:54+03:00",
"sender_phone_number": "+254999999999",
"amount": "100.0",
"currency": "KES",
"till_number": "K000000",
"system": "Lipa Na M-PESA",
"status": "Received",
"sender_first_name": "Joe",
"sender_middle_name": null,
"sender_last_name": "Buyer"
},
"errors": null
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"_links": {
"callback_url": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "http://sandbox.kopokopo.com/api/v2/incoming_payments/a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc"
}
}
}
}
incoming_payment = K2Client.new("API_KEY")
incoming_payment.parse_request(request)
stk_object = K2ProcessResult.process(incoming_payment.hash_body, API_KEY, incoming_payment.k2_signature)
# Processed stk result in json format
{
"data": {
"id": "a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"type": "incoming_payment",
"attributes": {
"initiation_time": "2020-10-19T09:24:48.622+03:00",
"status": "Success",
"event": {
"type": "Incoming Payment Request",
"resource": {
"id": "52f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"reference": "OJJ1MPU40Z",
"origination_time": "2020-10-19T09:24:54+03:00",
"sender_phone_number": "+254999999999",
"amount": "100.0",
"currency": "KES",
"till_number": "K514459",
"system": "Lipa Na M-PESA",
"status": "Received",
"sender_first_name": "Joe",
"sender_middle_name": nil,
"sender_last_name": "Buyer"
},
"errors": nil
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"_links": {
"callback_url": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "http://sandbox.kopokopo.com/api/v2/incoming_payments/a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc"
}
}
}
}
k2connect.initialize(CLIENT_ID, CLIENT_SECRET, BASE_URL)
result_handler = k2connect.ResultHandler
processed_payload = result_handler.process(request)
decomposed_result = payload_decomposer.decompose(processed_payload)
# Processed stk result in json format
{
"data": {
"id": "a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"type": "incoming_payment",
"attributes": {
"initiation_time": "2020-10-19T09:24:48.622+03:00",
"status": "Success",
"event": {
"type": "Incoming Payment Request",
"resource": {
"id": "52f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"reference": "OJJ1MPU40Z",
"origination_time": "2020-10-19T09:24:54+03:00",
"sender_phone_number": "+254999999999",
"amount": "100.0",
"currency": "KES",
"till_number": "K514459",
"system": "Lipa Na M-PESA",
"status": "Received",
"sender_first_name": "Joe",
"sender_middle_name": nil,
"sender_last_name": "Buyer"
},
"errors": nil
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"_links": {
"callback_url": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "http://sandbox.kopokopo.com/api/v2/incoming_payments/a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc"
}
}
}
}
{
"data": {
"id": "a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"type": "incoming_payment",
"attributes": {
"initiation_time": "2020-10-19T09:24:48.622+03:00",
"status": "Success",
"event": {
"type": "Incoming Payment Request",
"resource": {
"id": "52f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"reference": "OJJ1MPU40Z",
"origination_time": "2020-10-19T09:24:54+03:00",
"sender_phone_number": "+254999999999",
"amount": "100.0",
"currency": "KES",
"till_number": "K000000",
"system": "Lipa Na M-PESA",
"status": "Received",
"sender_first_name": "Joe",
"sender_middle_name": null,
"sender_last_name": "Buyer"
},
"errors": null
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"_links": {
"callback_url": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "http://sandbox.kopokopo.com/api/v2/incoming_payments/a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc"
}
}
}
}
<?
// The payload from the k2-connect-php SDK will look like this.
[
"status" => "success",
"data" => [
"id" => "cac95329-9fa5-42f1-a4fc-c08af7b868fb",
"type" => "incoming_payment",
"initiationTime" => "2018-06-20T22:45:12.790Z",
"status" => "Success",
"eventType" =>"Incoming Payment Request",
"resourceId" => "52f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"reference" => '123456789',
"originationTime" => "2017-01-20T22:45:12.790Z",
"senderPhoneNumber" => "+2549703119050",
"amount" => 20000,
"currency" => "KES",
"tillNumber" => "K000000",
"system" => "Lipa Na M-PESA",
"resourceStatus" => "Received",
"senderFirstName" => "John",
"senderMiddleName" => "O",
"senderLastName" => "Doe"
"errors" => [],
"metadata" => [
"customer_id" => "123456789",
"reference" => "123456",
"notes" => "Payment for invoice 123456"
],
"linkSelf" => "https://sandbox.kopokopo.com/payment_request_results/cac95329-9fa5-42f1-a4fc-c08af7b868fb",
"callbackUrl" => "https://webhook.site/fa3645c6-7199-426a-8efa-98e7b754babb",
]
]
// The result payload sent to your backend callback URL will look like this.
{
"data": {
"id": "a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"type": "incoming_payment",
"attributes": {
"initiation_time": "2020-10-19T09:24:48.622+03:00",
"status": "Success",
"event": {
"type": "Incoming Payment Request",
"resource": {
"id": "52f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"reference": "OJJ1MPU40Z",
"origination_time": "2020-10-19T09:24:54+03:00",
"sender_phone_number": "+254999999999",
"amount": "100.0",
"currency": "KES",
"till_number": "K000000",
"system": "Lipa Na M-PESA",
"status": "Received",
"sender_first_name": "Joe",
"sender_middle_name": null,
"sender_last_name": "Buyer"
},
"errors": null
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"_links": {
"callback_url": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "http://sandbox.kopokopo.com/api/v2/incoming_payments/a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc"
}
}
}
}
Unsuccessful Incoming Payment
- JSON
- Ruby
- Python
- JavaScript
- PHP
- Dart
{
"data": {
"id": "09bc45fc-3b97-4c44-b860-42a7bcbd7480",
"type": "incoming_payment",
"attributes": {
"initiation_time": "2020-10-15T09:45:18.843+03:00",
"status": "Failed",
"event": {
"type": "Incoming Payment Request",
"resource": null,
"errors": ["The initiator information is invalid."]
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"_links": {
"callback_url": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "https://sandbox.kopokopo.com/api/v2/incoming_payments/09bc45fc-3b97-4c44-b860-42a7bcbd7480"
}
}
}
}
{
"data": {
"id": "09bc45fc-3b97-4c44-b860-42a7bcbd7480",
"type": "incoming_payment",
"attributes": {
"initiation_time": "2020-10-15T09:45:18.843+03:00",
"status": "Failed",
"event": {
"type": "Incoming Payment Request",
"resource": null,
"errors": ["The initiator information is invalid."]
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"_links": {
"callback_url": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "https://sandbox.kopokopo.com/api/v2/incoming_payments/09bc45fc-3b97-4c44-b860-42a7bcbd7480"
}
}
}
}
{
"data": {
"id": "09bc45fc-3b97-4c44-b860-42a7bcbd7480",
"type": "incoming_payment",
"attributes": {
"initiation_time": "2020-10-15T09:45:18.843+03:00",
"status": "Failed",
"event": {
"type": "Incoming Payment Request",
"resource": null,
"errors": ["The initiator information is invalid."]
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"_links": {
"callback_url": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "https://sandbox.kopokopo.com/api/v2/incoming_payments/09bc45fc-3b97-4c44-b860-42a7bcbd7480"
}
}
}
}
{
"data": {
"id": "09bc45fc-3b97-4c44-b860-42a7bcbd7480",
"type": "incoming_payment",
"attributes": {
"initiation_time": "2020-10-15T09:45:18.843+03:00",
"status": "Failed",
"event": {
"type": "Incoming Payment Request",
"resource": null,
"errors": ["The initiator information is invalid."]
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"_links": {
"callback_url": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "https://sandbox.kopokopo.com/api/v2/incoming_payments/09bc45fc-3b97-4c44-b860-42a7bcbd7480"
}
}
}
}
<?
// The payload from the k2-connect-php SDK will look like this.
[
"status" => "success",
"data" => [
"id" => "cac95329-9fa5-42f1-a4fc-c08af7b868fb",
"type" => "incoming_payment",
"initiationTime" => "2018-06-20T22:45:12.790Z",
"status" => "Failed",
"eventType" =>"Incoming Payment Request",
"resource" => null,
"errors" => ["Insufficient funds"]
"metadata" => [
"customer_id" => "123456789",
"reference" => "123456",
"notes" => "Payment for invoice 123456"
],
"linkSelf" => "https://sandbox.kopokopo.com/payment_request_results/cac95329-9fa5-42f1-a4fc-c08af7b868fb",
"callbackUrl" => "https://webhook.site/fa3645c6-7199-426a-8efa-98e7b754babb",
]
]
// The result payload sent to your backend callback URL will look like this.
{
"data": {
"id": "09bc45fc-3b97-4c44-b860-42a7bcbd7480",
"type": "incoming_payment",
"attributes": {
"initiation_time": "2020-10-15T09:45:18.843+03:00",
"status": "Failed",
"event": {
"type": "Incoming Payment Request",
"resource": null,
"errors": ["The initiator information is invalid."]
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"_links": {
"callback_url": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "https://sandbox.kopokopo.com/api/v2/incoming_payments/09bc45fc-3b97-4c44-b860-42a7bcbd7480"
}
}
}
}
After a Incoming Payment is initiated, a Incoming Payment Result will be posted asynchronously to the call back URL specified in the Incoming Payment.
Incoming Payment Result Parameters (JSON)
Parameters contained in a successful Incoming Payment result;
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | The ID of the Incoming Payment |
| type | Yes | String | The topic of the request. incoming_payment in this instance. |
| initiation_time | Yes | String | The timestamp of when the Incoming Payment was created. |
| status | Yes | String | A status string denoting the status of the Incoming Payment |
| event | Yes | JSON | A JSON Object encapsulating the event of the request (see below) |
| metadata | No | JSON | An optional JSON objet containing a maximum of 5 key - value pairs that had been sent during the initiation of the request |
| _links | Yes | JSON | A JSON object containing links to the Incoming Payment and the corresponding Buygoods Transaction resource |
Event JSON
| Parameter | Required | Type | Description |
|---|---|---|---|
| type | Yes | String | The type of the event (Incoming Payment) |
| resource | Yes | JSON | The resource corresponding to the event. In this case this is a Buygoods Transaction |
| errors | No | String | A string containing information on the error than occured |
Resource (Buygoods Transaction) JSON
| Parameter | Required | Type | Description |
|---|---|---|---|
| reference | Yes | String | The reference of the transaction |
| origination_time | Yes | String | The transaction timestamp |
| sender_phone_number | Yes | String | The phone number that sent the payment |
| amount | Yes | Float | The amount of the transaction |
| currency | Yes | String | Currency |
| till_number | Yes | String | The Online Payments Account till number to which the payment was made |
| system | Yes | String | The mobile money system |
| sender_first_name | Yes | String | First name of payer |
| sender_middle_name | No | String | Middle name of payer |
| sender_last_name | Yes | String | Last name of payer |
Remember — if you are also subscribed to the buygoods_transaction_received webhook, the Request Payment Result
will also be sent to that end point.
Query Incoming Payment Status
GET https://sandbox.kopokopo.com/api/v2/incoming_payments/d79995cd-0111-e511-80da-0aa34a9b2388
Accept: application/json
Authorization: Bearer 0Sn0W6kzNicvoWhDbQcVSKLRUpGjIdlPSEYyrHqrDDoRnQwE7Q
User-Agent: < product >/< product-version > < comment >
- Ruby
- Python
- JavaScript
- PHP
- Dart
payment_request_url = 'https://sandbox.kopokopo.com/api/v2/incoming_payments/d76265cd-0951-e511-80da-0aa34a9b2388'
# Using K2 Connect - https://github.com/kopokopo/k2-connect-ruby (Recommended)
k2_stk = K2Stk.new("your_access_token")
k2_stk.receive_mpesa_payments(your_input)
# Query specific resource
k2_stk.query_resource(payment_request_url) or k2_stk.query_resource(k2_stk.location_url)
# Query recent transaction
k2_stk.query_status
payment_request_url = 'https://sandbox.kopokopo.com/api/v2/incoming_payments/d76265cd-0951-e511-80da-0aa34a9b2388'
# Using K2 Connect - https://github.com/kopokopo/k2-connect-python (Recommended)
k2connect.initialize(environ.get('CLIENT_ID'), environ.get('CLIENT_SECRET'), 'sandbox.kopokopo.com')
stk_service = k2connect.ReceivePayments
stk_push_location = stk_service.payment_request_status(access_token, payment_request_url)
var StkService = K2.StkService;
var stkUrl =
"https://sandbox.kopokopo.com/api/v2/incoming_payments/d76265cd-0951-e511-80da-0aa34a9b2388";
StkService.getStatus({ accessToken: "myRand0mAcc3ssT0k3n", location: stkUrl })
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
<?
$stk = $K2->StkService();
$options = [
'location' => 'https://sandbox.kopokopo.com/api/v2/incoming_payments/d76265cd-0951-e511-80da-0aa34a9b2388',
'accessToken' => 'myRand0mAcc3ssT0k3n',
];
$response = $stk->getStatus($options);
echo $response
final location = result.headers['location'];
final statusResponse = await service.requestStatus(
uri: location,
accessToken: tokenResponse.accessToken,
);
final status = statusResponse.attributes.status;
print('Payment status: $status');
The request above results the following JSON payload when a Incoming Payment Result exists
- JSON
- Ruby
- Python
- JavaScript
- PHP
- Dart
{
"data": {
"id": "a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"type": "incoming_payment",
"attributes": {
"initiation_time": "2020-10-19T09:24:48.622+03:00",
"status": "Success",
"event": {
"type": "Incoming Payment Request",
"resource": {
"id": "52f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"reference": "OJJ1MPU40Z",
"origination_time": "2020-10-19T09:24:54+03:00",
"sender_phone_number": "+254999999999",
"amount": "100.0",
"currency": "KES",
"till_number": "K000000",
"system": "Lipa Na M-PESA",
"status": "Received",
"sender_first_name": "Joe",
"sender_middle_name": null,
"sender_last_name": "Buyer"
},
"errors": null
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"_links": {
"callback_url": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "http://sandbox.kopokopo.com/api/v2/incoming_payments/a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc"
}
}
}
}
{
"data": {
"id": "a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"type": "incoming_payment",
"attributes": {
"initiation_time": "2020-10-19T09:24:48.622+03:00",
"status": "Success",
"event": {
"type": "Incoming Payment Request",
"resource": {
"id": "52f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"reference": "OJJ1MPU40Z",
"origination_time": "2020-10-19T09:24:54+03:00",
"sender_phone_number": "+254999999999",
"amount": "100.0",
"currency": "KES",
"till_number": "K000000",
"system": "Lipa Na M-PESA",
"status": "Received",
"sender_first_name": "Joe",
"sender_middle_name": null,
"sender_last_name": "Buyer"
},
"errors": null
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"_links": {
"callback_url": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "http://sandbox.kopokopo.com/api/v2/incoming_payments/a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc"
}
}
}
}
{
"data": {
"id": "a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"type": "incoming_payment",
"attributes": {
"initiation_time": "2020-10-19T09:24:48.622+03:00",
"status": "Success",
"event": {
"type": "Incoming Payment Request",
"resource": {
"id": "52f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"reference": "OJJ1MPU40Z",
"origination_time": "2020-10-19T09:24:54+03:00",
"sender_phone_number": "+254999999999",
"amount": "100.0",
"currency": "KES",
"till_number": "K000000",
"system": "Lipa Na M-PESA",
"status": "Received",
"sender_first_name": "Joe",
"sender_middle_name": null,
"sender_last_name": "Buyer"
},
"errors": null
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"_links": {
"callback_url": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "http://sandbox.kopokopo.com/api/v2/incoming_payments/a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc"
}
}
}
}
{
"data": {
"id": "a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"type": "incoming_payment",
"attributes": {
"initiation_time": "2020-10-19T09:24:48.622+03:00",
"status": "Success",
"event": {
"type": "Incoming Payment Request",
"resource": {
"id": "52f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"reference": "OJJ1MPU40Z",
"origination_time": "2020-10-19T09:24:54+03:00",
"sender_phone_number": "+254999999999",
"amount": "100.0",
"currency": "KES",
"till_number": "K000000",
"system": "Lipa Na M-PESA",
"status": "Received",
"sender_first_name": "Joe",
"sender_middle_name": null,
"sender_last_name": "Buyer"
},
"errors": null
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"_links": {
"callback_url": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "http://sandbox.kopokopo.com/api/v2/incoming_payments/a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc"
}
}
}
}
<?
// The payload from the k2-connect-php SDK will look like this.
[
"status" => "success",
"data" => [
"id" => "cac95329-9fa5-42f1-a4fc-c08af7b868fb",
"type" => "incoming_payment",
"initiationTime" => "2018-06-20T22:45:12.790Z",
"status" => "Success",
"eventType" =>"Incoming Payment Request",
"resourceId" => "52f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"reference" => '123456789',
"originationTime" => "2017-01-20T22:45:12.790Z",
"senderPhoneNumber" => "+2549703119050",
"amount" => 20000,
"currency" => "KES",
"tillNumber" => "K000000",
"system" => "Lipa Na M-PESA",
"resourceStatus" => "Received",
"senderFirstName" => "John",
"senderMiddleName" => "O",
"senderLastName" => "Doe"
"errors" => [],
"metadata" => [
"customer_id" => "123456789",
"reference" => "123456",
"notes" => "Payment for invoice 123456"
],
"linkSelf" => "https://sandbox.kopokopo.com/payment_request_results/cac95329-9fa5-42f1-a4fc-c08af7b868fb",
"callbackUrl" => "https://webhook.site/fa3645c6-7199-426a-8efa-98e7b754babb",
]
]
// The payload from the k2-connect-flutter SDK will look like this.
{
"id": "a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"type": "incoming_payment",
"attributes": {
"initiationTime": "2020-10-19T09:24:48.622+03:00",
"status": "Success",
"event": {
"type": "Incoming Payment Request",
"resource": {
"id": "52f86f-f2aa-4d70-baa2-ccfe4b78f4fc",
"reference": "OJJ1MPU40Z",
"origination_time": "2020-10-19T09:24:54+03:00",
"sender_phone_number": "+254999999999",
"amount": "100.0",
"currency": "KES",
"till_number": "K000000",
"system": "Lipa Na M-PESA",
"status": "Received",
"sender_first_name": "Joe",
"sender_middle_name": null,
"sender_last_name": "Buyer"
},
"errors": null
},
"metadata": {
"customerId": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"links": {
"callbackUrl": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "http://sandbox.kopokopo.com/api/v1/incoming_payments/a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc"
}
}
}
JSON structure returned when No corresponding Incoming Payment Result exists
- JSON
- Ruby
- Python
- JavaScript
- PHP
- Dart
{
"data": {
"id": "e192ac63-8b24-4caf-8637-a2a9b75a14e6",
"type": "incoming_payment",
"attributes": {
"initiation_time": "2020-10-27T11:16:42.364+03:00",
"status": "Pending",
"event": {
"type": "Incoming Payment Request",
"resource": null,
"errors": null
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"_links": {
"callback_url": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "https://sandbox.kopokopo.com/api/v2/incoming_payments/e192ac63-8b24-4caf-8637-a2a9b75a14e6"
}
}
}
}
{
"data": {
"id": "e192ac63-8b24-4caf-8637-a2a9b75a14e6",
"type": "incoming_payment",
"attributes": {
"initiation_time": "2020-10-27T11:16:42.364+03:00",
"status": "Pending",
"event": {
"type": "Incoming Payment Request",
"resource": null,
"errors": null
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"_links": {
"callback_url": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "https://sandbox.kopokopo.com/api/v2/incoming_payments/e192ac63-8b24-4caf-8637-a2a9b75a14e6"
}
}
}
}
{
"data": {
"id": "e192ac63-8b24-4caf-8637-a2a9b75a14e6",
"type": "incoming_payment",
"attributes": {
"initiation_time": "2020-10-27T11:16:42.364+03:00",
"status": "Pending",
"event": {
"type": "Incoming Payment Request",
"resource": null,
"errors": null
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"_links": {
"callback_url": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "https://sandbox.kopokopo.com/api/v2/incoming_payments/e192ac63-8b24-4caf-8637-a2a9b75a14e6"
}
}
}
}
{
"data": {
"id": "e192ac63-8b24-4caf-8637-a2a9b75a14e6",
"type": "incoming_payment",
"attributes": {
"initiation_time": "2020-10-27T11:16:42.364+03:00",
"status": "Pending",
"event": {
"type": "Incoming Payment Request",
"resource": null,
"errors": null
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"_links": {
"callback_url": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "https://sandbox.kopokopo.com/api/v2/incoming_payments/e192ac63-8b24-4caf-8637-a2a9b75a14e6"
}
}
}
}
<?
// The payload from the k2-connect-php SDK will look like this.
[
"status" => "success",
"data" => [
"id" => "cac95329-9fa5-42f1-a4fc-c08af7b868fb",
"type" => "incoming_payment",
"initiationTime" => "2018-06-20T22:45:12.790Z",
"status" => "Pending",
"eventType" =>"Incoming Payment Request",
"resource" => null,
"errors" => [],
"metadata" => [
"customer_id" => "123456789",
"reference" => "123456",
"notes" => "Payment for invoice 123456"
],
"linkSelf" => "https://sandbox.kopokopo.com/payment_request_results/cac95329-9fa5-42f1-a4fc-c08af7b868fb",
"callbackUrl" => "https://webhook.site/fa3645c6-7199-426a-8efa-98e7b754babb",
]
]
// The payload from the k2-connect-flutter SDK will look like this.
{
"id": "e192ac63-8b24-4caf-8637-a2a9b75a14e6",
"type": "incoming_payment",
"attributes": {
"initiationTime": "2020-10-27T11:16:42.364+03:00",
"status": "Pending",
"event": {
"type": "Incoming Payment Request",
"resource": null,
"errors": null
},
"metadata": {
"customer_id": "123456789",
"reference": "123456",
"notes": "Payment for invoice 12345"
},
"links": {
"callbackUrl": "https://webhook.site/675d4ef4-0629-481f-83cd-d101f55e4bc8",
"self": "https://sandbox.kopokopo.com/api/v2/incoming_payments/e192ac63-8b24-4caf-8637-a2a9b75a14e6"
}
}
}
With an Incoming Payment location url, you can query what the status of the Incoming Payment is. If a corresponding Incoming Payment Result
exists, it will be bundled in the payload of the result.
HTTP Request
GET https://sandbox.kopokopo.com/api/v2/incoming_payments/
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 Incoming Payment to retrieve |