Skip to content

Commit

Permalink
Merge pull request #19 from andrei-ghenov/feature/T-007-review-and-re…
Browse files Browse the repository at this point in the history
…finement

T-007: Verify Implementation Compliance with Requirements
  • Loading branch information
andrei-ghenov authored Mar 4, 2024
2 parents e5c6343 + d814f8d commit 0cb7b51
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
7 changes: 7 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<?php

/**
* The front controller for the QuickTopUp API.
*
* @package QuickTopUpAPI
*/

// Load the environment variables.
require_once __DIR__.'/../src/bootstrap.php';
15 changes: 8 additions & 7 deletions src/Api/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace QuickTopUpAPI\Api;

use DateTime;
use DateTimeZone;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;

Expand Down Expand Up @@ -76,10 +74,12 @@ public function sendRequest(
string $endpoint,
array $data = []
): mixed {
// Generate the timestamp in the specified format and ensure it's in GMT/UTC
// Generate the timestamp in GMT/UTC format
$timestamp = gmdate('Y-m-d\TH:i:s');
$authKey = $this->generateAuthHmac($timestamp, $this->apiSecurityKey);
$hashedPassword = $this->generateAuthHmac(hash('sha256', $this->apiPassword), $authKey);
$hashedPassword = $this->generateAuthHmac(
hash('sha256', $this->apiPassword), $authKey
);

// Add authentication parameters to the request data.
$data = array_merge([
Expand All @@ -106,12 +106,13 @@ public function sendRequest(
/**
* Generates an HMAC SHA256 hash using the API security key.
*
* @param string $message The message to hash.
* @param string $secret The secret key for HMAC.
* @param string $message The message to hash.
* @param string $secret The secret key for HMAC.
*
* @return string The base64-encoded HMAC hash.
*/
private function generateAuthHmac($message, $secret): string {
return base64_encode(hash_hmac('sha256', $message, $secret, true));
return base64_encode(hash_hmac('sha256', $message, $secret, TRUE));
}

}
5 changes: 4 additions & 1 deletion src/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
*
* @package QuickTopUpAPI\Model
*
* A simple product model.
* Note. This is a simple product model, in a real scenario it will be
* a database model.
*
* Not currently used, created to expand functionality.
*/
class Product {

Expand Down

0 comments on commit 0cb7b51

Please sign in to comment.