2013-11-01 106 views
2

我从来没有做过一个PayPal的整合,但我已经与其他门户合作。的PayPal量篡改

与其他门户有这也是形式邮递方式寄出的哈希值,这使人们无法用数据即改变量篡改。

这是如何篡改停止使用PayPal,有犯规出现任何哈希值。

<form method="post" action="https://www.sandbox.paypal.com/cgi-bin/webscr"> 
    <input type="hidden" value="_xclick" name="cmd"> 
    <input type="hidden" value="online****@theg*****.com" name="business"> 
    <!-- <input type="hidden" name="undefined_quantity" value="1" /> --> 
    <input type="hidden" value="Order" name="item_name"> 
    <input type="hidden" value="NA" name="item_number"> 
    <input type="hidden" value="22.16" name="amount"> 
    <input type="hidden" value="5.17" name="shipping"> 
    <input type="hidden" value="0" name="discount_amount">   
    <input type="hidden" value="0" name="no_shipping"> 
    <input type="hidden" value="No comments" name="cn"> 
    <input type="hidden" value="USD" name="currency_code"> 
    <input type="hidden" value="http://XXX/XXX/XXX/paypal/return" name="return"> 
    <input type="hidden" value="2" name="rm">  
    <input type="hidden" value="11255XXX" name="invoice"> 
    <input type="hidden" value="US" name="lc"> 
    <input type="hidden" value="PP-BuyNowBF" name="bn"> 
    <input type="submit" value="Place Order!" name="finalizeOrder" id="finalizeOrder" class="submitButton"> 
</form> 

那么我怎样才能阻止人们在发布到PayPal之前修改金额?即量应该是100,但人们将其更改为1

+0

这就是为什么大多数的网站介绍,用户贝宝重定向另一个页面的一个不错的审计结合起来,这个页面有最先进的最新信息并自动使用JavaScript做回发。所以基本上:检查页面>重定向>贝宝。用户仍然可以更改参数吗?是。如果你担心我会考虑贝宝的快速检出方法。所有信息都通过服务器端发送。 –

回答

0

你需要做的是实现一个简单的发票制度是什么。在您的数据库中有一个名为invoices (ID, User_Id, Invoice_Value, Payment_Status)的表(示例)。

当用户到达结账页面时,您现在应该已经在该数据库表格中为该用户插入一个条目,其总金额必须支付,并且初始支付状态为“待定”)。插入发票表格行后,获取最后一个插入标识和一个名为$invoice_id的变量。

现在,你的HTML输出PayPal支付按钮形式和隐藏的输入字段的一个应该是这样的:

<input type="hidden" value="<?php echo $invoice_id; ?>" name="custom"> 

现在,贝宝与IPN响应来回报您的网址,您的IPN处理程序应沿着这种方式行事:

<?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"; 
} 

// 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 ('ssl://sandbox.www.paypal.com', 443, $errno, $errstr, 30); 
if (!$fp) { 
    // HTTP ERROR 
} 
else 
{ 
    // Make Request To PayPal 
    fputs ($fp, $header . $req); 
    while (!feof($fp)) 
    { 
     // Read Response 
     $res = fgets ($fp, 1024); 

     // Check Response 
     if (strcmp ($res, "VERIFIED") == 0) 
     { 
      // PAYMENT VALIDATED & VERIFIED! 

      // Load the Invoice_Value from invoices table for $_POST['custom'] 
      // and compare it with paypal posted amount held in $_POST['mc_gross'] 
      // if it matches, paypal has authenticated the payment and the value has not been tampered with 
      // update the invoice table and set the payment status 
     } 
     else if (strcmp ($res, "INVALID") == 0) 
     { 
      // PAYMENT INVALID & INVESTIGATE MANUALY! 
     } 
    } 
    fclose ($fp); 
} 

?> 
+0

虽然我同意这会起作用,但它不会停止初始付款。 我真的想停止初始付款,否则我将不得不手动处理订单的退款。 但我同意,无论哪种方式,我想检查支付金额与订单金额。 – user2183216

5

有几种方法来防止这种情况。首先是使用PayPal的Instant Payment Notification(IPN)。使用这种方法,您可以比较PayPal发回给您的价格,以确认它们符合您的期望。如果它们不匹配,则取消订单。

示例工作流:

  • 用户订单项,并修改价格为$ 0.01
  • 令发布到贝宝,这说明港币$ 0.08的价格
  • 用户接受的价格和支付$ 0.01
  • 贝宝电话您的IPN的网址和岗位交易详情,显示该用户支付$ 0.01的事
  • 你IPN检查,贝宝收到的对价($ 0.01)VERUS你期待什么(> $ 0.01)。由于它们不匹配,您取消订单

PayPal IPN Flow

另一种选择,就是使用PayPal的Button API,创建动态,加密buttons。这些内容嵌入到您的页面中,用户点击它以进行订购。由于它是加密的,用户无法在交易过程中可靠地修改源代码。 answer中有一个很好的例子。此外,你可以将它与上面列出的IPN选项作为交易

+1

虽然我同意,付款仍然会通过,你可以退还的人,但你会出30美分:) –