diff --git a/README.md b/README.md index baf6094..3e54be8 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ $result = $transaction 'customer_name' => 'Nama Pelanggan', 'customer_email' => 'email@konsumen.id', 'customer_phone' => '081234567890', - 'expired_time' => Helper::makeTimestamp('6 HOUR'), + 'expired_time' => Helper::makeTimestamp('6 HOUR'), // see Supported Time Units ]); echo $result->getBody()->getContents(); @@ -70,3 +70,10 @@ echo json_encode($debugs, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); ``` Please check the `/examples` for the other examples + +## Supported Time Units +> :exclamation: All time units are in a singular noun +- SECOND +- MINUTE +- HOUR +- DAY diff --git a/examples/callback-handling.php b/examples/callback-handling.php index 4ba751e..8d63938 100644 --- a/examples/callback-handling.php +++ b/examples/callback-handling.php @@ -16,7 +16,7 @@ * * !! WARNING !! * Only enable it while debugging. - * Leaving it enabled can lead to security compromise + * Leaving it enabled can lead to security issue */ $callback->enableDebug(); diff --git a/src/Callback.php b/src/Callback.php index 8411e4b..93c5400 100644 --- a/src/Callback.php +++ b/src/Callback.php @@ -82,9 +82,9 @@ public function localSignature(): string /** * Get incoming signature * - * @return string|null + * @return string */ - public function incomingSignature(): ?string + public function incomingSignature(): string { return (string) (isset($_SERVER['HTTP_X_CALLBACK_SIGNATURE']) ? $_SERVER['HTTP_X_CALLBACK_SIGNATURE'] : ""); } diff --git a/src/Client.php b/src/Client.php index 45e08f7..0a332af 100644 --- a/src/Client.php +++ b/src/Client.php @@ -120,8 +120,8 @@ public function __construct(...$args) $this->merchantCode = (string) is_array($args[0]) ? $args[0]['merchant_code'] : $args[0]; $this->apiKey = (string) is_array($args[0]) ? $args[0]['api_key'] : $args[1]; - $this->privateKey = (string) is_array($args[0]) ? $args[0]['private_key'] : $args[1]; - $this->mode = (string) is_array($args[0]) ? $args[0]['mode'] : $args[2]; + $this->privateKey = (string) is_array($args[0]) ? $args[0]['private_key'] : $args[2]; + $this->mode = (string) is_array($args[0]) ? $args[0]['mode'] : $args[3]; $baseUri = ($this->mode == Constant::MODE_DEVELOPMENT) ? Constant::URL_DEVELOPMENT @@ -150,7 +150,7 @@ public function __construct(...$args) }, 'headers' => [ 'Authorization' => 'Bearer ' . $this->apiKey, - 'User-Agent' => 'zerosdev/tripay-sdk-php', + 'User-Agent' => 'github:zerosdev/tripay-sdk-php', ] ]; @@ -165,19 +165,40 @@ public function __construct(...$args) $this->client = $this->createHttpClient($options); } + /** + * Create HTTP client + * + * @param array $options + * @return HttpClient + */ private function createHttpClient(array $options): HttpClient { return new HttpClient($options); } - public function get($endpoint, array $headers = []): Response + /** + * Performe GET request + * + * @param string $endpoint + * @param array $headers + * @return Response + */ + public function get(string $endpoint, array $headers = []): Response { return $this->client->get($endpoint, [ 'headers' => $headers, ]); } - public function post($endpoint, array $payloads, array $headers = []): Response + /** + * Performe POST request + * + * @param string $endpoint + * @param array $payloads + * @param array $headers + * @return Response + */ + public function post(string $endpoint, array $payloads = [], array $headers = []): Response { return $this->client->post($endpoint, [ 'json' => $payloads, @@ -185,6 +206,11 @@ public function post($endpoint, array $payloads, array $headers = []): Response ]); } + /** + * Get debug data + * + * @return object + */ public function debugs(): object { return (object) $this->debugs; diff --git a/src/Support/Helper.php b/src/Support/Helper.php index d6d28e9..a0aed69 100644 --- a/src/Support/Helper.php +++ b/src/Support/Helper.php @@ -19,8 +19,7 @@ public static function makeSignature(Client $client, array $payloads): string { $merchantRef = isset($payloads['merchant_ref']) ? $payloads['merchant_ref'] : null; $amount = self::formatAmount($payloads['amount']); - - $payloads['amount'] = self::formatAmount($payloads['amount']); + return hash_hmac('sha256', $client->merchantCode . $merchantRef . $amount, $client->privateKey); } @@ -73,7 +72,7 @@ public static function checkRequiredPayloads(array $requireds, array $payloads): /** * Make unix timestamp - * Supported unit: SECOND, MINUTE, HOUR, DAY + * Supported time unit: SECOND, MINUTE, HOUR, DAY * i.e: "1 DAY", "13 HOUR", etc * * @param string $value @@ -98,7 +97,7 @@ public static function makeTimestamp(string $value): int $supportedUnits = ['SECOND', 'MINUTE', 'HOUR', 'DAY']; if (!in_array($unit, $supportedUnits)) { - throw new InvalidArgumentException('Unexpected unit. Supported: ' . implode(', ', $supportedUnits)); + throw new InvalidArgumentException('Unsupported time unit. Supported: ' . implode(', ', $supportedUnits)); } switch ($unit) {