5

I recently set up some automatic scripts to help me manage incoming orders for a Magento store by using observers and Magento events. My problem is dealing with the question when exactly an order is placed and saved in the system depending on the selected payment type.

For example: if someone simply choses prepayment, the order is saved immediately and the customer is automatically forwarded to a success page - so no problems so far.

If a customer pays via Paypal, the whole situation is completely different. After being redirected to PayPal, logging into the account and confirming the payment, the customer is not redirected to the Magento store. He can click on a link to return there which will also forward him to the success page but surely not everybody will do that and the problem is that the observer event I use only executes code if the user lands on that page. (The event I am working with is "checkout_Onepage_Controller_Success_Action").

Therefore I need to know from where Magento gets the information whether a PayPal payment was successful, has been cancelled or whatever. I looked through some of the PayPal controller files under /app/code/core/Mage/Paypal/controllers/ and the only thing that looked close to a possible solution was the function successAction() in StandardController.php. However, this function also seems to be triggered only when a customer choses to return to the Magento store so it doesn't help me.

Does anybody have some experience with that issue?

FlyingM
  • 217
  • 2
  • 7
  • 17
  • specify what paymennt method are you using exactly – Anton S Nov 28 '11 at 12:39
  • My example refers to the standard PayPal module of Magento v1.5.1.0 – FlyingM Nov 28 '11 at 12:49
  • try to bind to order object related events rather than controller events and please log out all events to a text file that are triggered inside your process then you can choose what is appropriate – Anton S Nov 28 '11 at 13:58
  • Do you have a particular example for a useful event? Before using the one I mentionned above, I also tried "sales_order_place_after" and "sales_order_save_after" but they both execute the code as soon as the customer clicks the "Place your order" link on the checkout page. I need an event that would trigger my code when a PayPal transaction is successfully finished. – FlyingM Nov 28 '11 at 14:19
  • see if those are fired: sales_order_invoice_pay sales_order_payment_capture – Anton S Nov 28 '11 at 19:35
  • I tried both and they do not seem to do anything at all, at least not during a normal PayPal transaction. – FlyingM Nov 29 '11 at 07:58
  • log out all events that are present to make your choice easier – Anton S Nov 29 '11 at 09:02

1 Answers1

0

I figured out a way to work around the problem: Appearently there are no events in Magento which correspond with incoming payments on PayPal. A possible solution might be to provide a IPN URL which triggers a script as soon as the payment is confirmed but I managed to redirect the customer to my store so I did not have to do that.

In the profile settings of the PayPal account under "website settings", there is an option called "automatic redirect". If this option is enabled and a URL is entered, the customer will automatically be forwarded to that URL. At first I thought this would not help me because as I said there are multiple web shops involved which all would have their own individual return URL and you can't specify more than one. However, if a return URL is passed over when contacting PayPal, it will override the one that is specified within the profile settings and since the Magento module does that by default, I just had to enter a random URL in the textfield and enable the option, now the customers are redirected back to my shop when they place an order and pay via PayPal.

FlyingM
  • 217
  • 2
  • 7
  • 17