From 2e0aa679bff23f3f792ec8cf65b2794c168c4506 Mon Sep 17 00:00:00 2001 From: Zeros Developer <33526722+zerosdev@users.noreply.github.com> Date: Fri, 3 Mar 2023 09:50:53 +0700 Subject: [PATCH 1/8] Update callback-handling.php --- examples/callback-handling.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(); From b36d2a7c2e20ee9311450a6f1206ae036c33ec75 Mon Sep 17 00:00:00 2001 From: Zeros Developer <33526722+zerosdev@users.noreply.github.com> Date: Mon, 6 Mar 2023 10:28:25 +0700 Subject: [PATCH 2/8] Fix return type incomingSignature() only return string --- src/Callback.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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'] : ""); } From 5ce068c49e740bb304aad3044877acf76c4795dc Mon Sep 17 00:00:00 2001 From: ZerosDev Date: Mon, 6 Mar 2023 10:41:54 +0700 Subject: [PATCH 3/8] Add comment, add type hint, make optional in post() --- src/Client.php | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 45e08f7..1b82703 100644 --- a/src/Client.php +++ b/src/Client.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; From a2b53956508058ff490dce74f74ade1bc0950515 Mon Sep 17 00:00:00 2001 From: Zeros Developer <33526722+zerosdev@users.noreply.github.com> Date: Sat, 25 Mar 2023 13:30:52 +0700 Subject: [PATCH 4/8] Remove unused code, fix unsupported time unit Remove unused code, fix unsupported time unit exception --- src/Support/Helper.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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) { From 4c47d6dad773a202935dc5a4ecff1f7c852dc594 Mon Sep 17 00:00:00 2001 From: Zeros Developer <33526722+zerosdev@users.noreply.github.com> Date: Sat, 25 Mar 2023 13:38:40 +0700 Subject: [PATCH 5/8] Update README.md --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 From 3107cfa9456ef20eef7c4c53f0939172ce627b5e Mon Sep 17 00:00:00 2001 From: AzniDev Date: Mon, 11 Nov 2024 17:27:02 +0700 Subject: [PATCH 6/8] fix development mode --- composer.json | 4 ++-- src/Client.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 3e2d260..fcbd491 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "zerosdev/tripay-sdk-php", + "name": "aznidev/tripay-sdk-php", "description": "Unofficial TriPay.co.id Integration Kit for PHP", "type": "library", "require": { @@ -21,4 +21,4 @@ "ZerosDev\\TriPay\\": "src/" } } -} +} \ No newline at end of file diff --git a/src/Client.php b/src/Client.php index 1b82703..93d419e 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 From 96898b3e7281c98e6328d9befe0e22ae97583388 Mon Sep 17 00:00:00 2001 From: Rony Wisnu Wardana <33526722+zerosdev@users.noreply.github.com> Date: Thu, 3 Apr 2025 21:00:38 +0700 Subject: [PATCH 7/8] Update user agent --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 1b82703..7808d92 100644 --- a/src/Client.php +++ b/src/Client.php @@ -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', ] ]; From 4322cf0eb4d26fd698b2528552094ea61ddd07f8 Mon Sep 17 00:00:00 2001 From: Rony Wisnu Wardana <33526722+zerosdev@users.noreply.github.com> Date: Thu, 3 Apr 2025 21:08:02 +0700 Subject: [PATCH 8/8] Update composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index fcbd491..3e2d260 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "aznidev/tripay-sdk-php", + "name": "zerosdev/tripay-sdk-php", "description": "Unofficial TriPay.co.id Integration Kit for PHP", "type": "library", "require": { @@ -21,4 +21,4 @@ "ZerosDev\\TriPay\\": "src/" } } -} \ No newline at end of file +}