Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using Klarna.Rest.Core.Common;
- using Klarna.Rest.Core.Commuication;
- using Klarna.Rest.Core.Model;
- using Klarna.Rest.Core.Model.Enum;
- namespace Klarna.Rest.Core.Examples
- {
- /// <summary>
- /// Create a checkout order
- /// </summary>
- public class CreateExample
- {
- /// <summary>
- /// Run the example code.
- /// Remember to replace username and password with valid Klarna credentials.
- /// </summary>
- static void Main()
- {
- var username = "0_abc";
- var password = "sharedsecret";
- 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.estore.com/terms.html",
- Checkout = "https://www.estore.com/checkout.html",
- Confirmation = "https://www.estore.com/confirmation.html",
- Push = "https://www.estore.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,
- }
- },
- CheckoutOptions = new CheckoutOptions
- {
- AllowSeparateShippingAddress = false,
- ColorButton = "#FF9900",
- ColorButtonText = "#FF9900",
- ColorCheckbox = "#FF9900",
- ColorCheckboxCheckmark = "#FF9900",
- ColorHeader = "#FF9900",
- ColorLink = "#FF9900",
- DateOfBirthMandatory = false,
- ShippingDetails = "bar",
- }
- };
- try
- {
- var createdOrder = client.Checkout.CreateOrder(order).Result;
- var orderId = createdOrder.OrderId;
- Console.WriteLine($"Order ID: {orderId}");
- }
- catch (ApiException ex)
- {
- Console.WriteLine(ex.ErrorMessage.ErrorCode);
- Console.WriteLine(ex.ErrorMessage.ErrorMessages);
- Console.WriteLine(ex.ErrorMessage.CorrelationId);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement