From 6f30c787d1d5d1480934cc970d823bf627786a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 10 Sep 2021 13:17:33 +0200 Subject: [PATCH] Return token if response is success --- app/PaymentDrivers/Braintree/CreditCard.php | 33 +++++++-------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/app/PaymentDrivers/Braintree/CreditCard.php b/app/PaymentDrivers/Braintree/CreditCard.php index 9803bd3c3047..2d289a961b31 100644 --- a/app/PaymentDrivers/Braintree/CreditCard.php +++ b/app/PaymentDrivers/Braintree/CreditCard.php @@ -136,30 +136,19 @@ class CreditCard $gateway_response = \json_decode($data['gateway_response']); - try { - $payment_method = $this->braintree->gateway->paymentMethod()->create([ - 'customerId' => $customerId, - 'paymentMethodNonce' => $gateway_response->nonce, - 'options' => [ - 'verifyCard' => true, - ], - ]); - - return $payment_method->paymentMethod->token; - } catch(\Exception $e) { - SystemLogger::dispatch( - $e->getMessage(), - SystemLog::CATEGORY_GATEWAY_RESPONSE, - SystemLog::EVENT_GATEWAY_FAILURE, - SystemLog::TYPE_BRAINTREE, - $this->braintree->client, - $this->braintree->client->company, - ); + $response = $this->braintree->gateway->paymentMethod()->create([ + 'customerId' => $customerId, + 'paymentMethodNonce' => $gateway_response->nonce, + 'options' => [ + 'verifyCard' => true, + ], + ]); - nlog(['e' => $e->getMessage(), 'class' => \get_class($e)]); - - throw new PaymentFailed($e->getMessage(), $e->getCode()); + if ($response->success) { + return $response->paymentMethod->token; } + + throw new PaymentFailed($response->message); } private function processSuccessfulPayment($response)