From 896e5f88acc60fed9ad87c98fe87eda32b826fca Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 22 Nov 2022 16:23:08 +1100 Subject: [PATCH] Fixes for blank client address in Swiss QR Codes --- app/Helpers/SwissQr/SwissQrGenerator.php | 8 +-- .../CheckoutComPaymentDriver.php | 49 +++++++++++++++++-- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/app/Helpers/SwissQr/SwissQrGenerator.php b/app/Helpers/SwissQr/SwissQrGenerator.php index 706689d99771..488c0d1a623c 100644 --- a/app/Helpers/SwissQr/SwissQrGenerator.php +++ b/app/Helpers/SwissQr/SwissQrGenerator.php @@ -87,10 +87,10 @@ class SwissQrGenerator $qrBill->setUltimateDebtor( QrBill\DataGroup\Element\StructuredAddress::createWithStreet( substr($this->client->present()->name(), 0 , 70), - $this->client->address1 ? substr($this->client->address1, 0 , 70) : '', - $this->client->address2 ? substr($this->client->address2, 0 , 16) : '', - $this->client->postal_code ? substr($this->client->postal_code, 0, 16) : '', - $this->client->city ? substr($this->client->city, 0, 35) : '', + $this->client->address1 ? substr($this->client->address1, 0 , 70) : '_', + $this->client->address2 ? substr($this->client->address2, 0 , 16) : '_', + $this->client->postal_code ? substr($this->client->postal_code, 0, 16) : '_', + $this->client->city ? substr($this->client->city, 0, 35) : '_', 'CH' )); diff --git a/app/PaymentDrivers/CheckoutComPaymentDriver.php b/app/PaymentDrivers/CheckoutComPaymentDriver.php index 6801d8f0ff41..daa9aa7fcd68 100644 --- a/app/PaymentDrivers/CheckoutComPaymentDriver.php +++ b/app/PaymentDrivers/CheckoutComPaymentDriver.php @@ -306,10 +306,53 @@ class CheckoutComPaymentDriver extends BaseDriver try { $response = $this->gateway->getCustomersClient()->create($request); - } catch (\Exception $e) { - // API error - throw new PaymentFailed($e->getMessage(), $e->getCode()); } + catch (CheckoutApiException $e) { + // API error + $request_id = $e->request_id; + $http_status_code = $e->http_status_code; + $error_details = $e->error_details; + + if(is_array($error_details)) { + $error_details = end($e->error_details['error_codes']); + } + + $human_exception = $error_details ? new \Exception($error_details, 400) : $e; + + + throw new PaymentFailed($human_exception); + } catch (CheckoutArgumentException $e) { + // Bad arguments + + $error_details = $e->error_details; + + if(is_array($error_details)) { + $error_details = end($e->error_details['error_codes']); + } + + $human_exception = $error_details ? new \Exception($error_details, 400) : $e; + + throw new PaymentFailed($human_exception); + } catch (CheckoutAuthorizationException $e) { + // Bad Invalid authorization + + $error_details = $e->error_details; + + if(is_array($error_details)) { + $error_details = end($e->error_details['error_codes']); + } + + $human_exception = $error_details ? new \Exception($error_details, 400) : $e; + + throw new PaymentFailed($human_exception); + } + + + + // catch (\Exception $e) { + // // API error + // throw new PaymentFailed($e->getMessage(), $e->getCode()); + // } return $response; }