Demo Paypal Transaction

  1. index.php  
  2. $url='https://www.sandbox.paypal.com/cgi-bin/webscr'; ?>  
  3. $email='[email protected]';  
  4. <form enctype="multipart/form-data" action='<?php echo $url; ?>' method='post'>  
  5. <input type='hidden' name='business' value='<?php echo $email; ?>'>  
  6. <input type='hidden' name='cmd' value='_xclick'>  
  7. <input type='hidden' name='item_name' value='<?php echo $name . " " . $surname;?>'>  
  8. <input type='hidden' name='item_number' value='<?php echo $artist_id;?>'>  
  9. <input type='hidden' name='amount' value='<?php echo $price;?>'>  
  10. <input type='hidden' name='buyer_name' value='<?php echo $b_name; ?>'>  
  11. <input type='hidden' name='buyer_phone' value='<?php echo $phone; ?>'>  
  12.   
  13. <input type='hidden' name='no_shipping' value='1'>  
  14. <input type='hidden' name='currency_code' value='EUR'>  
  15. <input type='hidden' name='handling' value='0'>  
  16. <input type='hidden' name='cancel_return' value='http://mywebsite.com/fail.php'>  
  17. <input type='hidden' name='return' value='http://mywebsite.com/success.php'>  
  18.   
  19. <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!">  
  20. 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  
  21.   
  22. success.php  
  23.   
  24. <?php  
  25.     $artist_id = $_POST['item_number'];  
  26.     $buyer_name = $_POST['buyer_name'];  
  27.     $buyer_phone = $_POST['buyer_phone'];  
  28.     $item_transaction = $_POST['tx'];  
  29.     $item_price = $_POST['amt'];  
  30.   
  31.     echo "Name: $item_no , Surname: $buyer_name, Price: $buyer_phone, ID: $item_transaction  $item_price<br/>";  
  32.   
  33.     //retrieve artist's details  
  34.     $getArtist = mysql_query("SELECT * FROM artist WHERE artist_id = '$item_no'");  
  35.     $details = mysql_fetch_array($getArtist);  
  36.     $name = $details['artist_name']; $surname = $details['artist_surname']; $price = $details['artist_budget']; $artist_id = $details['artist_id'];  
  37.   
  38.     //$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')");  
  39.     //if($result){  
  40.     //    echo "<p style='text-align: center;'><img src='images/success.png'><br/><br/>";  
  41.     //    echo "We will contact you as soon as possible for further details! Please check your email<br/>";  
  42.     //    echo "<a href='book.php'><b>Go Back</b></a></p><br/>";  
  43.   
  44.     //}else{  
  45.     //    echo "Payment Error";  
  46.     //}  
  47.         echo "Name: $name , Surname: $surname, Price: $price, ID: $artist_id";  
  48.     }  
  49.     else  
  50.     {  
  51.     echo "Payment Failed";  
  52.     }  
  53. ?>