2013-03-21 75 views
3

我們正在使用WorldPay的時間來處理分層會員制,爲此支付的金額差異取決於所選擇的會員級別付款。驗證支付金額與WorldPay的

支付經由形式後傳遞給WorldPay的從多個隱藏字段,其中包括:

<input type="hidden" name="amount" value="295.00" /> 

本質上,形式是通過POST提交WorldPay工作,並且用戶遵循若干步驟,過程他們的付款。完成後,用戶將被重定向到指定的確認頁面。

這似乎是在其中WorldPay的接受付款的典型方式。這裏存在一個明顯的問題,那就是隱藏字段的價值很容易被任何具有HTML基本知識的人篡改。該表格直接發佈到WorldPay,所以我們沒有用於驗證會員級別數量的PostBack。

我們必須驗證時付款通知是由路由通過確認頁之前的處理程序回調返回給我們從WorldPay的付款金額的選項;不過,我想避免在用戶提交表單篡改,支付金額不正確,並沒有收到會員的情況下,則必須聯繫該公司有自己的錢退還。

我們如何驗證提交的金額是否正確之前處理付款?

更新

它發生,我認爲我們有另外一個問題,由此,即使我們驗證表單後服務器端,有什麼能夠阻止惡意用戶欺騙形式後直接到WorldPay的。

+0

您是否嘗試過具有中間頁? – Yahya 2013-03-21 10:17:56

+0

[綜合實例(http://www.worldpay.com/support/bg/index.php?page=development&sub=integration&subsub=examples) – 2013-03-21 10:22:12

回答

-1

一個解決方案,我能想到的就是這一點,捕捉form標籤的submit

<form id="myForm" onsubmit="return validatePayment();"> 

,然後創建JavaScript文件,看起來像這樣:

var isValidAmount = false; 

function validatePayment() { 
    if (isValidAmount) { return true; } 

    // in here you want to issue an AJAX call back to your server 
    // with the appropriate information ... I would recommend using 
    // jQuery and so it might look something like this: 
    $.ajax({ 
     type: "POST", 
     url: url, 
     data: { amount: $("#amount").val(), someotherfield: somevalue }, 
     success: function(data, textStatus, jqXHR) { 
      // set the flag so that it can succeed the next time through 
      isValidAmount = true; 

      // resubmit the form ... it will reenter this function but leave 
      // immediately returning true so the submit will actually occur 
      $("myForm").submit(); 
     }, 
    }); 

    // this will keep the form from actually submitting the first time 
    return false; 
} 
+0

我不知道,這個解決我的問題 - 用戶可以簡單地關掉Javascript和表單郵件將立即發佈到WorldPay,其系統不會更聰明。 – 2013-03-21 11:31:16