Viincenttt / MollieApi

This project allows you to easily add the Mollie payment provider to your application.
MIT License
150 stars 85 forks source link

Unsupported Input Received with Status Code 415 (Unsupported Media Type) #256

Closed tfjanjua closed 3 years ago

tfjanjua commented 3 years ago

Hi, I am trying to calling https://api.mollie.com/v2/payments url from my backend by using httpClient.PostAsync.

So, initially it was responding me "Could not create SSL/TLS secure channel" error so then I followed this https://github.com/AuthorizeNet/sdk-dotnet/issues/203 and after adding the suggested 3 lines of code right before calling post method of httpClient and then its responding "Unsupported Input Received" with 415 status code.

// Code sample

public class MollieHelper
    {
        private readonly HttpClient httpClient = new HttpClient();
        public MollieHelper(string accessToken)
        {
            this.httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
            this.httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        }

        public async Task<object> PostAsync(string url, object obj)
        {
            // Suggested code from https://github.com/AuthorizeNet/sdk-dotnet/issues/203
            const SslProtocols sslProtocols = (SslProtocols)0x00000C00;
            const SecurityProtocolType securityProtocolType = (SecurityProtocolType)sslProtocols;
            ServicePointManager.SecurityProtocol = securityProtocolType;

            var response = await this.httpClient.PostAsync(new Uri(url), new StringContent(JsonConvert.SerializeObject(obj)));
            if (!response.IsSuccessStatusCode)
            {
                return null;
            }
            var result = await response.Content.ReadAsStringAsync();
            var data = JsonConvert.DeserializeObject(result);
            return data;
        }
    }

and I am sending data like { "amount": { "currency": "EUR", "value": "30" }, "description": "Please select the payment method", "redirectUrl": "https://mydomain.com" }

Viincenttt commented 3 years ago

Hi @tfjanjua ,

Take a look at the following issue to find several workarounds for any SSL version issues: https://github.com/Viincenttt/MollieApi/issues/236

Kind regards, Vincent