1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Merge pull request #6901 from beganovich/sentry-12548

Fixes for refunds using Braintree
This commit is contained in:
David Bomba 2021-10-26 07:55:20 +11:00 committed by GitHub
commit dc36e88aa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,8 +12,6 @@
namespace App\PaymentDrivers;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
@ -27,7 +25,6 @@ use App\PaymentDrivers\Braintree\CreditCard;
use App\PaymentDrivers\Braintree\PayPal;
use Braintree\Gateway;
use Exception;
use Illuminate\Http\Request;
class BraintreePaymentDriver extends BaseDriver
{
@ -40,7 +37,7 @@ class BraintreePaymentDriver extends BaseDriver
/**
* @var Gateway;
*/
public $gateway;
public Gateway $gateway;
public static $methods = [
GatewayType::CREDIT_CARD => CreditCard::class,
@ -118,8 +115,7 @@ class BraintreePaymentDriver extends BaseDriver
]);
if ($result->success) {
$address = $this->gateway->address()->create([
$address = $this->gateway->address()->create([
'customerId' => $result->customer->id,
'firstName' => $this->client->present()->name,
'streetAddress' => $this->client->address1,
@ -135,12 +131,9 @@ class BraintreePaymentDriver extends BaseDriver
{
$this->init();
try{
try {
$response = $this->gateway->transaction()->refund($payment->transaction_reference, $amount);
} catch (Exception $e) {
$data = [
'transaction_reference' => null,
'transaction_response' => json_encode($e->getMessage()),
@ -154,24 +147,19 @@ class BraintreePaymentDriver extends BaseDriver
return $data;
}
if($response->success)
{
if ($response->success) {
$data = [
'transaction_reference' => $response->id,
'transaction_reference' => $payment->transaction_reference,
'transaction_response' => json_encode($response),
'success' => (bool)$response->success,
'description' => $response->status,
'success' => (bool) $response->success,
'description' => ctrans('texts.plan_refunded'),
'code' => 0,
];
SystemLogger::dispatch(['server_response' => $response, 'data' => $data], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_BRAINTREE, $this->client, $this->client->company);
return $data;
}
else{
} else {
$error = $response->errors->deepAll()[0];
$data = [
@ -185,7 +173,6 @@ class BraintreePaymentDriver extends BaseDriver
SystemLogger::dispatch(['server_response' => $response, 'data' => $data], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_BRAINTREE, $this->client, $this->client->company);
return $data;
}
}