HOME


Mini Shell 1.0
DIR: /home/islapiiu/.cagefs/tmp/
Upload File :
Current File : /home/islapiiu/.cagefs/tmp/phpVmA98Y
home/islapiiu/sites/pramudi/payments.php000064400000005141150766003710014462 0ustar00<?php
include './class/include.php';
if (!isset($_SESSION)) {
    session_start();
}
?>
<h1>Your payment has been successful.</h1>
<?php
// dd($_POST);
//Store transaction information into database from PayPal
$item_number = $_POST['item_number'];
$txn_id = $_POST['txn_id'];
$payment_gross = $_POST['payment_gross'];
$currency_code = $_POST['mc_currency'];
$payment_status = $_POST['payment_status'];
//Get product price to store into database
$ORDER1 = new Order(NULL);
if (verifyTransaction($_POST)) {
// if (verifyTransaction($_POST) && $ORDER1->checkTxnid($txn_id)) {
    $ORDER = new Order($item_number);
    // dd(!empty($txn_id) && $payment_gross == $ORDER->amount);
    if (!empty($txn_id)) {
        //Insert tansaction data into the database
        $ORDER->paymentStatusCode = 2;
        $ORDER->statusCode = $payment_status;
        $ORDER->status = 1;
        $ORDER->txnid = $txn_id;
        // dd($ORDER);
        $res12 = $ORDER->updatePaymentStatusCodeAndStatus();
        unset($_SESSION["shopping_cart"]);
        if ($res12) {
            redirect('cart.php?status=success');
        }
    } else {
        redirect('checkout.php?status=error');
    }
}


function verifyTransaction($data)
{
    // global $paypalUrl;
    $req = 'cmd=_notify-validate';
    foreach ($data as $key => $value) {
        $value = urlencode(stripslashes($value));
        $value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i', '${1}%0D%0A${3}', $value); // IPN fix
        $req .= "&$key=$value";
    }
    $ch = curl_init('https://ipnpb.sandbox.paypal.com/cgi-bin/webscr');
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
    curl_setopt($ch, CURLOPT_SSLVERSION, 6);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
    $res = curl_exec($ch);
    if (!$res) {
        $errno = curl_errno($ch);
        $errstr = curl_error($ch);
        curl_close($ch);
        throw new Exception("cURL error: [$errno] $errstr");
    }
    $info = curl_getinfo($ch);
    // Check the http response
    $httpCode = $info['http_code'];
    if ($httpCode != 200) {
        throw new Exception("PayPal responded with http code $httpCode");
    }
    curl_close($ch);
    return $res === 'VERIFIED';
}


// dd($payment_status);

?>