public function createToken()
{
if ($customer = $this->customer()) {
$customerReference = $customer->token;
} else {
$data = $this->paymentDetails();
$tokenResponse = $this->gateway()->createCustomer(['customerData' => $this->customerData()])->send();
if ($tokenResponse->isSuccessful()) {
$customerReference = $tokenResponse->getCustomerData()->id;
} else {
return false;
}
}
if ($customerReference) {
$data['customerId'] = $customerReference;
if ($this->isGatewayType(GATEWAY_TYPE_PAYPAL)) {
$data['paymentMethodNonce'] = $this->input['sourceToken'];
}
$tokenResponse = $this->gateway->createPaymentMethod($data)->send();
if ($tokenResponse->isSuccessful()) {
$this->tokenResponse = $tokenResponse->getData()->paymentMethod;
} else {
return false;
}
}
return parent::createToken();
}