這不是一個編碼問題,但我想了解發生了什麼。這是我第一次不得不整合PayPal,所以我使用了沙盒環境和帶有硬編碼值的簡單樣本來開始。PayPal Express DoExpressCheckoutPayment Charged Amount
對於SetExpressCheckoutRequest,假設支付值爲x,一切正常(買家同意,令牌返回)。然後我意識到需要使用DoExpressCheckoutPayment來完成它,所以我使用了更多的示例代碼,而且它也工作得很好。
在DoExpressCheckoutPayment代碼示例中,假定支付值爲y。如上所述,我只是想讓裸骨的工作,並沒有打擾在價值等。
現在這是什麼讓我感到驚訝:貝寶沙箱帳戶中顯示的實際交易金額不是價值x的買方已批准,但是來自DoExpressCheckoutPayment的價值爲y。這裏的簡化示例代碼:
public ActionResult RunSample()
{
//...
PaymentDetailsItemType[] pdItem = new PaymentDetailsItemType[1];
pdItem[0] = new PaymentDetailsItemType()
{
Amount = new BasicAmountType() { currencyID = CurrencyCodeType.USD, Value = 1.50},
//...
};
var resp = new PayPalAPIAAInterfaceClient().SetExpressCheckout(ref type, req);
//...
return new RedirectResult(string.Format("{0}?cmd=_express-checkout&token={1}",
"https://www.sandbox.paypal.com/cgi-binwebscr?cmd=_express-checkout&token=EC-xxxxx", resp.Token));
}
public ActionResult RunSampleResult(string token, string payerId)
{
// result returned, buyer agreed to 1.50
var NVP = "METHOD=DoExpressCheckoutPayment";
//NVP += ...;
NVP += "&PAYMENTREQUEST_0_AMT=100";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api-3t.sandbox.paypal.com/nvp");
//...
string sResponse = string.Empty;
using (StreamWriter sw = new StreamWriter(request.GetRequestStream()))
{
sw.Write(NVP);
}
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
// => 100 is charged, not the 1.50 agreed to
}
這就是沙箱行爲嗎?當然,要超越買方同意的價值並不容易?我錯過了什麼?
謝謝,有道理 – devlock