PHP code example of akika / laravel-mpesa-multivendor
1. Go to this page and download the library: Download akika/laravel-mpesa-multivendor library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
akika / laravel-mpesa-multivendor example snippets
$response = Mpesa::using($credentials)
->c2b()
->registerUrls(
confirmationUrl: $confirmationUrl, // The URL to receive payment confirmation notifications.
validationUrl: $validationUrl, // The URL to receive payment validation requests.
ResponseType: $ResponseType, // nullable | Either Cancelled or Completed, default is Completed
);
$response = Mpesa::using($credentials)
->c2b()
->simulate(
phoneNumber: $phoneNumber,
amount: $amount,
billRefNumber: $billRefNumber // Account reference for Customer paybills and null for customer buy goods
);
$response = Mpesa::using($credentials)
->stk()
->push(
phoneNumber: $phoneNumber,
amount: $amount,
callbackUrl: $callbackUrl,
accountReference: $accountReference
receivingShortCode: $receivingShortCode // shortcode to receive funds, if null, the shortcode in credentials is used
);
$response = Mpesa::using($credentials)
->b2c()
->send(
phoneNumber: $phoneNumber,
amount: $amount,
resultUrl: $resultUrl,
queueTimeoutUrl: $timeoutUrl,
remarks: $remarks, // Comments that are sent along with the transaction.
occasion: $occasion, // A reference for the transaction, such as an invoice number or account number. (Max 100 characters)
commandId: $commandId, // The command ID for the transaction (default: 'BusinessPayment')
);
$response = Mpesa::using($credentials)
->b2b()
->expressCheckout(
partnerName: $partnerName, // The name of the organization that receives the transaction
destShortcode: $destShortcode,
amount: $amount,
paymentReference: $paymentReference, // The reference for the payment
callbackUrl: $callbackUrl
requestRefID: $requestRefID
);
$response = Mpesa::using($credentials)
->billManager()
->optin(
email: $email,
officialContact: $officialContact,
sendReminders: $sendReminders, // 1 or 0
logo: $logo, // Optional logo URL for the bill manager account.
callbackUrl: $callbackUrl
);
$response = Mpesa::using($credentials)
->billManager()
->singleInvoice(
externalReference: $externalReference, // A unique reference for the invoice.
billedFullName: $billedFullName, // The full name of the billed customer.
billedPhoneNumber: $billedPhoneNumber, // The phone number of the billed customer.
invoiceName: $invoiceName, // A descriptive name for the invoice (e.g., "Water Bill").
amount: $amount,
dueDate: $dueDate, // The due date for the invoice (in 'Y-m-d' format).
accountReference: $accountReference, // A reference for the account being billed.
billingPeriod: $billingPeriod, // The billing period (e.g., "June 2026").
items: $items, // Optional additional billable items to
$response = Mpesa::using($credentials)
->billManager()
->cancelSingleInvoice(
externalReference: $externalReference // The unique reference of the invoice to be cancelled.
);
$response = Mpesa::using($credentials)
->billManager()
->cancelBulkInvoices(
externalReferences: $externalReferences // An array of unique references for the invoices to be cancelled.
);
$response = Mpesa::using($credentials)
->taxRemmitance()
->remit(
amount: $amount,
accountReference: $accountReference, // The payment registration number (PRN) issued by KRA.
resultUrl: $resultUrl,
queueTimeoutUrl: $queueTimeoutUrl, // Optional remarks for the transaction (default: 'Tax remittance').
remarks: $remarks,
commandId: $commandId, // The due date for the invoice (in 'Y-m-d' format).
partyA: $partyA,
);
$response = Mpesa::using($credentials)
->ratiba()
->cancel(
standingOrderId: $standingOrderId, // Standing order to cancel
callbackUrl: $callbackUrl,
);
$response = Mpesa::using($credentials)
->transactionHistory()
->registerCallbackUrl(
nominatedNumber: $nominatedNumber, // The phone number to receive the transaction history callbacks (in international format, e.g., 2547XXXXXXXX).
callbackUrl: $callbackUrl,
);