3

我想实现 Paypal dodirect 方法,用户可以直接在我的网站上付款,而不是重定向到用户

所以为此我已将此 URL 添加为https://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl

我正在使用以下代码

PayPalAPIAAInterfaceClient objpaypalapiaainterfaceclient = new PayPalAPIAAInterfaceClient("paypalapiaa");
        CustomSecurityHeaderType objcustomsecurityheadertype = new CustomSecurityHeaderType();
        objcustomsecurityheadertype.Credentials = new UserIdPasswordType();
        objcustomsecurityheadertype.Credentials.Signature = "a8ft-8ji.2tzocnfshfjj4ahgxn4avlxzply8bmsbupxafkbty2--c6p";
        objcustomsecurityheadertype.Credentials.Username = "fred_1350925179_biz_api1.gmail.com";
        objcustomsecurityheadertype.Credentials.Password = "1350925199";

        DoDirectPaymentReq objdodirectpaymentreq = new DoDirectPaymentReq();
        objdodirectpaymentreq.DoDirectPaymentRequest = new DoDirectPaymentRequestType();
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType();
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentAction = new PaymentActionCodeType();
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentAction = PaymentActionCodeType.Sale;
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails = new PaymentDetailsType();
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard = new CreditCardDetailsType();
        //objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails.InvoiceID = "1";
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.IPAddress = Request.ServerVariables["remote_addr"].ToString();

        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.MasterCard;

        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal = new BasicAmountType();
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner = new PayerInfoType();
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName = new PersonNameType();
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.currencyID = CurrencyCodeType.USD;
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address = new AddressType();
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.Value = "120";
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CreditCardNumber ="1111222233334444";
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CVV2 = "258";
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.ExpMonth = 9;
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.ExpYear = 2013;
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Payer = "rahularyansharma@gmail.com";
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.FirstName = "Shakti";
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.LastName = "Kapoor";
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street1 ="test address";
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CityName = "Atlanta";
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.StateOrProvince = "ga";
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Country = CountryCodeType.US;
        objdodirectpaymentreq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.PostalCode = "12345";
        DoDirectPaymentResponseType objdodirectpaymentresponsetype = objpaypalapiaainterfaceclient.DoDirectPayment(ref objcustomsecurityheadertype, objdodirectpaymentreq);

现在,当我运行此代码时会抛出以下异常

' 请求被中止:无法创建 SSL/TLS 安全通道。说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。异常详细信息:System.Net.WebException:请求已中止:无法创建 SSL/TLS 安全通道。

4

2 回答 2

1

您可以使用https://www.ssllabs.com/ssltest确认https://www.sandbox.paypal.com的 SSL 协议 。屏幕截图显示它支持 TLS 1.2在进行 httpclient 调用时,您需要在代码中添加以下两行:在此处输入图像描述

ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

示例:在此处输入图像描述 实现应该解决问题。

于 2017-10-30T15:46:23.267 回答
0

抱歉,我无法将此添加为评论/问题。

似乎贝宝的证书之一不在受信任的列表中。

您可以尝试下载贝宝根证书并将其安装为受信任的 CA 吗?

我认为这两个链接可以帮助你: https ://www.sslshopper.com/ssl-certificate-not-trusted-error.html 和 http://raysilvadotnet.wordpress.com/2014/02/13/problema-system -net-webexception-the-request-was-aborted-could-not-create-ssltls-secure-channel/ (对不起,不能插入超过 2 个链接作为正常链接)

另外,请确保您通过登录名/密码而不是证书进行身份验证。如果您使用 API 证书,则应遵循此链接的最后一段

于 2014-10-28T16:59:51.767 回答