-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCartSample.cs
More file actions
46 lines (38 loc) · 1.72 KB
/
CartSample.cs
File metadata and controls
46 lines (38 loc) · 1.72 KB
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
using CSharpAmazonBusinessAPI;
using CSharpAmazonBusinessAPI.Model.Cart;
namespace CSharpAmazonBusinessAPI.SampleCode;
// `country` defaults to the connection's marketplace country — pass it explicitly only when
// you need to call against a different marketplace from one connection.
public class CartSample
{
private readonly AmazonBusinessConnection _connection;
public CartSample(AmazonBusinessConnection connection)
{
_connection = connection;
}
public Task<CartDetailsResult> ListCartsAsync(string customerEmail) =>
// Static sandbox accepts only `region` for this op — no pageToken, no pageSize.
// https://developer-docs.amazon.com/amazon-business/docs/cart-api-static-sandbox-guide
// For production: add pageSize / pageToken back as needed.
_connection.Cart.ListCartsAsync(customerEmail);
public Task<Cart> GetCartAsync(string cartId) =>
_connection.Cart.GetCartAsync(cartId);
public Task<CartItems> GetItemsAsync(string cartId) =>
_connection.Cart.GetItemsAsync(cartId);
public Task<AddItemsResult> AddItemAsync(string cartId, string asin, int quantity)
{
var request = new AddItemsRequest
{
Items = new List<AddItemRequest>
{
new AddItemRequest { ProductIdentifier = asin, Quantity = quantity },
},
};
return _connection.Cart.AddItemsAsync(cartId, request);
}
public Task<EstimatedTotalPurchaseCostResult> EstimateCostAsync(string cartId, Address shippingAddress)
{
var request = new EstimatedTotalPurchaseCostRequest { Address = shippingAddress };
return _connection.Cart.GetEstimatedTotalPurchaseCostAsync(cartId, request);
}
}