这不是一个编码问题,但我想了解发生了什么。这是我第一次不得不整合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