Payment Links
Payment links are a way to create a link that can be used to pay for a product or service via M-PESA.
Create a payment link
POST https://sandbox.kopokopo.com/api/v2/payment_links
Accept: application/json
Content-Type: application/json
Authorization: Bearer 0Sn0W6kzNicvoWhDbQcVSKLRUpGjIdlPSEYyrHqrDDoRnQwE7Q
User-Agent: < product >/< product-version > < comment >
- JSON
- Ruby
- Python
- JavaScript
- PHP
- Dart
{
"till_number": "till_number",
"currency": "KES",
"amount": 10,
"payment_reference": "order number or invoice number",
"note": "Notes",
"metadata": {
"something": "test",
"something_else": "Test data"
},
"_links": {
"callback_url": "https://webhook.site/e69b9144-530b-46ea-b3ed-ba110e189ca9"
}
}
your_input = {
till_number: 'till_number',
currency: 'KES',
amount: 10,
payment_reference: 'order number or invoice number',
note: 'Notes',
metadata: {},
callback_url: 'https://webhook.site/cc438b3e-ecf0-4600-b9cc-edba32ae7019'
}
# Using K2Connect - https://github.com/kopokopo/k2-connect-ruby (Recommended)
access_token = K2ConnectRuby.new('CLIENT_ID', 'CLIENT_SECRET').request_token
k2_payment_link = K2ConnectRuby::K2Entity::PaymentLink.new(access_token)
k2_payment_link.create_payment_link(your_input)
k2_payment_link.location_url # => "https://sandbox.kopokopo.com/api/v2/payment_links/cc438b3e-ecf0-4600-b9cc-edba32ae7019"
your_input = {
"till_number": "till_number",
"currency": "KES",
"amount": 10,
"payment_reference": "order number or invoice number",
"note": "Notes",
"metadata": {},
"callback_url": "https://webhook.site/cc438b3e-ecf0-4600-b9cc-edba32ae7019"
}
# Using K2Connect - https://github.com/kopokopo/k2-connect-python (Recommended)
payment_links_service = k2connect.PaymentLinks(access_token=access_token)
payment_link_location = payment_links_service.create_payment_link(your_input)
payment_link_location # => "https://sandbox.kopokopo.com/api/v2/payment_links/cc438b3e-ecf0-4600-b9cc-edba32ae7019"
const PaymentLinkService = K2.PaymentLinkService
const paymentLinkOptions = {
tillNumber: 'till_number',
currency: 'KES',
amount: 10,
paymentReference: 'order number or invoice number',
note: 'Notes',
metadata: {},
callbackUrl: 'https://webhook.site/cc438b3e-ecf0-4600-b9cc-edba32ae7019',
accessToken: 'myRand0mAcc3ssT0k3n'
}
PaymentLinkService
.createPaymentLink(paymentLinkOptions)
.then(response => {
console.log(response) // => 'https://sandbox.kopokopo.com/api/v2/payment_links/cc438b3e-ecf0-4600-b9cc-edba32ae7019'
})
.catch(error => {
console.log(error)
})
<?
// Using KopoKopoConnect - https://github.com/kopokopo/k2-connect-php (Recommended)
$paymentLink = $K2->PaymentLinkService();
$paymentLinkOptions = [
'tillNumber' => 'till_number',
'currency' => 'KES',
'amount' => 10,
'paymentReference' => 'order number or invoice number',
'note' => 'Notes',
'metadata' => [],
'callbackUrl' => 'https://webhook.site/cc438b3e-ecf0-4600-b9cc-edba32ae7019',
'accessToken' => 'myRand0mAcc3ssT0k3n'
];
$response = $paymentLink->createPaymentLink($paymentLinkOptions);
if($response['status'] == 'success')
{
echo "The resource location is:" . json_encode($response['location']);
// => 'https://sandbox.kopokopo.com/api/v2/payment_links/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/v2/payment_links
Accept: application/json
Content-Type: application/json
Authorization: Bearer 0Sn0W6kzNicvoWhDbQcVSKLRUpGjIdlPSEYyrHqrDDoRnQwE7Q
User-Agent: < product >/< product-version > < comment >
Request Parameters (JSON)
| Parameter | Required | Type | Description |
|---|---|---|---|
| till_number | yes | string | The till number of the till you want to create the payment link for |
| currency | yes | string | The currency of the payment link |
| amount | yes | number | The amount of the payment link |
| payment_reference | no | string | Unique reference for tracking the payment such as order number or invoice number |
| note | no | string | The note of the payment link to be seen by the customer |
| metadata | no | json | The metadata of the payment link |
| _links | yes | json | Object containing callback URL to the payment link API request |
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 Payment Link.
HTTP/1.1 201 Created
Location: https://sandbox.kopokopo.com/api/v2/payment_links/cc438b3e-ecf0-4600-b9cc-edba32ae7019
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" }
Payment link status
GET https://sandbox.kopokopo.com/api/v2/payment_links/cc438b3e-ecf0-4600-b9cc-edba32ae7019
Accept: application/json
Content-Type: application/json
Authorization: Bearer 0Sn0W6kzNicvoWhDbQcVSKLRUpGjIdlPSEYyrHqrDDoRnQwE7Q
User-Agent: < product >/< product-version > < comment >
- Ruby
- Python
- JavaScript
- PHP
- Dart
payment_link_reference = 'cc438b3e-ecf0-4600-b9cc-edba32ae7019'
# Using K2Connect - https://github.com/kopokopo/k2-connect-ruby (Recommended)
access_token = K2ConnectRuby.new('CLIENT_ID', 'CLIENT_SECRET').request_token
k2_payment_link = K2ConnectRuby::K2Entity::PaymentLink.new(access_token)
k2_payment_link.query_resource(payment_link_reference)
# Using K2Connect - https://github.com/kopokopo/k2-connect-python (Recommended)
your_input = {
"payment-link-reference": "cc438b3e-ecf0-4600-b9cc-edba32ae7019"
}
payment_links_service = k2connect.PaymentLinks(access_token=access_token)
payment_link_status = payment_links_service.fetch_payment_link(your_input)
// Using KopoKopoConnect - https://github.com/kopokopo/k2-connect-node (Recommended)
const PaymentLinkService = K2.PaymentLinkService
const paymentLinkOptions = {
location: 'https://sandbox.kopokopo.com/api/v2/payment_links/cc438b3e-ecf0-4600-b9cc-edba32ae7019',
accessToken: 'myRand0mAcc3ssT0k3n'
}
PaymentLinkService.getStatus(paymentLinkOptions)
<?
// Using KopoKopoConnect - https://github.com/kopokopo/k2-connect-php (Recommended)
$paymentLink = $K2->PaymentLinkService();
$statusOptions = [
'location' => 'cc438b3e-ecf0-4600-b9cc-edba32ae7019',
'accessToken' => 'myRand0mAcc3ssT0k3n'
]
$response = $paymentLink->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.
The request above results in the following JSON payload
- JSON
- Ruby
- Python
- JavaScript
- PHP
- Dart
{
"data": {
"id": "bb611130-0219-472e-869a-7eb31c453f22",
"type": "payment_link",
"attributes": {
"status": "Processed",
"created_at": "2026-02-10T07:35:43.850+03:00",
"till_name": "DiJon Dinin'",
"till_number": "112233",
"payment_reference": "test",
"currency": "KES",
"amount": 200,
"note": "Notes",
"payment_link": {
"status": "Active",
"expires_at": "2026-02-17T07:35:43.989+03:00",
"link": "https://sandbox.kopokopo.com/links/ef407998-c69b-4a57-a944-74ffb2131da2"
},
"errors": null,
"metadata": {
"something": "test",
"something_else": "Test data"
},
"_links": {
"callback_url": "https://webhook.site/6009e351-fd56-4d82-8d37-bd1da68eb8bc",
"self": "https://sandbox.kopokopo.com/api/v2/payment_links/bb611130-0219-472e-869a-7eb31c453f22"
}
}
}
}
{
"data": {
"id": "bb611130-0219-472e-869a-7eb31c453f22",
"type": "payment_link",
"attributes": {
"status": "Processed",
"created_at": "2026-02-10T07:35:43.850+03:00",
"till_name": "DiJon Dinin'",
"till_number": "112233",
"payment_reference": "test",
"currency": "KES",
"amount": 200,
"note": "Notes",
"payment_link": {
"status": "Active",
"expires_at": "2026-02-17T07:35:43.989+03:00",
"link": "https://sandbox.kopokopo.com/links/ef407998-c69b-4a57-a944-74ffb2131da2"
},
"errors": null,
"metadata": {
"something": "test",
"something_else": "Test data"
},
"_links": {
"callback_url": "https://webhook.site/6009e351-fd56-4d82-8d37-bd1da68eb8bc",
"self": "https://sandbox.kopokopo.com/api/v2/payment_links/bb611130-0219-472e-869a-7eb31c453f22"
}
}
}
}
{
"data": {
"id": "bb611130-0219-472e-869a-7eb31c453f22",
"type": "payment_link",
"attributes": {
"status": "Processed",
"created_at": "2026-02-10T07:35:43.850+03:00",
"till_name": "DiJon Dinin'",
"till_number": "112233",
"payment_reference": "test",
"currency": "KES",
"amount": 200,
"note": "Notes",
"payment_link": {
"status": "Active",
"expires_at": "2026-02-17T07:35:43.989+03:00",
"link": "https://sandbox.kopokopo.com/links/ef407998-c69b-4a57-a944-74ffb2131da2"
},
"errors": null,
"metadata": {
"something": "test",
"something_else": "Test data"
},
"_links": {
"callback_url": "https://webhook.site/6009e351-fd56-4d82-8d37-bd1da68eb8bc",
"self": "https://sandbox.kopokopo.com/api/v2/payment_links/bb611130-0219-472e-869a-7eb31c453f22"
}
}
}
}
{
"data": {
"id": "bb611130-0219-472e-869a-7eb31c453f22",
"type": "payment_link",
"attributes": {
"status": "Processed",
"created_at": "2026-02-10T07:35:43.850+03:00",
"till_name": "DiJon Dinin'",
"till_number": "112233",
"payment_reference": "test",
"currency": "KES",
"amount": 200,
"note": "Notes",
"payment_link": {
"status": "Active",
"expires_at": "2026-02-17T07:35:43.989+03:00",
"link": "https://sandbox.kopokopo.com/links/ef407998-c69b-4a57-a944-74ffb2131da2"
},
"errors": null,
"metadata": {
"something": "test",
"something_else": "Test data"
},
"_links": {
"callback_url": "https://webhook.site/6009e351-fd56-4d82-8d37-bd1da68eb8bc",
"self": "https://sandbox.kopokopo.com/api/v2/payment_links/bb611130-0219-472e-869a-7eb31c453f22"
}
}
}
}
<?
// The payload from the k2-connect-php SDK will look like this.
[
"status" => "success",
"data" => [
"id" => "2eab4ca0-1724-4c90-a734-0fb5ffc4391c",
"type" => "payment_link",
"attributes" => [
"status" => "Processed",
"created_at" => "2026-02-10T07:35:43.850+03:00",
"till_name" => "DiJon Dinin'",
"till_number" => "112233",
"payment_reference" => "test",
"currency" => "KES",
"amount" => 200,
"note" => "Notes",
"payment_link" => [
"status" => "Active",
"expires_at" => "2026-02-17T07:35:43.989+03:00",
"link" => "https://sandbox.kopokopo.com/links/ef407998-c69b-4a57-a944-74ffb2131da2"
],
"errors" => null,
"metadata" => [
"something" => "test",
"something_else" => "Test data"
],
"_links" => [
"callback_url" => "https://webhook.site/6009e351-fd56-4d82-8d37-bd1da68eb8bc",
"self" => "https://sandbox.kopokopo.com/api/v2/payment_links/bb611130-0219-472e-869a-7eb31c453f22"
]
]
]
]
// 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
GET https://sandbox.kopokopo.com/api/v2/payment_links/{payment_link_reference}
Accept: application/json
Content-Type: application/json
Authorization: Bearer 0Sn0W6kzNicvoWhDbQcVSKLRUpGjIdlPSEYyrHqrDDoRnQwE7Q
User-Agent: < product >/< product-version > < comment >
Request Parameters (JSON)
| Parameter | Required | Type | Description |
|---|---|---|---|
| payment_link_reference | yes | string | The reference of the payment link to view |
HTTP Response
Successful Response Result (JSON)
| Parameter | Type | Description |
|---|---|---|
| id | string | The ID of the payment link |
| type | string | The type of the payment link |
| attributes | object | The attributes of the payment link |
Attributes JSON
| Parameter | Type | Description |
|---|---|---|
| status | string | The status of the payment link |
| created_at | string | The date and time the payment link was created |
| till_name | string | The name of the till the payment link is for |
| till_number | string | The number of the till the payment link is for |
| payment_reference | string | The payment reference of the payment link |
| currency | string | The currency of the payment link |
| amount | number | The amount of the payment link |
| note | string | The note of the payment link |
| metadata | object | The metadata of the payment link |
| payment_link | object | The payment link object |
| errors | object | The errors of the payment link |
| _links | object | The links of the payment link |
Payment Link JSON
| Parameter | Type | Description |
|---|---|---|
| status | string | The status of the payment link |
| expires_at | string | The date and time the payment link will expire |
| link | string | The URL of the payment link |
Links JSON
| Parameter | Type | Description |
|---|---|---|
| callback_url | string | The URL of the callback url |
| self | string | The URL of the payment link |
{
"data": {
"id": "2eab4ca0-1724-4c90-a734-0fb5ffc4391c",
"type": "payment_link",
"attributes": {
"status": "Created",
"created_at": "2025-10-28T09:58:42.363+03:00",
"account_name": "UAT Testing",
"account_number": "K112233",
"initiator_name": "David Kariuki Mwangi",
"expires_at": "2025-11-04T09:58:42.429+03:00",
"payment_link": "https://sandbox.kopokopo.com/links/d60f5e34-8a36-49c3-8d56-fe0320538dbc",
"payment_link_status": "active",
"merchant_payment_reference": "test",
"currency": "KES",
"amount": 240001,
"note": "Notes",
"errors": null,
"_links": {
"self": "https://sandbox.kopokopo.com/api/v2/payment_links/2eab4ca0-1724-4c90-a734-0fb5ffc4391c"
}
}
}
}
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 404 Not Found
{ "error_code": 404, "error_message": "Payment link not found" }
Process Payment link API Result
After a Payment link request is initiated, a Payment link API result will be posted asynchronously to the callback URL specified in the initial request, once the payment link is paid, cancelled or expired.
POST https://your-callback-url.com/api/v2/payment_links
Content-Type: application/json
X-KopoKopo-Signature: 0Sn0W6kzNicvoWhDbQcVSKLRUpGjIdlPSEYyrHqrDDoRnQwE7Q
User-Agent: < product >/< product-version > < comment >
- JSON
- Ruby
- Python
- JavaScript
- PHP
- Dart
{
"data": {
"id": "55f74f06-5dea-4f1a-afba-e3decea28e03",
"type": "payment_link",
"attributes": {
"status": "Processed",
"created_at": "2026-04-27T00:58:43.389+03:00",
"till_name": "Till name",
"till_number": "till_number",
"payment_reference": "daud",
"currency": "KES",
"amount": 350,
"note": "Notes",
"payment_link": {
"status": "Paid",
"expires_at": "2026-05-04T00:58:43.424+03:00",
"link": "https://sandbox.kopokopo.com/links/d1a13e07-e92f-4c01-b49e-05294049793e",
"transaction_reference": "DAVSTK1777240982",
"sender_phone_number": "254996930902",
"origination_time": "2026-04-27T01:02:34.000+03:00"
},
"errors": null,
"metadata": {
"something": "test",
"something_else": "Test data"
},
"_links": {
"callback_url": "https://webhook.site/1e8e3abf-76c2-4149-9a72-6b4d97e39646",
"self": "https://sandbox.kopokopo.com/api/v2/payment_links/55f74f06-5dea-4f1a-afba-e3decea28e03"
}
}
}
}
{
"data": {
"id": "55f74f06-5dea-4f1a-afba-e3decea28e03",
"type": "payment_link",
"attributes": {
"status": "Processed",
"created_at": "2026-04-27T00:58:43.389+03:00",
"till_name": "Till name",
"till_number": "till_number",
"payment_reference": "daud",
"currency": "KES",
"amount": 350,
"note": "Notes",
"payment_link": {
"status": "Paid",
"expires_at": "2026-05-04T00:58:43.424+03:00",
"link": "https://sandbox.kopokopo.com/links/d1a13e07-e92f-4c01-b49e-05294049793e",
"transaction_reference": "DAVSTK1777240982",
"sender_phone_number": "254996930902",
"origination_time": "2026-04-27T01:02:34.000+03:00"
},
"errors": null,
"metadata": {
"something": "test",
"something_else": "Test data"
},
"_links": {
"callback_url": "https://webhook.site/1e8e3abf-76c2-4149-9a72-6b4d97e39646",
"self": "https://sandbox.kopokopo.com/api/v2/payment_links/55f74f06-5dea-4f1a-afba-e3decea28e03"
}
}
}
}
{
"data": {
"id": "55f74f06-5dea-4f1a-afba-e3decea28e03",
"type": "payment_link",
"attributes": {
"status": "Processed",
"created_at": "2026-04-27T00:58:43.389+03:00",
"till_name": "Till name",
"till_number": "till_number",
"payment_reference": "daud",
"currency": "KES",
"amount": 350,
"note": "Notes",
"payment_link": {
"status": "Paid",
"expires_at": "2026-05-04T00:58:43.424+03:00",
"link": "https://sandbox.kopokopo.com/links/d1a13e07-e92f-4c01-b49e-05294049793e",
"transaction_reference": "DAVSTK1777240982",
"sender_phone_number": "254996930902",
"origination_time": "2026-04-27T01:02:34.000+03:00"
},
"errors": null,
"metadata": {
"something": "test",
"something_else": "Test data"
},
"_links": {
"callback_url": "https://webhook.site/1e8e3abf-76c2-4149-9a72-6b4d97e39646",
"self": "https://sandbox.kopokopo.com/api/v2/payment_links/55f74f06-5dea-4f1a-afba-e3decea28e03"
}
}
}
}
{
"data": {
"id": "55f74f06-5dea-4f1a-afba-e3decea28e03",
"type": "payment_link",
"attributes": {
"status": "Processed",
"created_at": "2026-04-27T00:58:43.389+03:00",
"till_name": "Till name",
"till_number": "till_number",
"payment_reference": "daud",
"currency": "KES",
"amount": 350,
"note": "Notes",
"payment_link": {
"status": "Paid",
"expires_at": "2026-05-04T00:58:43.424+03:00",
"link": "https://sandbox.kopokopo.com/links/d1a13e07-e92f-4c01-b49e-05294049793e",
"transaction_reference": "DAVSTK1777240982",
"sender_phone_number": "254996930902",
"origination_time": "2026-04-27T01:02:34.000+03:00"
},
"errors": null,
"metadata": {
"something": "test",
"something_else": "Test data"
},
"_links": {
"callback_url": "https://webhook.site/1e8e3abf-76c2-4149-9a72-6b4d97e39646",
"self": "https://sandbox.kopokopo.com/api/v2/payment_links/55f74f06-5dea-4f1a-afba-e3decea28e03"
}
}
}
}
<?
// The payload from the k2-connect-php SDK will look like this.
[
"data" => [
"id" => "55f74f06-5dea-4f1a-afba-e3decea28e03",
"type" => "payment_link",
"attributes" => [
"status" => "Processed",
"created_at" => "2026-04-27T00:58:43.389+03:00",
"till_name" => "Till name",
"till_number" => "till_number",
"payment_reference" => "daud",
"currency" => "KES",
"amount" => 350,
"note" => "Notes",
"payment_link" => [
"status" => "Paid",
"expires_at" => "2026-05-04T00:58:43.424+03:00",
"link" => "https://sandbox.kopokopo.com/links/d1a13e07-e92f-4c01-b49e-05294049793e",
"transaction_reference" => "DAVSTK1777240982",
"sender_phone_number" => "254996930902",
"origination_time" => "2026-04-27T01:02:34.000+03:00"
],
"errors" => null,
"metadata" => [
"something" => "test",
"something_else" => "Test data"
],
"_links" => [
"callback_url" => "https://webhook.site/1e8e3abf-76c2-4149-9a72-6b4d97e39646",
"self" => "https://sandbox.kopokopo.com/api/v2/payment_links/55f74f06-5dea-4f1a-afba-e3decea28e03"
]
]
]
]
// 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 Payment Link
- JSON
- Ruby
- Python
- JavaScript
- PHP
- Dart
{
"data": {
"id": "3e5fb59e-f236-4d58-9bce-12691a610c95",
"type": "payment_link",
"attributes": {
"status": "Processed",
"created_at": "2026-04-27T01:05:34.026+03:00",
"till_name": "Till name",
"till_number": "Till number",
"payment_reference": "daud",
"currency": "KES",
"amount": 350,
"note": "Notes",
"payment_link": {
"status": "Active",
"expires_at": "2026-05-04T01:05:34.037+03:00",
"link": "https://sandbox.kopokopo.com/links/157d9213-3ac4-4f63-85a3-ae19c08e81b3",
"transaction_reference": null,
"sender_phone_number": null,
"origination_time": null
},
"errors": ["The balance is insufficient for the transaction"],
"metadata": {
"something": "test",
"something_else": "Test data"
},
"_links": {
"callback_url": "https://webhook.site/1e8e3abf-76c2-4149-9a72-6b4d97e39646",
"self": "https://sandbox.kopokopo.com/api/v2/payment_links/3e5fb59e-f236-4d58-9bce-12691a610c95"
}
}
}
}
{
"data": {
"id": "3e5fb59e-f236-4d58-9bce-12691a610c95",
"type": "payment_link",
"attributes": {
"status": "Processed",
"created_at": "2026-04-27T01:05:34.026+03:00",
"till_name": "Till name",
"till_number": "Till number",
"payment_reference": "daud",
"currency": "KES",
"amount": 350,
"note": "Notes",
"payment_link": {
"status": "Active",
"expires_at": "2026-05-04T01:05:34.037+03:00",
"link": "https://sandbox.kopokopo.com/links/157d9213-3ac4-4f63-85a3-ae19c08e81b3",
"transaction_reference": nil,
"sender_phone_number": nil,
"origination_time": nil
},
"errors": ["The balance is insufficient for the transaction"],
"metadata": {
"something": "test",
"something_else": "Test data"
},
"_links": {
"callback_url": "https://webhook.site/1e8e3abf-76c2-4149-9a72-6b4d97e39646",
"self": "https://sandbox.kopokopo.com/api/v2/payment_links/3e5fb59e-f236-4d58-9bce-12691a610c95"
}
}
}
}
{
"data": {
"id": "3e5fb59e-f236-4d58-9bce-12691a610c95",
"type": "payment_link",
"attributes": {
"status": "Processed",
"created_at": "2026-04-27T01:05:34.026+03:00",
"till_name": "Till name",
"till_number": "Till number",
"payment_reference": "daud",
"currency": "KES",
"amount": 350,
"note": "Notes",
"payment_link": {
"status": "Active",
"expires_at": "2026-05-04T01:05:34.037+03:00",
"link": "https://sandbox.kopokopo.com/links/157d9213-3ac4-4f63-85a3-ae19c08e81b3",
"transaction_reference": null,
"sender_phone_number": null,
"origination_time": null
},
"errors": ["The balance is insufficient for the transaction"],
"metadata": {
"something": "test",
"something_else": "Test data"
},
"_links": {
"callback_url": "https://webhook.site/1e8e3abf-76c2-4149-9a72-6b4d97e39646",
"self": "https://sandbox.kopokopo.com/api/v2/payment_links/3e5fb59e-f236-4d58-9bce-12691a610c95"
}
}
}
}
{
"data": {
"id": "3e5fb59e-f236-4d58-9bce-12691a610c95",
"type": "payment_link",
"attributes": {
"status": "Processed",
"created_at": "2026-04-27T01:05:34.026+03:00",
"till_name": "Till name",
"till_number": "Till number",
"payment_reference": "daud",
"currency": "KES",
"amount": 350,
"note": "Notes",
"payment_link": {
"status": "Active",
"expires_at": "2026-05-04T01:05:34.037+03:00",
"link": "https://sandbox.kopokopo.com/links/157d9213-3ac4-4f63-85a3-ae19c08e81b3",
"transaction_reference": null,
"sender_phone_number": null,
"origination_time": null
},
"errors": ["The balance is insufficient for the transaction"],
"metadata": {
"something": "test",
"something_else": "Test data"
},
"_links": {
"callback_url": "https://webhook.site/1e8e3abf-76c2-4149-9a72-6b4d97e39646",
"self": "https://sandbox.kopokopo.com/api/v2/payment_links/3e5fb59e-f236-4d58-9bce-12691a610c95"
}
}
}
}
[
"data" => [
"id" => "3e5fb59e-f236-4d58-9bce-12691a610c95",
"type" => "payment_link",
"attributes" => [
"status" => "Processed",
"created_at" => "2026-04-27T01:05:34.026+03:00",
"till_name" => "Till name",
"till_number" => "Till number",
"payment_reference" => "daud",
"currency" => "KES",
"amount" => 350,
"note" => "Notes",
"payment_link" => [
"status" => "Active",
"expires_at" => "2026-05-04T01:05:34.037+03:00",
"link" => "https://sandbox.kopokopo.com/links/157d9213-3ac4-4f63-85a3-ae19c08e81b3",
"transaction_reference" => null,
"sender_phone_number" => null,
"origination_time" => null
],
"errors" => ["The balance is insufficient for the transaction"],
"metadata" => [
"something" => "test",
"something_else" => "Test data"
],
"_links" => [
"callback_url" => "https://webhook.site/1e8e3abf-76c2-4149-9a72-6b4d97e39646",
"self" => "https://sandbox.kopokopo.com/api/v2/payment_links/3e5fb59e-f236-4d58-9bce-12691a610c95"
]
]
]
]
// 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.
Payment link Result Parameters (JSON)
Parameters contained in a successful Payment link result;
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | The ID of the payment_link request |
| type | Yes | String | The type of the API request (payment_link) |
| status | Yes | String | Status of the payment_link request |
| created_at | Yes | Date | Date and time the payment_link request was created |
| till_name | Yes | String | Till name where funds will be credited to |
| till_number | Yes | String | Till number where funds will be credited to |
| payment_reference | Yes | String | Payment reference that you provided |
| currency | Yes | String | Currency |
| amount | Yes | Float | The amount you provide for the payment_link request |
| note | Yes | String | Note sent with payment_link request |
| metadata | Yes | JSON | Metadata sent with the payment_link request |
| _links | Yes | JSON | Object containing links associated to the payment_link request |
| payment_link | Yes | JSON | Object containing the payment link details |
| errors | Yes | JSON | Object containing errors if any |
Payment link JSON
| Parameter | Required | Type | Description |
|---|---|---|---|
| status | Yes | String | The status of the payment link(Paid, Cancelled or Expired) |
| expires_at | Yes | Date | Date and time of when the payment link will expire |
| link | Yes | String | The URL that can be shared and used to make payment |
| transaction_reference | Yes | String | The reference for the transaction that paid the payment link |
| sender_phone_number | Yes | String | The phone number associated to the payment link |
| origination_time | Yes | Date | Date and time of when the transaction that paid the payment link occurred |
Cancel Payment Link
Cancel a payment link.
HTTP Request
POST https://sandbox.kopokopo.com/api/v2/payment_links/cc438b3e-ecf0-4600-b9cc-edba32ae7019/cancel
Accept: application/json
Content-Type: application/json
Authorization: Bearer 0Sn0W6kzNicvoWhDbQcVSKLRUpGjIdlPSEYyrHqrDDoRnQwE7Q
User-Agent: < product >/< product-version > < comment >
- Ruby
- Python
- JavaScript
- PHP
- Dart
payment_link_reference = 'https://sandbox.kopokopo.com/api/v2/payment_links/cc438b3e-ecf0-4600-b9cc-edba32ae7019'
# Using K2Connect - https://github.com/kopokopo/k2-connect-ruby (Recommended)
access_token = K2ConnectRuby.new('CLIENT_ID', 'CLIENT_SECRET').request_token
k2_payment_link = K2ConnectRuby::K2Entity::PaymentLink.new(access_token)
k2_payment_link.cancel_payment_link(payment_link_reference)
payment_link_reference = 'cc438b3e-ecf0-4600-b9cc-edba32ae7019'
# Using K2Connect - https://github.com/kopokopo/k2-connect-python (Recommended)
payment_links_service = k2connect.PaymentLinks(access_token=access_token)
your_input = {
"payment-link-reference": "cc438b3e-ecf0-4600-b9cc-edba32ae7019"
}
payment_links_service.cancel_payment_link(your_input)
const PaymentLinkService = K2.PaymentLinkService
const paymentLinkCancelOptions = {
location: 'https://sandbox.kopokopo.com/api/v2/payment_links/cc438b3e-ecf0-4600-b9cc-edba32ae7019',
accessToken: 'myRand0mAcc3ssT0k3n'
}
PaymentLinkService.cancelPaymentLink(paymentLinkCancelOptions)
<?
// Using KopoKopoConnect - https://github.com/kopokopo/k2-connect-php (Recommended)
$paymentLink = $K2->PaymentLinkService();
$cancelOptions = [
'location' => 'https://sandbox.kopokopo.com/api/v2/payment_links/cc438b3e-ecf0-4600-b9cc-edba32ae7019',
'accessToken' => 'myRand0mAcc3ssT0k3n'
]
$response = $paymentLink->cancelPaymentLink($cancelOptions);
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.
The request above results in the following JSON payload
- JSON
- Ruby
- Python
- JavaScript
- PHP
- Dart
{
"message": "Payment link cancelled."
}
{
"message": "Payment link cancelled."
}
{
"message": "Payment link cancelled."
}
{
"message": "Payment link cancelled."
}
<?
// The payload from the k2-connect-php SDK will look like this.
[
"status" => "success",
"data" => [
"message" => "Payment link cancelled."
]
]
// 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.
To cancel a payment link, you need to send a POST request to the payment link cancel endpoint.
Request Parameters (JSON)
| Parameter | Required | Type | Description |
|---|---|---|---|
| payment_link_reference | yes | string | The reference of the payment link to cancel |
POST https://sandbox.kopokopo.com/api/v2/payment_links/cc438b3e-ecf0-4600-b9cc-edba32ae7019/cancel
Accept: application/json
Content-Type: application/json
Authorization: Bearer 0Sn0W6kzNicvoWhDbQcVSKLRUpGjIdlPSEYyrHqrDDoRnQwE7Q
User-Agent: < product >/< product-version > < comment >
HTTP Response
Successful Response
Upon a successful request a HTTP Status 200 will be returned and the response will contain the payment link details.
HTTP/1.1 200 OK
{ "message": "Payment link cancelled." }
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": "Only active payment links can be cancelled." }