5

I am using PayPalStandard plugin of NopCommerce. When I placed the order & make payment with paypalstandard plugin after successful payment on paypal, it redirects to merchants site. At that time it gives error:

The request was aborted: Could not create SSL/TLS secure channel.

Also I am using Sandbox account of Paypal for testing.

It throws error from this line:

var sw = new StreamWriter(req.GetRequestStream()

Here is code below:

var req = (HttpWebRequest)WebRequest.Create(GetPaypalUrl());
        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded";
        req.ProtocolVersion = HttpVersion.Version10;

        string formContent = string.Format("cmd=_notify-synch&at={0}&tx={1}", _paypalStandardPaymentSettings.PdtToken, tx);
        req.ContentLength = formContent.Length;

        using (var sw = new StreamWriter(req.GetRequestStream(), Encoding.ASCII))
            sw.Write(formContent);
chitra
  • 556
  • 1
  • 4
  • 14
  • I started to see this happening a day or so ago. Perhaps an issue with the certificate of https://www.sandbox.paypal.com/? – bustrofedon Jan 22 '16 at 11:31
  • 9-10 months ago it doesn't throws any error with sandbox. Is it issue of sandbox? – chitra Jan 22 '16 at 11:40
  • Also this code works with paypal account successfully. It happens with sandbox account only. So it is issue of sandbox account? – chitra Jan 22 '16 at 11:48

2 Answers2

17

I had the same issue connecting to sandbox(nvp), everything was fine then yesterday the message "The request was aborted: Could not create SSL/TLS secure channel." appeared.

I believe PayPal updated their endpoints on 19/20 January 2016 to use TSL 1.2 and HTTP 1.1.

To resolve this, for .NET 4.5 and above add the following line of code before calling WebRequest.Create().

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
nqynik
  • 271
  • 3
  • 7
  • Thank you very much @nqynik. This resolved my issue. – chitra Jan 23 '16 at 08:03
  • 1
    This answer helps me too. One thing that you should add in your answer: `SecurityProtocolType.Tls12` is only available in .NET 4.5 or above, so if the target framework is .NET 4.0 then you will need to change the target framework. – ekad Jan 30 '16 at 01:50
  • You are a savior. Hopefully Microsoft updates its PayPal tutorial!!1 – Jose A Feb 14 '16 at 22:28
  • If you are using .Net 4.0 then you wouldn't get option for SecurityProtocolType.Tls12, in that case you can use following code: ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // SecurityProtocolType.Tls12 As given at this link- http://stackoverflow.com/questions/34939523/the-request-was-aborted-could-not-create-ssl-tls-secure-channel-sandbox-account – ramya Mar 23 '16 at 13:15
0

The answer that worked for us was listed on the PayPal blog post, Upcoming Security Changes Notice. There are a number of things listed in the post, but the one thing which we did, and that worked, was PayPal SDK Updates. We updated using NuGet and everything started working again.

jalayo
  • 43
  • 5