Can I test paypal api's from localhost

前端 未结 7 831
难免孤独
难免孤独 2020-12-25 13:07

UPDATE 1:

According to this tutorial on Using PayPal\'s Instant Payment Notification with PHP, PayPal cannot access locally hosted websites unless c

相关标签:
7条回答
  • 2020-12-25 13:40

    To use IPN your localhost has to be accessed from the web. One solution that definitly works is to use a virtual Machine, install VPN-Server, connect your Clinet via VPN and manage virtual host to redirect to your local IP-adress. That way, if you turn on VPN your server can be accessed from outside and IPN can be sent.

    0 讨论(0)
  • 2020-12-25 13:41

    If http://localhost doesn't validate use http://127.0.0.1

    0 讨论(0)
  • 2020-12-25 13:42

    Well, it most works, but also, you can setup a temporary local dns entry. All you have to do is:

    1. open your /etc/hosts
    2. add a new entry: yourwebsite.com 127.0.0.1

    So when your browser query for the website will be fetched from your 127.0.0.1, somethings your need to flush dns( /etc/init.d/nscd restart).

    and that is it all, but remember to remove the entry when you are ready for production.

    0 讨论(0)
  • 2020-12-25 13:43

    One simple solution is described in the official developers page of PayPal:

    developer.paypal.com - Local IPN Testing

    The trick consists on writing a small HTML file with this content:

    <form target="_new" method="post" action="https://www.YourDomain.com/Path/YourIPNHandler.php">
    
    <!-- start example variables: -->
    
    <input type="hidden" name="SomePayPalVar" value="SomeValue1"/>
    <input type="hidden" name="SomeOtherPPVar" value="SomeValue2"/>
        
    <!-- /end example variables -->
    
    <input type="submit"/>
    	
    </form>

    To get the real results you need to copy all of the IPN variables which PayPal sends. These real variables can be found into the PayPal account, under IPN History:

    IPNs History

    You need to click on the relative Message ID and then copy the "IPN Message" content (it will be something like mc_gross=27.00&invoice=Test-1&protection_eligibility=Ineligible&...) which must be converted into HTML hidden input fields. For example:

    <input type="hidden" name="mc_gross" value="27.00"/>
    <input type="hidden" name="invoice" value="Test-1"/>
    <input type="hidden" name="protection_eligibility" value="Ineligible"/>
    
    ....

    After setting up all of these variables and changing the action URL, you can open the file with a browser and then submit this form.

    0 讨论(0)
  • 2020-12-25 13:43

    It should work without a problem, however it might get picky if you send in "invalid URLs" for return urls and IPN message urls. Meaning, sending in http://localhost/cancelpaypal.php as cancelURL might tell you that it is an invalid url.

    I do however don't think it should.

    Having to open up router ports would only be needed for IPN, because the redirect in the normal flow is a regular "Location:" header hence it is your browser that needs to be able to access the site (localhost)

    0 讨论(0)
  • 2020-12-25 13:46

    It should work. I have made a payment integration with paypal last year, and it worked on localhost without problems.

    Are you using the paypal sandbox for development? https://developer.paypal.com/

    0 讨论(0)
提交回复
热议问题