homepage Welcome to WebmasterWorld Guest from 54.197.147.90
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
404 error on return
mikem1986




msg:4186824
 10:38 pm on Aug 13, 2010 (gmt 0)

Hi guys

I get a 404 error message once a client has paid me through my website which comes up as

The requested URL '/uk/cgi-bin/index2.php?merchant_return_link=Return+to+Merchant' was not found on this server.

m not understanding why i'm getting this message as far as i know my php coding is perfect but just in case my code is

<?php
//Configure Payments
$payPrice = $price / $payConfig;

?>
<h1>Pay Safely with PayPal</h1>
<p>Make sure the details below are correct and click the "Pay with PayPal" button. You will then be redirected
to PayPal's secure site to make your transaction.</p>
<p>Payment Amount: <?php if($paymentsMade == $payConfig){echo "There are no more payments to be made.";}else{echo "GBP: ".$payPrice.".00";}?></p>
<p>Payments Made: <?php echo $paymentsMade;?> of <?php echo $payConfig;?></p>
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">

<!-- Identify your business so that you can collect the payments. -->
<input class="hidden" type="hidden" name="business" value="<?php echo $businessEmail;?>">

<input class="hidden" type="hidden" name="cmd" value="_xclick">

<!-- Specify details about the item that buyers will purchase. -->
<input class="hidden" type="hidden" name="item_name" value="<?php echo $itemName;?>">
<input class="hidden" type="hidden" name="item_number" value="1">
<input class="hidden" type="hidden" name="amount" value="<?php echo $payPrice;?>">
<input class="hidden" type="hidden" name="currency_code" value="<?php echo $currency;?>">
<input class="hidden" type="hidden" name="no_shipping" value="0">

<!-- Display the payment button. -->
<input <?php if($paymentsMade >= $payConfig){echo "disabled='true'";}?> type="submit" value="<?php if($paymentsMade >= $payConfig){ echo "Payments Complete";}else{ echo "Pay with PayPal";} ?>">
<input class="hidden" type="hidden" name="return" value="index2.php?page=payment-complete">
</form>

 

dreamcatcher




msg:4186933
 5:21 am on Aug 14, 2010 (gmt 0)

I think you need to use the full http path for your return url.

<input class="hidden" type="hidden" name="return" value="http://www.example.com/index2.php?page=payment-complete">

dc

mikem1986




msg:4186996
 11:15 am on Aug 14, 2010 (gmt 0)

Thanks, ill give it a try and let you know what happens

mikem1986




msg:4187067
 4:23 pm on Aug 14, 2010 (gmt 0)

hi dreamcatcher

That works but the clients account isnt updated once the payment goes through?

How does this code look to you?

<?php
$paymentsMade = $paymentsMade + 1;

$sql = "UPDATE clients SET payments = '$paymentsMade' WHERE username = '$username'";
$sql2 = "INSERT INTO payments (user_id, date) VALUES ('$user_id', CURDATE())";

if (!mysql_query($sql,$conn))
{
die('Error: ' . mysql_error());
}
if (!mysql_query($sql2,$conn))
{
die('Error: ' . mysql_error());
}

//Alert Admin
$emailSubject = "Your client ".$fullname." has made a payment.";
$message = "Your client ".$fullname." has made a payment. They have made ".$paymentsMade." payments.";
mail($fromEmail, $emailSubject, $message, "From: ".$businessEmail);
?>
<h1>Payment Completed</h1>
<p><?php echo $paymentComplete; ?></p>

dreamcatcher




msg:4187234
 7:09 am on Aug 15, 2010 (gmt 0)

How are the $username & $user_id variables populated?

dc

rocknbil




msg:4187350
 5:00 pm on Aug 15, 2010 (gmt 0)

Right, look at the hidden fields in your original form, I don't see anywhere you're passing a variable from which you can extract $username. You can set a session variable before going over to payPal, but there are two problems with this.

First is that sessions inherently are cookie based, that is, setting a session sets the PHPSESSID cookie in your browser. If cookies are disabled, it will fail.

That one is **fairly** trivial, but one that is not: never rely on user action to compete a task. If you do, there is a very high possibility it will fail. I'm referring to the return to merchant link as the trigger to update your database - if they don't do this, it won't work. People don't like to read. :-)

What you want - nay, need - here is IPN, Instant Payment Notification - and it's not that hard to set up. You have most of the groundwork already. Here's how it works.

You go into PP and activate IPN, specify the IPN return URL. (Actually, you can specify return URL's just like above, but this is your starter script with IPN.) We'll call this a "listener script" which you haven't written yet.

On order, before sending them to payPal, you enter the data into your database and you have a field called something like "completed" which defaults to 0. Important in this is when you add the record, you obtain a unique id and pass it to payPal as trans_id.

They go to payPal, make the payment. And close the window, thinking they are done (which is what most users do.)

When paypal completes the transaction, it posts the trans_id of the completed transaction to your "listener script". You then look up the record, update the completed field to 1, send your emails, and whatever.

Though the biggest advantage is it no longer relies on sessions OR user action, it has another: you can now take eChecks. The IPN may not come for several days on an eCheck. No more zombie records, no more emails, then log in to PP and it's not complete . . . no more "Where's my stuff" emails.

These are just the cliff notes, look into IPN, there are samples on the payPal site for you to play with, it's very easy to set up.

mikem1986




msg:4188838
 8:53 pm on Aug 18, 2010 (gmt 0)

Apologies for the late reply guy, i went with rocknbill idea.

Thanks for all your help

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved