PHP code example of weddingjuma / omnipay-mpesa
1. Go to this page and download the library: Download weddingjuma/omnipay-mpesa 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/ */
weddingjuma / omnipay-mpesa example snippets
$gateway = \Omnipay\Omnipay::create('Mpesa');
$gateway->setApiKey('test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM');
$response = $gateway->purchase(
[
"amount" => "10.00",
"currency" => "EUR",
"description" => "My first Payment",
"returnUrl" => "https://webshop.example.org/mpesa-return.php"
]
)->send();
// Process response
if ($response->isSuccessful()) {
// Payment was successful
print_r($response);
} elseif ($response->isRedirect()) {
// Redirect to offsite payment gateway
$response->redirect();
} else {
// Payment failed
echo $response->getMessage();
}