Question

J'ai écrit un système automatisé de dons pour quelqu'un, pour que les gens qui jouent sur ses serveurs de jeu peuvent entrer leurs informations, faire un don, et être automatiquement ajoutées à une base de données. Son travail formidable, mais je ne suis pas très php saavy, donc je suis en espérant que vous les gars peuvent regarder et me dire ce que je dois ajouter. Je dois les enlever lorsque l'abonnement se termine, que je pense est subscr_eot, mais je ne peux pas trouver de bons exemples de l'utiliser. Et comme pour le reste, je suis juste en espérant qu'il a l'air bien, merci!

<?php

// database
include_once('config.php');

//Connect
$db_connect = mysql_connect($DB_host, $DB_username, $DB_password) or die(mysql_error());
mysql_select_db($DB_name) or die(mysql_error());

// 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'];
$txn_type = $_POST['txn_type'];
$receiver_email = $_POST['receiver_email'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$payer_email = $_POST['payer_email'];
$steam_id = $_POST['custom'];

if ($fp)
{
    fputs ($fp, $header . $req);
    while (!feof($fp))
    {
        $res = fgets ($fp, 1024);
        switch ($res)
        {
            //Payment is Validated
            case 'VERIFIED':

                if(strcmp($payment_status, "Completed") == 0)
                {
                    $firstlast = $first_name[0] . $last_name;
                    $username = strtolower($firstlast);

                    $query = "INSERT INTO sb_admins (user, authid, password, gid, email, validate, extraflags, immunity, srv_group, srv_password) VALUES('". $username ."', '". $steam_id ."', '', -1, '". mysql_real_escape_string($payer_email) ."', 0, 0, 0, '". $sm_group ."', 'password')";
                    mysql_query($query) or die(mysql_error());
                }

                // 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
                break;

            case 'INVALID':

                // PAYMENT INVALID & INVESTIGATE MANUALLY!
                $to      = $receiver_email;
                $subject = 'XA - BattleClan | Invalid Donation';
                $message = '

                Dear Administrator,

                A donation has been made but is flagged as INVALID.
                Please verify the payment manually and contact the donator.

                Donator Email: '.$email.'
                ';
                $headers = 'From:administrator@xa-battleclan.com' . "\r\n";

                mail($to, $subject, $message, $headers);
                break;

            default:
                break;
        }
    }
fclose ($fp);
}

?>

Était-ce utile?

La solution

Pour ceux qui cherchent à l'avenir, paypal fait appel à votre gestionnaire de nouveau. Il envoie une notification à tout URL que vous avez pour notify_url sur.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top