From 394d3b327dbb0f57bac992c9a9c8688e5ae5d1a7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 20 Apr 2022 08:51:27 +1000 Subject: [PATCH] Improve error handling within PayTrace --- app/PaymentDrivers/PayTrace/CreditCard.php | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/PaymentDrivers/PayTrace/CreditCard.php b/app/PaymentDrivers/PayTrace/CreditCard.php index 3e00f657e881..a1d00b31a166 100644 --- a/app/PaymentDrivers/PayTrace/CreditCard.php +++ b/app/PaymentDrivers/PayTrace/CreditCard.php @@ -99,6 +99,29 @@ class CreditCard $response = $this->paytrace->gatewayRequest('/v1/customer/pt_protect_create', $post_data); + if(!$response->success) + { + + $error = 'Error creating customer in gateway'; + $error_code = isset($response->response_code) ? $response->response_code : 'PT_ERR'; + + if(isset($response->errors)) + { + foreach($response->errors as $err) + { + $error = end($err); + } + } + + $data = [ + 'response' => $response, + 'error' => $error, + 'error_code' => $error_code, + ]; + + return $this->paytrace->processUnsuccessfulTransaction($data); + } + $cgt = []; $cgt['token'] = $response->customer_id; $cgt['payment_method_id'] = GatewayType::CREDIT_CARD; @@ -124,7 +147,6 @@ class CreditCard $profile = $this->paytrace->gatewayRequest('/v1/customer/export', [ 'integrator_id' => $this->paytrace->company_gateway->getConfigField('integratorId'), 'customer_id' => $customer_id, - // 'include_bin' => true, ]); return $profile->customers[0];