How to prevent duplicate PayPal payments?

2020-07-13 07:50发布

问题:

I have a simple Pay Now button, the code created through the button maker, with a "custom" hidden field added to identify it. I wonder if there is some additional hidden field I can add to tell PayPal that "This transaction should not be made twice".

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">

    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="hidden" name="custom" value="{MYUNIQUEID}">
    <input type="hidden" name="hosted_button_id" value="{MYHOSTEDBUTTONID}">
    <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif" 
    border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">

</form>

As it is now it's unlikely that the customer should be able to pay twice, but I noticed that when the Sandbox had a glitch I succeeded in paying the same transaction twice. Something that I absolutely want to avoid. Not just for the customer, that could get refunded, sure, but also since I don't want my database messed up and I would like to avoid extensive coding to catch duplicate payments...

回答1:

You would want to add a unique identifier to the "invoice" parameter; <input type="hidden" name="invoice" value="your unique invoice ID"> and enable "Block duplicate payments" within the 'Profile' > 'My selling tools' section on your account at www.paypal.com



回答2:

Thanks Robert! (above post)

I actually went so far that I was going to ask PayPal Merchant Technical Support about it and just before submitting my question there found a page with the answer -

Avoiding duplicate payments: https://ppmts.custhelp.com/app/answers/detail/a_id/165

Not sure if you have to log in to see above page so I'm quoting the page here for convenience:

You can avoid duplicate transactions by passing an invoice number to the PayPal system. This feature is available for Website Payments Standard, and Website Payments Pro (SOAP and NVP). The PayPal system will check to make sure the invoice number you pass has not already been paid in your account, as long as you have configured your profile to block duplicate invoice numbers.

Example: Invoice 001 has been paid, therefore if 001 is passed to the PayPal account a second time, it will be denied.

To block this in your profile:

Block accidental payments: You may prevent accidental payments by blocking duplicate invoice IDs

  1. Login at https://www.paypal.com

  2. Click the 'Profile' subtab

  3. Under 'Selling Preferences' click 'Payment Receiving Preferences'

  4. Choose 'Yes, block multiple payments per invoice ID' if you wish to utilize this feature while passing the "invoice" variable

  5. Scroll to the bottom and click the 'Save' button

To pass the invoice number for Website Payments Standard, you will need to add a line of code to your existing button code. You cannot add this code to a button originally created as encrypted. Example below:

For Website Payments Pro, the parameter you pass depends on the type of API calls you are making.

For SOAP: InvoiceID

For NVP: INVNUM

When using Pro, if a duplicate invoice number is detected the error 10412 will be returned. For a complete list of the API error codes, and details regarding the 10412 error Click Here