Skip to content

Instantly share code, notes, and snippets.

@Ammly
Created February 14, 2019 17:06
Show Gist options
  • Save Ammly/9a092a3004774a46ae0e4199c270f385 to your computer and use it in GitHub Desktop.
Save Ammly/9a092a3004774a46ae0e4199c270f385 to your computer and use it in GitHub Desktop.
JengaHq API Requests using GuzzleHttp for php
<?php
$account_id ={accountId};
$country_code='KE';
$date = date('Y-m-d');
$plainText = $account_id.$country_code.$date;
$privateKey = openssl_pkey_get_private('file://'.storage_path('privatekey.pem'));
$token = {token}; //returned from token function above
openssl_sign($plainText, $signature, $privateKey, OPENSSL_ALGO_SHA256);
// dd(base64_encode($signature));
try {
$client = new Client();
$request = $client->request('GET', 'https://uat.jengahq.io/account/v2/accounts/balances/'.{country_code}.'/'.{account_id},
[
'headers' => [
'Authorization' => 'Bearer '.$token,
'signature' => base64_encode($signature),
'Content-type' => 'application/json',
'Accept' => '*/*'
]
]);
$response = json_decode($request->getBody()->getContents());
dd($response);
} catch (RequestException $e) {
dd((string) $e->getResponse()->getBody());
}
<?php
$account_id ={accountId};
$country_code='KE';
$date = date('Y-m-d');
$plainText = $account_id.$country_code.$date;
$privateKey = openssl_pkey_get_private('file://'.storage_path('privatekey.pem'));
$token = {token}; //returned from token function above
openssl_sign($plainText, $signature, $privateKey, OPENSSL_ALGO_SHA256);
try {
$client = new Client();
$request = $client->request('POST', 'https://uat.jengahq.io/transaction/v2/remittance', [
'headers' => [
'Authorization' => 'Bearer '.$token,
'signature' => base64_encode($signature),
'Content-type' => 'application/json',
'Accept' => '*/*'
],
'json' => [
"source" => [
"countryCode" => $country_code,
"name" => "Testing bit",
"accountNumber" => $account_id
],
"destination" => [
"type" => "bank",
"countryCode" => $country_code,
"name" => "John Doe",
"mobileNumber" =>"0722199957",
"bankCode" => "63",
"accountNumber" => "0090207635001"
],
"transfer" => [
"type" => "PesaLink",
"amount" => "10",
"currencyCode" => "KES",
"reference" => "692194625798",
"date" => "2019-01-29",
"description" => "Status payment"
]
]
]);
$response = json_decode($request->getBody()->getContents());
dd($response);
} catch (RequestException $e) {
dd($e);
dd((string) $e->getResponse()->getBody());
}
<?php
try {
$client = new Client();
$request = $client->request('POST', 'https://uat.jengahq.io/identity/v2/token', [
'headers' => [
'Authorization' => {api_key},
'Content-type' => 'application/x-www-form-urlencoded'
],
'form_params' => [
'username' => {username},
'password' => {password}
]
]);
$response = json_decode($request->getBody()->getContents())->access_token;
return $response;
} catch (RequestException $e) {
dd((string) $e->getResponse()->getBody());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment