From 146cd8bc66f070634a89c761b7ab5b1d06883aa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Sun, 5 Sep 2021 12:31:17 +0200 Subject: [PATCH] Process `merchantAccountId` with Braintree transactions --- app/PaymentDrivers/Braintree/CreditCard.php | 20 ++++++++++++++++++-- resources/lang/en/texts.php | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/PaymentDrivers/Braintree/CreditCard.php b/app/PaymentDrivers/Braintree/CreditCard.php index b50ff72d6b..a61c103be6 100644 --- a/app/PaymentDrivers/Braintree/CreditCard.php +++ b/app/PaymentDrivers/Braintree/CreditCard.php @@ -88,14 +88,30 @@ class CreditCard $token = $this->getPaymentToken($request->all(), $customer->id); - $result = $this->braintree->gateway->transaction()->sale([ + $data = [ 'amount' => $this->braintree->payment_hash->data->amount_with_fee, 'paymentMethodToken' => $token, 'deviceData' => $state['client-data'], 'options' => [ 'submitForSettlement' => true ], - ]); + ]; + + if ($this->braintree->company_gateway->getConfigField('merchantAccountId')) { + /** https://developer.paypal.com/braintree/docs/reference/request/transaction/sale/php#full-example */ + $data['merchantAccountId'] = $this->braintree->company_gateway->getConfigField('merchantAccountId'); + } + + try { + $result = $this->braintree->gateway->transaction()->sale($data); + } catch(\Exception $e) { + if ($e instanceof \Braintree\Exception\Authorization) { + throw new PaymentFailed(ctrans('texts.generic_gateway_error'), $e->getCode()); + } + + throw new PaymentFailed($e->getMessage(), $e->getCode()); + } + if ($result->success) { $this->braintree->logSuccessfulGatewayResponse(['response' => $request->server_response, 'data' => $this->braintree->payment_hash], SystemLog::TYPE_BRAINTREE); diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 7ed8c1b22e..ba8a3e755c 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -4302,6 +4302,7 @@ $LANG = array( 'checking' => 'Checking', 'savings' => 'Savings', 'unable_to_verify_payment_method' => 'Unable to verify payment method.', + 'generic_gateway_error' => 'Gateway configuration error. Please check your credentials.', ); return $LANG;