App\Ninja\PaymentDrivers\BasePaymentDriver::createToken PHP Method

createToken() public method

public createToken ( )
    public function createToken()
    {
        $account = $this->account();
        if (!($customer = $this->customer())) {
            $customer = new AccountGatewayToken();
            $customer->account_id = $account->id;
            $customer->contact_id = $this->invitation->contact_id;
            $customer->account_gateway_id = $this->accountGateway->id;
            $customer->client_id = $this->client()->id;
            $customer = $this->creatingCustomer($customer);
            $customer->save();
        }
        // archive the old payment method
        $paymentMethod = PaymentMethod::clientId($this->client()->id)->isBankAccount($this->isGatewayType(GATEWAY_TYPE_BANK_TRANSFER))->first();
        if ($paymentMethod) {
            $paymentMethod->delete();
        }
        $paymentMethod = $this->createPaymentMethod($customer);
        if ($paymentMethod) {
            $customer->default_payment_method_id = $paymentMethod->id;
            $customer->save();
        }
        return $paymentMethod;
    }

Usage Example

 public function createToken()
 {
     $wepay = Utils::setupWePay($this->accountGateway);
     $token = intval($this->input['sourceToken']);
     if ($this->isGatewayType(GATEWAY_TYPE_BANK_TRANSFER)) {
         // Persist bank details
         $this->tokenResponse = $wepay->request('/payment_bank/persist', ['client_id' => WEPAY_CLIENT_ID, 'client_secret' => WEPAY_CLIENT_SECRET, 'payment_bank_id' => $token]);
     } else {
         // Authorize credit card
         $tokenResponse = $wepay->request('credit_card/authorize', ['client_id' => WEPAY_CLIENT_ID, 'client_secret' => WEPAY_CLIENT_SECRET, 'credit_card_id' => $token]);
         // Update the callback uri and get the card details
         $tokenResponse = $wepay->request('credit_card/modify', ['client_id' => WEPAY_CLIENT_ID, 'client_secret' => WEPAY_CLIENT_SECRET, 'credit_card_id' => $token, 'auto_update' => WEPAY_AUTO_UPDATE, 'callback_uri' => $this->accountGateway->getWebhookUrl()]);
         $this->tokenResponse = $wepay->request('credit_card', ['client_id' => WEPAY_CLIENT_ID, 'client_secret' => WEPAY_CLIENT_SECRET, 'credit_card_id' => $token]);
     }
     return parent::createToken();
 }
All Usage Examples Of App\Ninja\PaymentDrivers\BasePaymentDriver::createToken