Jump to content

paypal help please with php


redarrow

Recommended Posts

all i want to do is test if the page comes back and update the database and if cancel goto the correct page.

i have tried for hours with paypal to test the form no luck can anyone test the form to see if it works please.

or see if it all looks correct thank you so much.

dam that paypal testing is hard.

[code]
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="admin@hotmail.com">
<input type="hidden" name="item_name" value='<? echo"Freelance Programming Advert From $added_date to $exspire_date"?>'>
<input type="hidden" name="item_number" value='<?php echo $record['id'] ?>'>
<input type="hidden" name="amount" value='<?php echo $price ?>'>
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="return" value="http://xxxxxx?cmd=update&id=$id">
<input type="hidden" name="cancel_return" value="http://www.xxxxx.php">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but23.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
[/code]
Link to comment
Share on other sites

I had very little difficulty doing this... you'll need to define a few variables to use my script (below), but assuming you're using a shopping cart that's exactly the same as the one I wrote (somewhat unlikely) it should work. I hope that it'll make sense even if you haven't.
Anyway, enough waffle... I do this:
[code]<?php
$postage_max = 7.49;
$postage_total_without = 0;
$postage_total_with = 0;
echo '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_ext-enter">
<input type="hidden" name="redirect_cmd" value="_cart">
<input type="hidden" name="business" value="'.$my_email_address.'">
<input type="hidden" name="return" value="'.$transaction_completed_url.'">
<input type="hidden" name="cancel_return" value="'.$canceled_transaction_url.'">
<input type="hidden" name="email" value="'.$email.'">
<input type="hidden" name="first_name" value="'.$first_name.'">
<input type="hidden" name="last_name" value="'.$last_name.'">
<input type="hidden" name="address1" value="'.$address_line_1.'">
<input type="hidden" name="address2" value="'.$address_line_2.'">
<input type="hidden" name="city" value="'.$city.'">
<input type="hidden" name="state" value="'.$state.'">
<input type="hidden" name="zip" value="'.$zip.'">

<input type="hidden" name="upload" value="1">
<input type="hidden" name="currency_code" value="GBP">';
$i=1;
foreach($_SESSION['cart'] as $item_id => $quantity){
$id=mysql_fetch_array(mysql_query("select * from items where item_id='". $item_id."'"));
echo'
<input type="hidden" name="item_name_'.$i.'" value="';
// strip the " into '' marks
$item_title_var = str_replace("\"", "''", $id['item_title']);
echo $item_title_var;
echo' X '.$quantity.'">
<input type="hidden" name="item_number_'.$i.'" value="'.$id['item_id'].'">';
if (!isset($_SESSION['Logged_In'])){
echo'<input type="hidden" name="amount_'.$i.'" value="'.($quantity*$id['item_price']).'">';
}
else{
echo'<input type="hidden" name="amount_'.$i.'" value="'.($quantity*$id['item_member_price']).'">';
}
// calculate postage:
$psql=mysql_fetch_array(mysql_query("SELECT * FROM postage WHERE id='".$id['postage']."'"));

$this_postage = 0;
$apc=0;


$this_postage = ($quantity*$psql['first']);
$postage_total_with = $postage_total_without+$this_postage;

if ($postage_total_with<=7.49){
$apc=$this_postage;
}
else if ($postage_total_with>$postage_max){
$apc=($postage_max-$postage_total_without);
}


echo'<input type="hidden" name="shipping_'.$i.'" value="'.$apc.'">';
$postage_total_without=$postage_total_with;

echo'<input type="hidden" name="shipping2_'.$i.'" value="0">
<input type="hidden" name="handling_'.$i.'" value="0">
';
$i++;
}
echo'
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!">
</form>';
?>[/code]
Link to comment
Share on other sites

that code looks like mine and i like it

what i was trying to do is when the user comes back to the page is update the database but i can not seem to get paypal to return the varable from the return field like this
[code]
<input type="hidden" name="return" value=" http://www.url.com?cmd=update&id=$id">
[/code]

so then i can use a get and update the database with the users id

i dont think its possable is it cheers.
Link to comment
Share on other sites

This is from paypal surly we can alter this to do what i wont please help cheers.

[code]
<?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);

// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>
[/code]
Link to comment
Share on other sites

Afther a long read i still dont understand the ipn for paypal how does it work i read everthink on paypal and been looking at all the other websites that deal with pay pal.

when you use ipn do you have to suply a form with the address for the user and acoount information by your own website or do you use it like the button method.


i hope some one can exsplain the setup process please.

Link to comment
Share on other sites

i have put this on the paypal website but if you see whats wrong please tell me, the email address are fake ones to use the sandbox and the notification is on in the sandbox settings.

i dont get a succesfull transaction so please help thank you.


[code]
<?php

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);




// assign posted variables to local variables

$item_name = $_POST['item_name'];
$item_number =$_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email= $_POST['receiver_email'];
$payer_email= $_POST['payer_email'];



$query=" select * from payment where id='$id' order by added_date limit 1";

$result=mysql_query($query);

while($record=mysql_fetch_assoc($result)){


$item_name="advert";
$item_number=$record['id'];
$payment_amount=$price;
$payment_currency="GBP";
$receiver_email="admin@hotman.com";
$payer_email="admin@hotmail.com";

}


if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {

echo 'payment tacken';
}
else if (strcmp ($res, "INVALID") == 0) {

echo 'no payment sorry';
}
}
fclose ($fp);
}
}

?>
[/code]
Link to comment
Share on other sites

Sessions will probably allow enough time to write any details to the database. I write everything to a session directly before printing the paypal form. I then have the user sent off to a cheap gateway provider ;o) and when they're sent back, i just use the session info again.

It seems to work fine for me.
Alternatively, you could write it all to a temporary database table first, then echo out the form with the return URL including the auto-increment id of the temporary table's entry and when the user is returned, use the $_REQUEST['tmp_id'] thingie to get the details and move it to a permanent table, then clear the temporary one.

That'd be two nice ways to do it.

I currently use sessions, but the second method is nicer IMHO.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.