Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

[HTML/PHP] Working paypal scripts!

Hello,

Decided to contribute to the forum by giving some things others might have trouble with.

This is a HTML/PHP based paypal script that allow you to take automated payments.

paypal.php
PHP Code

<?php 
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
 <
input type="textarea" name="amount" value="" placeholder="How much Euo do you want to spend?"/><br/>
 <
input type="hidden" name="cmd" value="_xclick"/>
 <
input type="hidden" name="business" value="__YOUR_PAYPAL_ADDRESS__"/>
 <
input type="hidden" name="lc" value="en_US"/>
 <
input type="hidden" name="item_name" value="__DESCRIPTION_FOR_PAYMENT__"/>
 <
input type="hidden"  name="custom" value="<?php echo $account_id; ?>">
 <
input type="hidden" name="button_subtype" value="products"/>
 <
input type="hidden" name="currency_code" value="EUR"/>
 <
input type="hidden" name="no_shipping" value="1"/>
 <
input type="hidden" name="no_note" value="1"/>
 <
input type="hidden" name="notify_url" value="__YOUR_WEBSITE_ADDRESS__/ipn/paypal_ipn.php"/>
 <
input type="hidden" name="return" value="__WHERE_ON_WEBSITE_AFTER_SUCCESSFUL_PAYMENT__"/>
 <
input type="hidden" name="rm" value="0"/>
 <
input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest"/>
 <
input type="submit" class="btn btn-success" name="submit" value="Purchase with paypal"/>
</
form> 

/ipn/paypal_ipn.php (database connection not included)
PHP Code

<?php
error_reporting
(E_ERROR | E_WARNING | E_PARSE); //report all except notice
 
   if(gethostbyaddr($_SERVER['REMOTE_ADDR']) != 'notify.paypal.com'){ 
 
       exit();
 
   }
 
 include(
"__YOUR_SQL_FILE_LOCATION__");
 
// Variables //
 
$receiverEmail = htmlspecialchars(strtolower($_REQUEST['receiver_email']));
 
$paymentStatus = htmlspecialchars(strtolower($_REQUEST['payment_status']));
 
$account_id = (int)$_REQUEST['custom'];
 
$time = (int)time();
 
$transaction_id = htmlspecialchars($_REQUEST['txn_id']);
 
$transaction_type = htmlspecialchars($_REQUEST['txn_type']);
 
$money_gross = (int)$_REQUEST['mc_gross'];
 
$money_fee = (int)$_REQUEST['mc_fee'];
 
$money_net = (int)$money_gross-$money_fee;
 
$money_currency = htmlspecialchars(strtolower($_REQUEST['mc_currency']));
 
$payer_email = htmlspecialchars($_REQUEST['payer_email']);
 
$payer_id = htmlspecialchars($_REQUEST['payer_id']);
 
$first_name = htmlspecialchars($_REQUEST['first_name']);
 
$last_name = htmlspecialchars($_REQUEST['last_name']);
 
 
$points = 0;
 
