贝宝(Paypal)在沙盒上运作良好,但在直播中效果不佳

时间:2018-10-16 21:59:39

标签: php paypal

我已经将paypal集成到了我的php网站中,并且在沙箱中工作正常,但是当我更改网址以使其正常运行时,它不会进入第一个条件

即if(!empty($ txn_id)&& $ payment_gross == $ productPrice)

进入else并返回错误。

这是我的html表单

<form class="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" id="paypal_form" onsubmit="return confSubmit();">
                <!-- Identify your business so that you can collect the payments. -->
                <input type="hidden" name="business" value="omer@website.com">                  


                <!-- Specify a Buy Now button. -->
                <input type="hidden" name="cmd" value="_xclick">
                <!-- Specify details about the item that buyers will purchase. -->
                <input type="hidden" name="item_name" value="Shipping">
                <input type="hidden" name="item_number" value="1">
                <input type="hidden" name="amount" value="<?php echo $_SESSION['s_price']; ?>">

                <input type="hidden" name="currency_code" value="EUR">

                <!-- Specify URLs -->
                <input type='hidden' name='cancel_return' value='<?php echo $path?>/paypal/payment-cancelled.php'>
                <input type='hidden' name='return' value='<?php echo $path?>/paypal/payment-successful.php'></form>

这是Payment-successful.php

$item_number = $_GET['item_number']; 
$txn_id = $_GET['tx'];
$payment_gross = $_GET['amt'];
$currency_code = $_GET['cc'];
$payment_status = $_GET['st'];

//Get product price from database
// $productResult = $db->query("SELECT price FROM products WHERE id = ".$item_number);
// $productRow = $productResult->fetch_assoc();
// $productPrice = $productRow['price'];
$productPrice = $_SESSION['s_price'];

if(!empty($txn_id) && $payment_gross == $productPrice){
    //Check if payment data exists with the same TXN ID.

    $stmt = $con->prepare("SELECT * FROM payments WHERE txnid =?");
    $stmt->execute([$txn_id]);
    $counta = $stmt->rowCount();

    if($counta > 0){

        $paymentRow = $stmt->fetch(PDO::FETCH_ASSOC);        
        $last_insert_id = $paymentRow['id'];


        //$last_insert_id is the payment id that you can show to a user 

        //$paymentRow = $prevPaymentResult->fetch_assoc();
        //$last_insert_id = $paymentRow['id'];

    }else{
        //Insert tansaction data into the database
        $stmt = $con->prepare("INSERT INTO payments(itemid,txnid,payment_amount,payment_status) VALUES(?, ?, ?, ?)");
        $stmt->execute([$item_number, $txn_id, $payment_gross, $payment_status]);
        $resu = $stmt->fetch(PDO::FETCH_ASSOC);
        $last_insert_id = $resu['id'];

    }
?>

    <script>
     //alert("Payment Successful\n Payment ID: <?php //echo $last_insert_id;?>");
   window.location.href="<?php echo $path; ?>/Pages_Error_handler/data_insert.php";
    </script>

<?php 
    exit();
}else{ ?>
    <div class="row">
    <div class="col-md-3"></div>
    <div class="col-md-6">
    <h1>Your payment has failed.</h1>
<?php } ?>
        </br>
        <input type="button" class="btn btn-success" value="DONE" onclick="window.location.href='<?php echo $path?>/views/account_shipments.php';"/>    
    </div>
    <div class="col-md-3"></div>
</div>

0 个答案:

没有答案