Redgren Grumbholdt
Redgren Grumbholdt

Reputation: 1230

Paypal Sandbox not returning any variables

I have my code as follows:

    $paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; 
    $paypal_id = '[email protected]';

    $str .= "<form method='post' action='".$paypal_url."'>";
    $str .= "<input type='hidden' name='business' value='".$paypal_id."'>";
    $str .= "<input type='hidden' name='cmd' value='_xclick'>";
    $str .= "<input type='hidden' name='item_name' value='Room'>";
    $str .= "<input type='hidden' name='item_number' value='".getRoom($id)."'>";
    $str .= "<input type='hidden' name='currency_code' value='USD'>";
    $str .= "<input type='hidden' name='no_shipping' value='1'>";
    $str .= "<input type='hidden' name='amount' id='paypal_cost' value='".getBal($id)."'>";
    $str .= "<input name='notify_url' value='http://localhost/tropicana/guests/notify.php' type='hidden'>";
    $str .= "<input type='hidden' name='cancel_return' value='http://localhost/tropicana/guests/payments.php'>";
    $str .= "<input type='hidden' name='return' value='http://localhost/tropicana/guests/notify.php'>";
    $str .= "<button type='submit' name='submit' class='form-control btn-danger'>Pay $".getBal($id)." with <i>PayPal</i>";

    $str .= "</form>";

But after a successful payment, my return script notify.php is not receiving any variables.

When i try to print_r() the $_REQUEST, it returns an empty array.

Upvotes: 1

Views: 566

Answers (1)

kodeart
kodeart

Reputation: 1903

TL;DR: Your notify_url cannot be localhost since PayPal will send you the IPN messages (from outside), which means your development machine must be exposed to internet.

One way to expose your computer is using a tool like ngrok, or something like serveo, or similar. Once you do that, set your notify_url to that public URL to receive the IPN messages.

But, be warned:

  • if you use free ngrok option, your random subdomain (ex. 13bf0ee2.ngrok.com) will change on every ngrok re/start
  • if you test subscriptions, your previously created plans with ngrok notify_url won't be valid anymore and you will not receive the recurrent IPN messages.
  • because PayPal sandbox is one big piece of junk, you may not receive IPN messages at all simply because they are totally broken service.

Of course, you will scratch your head sometimes why things worked yesterday and not today. The best option is to boycott them and move on with your life and business with someone who's actually competent on this field.

Upvotes: 1

Related Questions