|
@@ 235-276 (lines=42) @@
|
| 232 |
|
* @param $Occasion | Optional Parameter |
| 233 |
|
* @return mixed|string |
| 234 |
|
*/ |
| 235 |
|
private function reversal($CommandID, $Initiator, $SecurityCredential, $TransactionID, $Amount, $ReceiverParty, $RecieverIdentifierType, $ResultURL, $QueueTimeOutURL, $Remarks, $Occasion){ |
| 236 |
|
|
| 237 |
|
$environment = $this->environment; |
| 238 |
|
if( $environment =="live"){ |
| 239 |
|
$url = 'https://api.safaricom.co.ke/mpesa/reversal/v1/request'; |
| 240 |
|
$this->generateLiveToken(); |
| 241 |
|
}elseif ($environment=="sandbox"){ |
| 242 |
|
$url = 'https://sandbox.safaricom.co.ke/mpesa/reversal/v1/request'; |
| 243 |
|
$this->generateSandBoxToken(); |
| 244 |
|
}else{ |
| 245 |
|
return json_encode(["Message"=>"invalid application status. Please set mpesa_env credential as either live or sandbox."]); |
| 246 |
|
} |
| 247 |
|
|
| 248 |
|
$token = $this->getAccessToken(); |
| 249 |
|
|
| 250 |
|
$curl = curl_init(); |
| 251 |
|
|
| 252 |
|
curl_setopt($curl, CURLOPT_URL, $url); |
| 253 |
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json','Authorization:Bearer '.$token)); |
| 254 |
|
|
| 255 |
|
$curl_post_data = array( |
| 256 |
|
'CommandID' => $CommandID, |
| 257 |
|
'Initiator' => $Initiator, |
| 258 |
|
'SecurityCredential' => $SecurityCredential, |
| 259 |
|
'TransactionID' => $TransactionID, |
| 260 |
|
'Amount' => $Amount, |
| 261 |
|
'ReceiverParty' => $ReceiverParty, |
| 262 |
|
'RecieverIdentifierType' => $RecieverIdentifierType, |
| 263 |
|
'ResultURL' => $ResultURL, |
| 264 |
|
'QueueTimeOutURL' => $QueueTimeOutURL, |
| 265 |
|
'Remarks' => $Remarks, |
| 266 |
|
'Occasion' => $Occasion |
| 267 |
|
); |
| 268 |
|
|
| 269 |
|
$data_string = json_encode($curl_post_data); |
| 270 |
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
| 271 |
|
curl_setopt($curl, CURLOPT_POST, true); |
| 272 |
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string); |
| 273 |
|
curl_setopt($curl, CURLOPT_HEADER, false); |
| 274 |
|
$curl_response = curl_exec($curl); |
| 275 |
|
return json_decode($curl_response); |
| 276 |
|
} |
| 277 |
|
|
| 278 |
|
/** |
| 279 |
|
* @param $InitiatorName | This is the credential/username used to authenticate the transaction request. |
|
@@ 446-489 (lines=44) @@
|
| 443 |
|
* @param $Occasion | Optional Parameter |
| 444 |
|
* @return mixed|string |
| 445 |
|
*/ |
| 446 |
|
private function transactionStatus($Initiator, $SecurityCredential, $CommandID, $TransactionID, $PartyA, $IdentifierType, $ResultURL, $QueueTimeOutURL, $Remarks, $Occasion){ |
| 447 |
|
|
| 448 |
|
$environment = $this->environment; |
| 449 |
|
|
| 450 |
|
if( $environment =="live"){ |
| 451 |
|
$url = 'https://api.safaricom.co.ke/mpesa/transactionstatus/v1/query'; |
| 452 |
|
$this->generateLiveToken(); |
| 453 |
|
}elseif ($environment=="sandbox"){ |
| 454 |
|
$url = 'https://sandbox.safaricom.co.ke/mpesa/transactionstatus/v1/query'; |
| 455 |
|
$this->generateSandBoxToken(); |
| 456 |
|
}else{ |
| 457 |
|
return json_encode(["Message"=>"invalid application status"]); |
| 458 |
|
} |
| 459 |
|
|
| 460 |
|
$token = $this->getAccessToken(); |
| 461 |
|
$curl = curl_init(); |
| 462 |
|
curl_setopt($curl, CURLOPT_URL, $url); |
| 463 |
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json','Authorization:Bearer '.$token)); //setting custom header |
| 464 |
|
|
| 465 |
|
|
| 466 |
|
$curl_post_data = array( |
| 467 |
|
'Initiator' => $Initiator, |
| 468 |
|
'SecurityCredential' => $SecurityCredential, |
| 469 |
|
'CommandID' => $CommandID, |
| 470 |
|
'TransactionID' => $TransactionID, |
| 471 |
|
'PartyA' => $PartyA, |
| 472 |
|
'IdentifierType' => $IdentifierType, |
| 473 |
|
'ResultURL' => $ResultURL, |
| 474 |
|
'QueueTimeOutURL' => $QueueTimeOutURL, |
| 475 |
|
'Remarks' => $Remarks, |
| 476 |
|
'Occasion' => $Occasion |
| 477 |
|
); |
| 478 |
|
|
| 479 |
|
$data_string = json_encode($curl_post_data); |
| 480 |
|
|
| 481 |
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
| 482 |
|
curl_setopt($curl, CURLOPT_POST, true); |
| 483 |
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string); |
| 484 |
|
curl_setopt($curl, CURLOPT_HEADER, false); |
| 485 |
|
$curl_response = curl_exec($curl); |
| 486 |
|
|
| 487 |
|
|
| 488 |
|
return $curl_response; |
| 489 |
|
} |
| 490 |
|
|
| 491 |
|
|
| 492 |
|
/** |