mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 02:07:33 -05:00 
			
		
		
		
	Merge pull request #6901 from beganovich/sentry-12548
Fixes for refunds using Braintree
This commit is contained in:
		
						commit
						dc36e88aa6
					
				@ -12,8 +12,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace App\PaymentDrivers;
 | 
					namespace App\PaymentDrivers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
 | 
					 | 
				
			||||||
use App\Jobs\Util\SystemLogger;
 | 
					use App\Jobs\Util\SystemLogger;
 | 
				
			||||||
use App\Models\ClientGatewayToken;
 | 
					use App\Models\ClientGatewayToken;
 | 
				
			||||||
use App\Models\GatewayType;
 | 
					use App\Models\GatewayType;
 | 
				
			||||||
@ -27,7 +25,6 @@ use App\PaymentDrivers\Braintree\CreditCard;
 | 
				
			|||||||
use App\PaymentDrivers\Braintree\PayPal;
 | 
					use App\PaymentDrivers\Braintree\PayPal;
 | 
				
			||||||
use Braintree\Gateway;
 | 
					use Braintree\Gateway;
 | 
				
			||||||
use Exception;
 | 
					use Exception;
 | 
				
			||||||
use Illuminate\Http\Request;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
class BraintreePaymentDriver extends BaseDriver
 | 
					class BraintreePaymentDriver extends BaseDriver
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -40,7 +37,7 @@ class BraintreePaymentDriver extends BaseDriver
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @var Gateway;
 | 
					     * @var Gateway;
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public $gateway;
 | 
					    public Gateway $gateway;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static $methods = [
 | 
					    public static $methods = [
 | 
				
			||||||
        GatewayType::CREDIT_CARD => CreditCard::class,
 | 
					        GatewayType::CREDIT_CARD => CreditCard::class,
 | 
				
			||||||
@ -118,8 +115,7 @@ class BraintreePaymentDriver extends BaseDriver
 | 
				
			|||||||
        ]);
 | 
					        ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($result->success) {
 | 
					        if ($result->success) {
 | 
				
			||||||
 | 
					            $address = $this->gateway->address()->create([
 | 
				
			||||||
             $address = $this->gateway->address()->create([
 | 
					 | 
				
			||||||
                'customerId' => $result->customer->id,
 | 
					                'customerId' => $result->customer->id,
 | 
				
			||||||
                'firstName' => $this->client->present()->name,
 | 
					                'firstName' => $this->client->present()->name,
 | 
				
			||||||
                'streetAddress' => $this->client->address1,
 | 
					                'streetAddress' => $this->client->address1,
 | 
				
			||||||
@ -135,12 +131,9 @@ class BraintreePaymentDriver extends BaseDriver
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->init();
 | 
					        $this->init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try{
 | 
					        try {
 | 
				
			||||||
 | 
					 | 
				
			||||||
            $response = $this->gateway->transaction()->refund($payment->transaction_reference, $amount);
 | 
					            $response = $this->gateway->transaction()->refund($payment->transaction_reference, $amount);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        } catch (Exception $e) {
 | 
					        } catch (Exception $e) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
            $data = [
 | 
					            $data = [
 | 
				
			||||||
                'transaction_reference' => null,
 | 
					                'transaction_reference' => null,
 | 
				
			||||||
                'transaction_response' => json_encode($e->getMessage()),
 | 
					                'transaction_response' => json_encode($e->getMessage()),
 | 
				
			||||||
@ -154,24 +147,19 @@ class BraintreePaymentDriver extends BaseDriver
 | 
				
			|||||||
            return $data;
 | 
					            return $data;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if($response->success)
 | 
					        if ($response->success) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            $data = [
 | 
					            $data = [
 | 
				
			||||||
                'transaction_reference' => $response->id,
 | 
					                'transaction_reference' => $payment->transaction_reference,
 | 
				
			||||||
                'transaction_response' => json_encode($response),
 | 
					                'transaction_response' => json_encode($response),
 | 
				
			||||||
                'success' => (bool)$response->success,
 | 
					                'success' => (bool) $response->success,
 | 
				
			||||||
                'description' => $response->status,
 | 
					                'description' => ctrans('texts.plan_refunded'),
 | 
				
			||||||
                'code' => 0,
 | 
					                '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);
 | 
					            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;
 | 
					            return $data;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            $error = $response->errors->deepAll()[0];
 | 
					            $error = $response->errors->deepAll()[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $data = [
 | 
					            $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);
 | 
					            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;
 | 
					            return $data;
 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user