ATutor

Learning Management Tools







Pages:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15


Strange Is this a permissions problem or something


  • 2007-07-20 13:26:39

    Strange Is this a permissions problem or something

    I've tried out the Payments module and its working fine. However, I'm using the same kind of code, but then something seems amiss. My ipn_response.php file is something like this:

    [php]
    <?php
    $_user_location = 'public';
    define('AT_INCLUDE_PATH', '../../include/');
    require(AT_INCLUDE_PATH.'vitals.inc.php');
    require('verify.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";
    }

    $host = parse_url($_config['cc_url']);
    $host = $host['host']; // either www.sandbox.paypal.com or just www.paypal.com
    if (strcasecmp($host, 'www.sandbox.paypal.com') && strcasecmp($host, 'www.paypal.com')) {
    // don't want to post this to the wrong URI
    exit;
    }

    // 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($host, 80, $errno, $errstr, 30);
    if (!$fp) { exit; }

    // 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_payment_status = check_payment_status($payment_status);
    if($check_payment_status == 1) {
    $txn_id_status = check_txn_id($txn_id);
    if(!($txn_id_status)) {
    //The transaction is a genuine first time transaction. So insert the details into the database after checking the receiver email
    if($receiver_email == $_config['cc_receiver_email']) {
    //Receiver verified. Final check for the payment_amount using the item_number
    $correct_amount = check_for_correct_item($item_number,$payment_amount);
    if($correct_amount) {
    //Everything is verified at this stage. Now insert the transaction_id into the database
    $final_result = insert_txn_id($item_number,$payment_amount,$txn_id);
    $type_id = determine_course_or_combo($item_number,$payment_amount,$txn_id);
    //$type_id[0] = 1 => course_id, $type_id[0] = 0 => combo_id, $type_id[1] will contain either the course_id or combo_id depending on the type
    $result_member = validate_payment($type_id);
    }
    }

    }
    else echo "Fraud Transaction!!";
    }
    }
    else if (strcmp ($res, "INVALID") == 0) {
    // log for manual investigation
    }
    }
    fclose ($fp);
    }

    $myFile = "logfile.txt";
    $fh = fopen($myFile, 'w') or die("can't open file");
    $stringData = "Done\n";
    fwrite($fh, $stringData);
    $stringData = "Writing\n";
    fwrite($fh, $stringData);
    fclose($fh);

    ?>
    [/php]

    PayPal is unable to contact this file at all I guess... What could be the problem?

  • 2007-07-20 15:33:31

    Re: Strange... Is this a permissions problem or something?

    I accidentally used $_SESSION[member_id] instead of $member_id in the script... Anyways, problem solved now...