Adyen / adyen-dotnet-api-library

Adyen API Library for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid URI: The format of the URI could not be determined

oldtune opened this issue · comments

Describe the bug
I'm trying to spin up my integration using the test envionment but keep getting the exception while trying to create a checkout /session
The value for returnUrl is: https://bfec-58-187-189-4.ap.ngrok.io/webhook/adyen-notification.
According to https://docs.adyen.com/api-explorer/Checkout/69/post/sessions. My provided returnUrl has the same format with the example but the exception is throw.

To Reproduce
Steps to reproduce the behavior:
Here's my function

        public async Task CreateCheckoutSession(long amount)
        {
            var checkout = new Checkout(_adyenClient);
            var paymentSetupRequest = new PaymentSetupRequest(merchantAccount: _adyenOptions.MerchantAccount,
            returnUrl: "https://bfec-58-187-189-4.ap.ngrok.io/webhook/adyen-notification",
            reference: Guid.NewGuid().ToString(),
            countryCode: "AUS",
            amount: new Amount(currency: "AUS", value: amount));

            var result = await checkout.PaymentSessionAsync(paymentSetupRequest); //exception throw when i hit this line.
            Console.WriteLine(result.PaymentSession);
        }

I've got the Client configured in Startup.cs as singleton:

            services.AddSingleton(new Client(new Config
            {
                XApiKey = adyenPaymentOptions.ApiKey,
                Environment = Adyen.Model.Enum.Environment.Test,
                HmacKey = adyenPaymentOptions.HmacKey,
            }));

Expected behavior
It should work correctly without the exception.

Screenshots
This is the exception i've got
image

Additional context
The full stack trace:

{
  "errors": [
    "Invalid URI: The format of the URI could not be determined."
  ],
  "additionalInfo": null,
  "stackTrace": "   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)\r\n   at System.Uri..ctor(String uriString)\r\n   at System.Net.WebRequest.Create(String requestUriString)\r\n   at Adyen.HttpClient.HttpUrlConnectionClient.GetHttpWebRequest(String endpoint, Config config, Boolean isApiKeyRequired, RequestOptions requestOptions)\r\n   at Adyen.HttpClient.HttpUrlConnectionClient.RequestAsync(String endpoint, String json, Config config, Boolean isApiKeyRequired, RequestOptions requestOptions)\r\n   at Adyen.Service.Checkout.PaymentSessionAsync(PaymentSetupRequest paymentSetupRequest)\r\n   at IdealposVoucher.Services.Payments.AdyenPaymentService.CreateCheckoutSession(Int64 amount) in C:\\Users\\do.tran\\Desktop\\Idealpos\\IdealposVoucher\\IdealposVoucher.Services\\Payments\\AdyenPaymentService.cs:line 35\r\n   at IdealposVoucher.Controllers.VoucherCheckoutController.CreateCheckoutSessionAdyen() in C:\\Users\\do.tran\\Desktop\\Idealpos\\IdealposVoucher\\IdealposVoucher\\Controllers\\VoucherCheckoutController.cs:line 247\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()\r\n--- End of stack trace from previous location ---\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)"
}

Turns out the issue has nothing to do with returnUrl. The constructor of Client which takes a Config object doesn't set the endpoint for you like the one that takes XApiKey and Environment.
image
I switched to latter one and it worked. Guess i will have to set Hmac this way

var client = new Client("", Adyen.Model.Enum.Environment.Test);
            client.Config.HmacKey = "myHMAC";

Hi @oldtune,

Thanks for reaching out to us. Indeed it seems this is broken on our main branch, apologies for that. We have completely restructured the client now, which will fix this issue. Trying to release it very soon!

Best, Jilling
Adyen