diff --git a/opencart2.0.x-2.2.x/upload/catalog/controller/payment/xendit.php b/opencart2.0.x-2.2.x/upload/catalog/controller/payment/xendit.php index b19352a..684c3cc 100644 --- a/opencart2.0.x-2.2.x/upload/catalog/controller/payment/xendit.php +++ b/opencart2.0.x-2.2.x/upload/catalog/controller/payment/xendit.php @@ -59,9 +59,10 @@ public function process_payment() try { $response = Xendit::request($request_url, Xendit::METHOD_POST, $request_payload, $request_options); - if(array_key_exists("error_code", $response)) { - $json = $response; - } else { + if (isset($response['error_code'])) { + $json['error'] = $response['message']; + } + else { $this->model_payment_xendit->addOrder($order, $response, $this->config->get('xendit_environment')); $message = 'Invoice ID: ' . $response['id'] . '. Redirecting..'; $this->model_checkout_order->addOrderHistory( diff --git a/opencart2.0.x-2.2.x/upload/catalog/controller/payment/xenditcc.php b/opencart2.0.x-2.2.x/upload/catalog/controller/payment/xenditcc.php index a3e3873..3eca03a 100644 --- a/opencart2.0.x-2.2.x/upload/catalog/controller/payment/xenditcc.php +++ b/opencart2.0.x-2.2.x/upload/catalog/controller/payment/xenditcc.php @@ -54,18 +54,19 @@ public function process_payment() { $response = Xendit::request($request_url, Xendit::METHOD_POST, $request_payload, $request_options); if (isset($response['error_code'])) { - throw new Exception('Failed to authenticate, please try again'); + $json['error'] = 'Failed to authenticate, please try again.'; + } + else { + $message = 'Authentication ID: ' . $response['id'] . '. Authenticating..'; + $this->model_checkout_order->addOrderHistory( + $order_id, + 1, + $message, + false + ); + + $json['redirect'] = $response['redirect']['url']; } - - $message = 'Authentication ID: ' . $response['id'] . '. Authenticating..'; - $this->model_checkout_order->addOrderHistory( - $order_id, - 1, - $message, - false - ); - - $json['redirect'] = $response['redirect']['url']; $this->response->addHeader('Content-Type: application/json'); $this->response->setOutput(json_encode($json)); diff --git a/opencart2.0.x-2.2.x/upload/catalog/view/theme/default/template/payment/xendit.tpl b/opencart2.0.x-2.2.x/upload/catalog/view/theme/default/template/payment/xendit.tpl index f5a0bb4..1eed0da 100644 --- a/opencart2.0.x-2.2.x/upload/catalog/view/theme/default/template/payment/xendit.tpl +++ b/opencart2.0.x-2.2.x/upload/catalog/view/theme/default/template/payment/xendit.tpl @@ -39,12 +39,11 @@ $('#button-confirm').button('reset'); }, success: function(json) { - if(json['error_code']) { - alert(json['message']); - } else { - if (json['redirect']) { - location = json['redirect'] + '#' + $('#invoice-hash').val(); - } + if (json['error']) { + alert(json['error']); + } + if (json['redirect']) { + location = json['redirect'] + '#' + $('#invoice-hash').val(); } }, error: function(xhr, ajaxOptions, thrownError) { diff --git a/opencart2.0.x-2.2.x/upload/catalog/view/theme/default/template/payment/xenditcc.tpl b/opencart2.0.x-2.2.x/upload/catalog/view/theme/default/template/payment/xenditcc.tpl index 76755d7..35b9f2f 100644 --- a/opencart2.0.x-2.2.x/upload/catalog/view/theme/default/template/payment/xenditcc.tpl +++ b/opencart2.0.x-2.2.x/upload/catalog/view/theme/default/template/payment/xenditcc.tpl @@ -86,7 +86,7 @@ - +