Code Snippets
Free, reusable code snippets for developers. Save time with ready-to-use solutions.
4 snippets found
PHP
Daraja API - STK Push (Lipa Na M-Pesa Online)
Complete PHP implementation of Safaricom Daraja API STK Push for Lipa Na M-Pesa Online. Includes access token generation and payment processing.
<?php
/**
* Daraja API - STK Push (Lipa Na M-Pesa Online)
* Complete implementation with error handling
*/
class MpesaSTKPush {
private $consumerKey;
private $consumerSecret;
...
PHP
Daraja API - C2B (Customer to Business)
Implement Customer to Business payments with validation and confirmation URLs
<?php
/**
* Daraja API - C2B (Customer to Business)
* Register URLs and process payments
*/
class MpesaC2B {
private $consumerKey;
private $consumerSecret;
private $shortCode;...
PHP
Daraja API - B2C (Business to Customer)
Send money from business to customer (B2C) - withdrawals, refunds, salary payments
<?php
/**
* Daraja API - B2C (Business to Customer)
* Send money to customers (withdrawals, refunds, salary)
*/
class MpesaB2C {
private $consumerKey;
private $consumerSecret;
...
PHP
Daraja API - Callback Handler
Handle STK Push callbacks and process payment notifications
<?php
/**
* Daraja API - Callback Handler
* Process STK Push callbacks
*/
// mpesa-callback.php
header("Content-Type: application/json");
// Get the callback data
$callbackData = file_g...
Code copied to clipboard!