0

I'm getting the following error when using stripe payment (test mode) on a ASP.MVC 4.0 application, published in 1and1 shared hosting:

Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. Does anyone has faced similar errors? I've read that shared hosting may have something to do because it uses "medium trust" configuration, but it's difficult to accept that stripe can not be used in shared hosting accounts (most websites runs in shared hosting I believe)

Thanks a lot!

rafa0212
  • 3
  • 2

1 Answers1

0

I have had the same issues. There seems to be an issue with the checks being performed to make sure your server wasn't redirected after the heartbleed issues. I am working with the author of the stripe.net nuget library to get it fixed. If you want to fix it yourself, head over to the Infrastructure\Requestor.cs file and edit the following section (I commented out the problem areas). After doing this you can run stripe.net in medium trust.

private static string ExecuteWebRequest(WebRequest webRequest)
    {
        //var verificationCallback = new RemoteCertificateValidationCallback(StripeCertificateVerificationCallback);

        try
        {
            //ServicePointManager.ServerCertificateValidationCallback += verificationCallback;

            using (var response = webRequest.GetResponse())
            {
                return ReadStream(response.GetResponseStream());
            }
        }
        catch (WebException webException)
        {
            if (webException.Response != null)
            {
                var statusCode = ((HttpWebResponse)webException.Response).StatusCode;

                var stripeError = new StripeError();

                if(webRequest.RequestUri.ToString().Contains("oauth"))
                    stripeError = Mapper<StripeError>.MapFromJson(ReadStream(webException.Response.GetResponseStream()));
                else
                    stripeError = Mapper<StripeError>.MapFromJson(ReadStream(webException.Response.GetResponseStream()), "error");

                throw new StripeException(statusCode, stripeError, stripeError.Message);
            }

            throw;
        }
        finally
        {
            //ServicePointManager.ServerCertificateValidationCallback -= verificationCallback;
        }
    }
Justin
  • 553
  • 4
  • 6
  • So, publishing on ssl configurated site will allow me to uncomment those lines, isn't it? – rafa0212 Jul 16 '14 at 02:30
  • No, I have tried that and it fails as well. If you are using a version of .net that is 4.0 or below this code will fail every time. If you are using 4.5+ you can actually keep everything commented like above and change the code (on the same .cs codepage). [github issue update](https://github.com/jaymedavis/stripe.net/pull/156#issue-31293572) – Justin Jul 16 '14 at 14:55