Jump to content

Which hook for order complete


iamgaurav

Recommended Posts

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

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

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

  • Thanks 2
Link to comment
Share on other sites

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

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

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

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

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

  • 3 years later...
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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...