HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/topswtw.komma.pro/app/controllers/PaymentController.php
<?php

use KommaApp\Shop\Checkout\CheckoutSession\CheckoutSession;
use KommaApp\Shop\Checkout\Payment\PaymentService;

use KommaApp\Shop\Countries\CountryService;

use KommaApp\Shop\Customers\CustomerService;

use KommaApp\Shop\Modules\Modules;

use KommaApp\Shop\Orders\OrderService;

use KommaApp\Shop\Pages\PageService;
use KommaApp\Shop\Orders\Order;


class PaymentController extends BaseController
{
    /**
     * @var OrderService
     */
    protected $orderService;

    /**
     * @var CheckoutSession
     */
    protected $checkoutSession;

    /**
     * @var PaymentService
     */
    private $paymentService;

    /**
     * @var PageService
     */
    private $pageService;

    /**
     * @var CustomerService
     */
    private $customerService;
    /**
     * @var CountryService
     */
    private $countryService;

    /**
     * @param CheckoutSession $checkoutSession
     * @param OrderService    $orderService
     * @param PaymentService  $paymentService
     * @param PageService     $pageService
     * @param CustomerService $customerService
     * @param CountryService  $countryService
     */
    function __construct(
        CheckoutSession $checkoutSession,
        OrderService $orderService,
        PaymentService $paymentService,
        PageService $pageService,
        CustomerService $customerService,
        CountryService $countryService
    )
    {
        $this->checkoutSession = $checkoutSession;
        $this->orderService = $orderService;
        $this->paymentService = $paymentService;
        $this->pageService = $pageService;
        $this->customerService = $customerService;
        $this->countryService = $countryService;
    }

    /*
     * Show Payment form
     * @return View
     */
    public function showPaymentProviderForm()
    {
        if (!$this->checkoutSession->cart()->products()) {
            return \Redirect::to(\Shop::getPageService()->page('cart')->route)->with(['errors' => [\Lang::get('checkout/cart.session_expired')]]);
        }

        if ($data = $this->checkoutSession->payment()->get()) {
            // This form crates a new OrderTransaction
            return $this->paymentService->form($data);
        }
        \App::Abort(404);
    }

    /*
     * Process the response from the payment provider
     * @return Redirect
     */
    public function processPaymentProviderResponse()
    {
        // Empty the cart
        $this->checkoutSession->cart()->clear();

        $result = $this->paymentService->processPaymentProviderResponse();
        if (!isset($result['order'])) {
            return $result['paymentData'];
        }


        // Switch payment status and redirect
        return $this->paymentService->redirectUsingStatus($result['paymentData'], $result['order']);
    }

    //changeOrderStatus


    /**
     * This url will be called by ingenoco to change the order status
     */
    public function proccesPaymentProviderPaymentResponse()
    {
        try {
            Log::info('Binnen gekomen op de proccesPaymentPagina');

            $lang_service = \Shop::getLanguageService();

            $result = $this->paymentService->processPaymentProviderResponse();
            if (!isset($result['order'])) {
                Log::error('Order niet geldig');
                return 0;
            }

            $lang_id = $result['order']['language_id'];
            $shop_id = $result['order']['shop_id'];

            \Shop::setShop($shop_id);
            $lang_service->bootFromLangId($lang_id);


            //        Log::info('shop'. \Shop::getShop()->id);
            //        Log::info('lang'. $lang_service->getCurrentLanguage());

            // Switch payment status and redirect
            if ($respons = $this->paymentService->changeOrderStatus($result['paymentData'], $result['order'])) {
                //Send an http 200 header to ogonem, so they know it is recieved
                Log::info('Order status van ingenico / ogone verwerkt! Word nu doorgegeven aan ingenico.');
                return \Response::make($respons, 200);
            }
            return \Response::make('Try again', 503);
        } catch (\Exception $exception) {
            Log::info('Order status van ingenico / ogone kon niet worden verwerkt: '.$exception->getMessage());
            Log::error($exception);
            return \Response::make('Try again', 500);
        }
    }


    /*®®
     * Show payment error form
     * @return View
     */
    public function showFailed()
    {
        // Empty the cart
        $this->checkoutSession->cart()->clear();

        $token = \Input::get('token');

        $entity = $this->pageService->getNodeById($this->routeData->routable->page_id);
        return \View::make( viewPrefix() . 'checkout.payment.failed')->with([
            'token' => $token,
            'entity' => $entity
        ]);
    }

    public function showToCancel()
    {
        // Empty the cart
        $this->checkoutSession->cart()->clear();

        $token = \Input::get('token');

        $entity = $this->pageService->getNodeById($this->routeData->routable->page_id);
        return \View::make( viewPrefix() . 'checkout.payment.to-cancel')->with([
            'token' => $token,
            'entity' => $entity
        ]);
    }

    public function CancelOrder()
    {
        // Empty the cart
        $token = \Input::get('token');

        $this->paymentService->cancelOrderWithToken($token);

        $entity = $this->pageService->getNodeById($this->routeData->routable->page_id);
        return \View::make( viewPrefix() . 'checkout.payment.canceled')->with([
            'token' => $token,
            'entity' => $entity
        ]);
    }

    /*
     * Show payment error form
     * @return View
     */
    public function showWaiting()
    {
        // Empty the cart
        $this->checkoutSession->cart()->clear();

        $token = \Input::get('token');

        // Get pending order
        $order = $this->orderService->getOrderByToken($token);

        $entity = $this->pageService->getNodeById($this->routeData->routable->page_id);
        return \View::make( viewPrefix() . 'checkout.payment.waiting')->with([
            'token' => $token,
            'entity' => $entity,
            'customerService' => $this->customerService,
            'order' => $order
        ]);
    }

    /*
     * Show payment error form
     * @return View
     */
    public function showPending()
    {
        // Empty the cart
        $this->checkoutSession->cart()->clear();

        $token = \Input::get('token');

        // Get pending order
        $order = $this->orderService->getOrderByToken($token);

        // Page entity containing titles, description etc.
        $entity = $this->pageService->getNodeById($this->routeData->routable->page_id);

        if (isset($order->status) && $order->status == Order::CANCELLED) {
            return \View::make( viewPrefix() . 'checkout.payment.pendingCanceled')->with([
                'bodyClasses' => 'pendingPayment',
                'token' => $token,
                'order' => $order,
                'entity' => $entity,
            ]);
        }

        if (isset($order->status) && $order->status != Order::OPEN) {
            return \View::make( viewPrefix() . 'checkout.payment.pendingCompleted')->with([
                'bodyClasses' => 'pendingPayment',
                'token' => $token,
                'order' => $order,
                'entity' => $entity,
            ]);
        }

        return \View::make( viewPrefix() . 'checkout.payment.completePending')->with([
            'bodyClasses' => 'pendingPayment',
            'token' => $token,
            'order' => $order,
            'entity' => $entity,
            'paymentMethods' => $this->paymentService->getPaymentMethods()
        ]);
    }

    public function processPending()
    {
        return $this->paymentService->processPending();
    }

    /*
     * Ingenico Template
     */
    public function showPaymentProviderTemplate()
    {
        $root = \Request::root();
        //$root = str_replace('https:','',$root);
        //$root = str_replace('http:','',$root);

        return View::make('checkout.payment.ingenico.paymentProviderTemplate')->withBase($root);
    }
}