Skip to main content

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.

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 >
{
"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"
}
}

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)​

ParameterRequiredTypeDescription
till_numberyesstringThe till number of the till you want to create the payment link for
currencyyesstringThe currency of the payment link
amountyesnumberThe amount of the payment link
payment_referencenostringUnique reference for tracking the payment such as order number or invoice number
notenostringThe note of the payment link to be seen by the customer
metadatanojsonThe metadata of the payment link
_linksyesjsonObject 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" }

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 >
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)

The request above results in the following JSON payload

{
"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"
}
}
}
}

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)​

ParameterRequiredTypeDescription
payment_link_referenceyesstringThe reference of the payment link to view

HTTP Response​

Successful Response Result (JSON)​

ParameterTypeDescription
idstringThe ID of the payment link
typestringThe type of the payment link
attributesobjectThe attributes of the payment link

Attributes JSON

ParameterTypeDescription
statusstringThe status of the payment link
created_atstringThe date and time the payment link was created
till_namestringThe name of the till the payment link is for
till_numberstringThe number of the till the payment link is for
payment_referencestringThe payment reference of the payment link
currencystringThe currency of the payment link
amountnumberThe amount of the payment link
notestringThe note of the payment link
metadataobjectThe metadata of the payment link
payment_linkobjectThe payment link object
errorsobjectThe errors of the payment link
_linksobjectThe links of the payment link

Payment Link JSON

ParameterTypeDescription
statusstringThe status of the payment link
expires_atstringThe date and time the payment link will expire
linkstringThe URL of the payment link

Links JSON

ParameterTypeDescription
callback_urlstringThe URL of the callback url
selfstringThe 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" }

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 >
{
"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"
}
}
}
}

Unsuccessful Payment Link

{
"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"
}
}
}
}

Parameters contained in a successful Payment link result;

ParameterRequiredTypeDescription
idYesStringThe ID of the payment_link request
typeYesStringThe type of the API request (payment_link)
statusYesStringStatus of the payment_link request
created_atYesDateDate and time the payment_link request was created
till_nameYesStringTill name where funds will be credited to
till_numberYesStringTill number where funds will be credited to
payment_referenceYesStringPayment reference that you provided
currencyYesStringCurrency
amountYesFloatThe amount you provide for the payment_link request
noteYesStringNote sent with payment_link request
metadataYesJSONMetadata sent with the payment_link request
_linksYesJSONObject containing links associated to the payment_link request
payment_linkYesJSONObject containing the payment link details
errorsYesJSONObject containing errors if any

Payment link JSON

ParameterRequiredTypeDescription
statusYesStringThe status of the payment link(Paid, Cancelled or Expired)
expires_atYesDateDate and time of when the payment link will expire
linkYesStringThe URL that can be shared and used to make payment
transaction_referenceYesStringThe reference for the transaction that paid the payment link
sender_phone_numberYesStringThe phone number associated to the payment link
origination_timeYesDateDate and time of when the transaction that paid the payment link occurred

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 >
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)

The request above results in the following JSON payload

{
"message": "Payment link cancelled."
}

To cancel a payment link, you need to send a POST request to the payment link cancel endpoint.

Request Parameters (JSON)​

ParameterRequiredTypeDescription
payment_link_referenceyesstringThe 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." }