public function invoice()
    {
        $this->checkAuth();
        $this->checkCartNotEmpty();
        $this->checkValidDelivery();

        $message = false;

        $orderPayment = $this->createForm(FrontForm::ORDER_PAYMENT);

        try {
            $form = $this->validateForm($orderPayment, "post");

            $invoiceAddressId = $form->get("invoice-address")->getData();
            $paymentModuleId = $form->get("payment-module")->getData();

            /* check that the invoice address belongs to the current customer */
            $invoiceAddress = AddressQuery::create()->findPk($invoiceAddressId);
            if ($invoiceAddress->getCustomerId() !== $this->getSecurityContext()->getCustomerUser()->getId()) {
                throw new \Exception(
                    $this->getTranslator()->trans(
                        "Invoice address does not belong to the current customer",
                        [],
                        Front::MESSAGE_DOMAIN
                    )
                );
            }

            $orderEvent = $this->getOrderEvent();
            $orderEvent->setInvoiceAddress($invoiceAddressId);
            $orderEvent->setPaymentModule($paymentModuleId);

            $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_INVOICE_ADDRESS, $orderEvent);
            $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_PAYMENT_MODULE, $orderEvent);

            return $this->generateRedirectFromRoute("order.payment.process");

        } catch (FormValidationException $e) {
            $message = $this->getTranslator()->trans(
                "Please check your input: %s",
                ['%s' => $e->getMessage()],
                Front::MESSAGE_DOMAIN
            );
        } catch (PropelException $e) {
            $this->getParserContext()->setGeneralError($e->getMessage());
        } catch (\Exception $e) {
            $message = $this->getTranslator()->trans(
                "Sorry, an error occured: %s",
                ['%s' => $e->getMessage()],
                Front::MESSAGE_DOMAIN
            );
        }

        if ($message !== false) {
            Tlog::getInstance()->error(
                sprintf("Error during order payment process : %s. Exception was %s", $message, $e->getMessage())
            );

            $orderPayment->setErrorMessage($message);

            $this->getParserContext()
                ->addForm($orderPayment)
                ->setGeneralError($message)
            ;
        }

        return $this->generateErrorRedirect($orderPayment);
    }
public function invoice()
    {
        $this->checkAuth();
        $this->checkCartNotEmpty();
        $this->checkValidDelivery();

        $message = false;

        $orderPayment = $this->createForm(FrontForm::ORDER_PAYMENT);

        try {
            $form = $this->validateForm($orderPayment, "post");

            $invoiceAddressId = $form->get("invoice-address")->getData();
            $paymentModuleId = $form->get("payment-module")->getData();

            /* check that the invoice address belongs to the current customer */
            $invoiceAddress = AddressQuery::create()->findPk($invoiceAddressId);
            if ($invoiceAddress->getCustomerId() !== $this->getSecurityContext()->getCustomerUser()->getId()) {
                throw new \Exception(
                    $this->getTranslator()->trans(
                        "Invoice address does not belong to the current customer",
                        [],
                        Front::MESSAGE_DOMAIN
                    )
                );
            }

            $orderEvent = $this->getOrderEvent();
            $orderEvent->setInvoiceAddress($invoiceAddressId);
            $orderEvent->setPaymentModule($paymentModuleId);

            $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_INVOICE_ADDRESS, $orderEvent);
            $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_PAYMENT_MODULE, $orderEvent);

            return $this->generateRedirectFromRoute("order.payment.process");

        } catch (FormValidationException $e) {
            $message = $this->getTranslator()->trans(
                "Please check your input: %s",
                ['%s' => $e->getMessage()],
                Front::MESSAGE_DOMAIN
            );
        } catch (PropelException $e) {
            $this->getParserContext()->setGeneralError($e->getMessage());
        } catch (\Exception $e) {
            $message = $this->getTranslator()->trans(
                "Sorry, an error occured: %s",
                ['%s' => $e->getMessage()],
                Front::MESSAGE_DOMAIN
            );
        }

        if ($message !== false) {
            Tlog::getInstance()->error(
                sprintf("Error during order payment process : %s. Exception was %s", $message, $e->getMessage())
            );

            $orderPayment->setErrorMessage($message);

            $this->getParserContext()
                ->addForm($orderPayment)
                ->setGeneralError($message)
            ;
        }

        return $this->generateErrorRedirect($orderPayment);
    }
public function invoice ( ) { $ this -> checkAuth ( ) ; $ this -> checkCartNotEmpty ( ) ; $ this -> checkValidDelivery ( ) ; $ message = false ; $ orderPayment = $ this -> createForm ( FrontForm :: ORDER_PAYMENT ) ; try { $ form = $ this -> validateForm ( $ orderPayment , "post" ) ; $ invoiceAddressId = $ form -> get ( "invoice-address" ) -> getData ( ) ; $ paymentModuleId = $ form -> get ( "payment-module" ) -> getData ( ) ; /* check that the invoice address belongs to the current customer */ $ invoiceAddress = AddressQuery :: create ( ) -> findPk ( $ invoiceAddressId ) ; if ( $ invoiceAddress -> getCustomerId ( ) !== $ this -> getSecurityContext ( ) -> getCustomerUser ( ) -> getId ( ) ) { throw new \ Exception ( $ this -> getTranslator ( ) -> trans ( "Invoice address does not belong to the current customer" , [ ] , Front :: MESSAGE_DOMAIN ) ) ; } $ orderEvent = $ this -> getOrderEvent ( ) ; $ orderEvent -> setInvoiceAddress ( $ invoiceAddressId ) ; $ orderEvent -> setPaymentModule ( $ paymentModuleId ) ; $ this -> getDispatcher ( ) -> dispatch ( TheliaEvents :: ORDER_SET_INVOICE_ADDRESS , $ orderEvent ) ; $ this -> getDispatcher ( ) -> dispatch ( TheliaEvents :: ORDER_SET_PAYMENT_MODULE , $ orderEvent ) ; return $ this -> generateRedirectFromRoute ( "order.payment.process" ) ; } catch ( FormValidationException $ e ) { $ message = $ this -> getTranslator ( ) -> trans ( "Please check your input: %s" , [ '%s' => $ e -> getMessage ( ) ] , Front :: MESSAGE_DOMAIN ) ; } catch ( PropelException $ e ) { $ this -> getParserContext ( ) -> setGeneralError ( $ e -> getMessage ( ) ) ; } catch ( \ Exception $ e ) { $ message = $ this -> getTranslator ( ) -> trans ( "Sorry, an error occured: %s" , [ '%s' => $ e -> getMessage ( ) ] , Front :: MESSAGE_DOMAIN ) ; } if ( $ message !== false ) { Tlog :: getInstance ( ) -> error ( sprintf ( "Error during order payment process : %s. Exception was %s" , $ message , $ e -> getMessage ( ) ) ) ; $ orderPayment -> setErrorMessage ( $ message ) ; $ this -> getParserContext ( ) -> addForm ( $ orderPayment ) -> setGeneralError ( $ message ) ; } return $ this -> generateErrorRedirect ( $ orderPayment ) ; }
set invoice address
set payment module
set invoice address set payment module