iamgaurav Posted September 27, 2014 Share Posted September 27, 2014 Hello I am developing my own module for delivery of virtual products. I have completed the product configuration part now i am working on the product delivery. I need to know which hook i should use to know when the order is completed ( Payment received ) after reading the hooks page i am in a doubt its either actionPaymentConfirmation or hookActionOrderStatusPostUpdate . Would be great if anyone could confirm me which is the right one to use. PS : I'm on 1.6.x Regards Link to comment Share on other sites More sharing options...
iamgaurav Posted September 28, 2014 Author Share Posted September 28, 2014 Any help :S Link to comment Share on other sites More sharing options...
vekia Posted September 28, 2014 Share Posted September 28, 2014 and what when someone order something, and then this order will be cancelled? i think that you're looking for something to check order status, in this case i will deal with actionOrderStatusUpdate and i will check order status there and if order status = Payment Accepted then do something Link to comment Share on other sites More sharing options...
bellini13 Posted September 28, 2014 Share Posted September 28, 2014 if you are looking to do something every time there is a new order, then use "actionValidateOrder" hook. This does not mean payment was accepted, or even received, that all depends on what payment methods you use. for example, bankwire or check will have a new order, but payment is not receive until you physically get a check, deposit it and it clears, or you confirm receipt of the wire transfer. now you can use "actionPaymentConfirmation" hook which is triggered anytime the order status changes to "payment accepted" since you have not provided enough information to assess what you are trying to accomplish, it is difficult to give you an exact answer. If you can explain your process flow and what you are trying to accomplish, I'm sure we can give you the exact answer 2 Link to comment Share on other sites More sharing options...
iamgaurav Posted September 28, 2014 Author Share Posted September 28, 2014 Well basically i will be providing one time products ( virtual key's ) and i am going to use only PayPal and Skrill also using FraudLabs pro Fraud Detection along with this. So basically what i want is once an Order receives it's payment my module will be emailing the client with the one time use license key. I tried the following code public function install() { if (!parent::install() || !$this->registerHook('displayAdminProductsExtra') || !$this->registerHook('actionProductUpdate') || !$this->registerHook('actionPaymentConfirmation') || !$this->registerHook('hookActionPaymentConfirmation')) return false; return true; } public function hookActionPaymentConfirmation($params) { mail("[email protected]", "test", print_r($params,true)); } public function actionPaymentConfirmation($params) { mail("[email protected]", "test", print_r($params,true)); } I placed two orders first one was of 0 $ and the order was marked paid instantly and the second one i kept a order of 0.1$ and made a payment still i never could get an Email if the action worked or not. Link to comment Share on other sites More sharing options...
Eolia Posted September 28, 2014 Share Posted September 28, 2014 Solution: ( I use it) public function hookActionValidateOrder($params) { if(!empty($params['orderStatus'])) { if ($params['orderStatus']->id == Configuration::get('PS_OS_WS_PAYMENT') || $params['orderStatus']->id == Configuration::get('PS_OS_PAYMENT')) //my function } } public function hookActionOrderStatusUpdate($params) { if(!empty($params['newOrderStatus'])) { if ($params['newOrderStatus']->id == Configuration::get('PS_OS_WS_PAYMENT') || $params['newOrderStatus']->id == Configuration::get('PS_OS_PAYMENT')) //my function } } Link to comment Share on other sites More sharing options...
iamgaurav Posted September 28, 2014 Author Share Posted September 28, 2014 Hello But i don't understand why i'm not receiving the emails using these two functions public function hookActionPaymentConfirmation($params) { mail("[email protected]", "test", print_r($params,true)); } public function actionPaymentConfirmation($params) { mail("[email protected]", "test", print_r($params,true)); } How do i manually check it ? Putting a manual order doesn't help. Regards Link to comment Share on other sites More sharing options...
Eolia Posted September 28, 2014 Share Posted September 28, 2014 because in Prestashop you must use the send() function... Mail::Send((int)Context::getContext()->language->id,'name_of_the_template_mail', $title, $datas, $your_mail, null, null, null, null, null, dirname(__FILE__).'/mails/'); Link to comment Share on other sites More sharing options...
bellini13 Posted September 28, 2014 Share Posted September 28, 2014 you don't have to use the Mail class, using the standard php mail function should work, that is all the Mail class would be doing. But this assumes that your php is configured properly to send mail Your function should be named hookActionPaymentConfirmation. As I stated before, this only gets triggered when you mark the order status as Payment Accepted. It has nothing to do with the amount of money you receive. You have not stated anywhere in your posts that you have changed the order status to payment accepted. Link to comment Share on other sites More sharing options...
Eolia Posted September 28, 2014 Share Posted September 28, 2014 bellini13 +1 iamgaurav, use my solution and test, it's ok for all validated orders in front or by admin Link to comment Share on other sites More sharing options...
iamgaurav Posted September 28, 2014 Author Share Posted September 28, 2014 Hello Eolia, I am currently using your code the only thing is i really can't understand the difference between your hook usage and hookActionPaymentConfirmation hook. Also bellini13 you were right there was something wrong with my sendmail when i used Prestashop's email class it did work fine since i have setup'd SMTP for it and wasn't using php mail for it. Regards Link to comment Share on other sites More sharing options...
PrestashopEnthu Posted April 24, 2018 Share Posted April 24, 2018 On 29/09/2014 at 1:08 AM, Eolia said: Solution: ( I use it) public function hookActionValidateOrder($params) { if(!empty($params['orderStatus'])) { if ($params['orderStatus']->id == Configuration::get('PS_OS_WS_PAYMENT') || $params['orderStatus']->id == Configuration::get('PS_OS_PAYMENT')) //my function } } public function hookActionOrderStatusUpdate($params) { if(!empty($params['newOrderStatus'])) { if ($params['newOrderStatus']->id == Configuration::get('PS_OS_WS_PAYMENT') || $params['newOrderStatus']->id == Configuration::get('PS_OS_PAYMENT')) //my function } } Hi Eolia, This may seem far-fetched as it has been a long time but I chanced upon your post. You are using hookActionValidateOrder and successfully execute actions upon new orders. I am facing a problem whereby it is only working for a particular payment gateway called STRIPE. I am missing the code execution for back-office creation and also PayPal. By any chance, you faced this before? Thank you. Link to comment Share on other sites More sharing options...
Eolia Posted April 24, 2018 Share Posted April 24, 2018 The Stripe Module exists and it's free Why rewrite code ? Link to comment Share on other sites More sharing options...
PrestashopEnthu Posted April 24, 2018 Share Posted April 24, 2018 2 hours ago, Eolia said: The Stripe Module exists and it's free Why rewrite code ? Hi Eolia, Yes, it is free. Upon new order, I would like to send out via API, thus I am creating a module to do just that. But I have 3 ways of creating a new order, STRIPE, PayPal and back-office order creation for free orders. Thank you. Link to comment Share on other sites More sharing options...
bellini13 Posted April 25, 2018 Share Posted April 25, 2018 your module must implement the actionValidateOrder hook. this hook would be executed for any new order, regardless of where it was created. Link to comment Share on other sites More sharing options...
PrestashopEnthu Posted April 26, 2018 Share Posted April 26, 2018 17 hours ago, bellini13 said: your module must implement the actionValidateOrder hook. this hook would be executed for any new order, regardless of where it was created. Yes, I am have hooked on actionValidateOrder but back-office creation of orders did not trigger the codes. Test code: public function hookActionValidateOrder($params) { $id_order = $params['order']->id; $status = $params['orderStatus']->id; $result = $id_order.' - '.$status; file_put_contents('./modules/executevalidateorder/results.txt', $result, LOCK_EX); } Thank you. Link to comment Share on other sites More sharing options...
bellini13 Posted April 26, 2018 Share Posted April 26, 2018 what exact version of Prestashop? Link to comment Share on other sites More sharing options...
PrestashopEnthu Posted April 26, 2018 Share Posted April 26, 2018 5 minutes ago, bellini13 said: what exact version of Prestashop? Hi bellini13, Version 1.6.1.14 Thank you. Link to comment Share on other sites More sharing options...
bellini13 Posted April 26, 2018 Share Posted April 26, 2018 And you only create free orders manually from the back office? Have you tried creating an order in the back office that is not free? And if so, does it work? Link to comment Share on other sites More sharing options...
bellini13 Posted April 26, 2018 Share Posted April 26, 2018 use this instead. the issue is with your file_put_contents location. the current working directory is not the same when orders are created from the back and front office. In the future, review your php error log public function hookActionValidateOrder($params) { $id_order = $params['order']->id; $status = $params['orderStatus']->id; $result = $id_order.' - '.$status; file_put_contents(_PS_MODULE_DIR_ . 'temp/results.txt', $result, LOCK_EX); } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now