我正在尝试将Paypal支付整合到.NET 4.0 C#WinForm应用程序中,执行DirectPayment(无需使用paypal网站打开浏览器),从webMethod调用此方法的asmx webservices
public DoDirectPaymentResponseType DoDirectPaymentAPIOperation(string
amountinUSDollar, string creditCardType, string creditCardNumber, int
exp_month, int exp_year, string firstName, string middleName, string
lastName, string address1, string address2, string city, string state,
string zip, string phoneNumber, string CVV2)
{
DoDirectPaymentResponseType response = new
DoDirectPaymentResponseType();
DoDirectPaymentReq wrapper = new DoDirectPaymentReq();
DoDirectPaymentRequestType request = new DoDirectPaymentRequestType();
DoDirectPaymentRequestDetailsType requestDetails = new
DoDirectPaymentRequestDetailsType();
requestDetails.PaymentAction = (PaymentActionCodeType)
Enum.Parse(typeof(PaymentActionCodeType), "SALE");
CreditCardDetailsType creditCard = new CreditCardDetailsType();
PayerInfoType cardOwner = new PayerInfoType();
PersonNameType payer = new PersonNameType();
payer.FirstName = firstName;
payer.MiddleName = middleName;
payer.LastName = lastName;
cardOwner.PayerName = payer;
creditCard.CardOwner = cardOwner;
creditCard.CreditCardNumber = creditCardNumber;
if (creditCardType == "VISA")
{
creditCard.CreditCardType = CreditCardTypeType.VISA;
}
else if (creditCardType == "MasterCard")
{
creditCard.CreditCardType = CreditCardTypeType.MASTERCARD;
}
creditCard.CVV2 = CVV2;
creditCard.ExpMonth = exp_month;
creditCard.ExpYear = exp_year;
requestDetails.PaymentDetails = new PaymentDetailsType();
requestDetails.PaymentDetails.NotifyURL = "http://IPNhost";
BasicAmountType paymentAmount = new
BasicAmountType(CurrencyCodeType.USD, amountinUSDollar);
requestDetails.PaymentDetails.OrderTotal = paymentAmount;
wrapper.DoDirectPaymentRequest = request;
Dictionary<string, string> config = getConfigDict();
PayPalAPIInterfaceServiceService service = new
PayPalAPIInterfaceServiceService(config);
response = service.DoDirectPayment(wrapper);
}
当它尝试调用API时,在代码的最后一行我收到此错误: “HttpConnection中的异常执行:无效的HTTP响应请求被中止:无法创建SSL / TLS安全通道。”} System.Exception {PayPal.Exception.PayPalException}。
我有一个集成了Paypal的.NET 4.5 WebForm Web应用程序,我必须在其中定义
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
在其Global.asax文件中,它解决了该特定应用程序的问题,我发现我必须使用此
ServicePointManager.SecurityProtocol = (SecurityProtocolType) 3072;
对于.NET 4.0,但我的问题是:
如果这可能是问题的解决方案,我应该把这一行放在我的代码中?因为我的asmx webservice中没有Global.asax。
答案 0 :(得分:1)
根据OP中的评论概述上述报告问题的来源。抛出异常是因为NotifyURL
不在https
。