PHP code example of techsolutions / m-pesa
1. Go to this page and download the library: Download techsolutions/m-pesa 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/ */
techsolutions / m-pesa example snippets
use Techsolutions\MPesa\Config\Config;
// Configuração da API M-Pesa
Mpesa::config(
api_key: 'your-api-key',
public_key: 'your-public-key',
environment: 'development', // ou 'production'
service_provider_code: '171717',
origin: 'developer.mpesa.vm.co.mz',
initiatorIdentifier: 'your-initiator-id',
securityCredential: 'your-security-credential'
);
Techsolutions\MPesa\Mpesa;
// Configuração da API M-Pesa
Mpesa::config(
api_key: 'your-api-key',
public_key: 'your-public-key',
environment: 'environment', // development ou 'production'
service_provider_code: 'service-provider',
origin: 'origin',
initiatorIdentifier: 'your-initiator-id',
securityCredential: 'your-security-credential'
);
$transactionReference = bin2hex(random_bytes(6));
$thirdPartyReference = bin2hex(random_bytes(6));
$response = Mpesa::c2b(1, '258846568447', $transactionReference, $thirdPartyReference);
echo '<pre>';
print_r($response->toArray());
Techsolutions\MPesa\Mpesa;
// Configuração da API M-Pesa
Mpesa::config(
api_key: 'your-api-key',
public_key: 'your-public-key',
environment: 'environment', // development ou 'production'
service_provider_code: 'service-provider',
origin: 'origin',
initiatorIdentifier: 'your-initiator-id',
securityCredential: 'your-security-credential'
);
$transactionReference = bin2hex(random_bytes(6));
$thirdPartyReference = bin2hex(random_bytes(6));
$response = Mpesa::b2c(1, '258846568447', $transactionReference, $thirdPartyReference);
echo '<pre>';
print_r($response->toArray());
Techsolutions\MPesa\Mpesa;
// Configuração da API M-Pesa
Mpesa::config(
api_key: 'your-api-key',
public_key: 'your-public-key',
environment: 'environment', // development ou 'production'
service_provider_code: 'service-provider',
origin: 'origin',
initiatorIdentifier: 'your-initiator-id',
securityCredential: 'your-security-credential'
);
$transactionReference = bin2hex(random_bytes(6));
$thirdPartyReference = bin2hex(random_bytes(6));
$response = Mpesa::b2b(1, '258846568447', $transactionReference, $thirdPartyReference);
echo '<pre>';
print_r($response->toArray());
Techsolutions\MPesa\Mpesa;
// Configuração da API M-Pesa
Mpesa::config(
api_key: 'your-api-key',
public_key: 'your-public-key',
environment: 'environment', // development ou 'production'
service_provider_code: 'service-provider',
origin: 'origin',
initiatorIdentifier: 'your-initiator-id',
securityCredential: 'your-security-credential'
);
$transactionReference = bin2hex(random_bytes(6));
$thirdPartyReference = bin2hex(random_bytes(6));
$response = Mpesa::transaction($transactionReference, $thirdPartyReference);
echo '<pre>';
print_r($response->toArray());
Techsolutions\MPesa\Mpesa;
// Configuração da API M-Pesa
Mpesa::config(
api_key: 'your-api-key',
public_key: 'your-public-key',
environment: 'environment', // development ou 'production'
service_provider_code: 'service-provider',
origin: 'origin',
initiatorIdentifier: 'your-initiator-id',
securityCredential: 'your-security-credential'
);
$transactionReference = bin2hex(random_bytes(6));
$thirdPartyReference = bin2hex(random_bytes(6));
$response = Mpesa::reversal(1, $transactionReference, $thirdPartyReference);
echo '<pre>';
print_r($response->toArray());