Skip to content

Instantly share code, notes, and snippets.

@levizwannah
Created July 31, 2023 14:28
Show Gist options
  • Save levizwannah/f366c63822f0a3c44fd22b5fc8ac5df4 to your computer and use it in GitHub Desktop.
Save levizwannah/f366c63822f0a3c44fd22b5fc8ac5df4 to your computer and use it in GitHub Desktop.
mpesa-sdk-reversal
<?php
// initialize Mpesa
// ...autoloading
$mpesa = Mpesa::new()->configure([
"key" => "consumer key",
"secret" => "consumer secret",
"code" => "business short code",
"till" => "business till if necessary",
"initiator" => "initiator name",
"credential" => "security credential"
]);
$reversal = $mpesa->reversal();
$reversal->transId("TRANACTION-ID")
->amount(1000)
->timeoutUrl("https://your-domain.com/your/path")
->resultUrl("https://your-domain.com/your/path")
->remarks('Any remarks') // optional
->occasion('Any occasion') // optional
->type('11'); // optional
$reversal->make();
if(!$reversal->accepted()){
echo "Reversal was not accepted";
print_r($reversal->error());
exit;
}
$response = $reversal->response();
// do something with the response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment