Language
Tools
Check the Incoming Payment Request status
You can query the status of a Payment Request by querying the Payment Request by its ID. If the Payment Request as been processed and a Incoming Payment Result
exists for the Incoming Payment
, the Incoming Payment Result
will be included in the payload of the Incoming Payment
in addition to the original Incoming Payment
. If no Incoming Payment Result
null will be assigned to the object.
Request and response (view schema in ‘raw’):
GET https://sandbox.kopokopo.com/api/v1/incoming_payments/d79995cd-0111-e511-80da-0aa34a9b2388
Accept: application/json
Authorization: Bearer 0Sn0W6kzNicvoWhDbQcVSKLRUpGjIdlPSEYyrHqrDDoRnQwE7Q
...
{
"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": "https://sandbox.kopokopo.com/api/v1/incoming_payments/a652f86f-f2aa-4d70-baa2-ccfe4b78f4fc"
}
}
}
}
payment_request_url = 'https://sandbox.kopokopo.com/api/v1/incoming_payments/d76265cd-0951-e511-80da-0aa34a9b2388'
k2stk = K2Stk.new('access_token')
# Using Kopo Kopo Connect - https://github.com/kopokopo/k2-connect-ruby (Recommended)
# To query a specific resource location url
k2_stk.query_resource(location_url)
# the location_url is the location resource url returned from creating a payment request
# Response will be in the following:
k2stk.k2_response_body # => response body
// Using Kopo Kopo Connect - https://github.com/kopokopo/k2-connect-node (Recommended)
const StkService = K2.StkService
var incomingPaymentsUrl = 'https://sandbox.kopokopo.com/api/v1/incoming_payments/d76265cd-0951-e511-80da-0aa34a9b2388'
StkService
.getStatus({accessToken: 'myRand0mAcc3ssT0k3n', location: incomingPaymentsUrl})
.then(response => { console.log(response) })
.catch(error => { console.log(error) })
payment_request_url = 'https://sandbox.kopokopo.com/api/v1/incoming_payments/d76265cd-0951-e511-80da-0aa34a9b2388'
# Using Kopo Kopo Connect - https://github.com/kopokopo/kopokopop-connect-python (Recommended)
k2connect.initialize(CLIENT_ID, CLIENT_SECRET, BASE_URL)
stk_service = k2connect.ReceivePayments
stk_payload = stk_service.payment_request_status(ACCESS_TOKEN, stk_push_location)
# the stk_push_location is the location resource url returned from creating a payment request
<?
// Using Kopo Kopo Connect - https://github.com/kopokopo/k2-connect-php (Recommended)
$stk = $K2->StkService();
$options = [
'location' => 'https://sandbox.kopokopo.com/api/v1/incoming_payments/d76265cd-0951-e511-80da-0aa34a9b2388',
'accessToken' => 'myRand0mAcc3ssT0k3n',
];
$response = $stk->getStatus($options);
echo $response;
You have now successfully received an M-PESA payment from your user(s). Please note if you have also subscribed for the buygoods_transaction_received
event webhook, you will also receive a notification of this transaction to the url specified in the webhook subscription.
© 2024 Kopo Kopo, Inc.