$pointsPerEuro = 10;
 if(
$money_gross > 0){
 
$points = (int)($money_gross*$pointsPerEuro);
 }
 
 
   // Setup
 
   $receiver = '__YOUR_PAYPAL_ADDRESS__';
 
   if($paymentStatus == 'completed' && ($receiverEmail == $receiver) && $money_gross > 0 && $money_currency == "eur")
 
   {
 
// Payment was successful..
 // Yours SQL handler to make queries.
 // for example:
 // mysqli_query("UPDATE `accounts` SET `points`=`points`+".$points." WHERE `id`=".$account_id." LIMIT 1;");
 
   }elseif($paymentStatus == 'reversed' && ($receiverEmail == $receiver)){
 
// Someone did a chargeback, log it and/or ban the user.
 // for example
 // mysqli_query("UPDATE `accounts` SET `banished`=1 WHERE `id`=".$account_id." LIMIT 1;");
 
   }else{
 
       exit();
 
    

If you don't know how to include and work out your database handlers, you can use this script instead:
/ipn/paypal_ipn.php
PHP Code

<?php
error_reporting
(E_ERROR | E_WARNING | E_PARSE); //report all except notice
 
   if(gethostbyaddr($_SERVER['REMOTE_ADDR']) != 'notify.paypal.com'){ 
 
       exit();
 
   }
 
 
$cfg = array(
 
"SQL_Server" => "localhost",
 
"SQL_User" => "root",
 
"SQL_Password" => "myDatabasePassword",
 
"SQL_Database" => "myDatabaseName",
 );
 
 
$con = mysqli_connect($cfg['SQL_Server'],$cfg['SQL_User'],$cfg['SQL_Password'],$cfg['SQL_Database']);
 if (!
$con){
 die(
"Couldn't establish connection to database!");
 }
 
 
// Variables //
 
$receiverEmail = htmlspecialchars(strtolower($_REQUEST['receiver_email']));
 
$paymentStatus = htmlspecialchars(strtolower($_REQUEST['payment_status']));
 
$account_id = (int)$_REQUEST['custom'];
 
$time = (int)time();
 
$transaction_id = htmlspecialchars($_REQUEST['txn_id']);
 
$transaction_type = htmlspecialchars($_REQUEST['txn_type']);
 
$money_gross = (int)$_REQUEST['mc_gross'];
 
$money_fee = (int)$_REQUEST['mc_fee'];
 
$money_net = (int)$money_gross-$money_fee;
 
$money_currency = htmlspecialchars(strtolower($_REQUEST['mc_currency']));
 
$payer_email = htmlspecialchars($_REQUEST['payer_email']);
 
$payer_id = htmlspecialchars($_REQUEST['payer_id']);
 
$first_name = htmlspecialchars($_REQUEST['first_name']);
 
$last_name = htmlspecialchars($_REQUEST['last_name']);
 
 
$points = 0;
 
$pointsPerEuro = 10;
 if(
$money_gross > 0){
 
$points = (int)($money_gross*$pointsPerEuro);
 }
 
 
   // Setup
 
   $receiver = '__YOUR_PAYPAL_ADDRESS__';
 
   if($paymentStatus == 'completed' && ($receiverEmail == $receiver) && $money_gross > 0 && $money_currency == "eur")
 
   {
 
// Payment was successful..
 // Yours SQL handler to make queries.
 // for example:
 
mysqli_query($con, "UPDATE `accounts` SET `points`=`points`+".$points." WHERE `id`=".$account_id." LIMIT 1;");
 
 
   }elseif($paymentStatus == 'reversed' && ($receiverEmail == $receiver)){
 
// Someone did a chargeback, log it and/or ban the user.
 // for example
 
mysqli_query($con, "UPDATE `accounts` SET `banished`=1 WHERE `id`=".$account_id." LIMIT 1;");
 
   }else{
 
       exit();
 
   }
 
mysqli_close($con);
?>

Hope this might help a few people out,
If you got questions or need explaining done, just ask  😁

Edit:
due to my low post count I couldn't post the necessary post action url, I've asked a moderator to change and include the url for me :)


a moderator fixed the url for me, so now ignore my "edit" in the end of the post.
I'd remove that, but I can't post it again because the url is there now and I'm forbidden to post urls xD


Possibly Related Threads...
Thread / Author Replies Views Last Post
by SunsetblvdAug 29, 2021 05:24 AM 0 139 Aug 29, 2021 05:24 AM
Last Post: Sunsetblvd
by newpriyaDec 2, 2020 11:57 AM 139 1,897 Dec 2, 2020 11:57 AM
Last Post: GroguMando
by ιNʂσɱɳιαƈApr 17, 2019 10:04 AM 0 140 Apr 17, 2019 10:04 AM
Last Post: ιNʂσɱɳιαƈ