2016-02-06 109 views
0

我的PayPal快速檢出工作之前,我試圖爲優惠券折扣添加負值。基本上我無法理解我的編碼如何傳遞一個負值。請參閱我的腳本如下:無法在PayPal快速結賬時傳遞負值

//pass all products 

foreach($_POST['item_name'] as $key=>$itmname) 
{ 
    $product_code = filter_var($_POST['item_code'][$key], FILTER_SANITIZE_STRING); 

    $results = $dbh->query("SELECT name, price FROM products WHERE id='$product_code' LIMIT 1"); 
    $obj = $results->fetch_object(); 

    $paypal_data .= '&L_PAYMENTREQUEST_0_NAME'.$key.'='.urlencode($obj->name). 
        '&L_PAYMENTREQUEST_0_NUMBER'.$key.'='.urlencode($_POST['item_code'][$key]). 
        '&L_PAYMENTREQUEST_0_AMT'.$key.'='.urlencode($obj->price).  
        '&L_PAYMENTREQUEST_0_QTY'.$key.'='. urlencode($_POST['item_qty'][$key]); 

    // item price X quantity 
    $subtotal = ($obj->price*$_POST['item_qty'][$key]); 

    //total price 
    $ItemTotalPrice = $ItemTotalPrice + $subtotal; 

} 

############################################## 
// Trying to pass a negative value in this way 

if($_SESSION["Coupon_discount"] > $ItemTotalPrice){ 
     $cname = "Coupon Discount"; 
     $ccode = "code"; 
     $cqty = 1; 
     $camt = 5; 
    $paypal_data .= '&L_PAYMENTREQUEST_0_NAME='.urlencode($cname). 
        '&L_PAYMENTREQUEST_0_NUMBER='.urlencode($ccode). 
        '&L_PAYMENTREQUEST_0_QTY='.urlencode($cqty). 
        '&L_PAYMENTREQUEST_0_AMT='.urlencode($camt);   
} 
############################################## 


// Others Paypal process 
$TotalTaxAmount  = 0; 
$HandalingCost = 0; 
$InsuranceCost = 0; 
$ShippinDiscount = 0; 
$ShippinCost  = 0; 

$GrandTotal = ($ItemTotalPrice + $TotalTaxAmount + $HandalingCost + $InsuranceCost + $ShippinCost + $ShippinDiscount); 

$padata = '&METHOD=SetExpressCheckout'. 
      '&RETURNURL='.urlencode($PayPalReturnURL). 
      '&CANCELURL='.urlencode($PayPalCancelURL). 
      '&PAYMENTREQUEST_0_PAYMENTACTION='.urlencode("SALE"). 
      $paypal_data.    
      '&NOSHIPPING=0'. 
      '&PAYMENTREQUEST_0_ITEMAMT='.urlencode($ItemTotalPrice). 
      '&PAYMENTREQUEST_0_TAXAMT='.urlencode($TotalTaxAmount). 
      '&PAYMENTREQUEST_0_SHIPPINGAMT='.urlencode($ShippinCost). 
      '&PAYMENTREQUEST_0_HANDLINGAMT='.urlencode($HandalingCost). 
      '&PAYMENTREQUEST_0_SHIPDISCAMT='.urlencode($ShippinDiscount). 
      '&PAYMENTREQUEST_0_INSURANCEAMT='.urlencode($InsuranceCost). 
      '&PAYMENTREQUEST_0_AMT='.urlencode($GrandTotal). 
      '&PAYMENTREQUEST_0_CURRENCYCODE='.urlencode($PayPalCurrencyCode). 
      '&LOCALECODE=GB'. 
      '&LOGOIMG=http://www.myweb.com/images/logo.png'. 
      '&CARTBORDERCOLOR=000000'. 
      '&ALLOWNOTE=1'; 

    // SetExpressCheckOut method to obtain paypal token 

    $paypal= new MyPayPal(); 
    $httpParsedResponseAr = $paypal->PPHttpPost('SetExpressCheckout', $padata, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode); 

    // Success or Error done here 

這裏問題明星之後添加這些行

if($_SESSION["Coupon_discount"] > $ItemTotalPrice){ 
     $cname = "Coupon Discount"; 
     $ccode = "code"; 
     $cqty = 1; 
     $camt = 5; 
    $paypal_data .= '&L_PAYMENTREQUEST_0_NAME='.urlencode($cname). 
        '&L_PAYMENTREQUEST_0_NUMBER='.urlencode($ccode). 
        '&L_PAYMENTREQUEST_0_QTY='.urlencode($cqty). 
        '&L_PAYMENTREQUEST_0_AMT='.urlencode($camt);   
} 
+0

以這種方式顯示錯誤超時10001 – koc

回答

1

這一個讓我微笑。基本上,某人只能將資金轉入您的帳戶,否則聰明人可能會使用負值來耗盡您的帳戶。它的安全性。

+0

所有金額將來自我的數據庫。但是作爲測試目的,我使用會話變量。謝謝。 – koc