Viincenttt / MollieApi

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

Body of PaymentRequest is empty #257

Closed BlackWolves-nl closed 3 years ago

BlackWolves-nl commented 3 years ago

When i try to Create a Payment their is no body being sent with the request. Resulting in a error from mollie api. I'm using the following code: IPaymentClient paymentClient = new PaymentClient(configuration.Single(x => x.Key == "MollieApiKey").Value); PaymentRequest paymentRequest = new PaymentRequest() { Amount = new Amount(Mollie.Api.Models.Currency.EUR, amount), Description = paymentOrder.Description, RedirectUrl = returnUrl }; return await paymentClient.CreatePaymentAsync(paymentRequest);

This wil result in the following http request and response: POST https://api.mollie.com/v2/payments HTTP/1.1 Host: api.mollie.com Accept: application/json Authorization: Bearer test_mykey

HTTP/1.1 422 Unprocessable Entity Server: nginx Date: Thu, 21 Oct 2021 10:12:16 GMT Content-Type: application/hal+json Content-Length: 215 Strict-Transport-Security: max-age=31536000; includeSubDomains; preload

{"status":422,"title":"Unprocessable Entity","detail":"The amount is required for payments","field":"amount","_links":{"documentation":{"href":"https://docs.mollie.com/overview/handling-errors","type":"text/html"}}}

A logical error from the mollie api. But how is my body of the request empty.

Using the latest version from nuget and running in .Net 5.0.

Any ideas?

Viincenttt commented 3 years ago

Hi @BlackWolves-nl ,

I'm not sure what's going on, the code you have provided looks good. In fact, I have an integration test with the exact same code that seems to pass just fine: https://github.com/Viincenttt/MollieApi/blob/2d1c366bc5229776fe2c7599e14354dd714dd1e8/Mollie.Tests.Integration/Api/PaymentTests.cs#L68

Could you try running the integration test to see if you have the same issue?

Kind regards Vincent

BlackWolves-nl commented 3 years ago

Hi @Viincenttt ,

I downloaded the master code and run the test. The tests are running fine. (with the expected errors for some payment methods to be disabled).

What i do notice is that the package version in the master code is 2.1.0.7 instead of 2.1.0.8. (Or does that have something todo with your build system?)

I tried compiling and using the dll from the master brench but that gives me same error. I tried updating newtonsoft in the mollie solution to 13 (same as in my solution). But then the tests also run fine.

Monday I will import the mollie project into my solution and try to debug from there and see if that will yield any results.

BlackWolves-nl commented 3 years ago

Hi @Viincenttt ,

Importing the project did not gave me more info. (All the same results. Including the tests below) But I did some more testing.

When i run the code in a fresh .net 5.0 console application it works. When I run the code in my existing .net 5.0 test console application it works. When I have the code in my business library (.net standard 2.1) and call that from the console app above it does not work.

When i run the code in both console and library in the same session. The code from the console works but from the library it does not.

I'll keep trying. But if you have any tips or ideas. Please let me know. Cause my head is spinning atm :P.

BlackWolves-nl commented 3 years ago

Hi @Viincenttt ,

Uhmm. There was a hidden newline character in the apikey(at the end) that was being used in the business library. That somehow blocks anything from being outputted after that. All works now.

Viincenttt commented 3 years ago

Good to hear it's working now!