6

When I try to make payment via PayPal Gateway then I am getting this error:

"PayPal gateway has rejected request. Payment has already been made for this InvoiceID (#10412: Duplicate invoice).

I am using paypal express checkout. Some times it works well, but some times it gives error after redirecting to cart page.

Please help.

5 Answers 5

3

I have just met the same issue when I migrated from 1.7 to 1.9. The problem came from using old database version.

When an order is paid via PayPal, it will use our order_id as invoice id inside paypal.

invoice id used magento auto increment id

Because I used old database so my magento site generate an order id that used on PayPal which cause payment exception above.

There are 2 ways for sorting out this issue:

  1. using latest version of your database.
  2. creating some orders via admin so the system will increase order id until it goes over the largest invoice id on PayPal.

(I used #2 for quicker fix)

2
  • This helped me but can you explain the reason for this error. In what situation, do this happens? Commented Nov 8, 2016 at 13:15
  • Perfect solution...!!! Commented Aug 8, 2020 at 15:01
0

Enter your business account and go to Profile > Payment Recieving Preferences > and set Block accidental payments to No.

source: http://forum.azmagento.com/how-to/receiving-paypal-error-at-checkout-please-help-me-nbsp--31746.html

1
  • 1
    Is there a risk of duplicate charges when setting Block accidental payments to No?
    – ramiwi
    Commented Oct 27, 2015 at 19:03
0

It could be a deadlock issue. Check for the deadlock errors in MySQL. It was happening for randomly and fixed after I fixing the deadlock. Please refer my blog on deadlock

0

This seem to be a bug in the way Mage_Paypal handle invoice number.

If a paypal payment fail when a customer is trying to checkout and they try to checkout again whether it is a week or months later, once the quote session is still available magento will issue the same order increment id/invoice number to paypal

See /app/code/core/Mage/Paypal/Model/Express/Checkout.php

public function start($returnUrl, $cancelUrl, $button = null)
{
    ......
    $this->_api->setAmount($this->_quote->getBaseGrandTotal())
        ->setCurrencyCode($this->_quote->getBaseCurrencyCode())
        ->setInvNum($this->_quote->getReservedOrderId())

Paypal invoice number is set using $this->_quote->getReservedOrderId()

See app/code/core/Mage/Sales/Model/Quote.php

public function reserveOrderId()
{
    if (!$this->getReservedOrderId()) {
        $this->setReservedOrderId($this->_getResource()->getReservedOrderId($this));
    } else {
        //checking if reserved order id was already used for some order
        //if yes reserving new one if not using old one
        if ($this->_getResource()->isOrderIncrementIdUsed($this->getReservedOrderId())) {
            $this->setReservedOrderId($this->_getResource()->getReservedOrderId($this));
        }
    }
    return $this;
}

Since the order increment id/was never converted to an order $this->_getResource()->isOrderIncrementIdUsed($this->getReservedOrderId() will return false and the order increment number/invoice will stay unchanged.

Also take a look at Magento PayPal Duplicate Invoice Error

3
  • Last 2 years working good, suddenly what is cause for this issue? @Renon Stewart
    – zus
    Commented Nov 28, 2019 at 4:51
  • @zus .. did anything change on your side (Magento update etc)? Commented Nov 28, 2019 at 22:20
  • No, there is no changes.
    – zus
    Commented Nov 28, 2019 at 23:45
0

This is most likely due to something like rolling back to a previous database version, where your auto incrementing ID for order IDs is now moving through IDs that were previously used on PayPal.

If you have access to your database, you can update the ID that is being incremented as explained on this page:

https://www.warpconduit.net/2012/04/18/how-to-change-the-order-increment-id-and-prefix-in-magento/

The SQL to modify it on all stores:

UPDATE eav_entity_store
INNER JOIN eav_entity_type ON eav_entity_type.entity_type_id = eav_entity_store.entity_type_id
SET eav_entity_store.increment_last_id='XXXXXXXXXX'
WHERE eav_entity_type.entity_type_code='order';

Where XXXXXXXXXX is the last order that successfully went through.

To just update a specific store(if your Magento installation has more than one:

UPDATE eav_entity_store
INNER JOIN eav_entity_type ON eav_entity_type.entity_type_id = eav_entity_store.entity_type_id
SET eav_entity_store.increment_last_id='XXXXXXXXXX'
WHERE eav_entity_type.entity_type_code='order' AND eav_entity_store.store_id = 'Y';

Change out Y for the store ID you're updating.

Worked for me, hopefully it helps anyone else trying to fix this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.