After tearing my hair out for weeks working on a problem where no matter what i tried every time an order was placed on a customers magento website, where paypal was the selected payment gateway the order would always automatically cancel nearly immediately after the order was placed.

The logs werent helpful, and the magento order status notes would basically just say that the order was cancelled, and the customer notified. We noticed this was only occuring for paypal customers, other payment gateways would allow the order to go through as normal.

Initially we thought it must have been a database conflict after we had reset a bunch of test orders. We even went as far as a full magento re-install to try and fix the issue. All with no fix. 🙁

Finally one afternoon, i found the answer! And boy was it frustratingly simple (as it often is)

In the end the issue was with Paypal – not magento at all!

Paypal has a feature that is enabled by default. “Block accidental payments”

What does this do? PayPal states “You may prevent accidental payments by blocking duplicate invoice IDs”

So hows this affect us you ask?

In my customers case this wasn’t the first time they had used their paypal account for accepting orders through an online store, so the security feature above was jumping in and not allowing the payment to complete, this would then send the failed hit back to magento.

All because invoices with that reference number had been previously run through Paypal (even if it was for a totally different site). To fix it we simply disabled this option as it was the best for us. You do however have a few options depending on your situation.