Sarah92
Sarah92

Reputation: 87

Return to Merchant Website after PayPal Payment

I have a PHP form on my website, when the user clicks submit - they are redirected to a Booking Confirmation page. At this point, I have set up a PayPal connection (Sandbox) as follows;

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

        <input type="hidden" name="cmd" value="_cart">
        <input type="hidden" name="business" value="[email protected]">
        <input type="hidden" name="currency_code" value="EUR">
        <input type="hidden" name="upload" value="1">

        <b>First name:</b><span style="padding-left:5em;"></span>
        <input type="text" name="first_name" style="width:20em;">
        <br><br>
        <b>Last name:</b><span style="padding-left:5.1em;"></span>
        <input type="text" name="last_name" style="width:20em;">
        <br>
        <b>Email Address:</b><span style="padding-left:3.35em;"></span>
        <input type="text" name="email" style="width:20em;">

        <input type="hidden" name="custom" value="<?php echo $randomString ?>"/>
        <input type="hidden" name="return" value="http://www.example.com/thank-you/">
        <input type="hidden" name="notify_url" value="https://www.example.com/my_ipn.php">
        <input type="hidden" name="rm" value="2"> 

        <?php 
        if (($Adults > 0) && ($Students > 0) && ($Children > 0))
        {
            echo "<input type='hidden' name='item_name_1' value='" . $selectroute ." (Adult - " . $ticket .")'>";
            echo "<input type='hidden' name='amount_1' value='15'>";
            echo "<input type='hidden' name='quantity_1' value='" . $Adults . "'>";

            echo "<input type='hidden' name='item_name_2' value='" . $selectroute ." (Student - " . $ticket .")'>";
            echo "<input type='hidden' name='amount_2' value='15'>";
            echo "<input type='hidden' name='quantity_2' value='" . $Students . "'>";

            echo "<input type='hidden' name='item_name_3' value='" . $selectroute ." (Child - " . $ticket .")'>";
            echo "<input type='hidden' name='amount_3' value='15'>";
            echo "<input type='hidden' name='quantity_3' value='" . $Children . "'>";
        }
        elseif (($Adults > 0) && ($Students > 0))
        {
            echo "<input type='hidden' name='item_name_1' value='" . $selectroute ." (Adult - " . $ticket .")'>";
            echo "<input type='hidden' name='amount_1' value='15'>";
            echo "<input type='hidden' name='quantity_1' value='" . $Adults . "'>";

            echo "<input type='hidden' name='item_name_2' value='" . $selectroute ." (Student - " . $ticket .")'>";
            echo "<input type='hidden' name='amount_2' value='15'>";
            echo "<input type='hidden' name='quantity_2' value='" . $Students . "'>";
        }
        elseif (($Students > 0) && ($Children > 0))
        {
            echo "<input type='hidden' name='item_name_1' value='" . $selectroute ." (Student - " . $ticket .")'>";
            echo "<input type='hidden' name='amount_1' value='15'>";
            echo "<input type='hidden' name='quantity_1' value='" . $Students . "'>";

            echo "<input type='hidden' name='item_name_2' value='" . $selectroute ." (Child - " . $ticket .")'>";
            echo "<input type='hidden' name='amount_2' value='15'>";
            echo "<input type='hidden' name='quantity_2' value='" . $Children . "'>";
        }
        elseif (($Adults > 0) && ($Children > 0))
        {
            echo "<input type='hidden' name='item_name_1' value='" . $selectroute ." (Adult - " . $ticket .")'>";
            echo "<input type='hidden' name='amount_1' value='15'>";
            echo "<input type='hidden' name='quantity_1' value='" . $Adults . "'>";

            echo "<input type='hidden' name='item_name_2' value='" . $selectroute ." (Child - " . $ticket .")'>";
            echo "<input type='hidden' name='amount_2' value='15'>";
            echo "<input type='hidden' name='quantity_2' value='" . $Children . "'>";
        }
        elseif ($Adults > 0)
        {
            echo "<input type='hidden' name='item_name_1' value='" . $selectroute ." (Adult - " . $ticket .")'>";
            echo "<input type='hidden' name='amount_1' value='15'>";
            echo "<input type='hidden' name='quantity_1' value='" . $Adults . "'>";
        }
        elseif ($Students > 0)
        {
            echo "<input type='hidden' name='item_name_1' value='" . $selectroute ." (Student - " . $ticket .")'>";
            echo "<input type='hidden' name='amount_1' value='15'>";
            echo "<input type='hidden' name='quantity_1' value='" . $Students . "'>";
        }
        elseif ($Children > 0)
        {
            echo "<input type='hidden' name='item_name_1' value='" . $selectroute ." (Child - " . $ticket .")'>";
            echo "<input type='hidden' name='amount_1' value='15'>";
            echo "<input type='hidden' name='quantity_1' value='" . $Children . "'>";
        }
        ?>

        <input type="image" src="https://www.paypalobjects.com/webstatic/en_US/btn/btn_paynow_cc_144x47.png" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" style="position:relative; top: 8em; padding-left:15em;">
        <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
    </form>

The above form takes the values that the user entered on the PHP booking form and displays them in the Order Summary section of Paypal, as expected. I can then login as the buyer and make a payment. I then want to be returned to the http://www.example.com/thank-you/ but instead I am landed on a PayPal page which states the Transaction ID and confirmation that the payment has been processed.

How do I return to the Thank You page on the Merchant website rather than on the PayPal website?

I have Auto-Return turned on, and a Return URL set. As you can see above, I have specified the return and rm variables but no luck.

Any suggestions would be greatly appreciated.

Upvotes: 0

Views: 967

Answers (1)

Sarah92
Sarah92

Reputation: 87

At long last - I got it working.

Bit of a silly mistake - but just in case anyone else experiences this problem - I had left the business email in the code as [email protected] as shown above.

Once I changed the business variable value to the merchant email address - it worked!

Upvotes: 1

Related Questions