【发布时间】:2016-04-29 21:25:10
【问题描述】:
这不是一个编码问题,但我想了解发生了什么。这是我第一次必须集成 PayPal,因此我使用了沙盒环境和带有硬编码值的简单示例。
对于 SetExpressCheckoutRequest,假设付款值为 x,一切正常(买方同意,代币退回)。然后我意识到需要 DoExpressCheckoutPayment 来完成它,所以我使用了更多示例代码,它也运行良好。
在 DoExpressCheckoutPayment 代码示例中,假定支付值 y。如前所述,我只想让最基本的工作正常工作,并没有费心去绑定值等。
现在让我感到惊讶的是:PayPal 沙盒账户中显示的实际交易金额不是买家批准的值 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
}
这只是沙盒行为吗?推翻买家同意的价值肯定不是那么容易吗?我错过了什么?
【问题讨论】:
标签: c# paypal paypal-sandbox