Language

Step 1: Obtain an application access token

Your application will need to exchange its client_id, client_secret, and grant_type=client_credentials for an application access token. With this token, you can then make API requests to the Kopo Kopo API.

Step 2: Creating a payment link

To make the following request, we need to use the access_token we obtained in step 1.

POST https://sandbox.kopokopo.com/api/v2/payment_links
Content-Type: application/json
Accept: application/json
Authorization: Bearer < AccessToken >
{
  "currency": "KES,
  "amount": "1000",
  "till_number": "4321",
  "payment_reference": "INV0298192",
  "note": "Payment for your monthly internet subscription",
  "metadata": {},
  "_links": {
      "callback_url": "https://webhook.site/e69b9144-530b-46ea-b3ed-ba110e189ca9"
    }
}
# Using K2Connect - https://github.com/kopokopo/k2-connect-ruby (Recommended)
payment_link_params = {
  till_number: "4321",
  currency: "KES",
  amount: 1000,
  payment_reference: "INV02932922",
  note: "Payment for monthly internet subscription",
  metadata: {
    account_number: "1234567",
  },
  callback_url: "https://example.com/callback",
}

k2_payment_links = K2ConnectRuby::K2Entity::PaymentLink.new("your_access_token")
k2_payment_links.create_payment_link(payment_link_params)

k2_payment_links.payment_link_location_url # https://sandbox.kopokopo.com/api/v2/payment_links/f387e4d7-6a32-4f2d-ba1e-809eab2d9614 
#  Using Kopo Kopo Connect - https://github.com/kopokopo/k2-connect-python (Recommended)
import k2connect

k2connect.initialize(CLIENT_ID, CLIENT_SECRET, BASE_URL)
payment_links_service = k2connect.PaymentLinks(access_token=access_token)

request_payload = {
  "currency": "KES",
  "amount": 1000,
  "till_number": "4321",
  "payment_reference": "INV0298192",
  "note": "Payment for your monthly internet subscription",
  "callback_url": "https://callback_to_your_app.your_application.com",
}
payment_link_resource_location_url = payment_links_service.create_payment_link(request_payload)
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 Kopo Kopo Connect - https://github.com/kopokopo/k2-connect-php (Recommended)
$paymentLinkService = $K2->PaymentLinkService();

$paymentLinkOptions = [
  "tillNumber" => "4321",
  "currency" => "KES",
  "amount" => 1000.00,
  "paymentReference" => "INV0298192",
  "note" => "Payment for your monthly internet subscription",
  "metadata" => [
    "customerId" => "#3948593",
  ],
  "callbackUrl" => "https://dummy_callback_url/payment_link_result",
  "accessToken" => $accessToken,
];

$response = $paymentLinkService->createPaymentLink($paymentLinkOptions);
print_r($response); // Array([status] => success [location] => https://sandbox.kopokopo.com/api/v2/payment_links/15513d7f-62c0-4e8d-91da-e5df670acfa6)
// Not Supported
// 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.