From 6517bd3f32c13648531822265f6eb5bb104b497d Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 5 Jan 2023 08:42:42 +0700 Subject: [PATCH 1/2] Improve tracking metric logging --- modules/gateways/xendit.php | 20 ++++++++++--- modules/gateways/xendit/lib/XenditRequest.php | 30 +++++++++++++------ 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/modules/gateways/xendit.php b/modules/gateways/xendit.php index f7b0017..b949b46 100644 --- a/modules/gateways/xendit.php +++ b/modules/gateways/xendit.php @@ -77,8 +77,14 @@ function xendit_link($params) $xenditRequest = new XenditRequest(); try { return $paymentLink->generatePaymentLink($params); - } catch (\Exception $e) { - $metricPayload = $xenditRequest->constructMetricPayload('whmcs_checkout', 'error', $payment_method); + } catch (\Throwable $e) { + $metricPayload = $xenditRequest->constructMetricPayload( + 'whmcs_checkout', + array( + 'type' => 'error', + 'error_message' => $e->getMessage() + ) + ); $xenditRequest->trackMetricCount($metricPayload); return $paymentLink->errorMessage($e->getMessage()); @@ -429,8 +435,14 @@ function xendit_refund($params) try { $refundResponse = $xenditRequest->createRefund($chargeId, $body); - } catch (Exception $e) { - $metricPayload = $xenditRequest->constructMetricPayload('whmcs_refund', 'error', $payment_method); + } catch (\Throwable $e) { + $metricPayload = $xenditRequest->constructMetricPayload( + 'whmcs_refund', + array( + 'type' => 'error', + 'error_message' => $e->getMessage() + ) + ); $xenditRequest->trackMetricCount($metricPayload); return array( diff --git a/modules/gateways/xendit/lib/XenditRequest.php b/modules/gateways/xendit/lib/XenditRequest.php index 29129f9..36cb051 100644 --- a/modules/gateways/xendit/lib/XenditRequest.php +++ b/modules/gateways/xendit/lib/XenditRequest.php @@ -4,7 +4,7 @@ class XenditRequest { - protected $tpi_server_domain = "https://tpi.xendit.co"; + protected $tpi_server_domain = "https://tpi-service-live.us-west-2.stg.tidnex.dev"; /** * @return mixed @@ -265,14 +265,13 @@ public function getCardSettings() } /** - * @param array $param - * @return true|false|string - * @throws \Exception + * @param array $payload + * @return bool */ public function trackMetricCount(array $payload = []) { try { - $response = $this->request( + $this->request( '/log/metrics/count', [ 'headers' => $this->defaultHeader(), @@ -286,12 +285,25 @@ public function trackMetricCount(array $payload = []) } } - function constructMetricPayload($name, $type, $error_code = '') - { + /** + * @param string $name + * @param array $additional_tags + * @param string $error_code + * @return array + */ + public function constructMetricPayload( + string $name, + array $additional_tags, + string $error_code = '' + ): array { $metrics = array( 'name' => $name, - 'additional_tags' => array( - 'type' => $type + 'additional_tags' => array_merge( + array( + 'version' => XENDIT_PAYMENT_GATEWAY_VERSION, + 'is_live' => $this->isTestMode() + ), + $additional_tags ) ); From 3bc9e2d7186baaabea8103816d9df8ae906b0607 Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 5 Jan 2023 08:43:57 +0700 Subject: [PATCH 2/2] update --- modules/gateways/xendit/lib/XenditRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gateways/xendit/lib/XenditRequest.php b/modules/gateways/xendit/lib/XenditRequest.php index 36cb051..0e91860 100644 --- a/modules/gateways/xendit/lib/XenditRequest.php +++ b/modules/gateways/xendit/lib/XenditRequest.php @@ -4,7 +4,7 @@ class XenditRequest { - protected $tpi_server_domain = "https://tpi-service-live.us-west-2.stg.tidnex.dev"; + protected $tpi_server_domain = "https://tpi.xendit.co"; /** * @return mixed