Fix for adding new cards with Braintree

This commit is contained in:
Hillel Coren 2017-08-11 10:55:54 +03:00
parent 24997c9382
commit ed09cb3c78

View File

@ -5,6 +5,7 @@ namespace App\Ninja\PaymentDrivers;
use Braintree\Customer; use Braintree\Customer;
use Exception; use Exception;
use Session; use Session;
use Utils;
use App\Models\GatewayType; use App\Models\GatewayType;
class BraintreePaymentDriver extends BasePaymentDriver class BraintreePaymentDriver extends BasePaymentDriver
@ -98,14 +99,16 @@ class BraintreePaymentDriver extends BasePaymentDriver
public function createToken() public function createToken()
{ {
$data = $this->paymentDetails();
if ($customer = $this->customer()) { if ($customer = $this->customer()) {
$customerReference = $customer->token; $customerReference = $customer->token;
} else { } else {
$data = $this->paymentDetails();
$tokenResponse = $this->gateway()->createCustomer(['customerData' => $this->customerData()])->send(); $tokenResponse = $this->gateway()->createCustomer(['customerData' => $this->customerData()])->send();
if ($tokenResponse->isSuccessful()) { if ($tokenResponse->isSuccessful()) {
$customerReference = $tokenResponse->getCustomerData()->id; $customerReference = $tokenResponse->getCustomerData()->id;
} else { } else {
Utils::logError($tokenResponse->getMessage());
return false; return false;
} }
} }
@ -121,6 +124,7 @@ class BraintreePaymentDriver extends BasePaymentDriver
if ($tokenResponse->isSuccessful()) { if ($tokenResponse->isSuccessful()) {
$this->tokenResponse = $tokenResponse->getData()->paymentMethod; $this->tokenResponse = $tokenResponse->getData()->paymentMethod;
} else { } else {
Utils::logError($tokenResponse->getMessage());
return false; return false;
} }
} }