这发生在沙盒或生产中。在沙箱中,如果我输入带有代码和到期日期的 4111111111111111 签证...当我点击 payment.Creat(token) 行时,会引发异常,“流不可读”。如果我输入一些其他的 CC 号码,例如 4234567890123456,付款就可以了。在生产中,如果我使用那个 4234... 我得到流不可读错误。我了解测试卡并不总是有效,但我希望收到信用卡无效响应。我遇到的问题是我的一些客户遇到了流错误......所以有时它会正确发回,有时是 Stream 错误......我最近使用 Nuget 将包更新为最新和最好的 API,
这是我的相关代码 try { var token = GetAPIToken();
var creditCard = new CreditCard();
creditCard.number = req.CardNumber;
creditCard.expire_month = req.ExpMonth;
creditCard.expire_year = req.ExpYear;
creditCard.first_name = req.FirstName;
creditCard.last_name = req.LastName;
creditCard.type = req.CardType;
creditCard.payer_id = req.UserId.ToString();
creditCard.cvv2 = req.SecurityCode;
creditCard.billing_address = new Address()
{
line1 = req.Address1,
city = req.City,
state = req.State,
postal_code = req.ZipCode,
country_code = "US"
};
var payment = new Payment();
payment.intent = "sale";
payment.payer = new Payer();
payment.transactions = new List<Transaction>();
var t = new Transaction()
{
description = req.Description,
amount = new Amount()
{
total = req.TotalPayment.ToString("N2"),
currency = "USD",
},
};
t.item_list = new ItemList();
t.item_list.items = new List<Item>();
t.item_list.items.Add(new Item()
{
name = req.Description,
quantity = "1",
price = req.TotalPayment.ToString("N2"),
currency = "USD",
});
payment.transactions.Add(t);
payment.payer.funding_instruments = new List<FundingInstrument>();
payment.payer.payment_method = "credit_card";
var fundingInstrument = new FundingInstrument();
fundingInstrument.credit_card = creditCard;
payment.payer.funding_instruments.Add(fundingInstrument);
var pay = payment.Create(token);
if (req.PaymentOption != PayOption.UsePayPal && pay.state == PayPalStateApproved
&& pay.transactions.Any() && pay.transactions[0].related_resources.Any()
&& pay.transactions[0].related_resources[0].sale != null
&& !String.IsNullOrEmpty(pay.transactions[0].related_resources[0].sale.id))
{
resp.TransactionID = pay.transactions[0].related_resources[0].sale.id;
}
else
{
resp.Status = Status.Error;
resp.Messages.Add(new Message { Code = "paypal", Text = pay.state });
}
}
catch (Exception ex)
{
var err = CheckPayPalError(ex);
resp.Messages.Add(new Message { Code = "paypal", Text = String.IsNullOrEmpty(err) ? ex.Message : err });
resp.Status = Status.Error;
}
return resp;
这是日志条目,第一个是如果重试设置为> 0,第二个是不重试 2013-08-29 09:41:45,852 [33] DEBUG PayPal.PayPalResource [(null)] User-Agent:PayPalSDK /rest-sdk-dotnet 0.7.3 ;lang=DOTNET;v=4.0.30319.18052;bit=64;os=Windows 7 6.1.7601.65536; 2013-08-29 09:41:45,852 [33] 调试 PayPal.PayPalResource [(null)] PayPal-Request-Id:a781e6bb-c0b0-4f06-abf8-1202dbc17a59 2013-08-29 09:41:45,920 [33]调试 PayPal.Manager.ConnectionManager [(null)] {"intent":"sale","payer":{"payment_method":"credit_card","funding_instruments":[{"credit_card":{"number":"4234567890123456 ","type":"visa","expire_month":5,"expire_year":2015,"cvv2":"123","first_name":"MIckey","https://developer.paypal.com/webapps/developer/docs/api/#INTERNAL_SERVICE_ERROR","debug_id":"2520071cde1ca"} 2013-08-29 09:41:49,506 [33] INFO PayPal.Manager.ConnectionManager [(null)] 从服务器 2013-08-29 09:41:49,507 获得 InternalServerError 状态代码[33] 错误 PayPal.Exception.PayPalException [(null)] HttpConnection Execute 中的异常:Stream 不可读。PayPal.Exception.PayPalException:HttpConnection Execute 中的异常:Stream 不可读。---> System.ArgumentException:Stream 是不可读。在 System.IO.StreamReader..ctor(Stream stream) 在 PayPal.HttpConnection.Execute(String payLoad) , HttpWebRequest httpRequest) --- 内部异常堆栈跟踪结束 ---
这是第二个 2013-08-29 09:44:27,685 [16] DEBUG PayPal.PayPalResource [(null)] User-Agent:PayPalSDK/rest-sdk-dotnet 0.7.3 ;lang=DOTNET;v=4.0.30319.18052 ;bit=64;os=Windows 7 6.1.7601.65536; 2013-08-29 09:44:27,686 [16] 调试 PayPal.PayPalResource [(null)] PayPal-Request-Id:1d5c68e5-4b4b-4876-8bf4-3b9f64d0afb6 2013-08-29 09:44:27,753 [16]调试 PayPal.Manager.ConnectionManager [(null)] {"intent":"sale","payer":{"payment_method":"credit_card","funding_instruments":[{"credit_card":{"number":"4234567890123456 ","type":"visa","expire_month":5,"expire_year":2015,"cvv2":"123","first_name":"MIckey","last_name":"Keenan","billing_address": {"https://developer.paypal.com/webapps/developer/docs/api/#INTERNAL_SERVICE_ERROR ","debug_id":"465701e606a56"} 2013-08-29 09:44:28,848 [16] 信息 PayPal.Manager.ConnectionManager [ (空)]从服务器 2013-08-29 09:44:28,850 [16] 错误 PayPal.Exception.PayPalException [(null)] HttpConnection 执行中的异常 PayPal.Exception.PayPalException:HttpConnection 执行中的异常