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..0e91860 100644 --- a/modules/gateways/xendit/lib/XenditRequest.php +++ b/modules/gateways/xendit/lib/XenditRequest.php @@ -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 ) );