Comments (5)
I have same problem. There is no any response from Klarna.
klarna.Payment.CreateCreditSession(paymentSession) not working.
from kco_rest_dotnet.
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.
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.
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.
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)
- Code hangs on payment execution. HOT 1
- Handle card payment HOT 1
- shipping_method "" cannot be serialized into Enum OrderManagementShippingMethod
- Async/Await issue HOT 5
- Typo in endpoint for "Release remaining authorization" HOT 2
- The wrong type for "refunds" is used in the "OrderManagementOrder" class HOT 3
- Issue installing the Klarna nuget package HOT 1
- Typo in SettlementsGetAllPayoutsResponse.cs "Paginatinon" HOT 2
- Allow usage of WebProxy in HttpClient HOT 2
- Typo in Klarna.Rest/Klarna.Rest.Core/Commuication namespace HOT 2
- HostedPaymentPage: DistributeLinkToSession does not send body payout
- HostedPaymentPageSessionStatus model is not aligned with API
- Missing Payment Method categories property in HostedPaymentPageOptions HOT 1
- GetSessionStatus points to the wrong url
- Hosted Payment Pages: Add support of Session disabling HOT 1
- Promo codes (custom payment methods) contract issue HOT 1
- Discrepancy between SDK models and API models HOT 2
- Can Not Install On .NET Framework 4.8 HOT 1
- Klarna examples using deprecated code HOT 7
- PaymentAPI problems with response results HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kco_rest_dotnet.