开发者

wordpress page redirect from iframe to paypal page

I have a Wordpress page with iframe integrated which contains booking calendar script as per below.

<div class="booking-calendar">
                    <iframe id="frame1" name="frame1" src="http://www.xxxxxx.co.uk/booking/frontend/" width="100%" height="450px" frameborder="0" scrolling="auto"></iframe>

                    </div>

Demo for the script in this iframe can be found here: http://www.phpjabbers.com/hotels-booking-system/ What I want to开发者_开发技巧 do is once the user clicks on Book now button is to redirect them to Paypal page. At the moment is set up so that they have to click on 'Pay now' button to get to this Paypal page where they make a payment. The code for this Pay now button is as follows:

<?php
    if ($deposit > 0) {
        if ($_REQUEST['payment_type'] == 'paypal') {
            ?>
            <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
                <input type="hidden" name="cmd" value="_xclick">
                <input type="hidden" name="business" value="<?php echo $SETTINGS_DB["paypal_address"]; ?>">
                <input type="hidden" name="item_name" value="Booking confirmation - <?php echo $BookingID; ?>">
                <input type="hidden" name="item_number" value="">
                <input type="hidden" name="amount" value="<?php echo number_format($deposit, 2, '.', ''); ?>">
                <input type="hidden" name="no_shipping" value="1">
                <input type="hidden" name="no_note" value="1">
                <input type="hidden" name="currency_code" value="<?php echo $Currencies[$SETTINGS_DB["currency"]]; ?>">
                <input type="hidden" name="lc" value="US">
                <input type="hidden" name="bn" value="PP-BuyNowBF">
                <input type="hidden" name="return" value="<?php echo $SETTINGS_DB["thankyou_page"]; ?>">
                <input name="submit" type='submit' value='PAY NOW' >
            </form>
            <?php
                header ("https://www.paypal.com/cgi-bin/webscr");
                exit;
            ?>

I was wondering how could I make a redirect so that the user goes automatically to Paypal page without clicking on Pay now? If somebody can put me in the right direction that would be great. I understand that hidden values have to be carried over to Paypal page, I just don't know how to make it so they get carried over. Any ideas? Any tips would be really appreciated.


I have been trying to sort it out myself so what I did so far: As I want the redirect to PayPal happen once the user clicks on Book button, I copied hidden fields which are part of Pay now form to the part with Book button --> part of the last bit of code:

($deposit > 0) { 

        <input type="hidden" name="cmd" value="_xclick">
                <input type="hidden" name="business" value="<?php echo $SETTINGS_DB["paypal_address"]; ?>">
                <input type="hidden" name="item_name" value="Booking confirmation - <?php echo $BookingID; ?>">
                <input type="hidden" name="item_number" value="">
                <input type="hidden" name="amount" value="<?php echo number_format($deposit, 2, '.', ''); ?>">
                <input type="hidden" name="no_shipping" value="1">
                <input type="hidden" name="no_note" value="1">
                <input type="hidden" name="currency_code" value="<?php echo $Currencies[$SETTINGS_DB["currency"]]; ?>">
                <input type="hidden" name="lc" value="US">
                <input type="hidden" name="bn" value="PP-BuyNowBF">
                <input type="hidden" name="return" value="<?php echo $SETTINGS_DB["thankyou_page"]; ?>">
    <?php   }
?>
        <div style="float:left"><input type="submit" value="Book"></div>
        <div style="clear:both"></div>

</form> 

Once the user clicks on Book button, the code will check if it's been submitted with this:

elseif ($_REQUEST["ac"]=='save_booking') {

and then the Booking details (name, tel, email,..) will be inserted into the database like this:

$sql = "INSERT INTO ".$TABLES["bookings"]." SET
                  `from` = '".Date2MySQL(SaveToDB($_REQUEST["from"]))."',
                  `to` = '".Date2MySQL(SaveToDB($_REQUEST["to"]))."',
                  `name` = '".SaveToDB($_REQUEST["name"])."',
                  `email` = '".SaveToDB($_REQUEST["email"])."',
                  `phone` = '".SaveToDB($_REQUEST["phone"])."',
                  `notes` = '".SaveToDB($_REQUEST["notes"])."',
                  `people` = '".SaveToDB($_REQUEST["people"])."',
                  `payment_type` = '".SaveToDB($_REQUEST["payment_type"])."',
                  `dt` = now()";
            $sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql.mysql_error());
            $BookingID = mysql_insert_id();

            $total_price = 0;
            $sql = "SELECT * FROM ".$TABLES["rooms"]." ORDER BY id DESC";
            $sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
            while ($row = mysql_fetch_assoc($sql_result)) {
                if ($_REQUEST["room_".$row["id"]]>0) {
                    $sql = "INSERT INTO ".$TABLES["bookings_rooms"]." SET
                          `booking_id` = '".$BookingID."',
                          `room_id` = '".$row["id"]."',
                          `quantity` = '".SaveToDB($_REQUEST["room_".$row["id"]])."'";
                    $sql_resultT = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql.mysql_error());
                    $total_price = $total_price + $_REQUEST["room_price_".$row["id"]]*$_REQUEST["room_".$row["id"]];
                };
            };

            $sql = "UPDATE ".$TABLES["bookings"]." SET
                  `price` = '".$total_price."'
                  WHERE id = '".$BookingID."'";
            $sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql.mysql_error());

            $deposit = $SETTINGS_DB["payment_deposit"];


            $sql = "SELECT * FROM ".$TABLES["bookings"]." WHERE id='".$BookingID."'";
            $sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
            $booking = mysql_fetch_assoc($sql_result);

            $sql = "SELECT * FROM `".$TABLES["bookings_rooms"]."` INNER JOIN ".$TABLES["rooms"]." ON ".$TABLES["rooms"].".id = ".$TABLES["bookings_rooms"].".room_id WHERE `".$TABLES["bookings_rooms"]."`.booking_id='".$BookingID."'";
            $sql_resultP = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
            while ($rooms = mysql_fetch_assoc($sql_resultP)) {
                 $roomsemail .= $rooms["quantity"]." x ".$rooms["room_type"].", ";
            };

            $message = ReadFromDB($SETTINGS_DB["email_message"]);
            $search_tokens=array("{name}","{email}","{phone}","{from_date}","{to_date}","{price}","{rooms}");
            $replace_tokens=array(ReadFromDB($booking["name"]),ReadFromDB($booking["email"]),ReadFromDB($booking["phone"]),MySQL2Date(ReadFromDB($booking["from"])),MySQL2Date(ReadFromDB($booking["to"])),formatCurrencyExport($booking["price"]),$roomsemail);
            $message=str_replace($search_tokens,$replace_tokens,$message);


            $mailheader    = "From: ".$SETTINGS_DB["admin_email"]."\r\n";
            $mailheader   .= "Reply-To: ".$SETTINGS_DB["admin_email"]."\r\n";
            $mailheader   .= "Content-type: text/plain; charset=UTF-8\r\n";

            mail($booking["email"], $SETTINGS_DB["email_subject"], $message, $mailheader);
            if ($SETTINGS_DB["admin_email"]) {
                mail($SETTINGS_DB["admin_email"], $SETTINGS_DB["email_subject"], $message, $mailheader);

            }

After the data has been inserted into the database I want the user to go automatically to PayPal payment page, so I inserted this code after the above code:

header ("https://www.paypal.com/cgi-bin/webscr");
                exit;
?>

Now when I click on Book button nothing happens, well the form disappears, so I just have some instruction text on the page, but we are not redirected to the PayPal page. Could somebody please point me to the right direction?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