/// <summary> /// Create a new credit session /// <a href="https://developers.klarna.com/api/#payments-api-create-a-new-credit-session">https://developers.klarna.com/api/#payments-api-create-a-new-credit-session</a> /// </summary> /// <param name="creditSession">The <see cref="PaymentCreditSession"/> object</param> /// <returns><see cref="PaymentCreditSessionResponse"/></returns> public async Task <PaymentCreditSessionResponse> CreateCreditSession(PaymentCreditSession creditSession) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri); var response = await Post <PaymentCreditSessionResponse>(url, creditSession); return(response); }
/// <summary> /// Update an existing credit session /// <a href="https://developers.klarna.com/api/#payments-api-update-an-existing-credit-session">https://developers.klarna.com/api/#payments-api-update-an-existing-credit-session</a> /// </summary> /// <param name="sessionId">Id of the credit session to update</param> /// <param name="creditSession">The <see cref="PaymentCreditSession"/> object</param> /// <returns></returns> public async Task UpdateCreditSession(string sessionId, PaymentCreditSession creditSession) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri, sessionId); await Post(url, creditSession); }
public ActionResult Kp() { var client = new Client(_username, _password, KlarnaEnvironment.TestingEurope); try { var paymentSession = new PaymentCreditSession { PurchaseCountry = "GB", PurchaseCurrency = "GBP", Locale = "en-GB", OrderAmount = 10000, OrderTaxAmount = 2000, OrderLines = new List <OrderLine>() { new OrderLine { Type = OrderLineType.physical, Name = "Foo", Quantity = 1, UnitPrice = 10000, TaxRate = 2500, TotalAmount = 10000, TotalTaxAmount = 2000, TotalDiscountAmount = 0, } }, MerchantReference1 = "StoreOrderId", Options = new PaymentOptions { ColorButton = "#000000" }, BillingAddress = new PaymentAddressInfo { GivenName = "John", FamilyName = "Doe", StreetAddress = "13 New Burlington St", PostalCode = "W13 3BG", Country = "GB", Email = "*****@*****.**", City = "London", Phone = "01895808221" } }; var creditSession = client.Payment.CreateCreditSession(paymentSession).Result; ViewBag.ClientToken = creditSession.ClientToken; ViewBag.Payments = creditSession.PaymentMethodCategories; } catch (AggregateException ae) { foreach (var e in ae.InnerExceptions) { if (e is ApiException) { var apiException = (ApiException)e; ViewBag.Error = "Status code: " + apiException.StatusCode + "; Error: " + string.Join("; ", apiException.ErrorMessage.ErrorMessages); } else { ViewBag.Error = e.Message; } } } return(View()); }
public void CreateSession() { var username = "******"; var password = "******"; var klarna = new Klarna(username, password, KlarnaEnvironment.TestingEurope); try { var paymentSession = new PaymentCreditSession { PurchaseCountry = "SE", PurchaseCurrency = "SEK", Locale = "sv-se", OrderAmount = 1000, OrderTaxAmount = 2000, OrderLines = new List <OrderLine>() { new OrderLine { Type = OrderLineType.physical, Name = "Foo", Quantity = 1, UnitPrice = 10000, TaxRate = 2500, TotalAmount = 10000, TotalTaxAmount = 2000, TotalDiscountAmount = 0, } }, MerchantReference1 = "StoreOrderId", Options = new PaymentOptions { ColorButton = "000000" }, BillingAddress = new PaymentAddressInfo { GivenName = "John", FamilyName = "Doe", StreetAddress = "Sveavägen 46", PostalCode = "103 69", Country = "SE", Email = "*****@*****.**", City = "Stockholm", Phone = "+46752242244" } }; var creditSession = klarna.Payment.CreateCreditSession(paymentSession).Result; Console.WriteLine("Client Token: " + creditSession.ClientToken); Console.WriteLine("Session ID: " + creditSession.SessionId); Console.WriteLine("The following categories are avaliable"); foreach (PaymentMethodCategory category in creditSession.PaymentMethodCategories) { Console.WriteLine("Name: " + category.Name); Console.WriteLine("Assets Url: " + category.AssetUrls); Console.WriteLine("Unique Identifier: " + category.Identifier); } } catch (AggregateException ae) { foreach (var e in ae.InnerExceptions) { if (e is ApiException) { var apiException = (ApiException)e; Console.WriteLine("Status code: " + apiException.StatusCode); Console.WriteLine("Error: " + string.Join("; ", apiException.ErrorMessage.ErrorMessages)); } else { // Rethrow any other exception or process it Console.WriteLine(e.Message); throw; } } } }