This repository has been archived by the owner on Jun 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
CheckoutStore.cs
65 lines (55 loc) · 2.95 KB
/
CheckoutStore.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System.Threading.Tasks;
using Klarna.Rest.Core.Common;
using Klarna.Rest.Core.Commuication;
using Klarna.Rest.Core.Commuication.Dto;
using Klarna.Rest.Core.Model;
using Klarna.Rest.Core.Serialization;
namespace Klarna.Rest.Core.Store
{
/// <summary>
/// The checkout API is used to create a checkout with Klarna and update the checkout order during the purchase.
/// As soon as the purchase is completed the order should be read and handled using the Order Management API.
/// </summary>
public class CheckoutStore : BaseStore
{
internal CheckoutStore(ApiSession apiSession, IJsonSerializer jsonSerializer) : base(apiSession, ApiControllers.Checkout, jsonSerializer) { }
/// <summary>
/// Use this API call to create a new order.
/// <a href="https://developers.klarna.com/api/#checkout-api-create-a-new-order">https://developers.klarna.com/api/#checkout-api-create-a-new-order</a>
/// </summary>
/// <param name="order">The <see cref="CheckoutOrder"/> object</param>
/// <returns><see cref="CheckoutOrder"/></returns>
public async Task<CheckoutOrder> CreateOrder(CheckoutOrder order)
{
var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri);
var response = await Post<CheckoutOrder>(url, order);
return response;
}
/// <summary>
/// Use this API call to read an order from Klarna.
/// Note that orders should only be read from the checkout API until the order is completed. Completed orders should be read using the order management API
/// <a href="https://developers.klarna.com/api/#checkout-api-retrieve-an-order">https://developers.klarna.com/api/#checkout-api-retrieve-an-order</a>
/// </summary>
/// <param name="orderId">ID of the order to retrieve</param>
/// <returns><see cref="CheckoutOrder"/></returns>
public async Task<CheckoutOrder> GetOrder(string orderId)
{
var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri, orderId);
var response = await Get<CheckoutOrder>(url);
return response;
}
/// <summary>
/// Updates an existing order.
/// Please note: an order can only be updated when the status is 'checkout_incomplete'.
/// <a href="https://developers.klarna.com/api/#checkout-api-update-an-order">https://developers.klarna.com/api/#checkout-api-update-an-order</a>
/// </summary>
/// <param name="order">The <see cref="CheckoutOrder"/> object</param>
/// <returns><see cref="CheckoutOrder"/></returns>
public async Task<CheckoutOrder> UpdateOrder(CheckoutOrder order)
{
var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri, order.OrderId);
var response = await Post<CheckoutOrder>(url, order);
return response;
}
}
}