Hi,
The required URLs in the configuration example in the README.md for Klarna Checkout are written as paths with a leading "/" (see below).
"CheckoutUrl": "/checkout",
"ConfirmationUrl": "/checkout/KlarnaCheckoutConfirmation?orderGroupId={orderGroupId}&klarna_order_id={checkout.order.id}",
"TermsUrl": "/terms",
"PushUrl": "/klarnacheckout/cart/{orderGroupId}/push?klarna_order_id={checkout.order.id}",
I found that the package fails to convert these settings to absolute URLs with the method and domain name of the current website when creating an order. This leads to the following error from the API endpoint:
Error Code: 'BAD_VALUE'; CorrelationId: 'f0644e9a-5091-4acf-a6d1-b4f2edbe5766'; Messages: 'Bad value: merchant_urls.checkout (must be a valid http or https URI), merchant_urls.confirmation (must be a valid http or https URI), merchant_urls.terms (must be a valid http or https URI)'
Klarna.Common.Models.ApiException: Error when calling POST https://api.playground.klarna.com/checkout/v3/orders.
The reason seems to be that Uri.TryCreate(url, UriKind.Absolute, out var uri) on line 534 in src/Klarna.Checkout/KlarnaCheckoutService.cs returns true even if the resulting URI is not actually an absolute http/https address. So, calling the method with a url value of, for example, "/terms" will return a Uri that has no domain name and will be inserted as file:///terms into the API call.
Specifying the same configuration parameters without a leading "/" works fine and gives the behaivor that one would expect. Thus, this configuration example would be better:
"CheckoutUrl": "checkout",
"ConfirmationUrl": "checkout/KlarnaCheckoutConfirmation?orderGroupId={orderGroupId}&klarna_order_id={checkout.order.id}",
"TermsUrl": "terms",
"PushUrl": "klarnacheckout/cart/{orderGroupId}/push?klarna_order_id={checkout.order.id}",
It was not entirely straightforward to troubleshoot this, so it would be useful if the example could be updated.
Hi,
The required URLs in the configuration example in the README.md for Klarna Checkout are written as paths with a leading "/" (see below).
I found that the package fails to convert these settings to absolute URLs with the method and domain name of the current website when creating an order. This leads to the following error from the API endpoint:
The reason seems to be that
Uri.TryCreate(url, UriKind.Absolute, out var uri)on line 534 insrc/Klarna.Checkout/KlarnaCheckoutService.csreturnstrueeven if the resulting URI is not actually an absolute http/https address. So, calling the method with aurlvalue of, for example, "/terms" will return aUrithat has no domain name and will be inserted asfile:///termsinto the API call.Specifying the same configuration parameters without a leading "/" works fine and gives the behaivor that one would expect. Thus, this configuration example would be better:
It was not entirely straightforward to troubleshoot this, so it would be useful if the example could be updated.