Giter VIP home page Giter VIP logo

Comments (5)

generalengels avatar generalengels commented on June 19, 2024

I have same problem. There is no any response from Klarna.
klarna.Payment.CreateCreditSession(paymentSession) not working.

from kco_rest_dotnet.

DUAB-Johan avatar DUAB-Johan commented on June 19, 2024

Metoden är async vad jag kan se. Prova nedan

            Task<CheckoutOrder> callTask = Task.Run(() => klarna.Checkout.CreateOrder(order));
            // Wait finish
            callTask.Wait();
            // Get result                
            var createdOrder = callTask.Result;

from kco_rest_dotnet.

NiclasOhlsson avatar NiclasOhlsson commented on June 19, 2024

Also having the same issue. Running the test code in a console application works fine but running that same code in a clean ASP.NET WebForms application freezes the application. The solution suggested by @DUAB-Johan does not solve the issue.

Generally it appears to be discouraged to run asynchronous methods in a synchronous way as done in the Klarna library (see for example: https://devblogs.microsoft.com/pfxteam/should-i-expose-synchronous-wrappers-for-asynchronous-methods/) and I am wondering if this is indeed the underlying issue; resulting in an application deadlock.

More disturbingly it would suggest Klarna has never actually tested their own code beyond the context of a console application (as is indeed the format of the provided sample project).

from kco_rest_dotnet.

NiclasOhlsson avatar NiclasOhlsson commented on June 19, 2024

Considering this code works (main method console application):

public static void Main()
        {
            var username = "user";
            var password = "password";

            var client = new Klarna(username, password, KlarnaEnvironment.TestingEurope);

            var order = new CheckoutOrder
            {
                PurchaseCountry = "se",
                PurchaseCurrency = "sek",
                Locale = "sv-se",
                OrderAmount = 10000,
                OrderTaxAmount = 2000,
                MerchantUrls = new CheckoutMerchantUrls
                {
                    Terms = "https://www.example.com/terms.html",
                    Checkout = "https://www.example.com/checkout.html",
                    Confirmation = "https://www.example.com/confirmation.html",
                    Push = "https://www.example.com/push.html"
                },
                OrderLines = new List<OrderLine>()
                {
                    new OrderLine
                    {
                        Type = OrderLineType.physical,
                        Name = "Foo",
                        Quantity = 1,
                        UnitPrice = 10000,
                        TaxRate = 2500,
                        TotalAmount = 10000,
                        TotalTaxAmount = 2000,
                        TotalDiscountAmount = 0,
                    }
                }
            };

            try
            {
                var createdOrder = client.Checkout.CreateOrder(order).Result;
                var orderId = createdOrder.OrderId;
                Console.WriteLine($"Order ID: {orderId}");
            }
            catch (AggregateException ae)
            {
            }
        }

…while this code doesn't (page load method, asp.net WebForms aspx page):

protected void Page_Load(object sender, EventArgs e)
        {
            var username = "user";
            var password = "password";

            var client = new Klarna(username, password, KlarnaEnvironment.TestingEurope);

            var order = new CheckoutOrder
            {
                PurchaseCountry = "se",
                PurchaseCurrency = "sek",
                Locale = "sv-se",
                OrderAmount = 10000,
                OrderTaxAmount = 2000,
                MerchantUrls = new CheckoutMerchantUrls
                {
                    Terms = "https://www.example.com/terms.html",
                    Checkout = "https://www.example.com/checkout.html",
                    Confirmation = "https://www.example.com/confirmation.html",
                    Push = "https://www.example.com/push.html"
                },
                OrderLines = new List<OrderLine>()
                {
                    new OrderLine
                    {
                        Type = OrderLineType.physical,
                        Name = "Foo",
                        Quantity = 1,
                        UnitPrice = 10000,
                        TaxRate = 2500,
                        TotalAmount = 10000,
                        TotalTaxAmount = 2000,
                        TotalDiscountAmount = 0,
                    }
                }
            };

            try
            {
                var createdOrder = client.Checkout.CreateOrder(order).Result;
                var orderId = createdOrder.OrderId;
                Console.WriteLine($"Order ID: {orderId}");
            }
            catch (AggregateException ae)
            {
            }
        }

from kco_rest_dotnet.

alexions avatar alexions commented on June 19, 2024

Thanks @DUAB-Johan for the solution.

Actually due to the Web Forms limitations you cannot use Task.Result in the Main thread
There is the nice article about this limitation: https://blogs.msdn.microsoft.com/jpsanders/2017/08/28/asp-net-do-not-use-task-result-in-main-context/

To make the things easier we created a nice example using WebForms to demonstrate how you can use the SDK together with the WebForms: https://github.com/klarna/kco_rest_dotnet/tree/v3.x/Klarna.Rest/SampleProjects/WebForms

Follow the link, clone the project and run the example. I hope this example will help you to resolve the issue.

Thanks everyone for the feedback!

from kco_rest_dotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.