Advertisement
Guest User

Untitled

a guest
Dec 20th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using Klarna.Rest.Core.Common;
  4. using Klarna.Rest.Core.Commuication;
  5. using Klarna.Rest.Core.Model;
  6. using Klarna.Rest.Core.Model.Enum;
  7.  
  8. namespace Klarna.Rest.Core.Examples
  9. {
  10. /// <summary>
  11. /// Create a checkout order
  12. /// </summary>
  13. public class CreateExample
  14. {
  15. /// <summary>
  16. /// Run the example code.
  17. /// Remember to replace username and password with valid Klarna credentials.
  18. /// </summary>
  19. static void Main()
  20. {
  21. var username = "0_abc";
  22. var password = "sharedsecret";
  23.  
  24. var client = new Klarna(username, password, KlarnaEnvironment.TestingEurope);
  25.  
  26. var order = new CheckoutOrder
  27. {
  28. PurchaseCountry = "se",
  29. PurchaseCurrency = "sek",
  30. Locale = "sv-se",
  31. OrderAmount = 10000,
  32. OrderTaxAmount = 2000,
  33. MerchantUrls = new CheckoutMerchantUrls
  34. {
  35. Terms = "https://www.estore.com/terms.html",
  36. Checkout = "https://www.estore.com/checkout.html",
  37. Confirmation = "https://www.estore.com/confirmation.html",
  38. Push = "https://www.estore.com/push.html"
  39. },
  40. OrderLines = new List<OrderLine>()
  41. {
  42. new OrderLine
  43. {
  44. Type = OrderLineType.physical,
  45. Name = "Foo",
  46. Quantity = 1,
  47. UnitPrice = 10000,
  48. TaxRate = 2500,
  49. TotalAmount = 10000,
  50. TotalTaxAmount = 2000,
  51. TotalDiscountAmount = 0,
  52. }
  53. },
  54. CheckoutOptions = new CheckoutOptions
  55. {
  56. AllowSeparateShippingAddress = false,
  57. ColorButton = "#FF9900",
  58. ColorButtonText = "#FF9900",
  59. ColorCheckbox = "#FF9900",
  60. ColorCheckboxCheckmark = "#FF9900",
  61. ColorHeader = "#FF9900",
  62. ColorLink = "#FF9900",
  63. DateOfBirthMandatory = false,
  64. ShippingDetails = "bar",
  65. }
  66. };
  67.  
  68. try
  69. {
  70. var createdOrder = client.Checkout.CreateOrder(order).Result;
  71. var orderId = createdOrder.OrderId;
  72. Console.WriteLine($"Order ID: {orderId}");
  73. }
  74. catch (ApiException ex)
  75. {
  76. Console.WriteLine(ex.ErrorMessage.ErrorCode);
  77. Console.WriteLine(ex.ErrorMessage.ErrorMessages);
  78. Console.WriteLine(ex.ErrorMessage.CorrelationId);
  79. }
  80. catch (Exception ex)
  81. {
  82. Console.WriteLine(ex.Message);
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement