From ec7d4471dc513a810a6ec0c933122a1f821e93a8 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Thu, 19 Sep 2013 15:59:16 +0200 Subject: [PATCH] payment process --- core/lib/Thelia/Action/Order.php | 20 +++++++++++++------- core/lib/Thelia/Form/OrderDelivery.php | 7 +++++++ core/lib/Thelia/Form/OrderPayment.php | 9 ++++++++- core/lib/Thelia/Model/Order.php | 6 ++++-- local/modules/Cheque/Cheque.php | 2 +- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/core/lib/Thelia/Action/Order.php b/core/lib/Thelia/Action/Order.php index bb1e0b4ec..4a982673a 100755 --- a/core/lib/Thelia/Action/Order.php +++ b/core/lib/Thelia/Action/Order.php @@ -29,6 +29,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\OrderEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Base\AddressQuery; +use Thelia\Model\ModuleQuery; use Thelia\Model\OrderStatus; use Thelia\Model\Map\OrderTableMap; use Thelia\Model\OrderAddress; @@ -114,6 +115,8 @@ class Order extends BaseAction implements EventSubscriberInterface $deliveryAddress = AddressQuery::create()->findPk($sessionOrder->chosenDeliveryAddress); $invoiceAddress = AddressQuery::create()->findPk($sessionOrder->chosenInvoiceAddress); + $paymentModule = ModuleQuery::findPk($placedOrder->getPaymentModuleId()); + /* fulfill order */ $placedOrder->setCustomerId($customer->getId()); $placedOrder->setCurrencyId($currency->getId()); @@ -162,21 +165,22 @@ class Order extends BaseAction implements EventSubscriberInterface /* fulfill order_products and decrease stock // @todo dispatch event */ - /* discount */ - - /* postage */ - + /* discount @todo */ $con->commit(); - - /* dispatch mail event */ + /* T1style : dispatch mail event ? */ /* clear session ? */ /* call pay method */ + $paymentModuleReflection = new \ReflectionClass($paymentModule->getFullNamespace()); + $paymentModuleInstance = $paymentModuleReflection->newInstance(); - $out = true; + $paymentModuleInstance->setRequest($this->request); + $paymentModuleInstance->setDispatcher($this->dispatcher); + + $paymentModuleInstance->pay(); } /** @@ -184,6 +188,8 @@ class Order extends BaseAction implements EventSubscriberInterface */ public function setReference(OrderEvent $event) { + $x = true; + $this->setRef($this->generateRef()); } diff --git a/core/lib/Thelia/Form/OrderDelivery.php b/core/lib/Thelia/Form/OrderDelivery.php index 3ef1444f6..e23ae92b2 100755 --- a/core/lib/Thelia/Form/OrderDelivery.php +++ b/core/lib/Thelia/Form/OrderDelivery.php @@ -85,6 +85,13 @@ class OrderDelivery extends BaseForm if(null === $module) { $context->addViolation("Delivery module ID not found"); } + + $moduleReflection = new \ReflectionClass($module->getFullNamespace()); + if ($moduleReflection->isSubclassOf("Thelia\Module\DeliveryModuleInterface") === false) { + $context->addViolation( + sprintf("delivery module %s is not a Thelia\Module\DeliveryModuleInterface", $module->getCode()) + ); + } } public function getName() diff --git a/core/lib/Thelia/Form/OrderPayment.php b/core/lib/Thelia/Form/OrderPayment.php index d3ebe4daf..6a6305971 100755 --- a/core/lib/Thelia/Form/OrderPayment.php +++ b/core/lib/Thelia/Form/OrderPayment.php @@ -80,11 +80,18 @@ class OrderPayment extends BaseForm ->filterByType(BaseModule::PAYMENT_MODULE_TYPE) ->filterByActivate(1) ->filterById($value) - ->find(); + ->findOne(); if(null === $module) { $context->addViolation("Payment module ID not found"); } + + $moduleReflection = new \ReflectionClass($module->getFullNamespace()); + if ($moduleReflection->isSubclassOf("Thelia\Module\PaymentModuleInterface") === false) { + $context->addViolation( + sprintf("delivery module %s is not a Thelia\Module\PaymentModuleInterface", $module->getCode()) + ); + } } public function getName() diff --git a/core/lib/Thelia/Model/Order.php b/core/lib/Thelia/Model/Order.php index 0ba2a7185..c5d03b7e7 100755 --- a/core/lib/Thelia/Model/Order.php +++ b/core/lib/Thelia/Model/Order.php @@ -17,10 +17,12 @@ class Order extends BaseOrder /** * {@inheritDoc} */ - /*public function postInsert(ConnectionInterface $con = null) + public function preInsert(ConnectionInterface $con = null) { $this->dispatchEvent(TheliaEvents::ORDER_SET_REFERENCE, new OrderEvent($this)); - }*/ + + return true; + } /** * calculate the total amount diff --git a/local/modules/Cheque/Cheque.php b/local/modules/Cheque/Cheque.php index d6b462194..f4438db4e 100755 --- a/local/modules/Cheque/Cheque.php +++ b/local/modules/Cheque/Cheque.php @@ -56,7 +56,7 @@ class Cheque extends BaseModule implements PaymentModuleInterface public function pay() { - // TODO: Implement pay() method. + // no special process, waiting for the cheque. } public function install()