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

startPurchase() public method

public startPurchase ( $input = false, $sourceId = false )
    public function startPurchase($input = false, $sourceId = false)
    {
        $this->input = $input;
        $this->sourceId = $sourceId;
        Session::put('invitation_key', $this->invitation->invitation_key);
        Session::put($this->invitation->id . 'gateway_type', $this->gatewayType);
        Session::put($this->invitation->id . 'payment_ref', $this->invoice()->id . '_' . uniqid());
        $gateway = $this->accountGateway->gateway;
        if (!$this->meetsGatewayTypeLimits($this->gatewayType)) {
            // The customer must have hacked the URL
            Session::flash('error', trans('texts.limits_not_met'));
            return redirect()->to('view/' . $this->invitation->invitation_key);
        }
        if ($this->isGatewayType(GATEWAY_TYPE_TOKEN) || $gateway->is_offsite) {
            if (Session::has('error')) {
                Session::reflash();
            } else {
                $this->completeOnsitePurchase();
                Session::flash('message', trans('texts.applied_payment'));
            }
            return redirect()->to('view/' . $this->invitation->invitation_key);
        }
        $data = ['details' => !empty($input['details']) ? json_decode($input['details']) : false, 'accountGateway' => $this->accountGateway, 'acceptedCreditCardTypes' => $this->accountGateway->getCreditcardTypes(), 'gateway' => $gateway, 'showAddress' => $this->accountGateway->show_address, 'showBreadcrumbs' => false, 'url' => 'payment/' . $this->invitation->invitation_key, 'amount' => $this->invoice()->getRequestedAmount(), 'invoiceNumber' => $this->invoice()->invoice_number, 'client' => $this->client(), 'contact' => $this->invitation->contact, 'gatewayType' => $this->gatewayType, 'currencyId' => $this->client()->getCurrencyId(), 'currencyCode' => $this->client()->getCurrencyCode(), 'account' => $this->account(), 'sourceId' => $sourceId, 'clientFontUrl' => $this->account()->getFontsUrl(), 'tokenize' => $this->tokenize(), 'transactionToken' => $this->createTransactionToken()];
        return view($this->paymentView(), $data);
    }

Usage Example

 public function startPurchase($input = false, $sourceId = false)
 {
     $data = parent::startPurchase($input, $sourceId);
     if ($this->isGatewayType(GATEWAY_TYPE_PAYPAL)) {
         /*
         if ( ! $sourceId || empty($input['device_data'])) {
             throw new Exception();
         }
         
         Session::put($this->invitation->id . 'device_data', $input['device_data']);
         */
         $data['details'] = !empty($input['device_data']) ? json_decode($input['device_data']) : false;
     }
     return $data;
 }