Last active
October 28, 2019 15:40
-
-
Save Sadicko/8c518a109e0f894e9b4c256534248a51 to your computer and use it in GitHub Desktop.
Request to pay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_once 'HTTP/Request2.php'; | |
$request = new \Http_Request2('https://sandbox.momodeveloper.mtn.com/collection/v1_0/requesttopay'); | |
$url = $request->getUrl(); | |
$token = Collections::token(); //these is just a function that generate the token, it works fine | |
$profileKey = Details::profileKey(); //these is just a function that get the apiu key, it works fine | |
$x_reference = Gen_uuid::uuid(); //these is just a function that generate the uuid, it works fine | |
$headers = array( | |
// Request headers | |
'Authorization' => 'Bearer '.$token, | |
'X-Callback-Url' => 'localhost:8000', | |
'X-Reference-Id' => $x_reference, | |
'X-Target-Environment' => 'sandbox', | |
'Content-Type' => 'application/json', | |
'Ocp-Apim-Subscription-Key' => $profileKey, | |
); | |
// return $headers; | |
$request->setHeader($headers); | |
$parameters = array( | |
// Request parameters | |
); | |
$url->setQueryVariables($parameters); | |
$request->setMethod(\HTTP_Request2::METHOD_POST); | |
$body = array( | |
"amount"=> "100", | |
"currency"=> "EUR", | |
"externalId"=> "123456789", | |
"payer"=> [ | |
"partyIdType"=> "MSISDN", | |
"partyId"=> "46733123453" | |
], | |
"payerMessage"=> "Pay now", | |
"payeeNote"=> "Make Payment" | |
); | |
$body = json_encode($body); | |
// Request body | |
$request->setBody($body); | |
try | |
{ | |
$response = $request->send(); | |
echo $response->getBody(); | |
} | |
catch (HttpException $ex) | |
{ | |
echo $ex; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment