Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

error, when I click the confirm order(paypal ipn)


peter888

Recommended Posts

Posted

got error, sometimes, when I click the confirm order, attached is the following, any one knows why???

 

 

"

Error Detected

This invoice has already been paid. For more information, please contact the merchant

 

"

 

Thanks

Posted

Hi peter888,

 

This is from one of the help files that comes with the paypal IPN contribution:

 

"This invoice has already been paid" PayPal error message

Background:
The PayPal IPN sends a parameter "invoice" to PayPal. This parameter is equal to the order ID (1,2,3,4 etc). However, PayPal requires the invoice parameter to be unique so if you have already sent an order ID with the same number, then it will be refused. Sending the same order ID can e.g. happen if you have two osCom shops linked to one PayPal account - the PayPal account cannot distinguish between different shops / domains / databases, it just looks at the number and says "hey, that's already been paid!"

There are two possible solutions:


******************************************

1. Create a unique invoice ID for each shop
this solution keeps the invoice ID check functionality but allows you to create unique IDs

Description:
If you have multiple shops linked to your PayPal account, then you get around this problem by adding a unique letter to your invoice parameter. As the invoice parameter can be any string (max length 127), it doesn't matter that it's not numeric. If you run several shops all with one PayPal account, then choose a different letter for each shop.

Note: this solution is for coders who have a reasonable knowledge of PHP. To alter your invoice parameter:

In /includes/modules/payment/paypal_ipn.php find this code:
$parameters['invoice'] = substr($cart_PayPal_IPN_ID, strpos($cart_PayPal_IPN_ID, '-')+1);

and change to this:
$parameters['invoice'] = 'K' . substr($cart_PayPal_IPN_ID, strpos($cart_PayPal_IPN_ID, '-')+1);

choose any letter but keep it to ONE letter only (or change the substr command accordingly, just make sure to keep it in sync)

In /ext/modules/payment/paypal/ipn.php replace all occurrences of
$_POST['invoice']

with
substr($_POST['invoice'],1)


The above code will add the letter to the order ID when sending to PayPal and then strip it back out again with the substr command. It's vital that you replace all occurences of the variable in ipn.php as otherwise your database update won't happen or be wrong.

I've tested it on my online shop and it's all working in Sandbox - I think it's a cleaner solution than just changing the order IDs to something higher as previously suggested. And it's also sustainable over time (think 10 years down the road when you have thousands of orders), plus even with just one letter you can run up to 26 different shops on one PayPal account. 

******************************************

2. Disable the inoice ID checking
with this solution PayPal will not check for duplicate order IDs - a potential problem if customers e.g. hit a button twice. I'd recommend to try the first solution first, and only if that fails, try this second one:

In your PayPal account, go to "Profile" - > "Payment Receiving Preferences". In there you will have the option:
Block accidental payments:
You may prevent accidental payments by blocking duplicate invoice IDs
Yes, block multiple payments per invoice ID
No, allow multiple payments per invoice ID

Select "No".

PayPal will now allow all orders to be paid, even if the order ID has already been paid previously. A potential problem is if customers pay an invoice twice by mistake (e.g. refreshing browser, hitting button twice etc.).

 

Basically what it's saying is that it thinks the invoice number (aka order number) has already been paid. You can get around it by switching off the setting in PayPal that makes it check order numbers, or, if you're running more than one shop that uses the paypal payment method, by assigning a unique order numbering system to each shop, thereby preventing duplicates.

 

I hope this helps!

Max.

Posted

For the first solution: I have to do the following two steps???

 

1): In /includes/modules/payment/paypal_ipn.php find this code:

$parameters['invoice'] = substr($cart_PayPal_IPN_ID, strpos($cart_PayPal_IPN_ID, '-')+1);

 

and change to this:

$parameters['invoice'] = 'K' . substr($cart_PayPal_IPN_ID, strpos($cart_PayPal_IPN_ID, '-')+1);

 

2:) In /ext/modules/payment/paypal/ipn.php replace all occurrences of

$_POST['invoice']

 

with

substr($_POST['invoice'],1)

--------------------------------------------------------------------------------

My question is: do I need modify the above two steps or just one of the two???

 

Thanks.

Posted

I just tested the first solution: and did the following two steps???

 

1): In /includes/modules/payment/paypal_ipn.php find this code:

$parameters['invoice'] = substr($cart_PayPal_IPN_ID, strpos($cart_PayPal_IPN_ID, '-')+1);

 

and change to this:

$parameters['invoice'] = 'K' . substr($cart_PayPal_IPN_ID, strpos($cart_PayPal_IPN_ID, '-')+1);

 

2:) In /ext/modules/payment/paypal/ipn.php replace all occurrences of

$_POST['invoice']

 

with

substr($_POST['invoice'],1)

--------------------------------------------------------------------------------

NOW, we have another problem. on the admin(Payment Modules), I Set:

-----------------------------------

Set Preparing Order Status

Preparing [PayPal IPN]

 

Set PayPal Acknowledged Order Status

default(is pending)

-------------------------------------

Now, NO payments go to pending, all payments are in Preparing [PayPal IPN]. we can not make difference who paid.

 

Can you advise me what to do next?

 

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...