TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Demo Paypal Transaction
kamal sooftphoton
Apr 28
2015
Code
2.5
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
demopaypal.zip
index.php
$url
=
'https://www.sandbox.paypal.com/cgi-bin/webscr'
; ?>
$email
=
'
[email protected]
'
;
<form enctype=
"multipart/form-data"
action=
'<?php echo $url; ?>'
method=
'post'
>
<input type=
'hidden'
name=
'business'
value=
'<?php echo $email; ?>'
>
<input type=
'hidden'
name=
'cmd'
value=
'_xclick'
>
<input type=
'hidden'
name=
'item_name'
value=
'<?php echo $name . " " . $surname;?>'
>
<input type=
'hidden'
name=
'item_number'
value=
'<?php echo $artist_id;?>'
>
<input type=
'hidden'
name=
'amount'
value=
'<?php echo $price;?>'
>
<input type=
'hidden'
name=
'buyer_name'
value=
'<?php echo $b_name; ?>'
>
<input type=
'hidden'
name=
'buyer_phone'
value=
'<?php echo $phone; ?>'
>
<input type=
'hidden'
name=
'no_shipping'
value=
'1'
>
<input type=
'hidden'
name=
'currency_code'
value=
'EUR'
>
<input type=
'hidden'
name=
'handling'
value=
'0'
>
<input type=
'hidden'
name=
'cancel_return'
value=
'http://mywebsite.com/fail.php'
>
<input type=
'hidden'
name=
'return'
value=
'http://mywebsite.com/success.php'
>
<input type=
"image"
src=
"https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif"
border=
"0"
name=
"submit"
alt=
"PayPal - The safer, easier way to pay online!"
>
When a user clicks on the button, it goes to paypal site where it shows product details etc. If the payment is successfull, it sends the users to success.php script where it should get the data (cmd, item_name, item_number, amount etc) from the form in index.php
success.php
<?php
$artist_id
=
$_POST
[
'item_number'
];
$buyer_name
=
$_POST
[
'buyer_name'
];
$buyer_phone
=
$_POST
[
'buyer_phone'
];
$item_transaction
=
$_POST
[
'tx'
];
$item_price
=
$_POST
[
'amt'
];
echo
"Name: $item_no , Surname: $buyer_name, Price: $buyer_phone, ID: $item_transaction $item_price<br/>"
;
//retrieve artist's details
$getArtist
= mysql_query(
"SELECT * FROM artist WHERE artist_id = '$item_no'"
);
$details
= mysql_fetch_array(
$getArtist
);
$name
=
$details
[
'artist_name'
];
$surname
=
$details
[
'artist_surname'
];
$price
=
$details
[
'artist_budget'
];
$artist_id
=
$details
[
'artist_id'
];
//$result = mysql_query("INSERT INTO booked_event (pid, buyer_name, buyer_phone, saledate, transactionid) VALUES('$singer_no', '$buyer_name', '$buyer_phone','$event_date','$item_transaction')");
//if($result){
// echo "<p style='text-align: center;'><img src='images/success.png'><br/><br/>";
// echo "We will contact you as soon as possible for further details! Please check your email<br/>";
// echo "<a href='book.php'><b>Go Back</b></a></p><br/>";
//}else{
// echo "Payment Error";
//}
echo
"Name: $name , Surname: $surname, Price: $price, ID: $artist_id"
;
}
else
{
echo
"Payment Failed"
;
}
?>
php
Paypal Transaction
Demo Transaction