forked from ordercloud-api/ordercloud-dotnet-catalyst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathITaxCalculator.cs
145 lines (138 loc) · 4.84 KB
/
ITaxCalculator.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using OrderCloud.SDK;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace OrderCloud.Catalyst
{
/// <summary>
/// An interface to define expected responses from tax calculation. Meant to be used in OrderCloud ecommerce checkout.
/// </summary>
public interface ITaxCalculator
{
/// <summary>
/// Calculates tax for an order without creating any records. Use this to display tax amount to user prior to order submit.
/// </summary>
Task<OrderTaxCalculation> CalculateEstimateAsync(OrderSummaryForTax orderSummary, OCIntegrationConfig configOverride = null);
/// <summary>
/// Creates a tax transaction record in the calculating system. Use this once per order - on order submit, payment capture, or fulfillment.
/// </summary>
Task<OrderTaxCalculation> CommitTransactionAsync(OrderSummaryForTax orderSummary, OCIntegrationConfig configOverride = null);
}
/// <summary>
/// Represents the details of the tax costs on one Order.
/// </summary>
public class OrderTaxCalculation
{
/// <summary>
/// ID of the OrderCloud Order
/// </summary>
public string OrderID { get; set; }
/// <summary>
/// An ID from the tax calculation system that identifies this transaction or calculation
/// </summary>
public string ExternalTransactionID { get; set; }
/// <summary>
/// The total tax to be paid by the purchaser on the order
/// </summary>
public decimal TotalTax { get; set; }
/// <summary>
/// Tax details by line item. Does not include possible shipping tax.
/// </summary>
public List<LineItemTaxCalculation> LineItems { get; set; } = new List<LineItemTaxCalculation>();
/// <summary>
/// Taxes that apply across the order. For example, shipping tax.
/// </summary>
public List<TaxDetails> OrderLevelTaxes { get; set; } = new List<TaxDetails>();
}
/// <summary>
/// Represents the details of the tax costs on one LineItem. Does not include possible shipping tax.
/// </summary>
public class LineItemTaxCalculation
{
/// <summary>
/// ID of the OrderCloud line item
/// </summary>
public string LineItemID { get; set; }
/// <summary>
/// The sum of taxes that apply specifically to this line item. Does not include possible shipping tax.
/// </summary>
public decimal LineItemTotalTax { get; set; }
/// <summary>
/// Taxes that apply specifically to this line item. Does not include possible shipping tax.
/// </summary>
public List<TaxDetails> LineItemLevelTaxes { get; set; } = new List<TaxDetails>();
}
/// <summary>
/// A tax cost levied by one juristdiction and applied to some element of an Order (lineItem, shipping, ect.).
/// </summary>
public class TaxDetails
{
/// <summary>
/// The tax to be paid by the purchaser
/// </summary>
public decimal Tax { get; set; }
/// <summary>
/// The amount of the line item cost on which tax applies
/// </summary>
public decimal Taxable { get; set; }
/// <summary>
/// The amount of the line item cost on which tax does not apply
/// </summary>
public decimal Exempt { get; set; }
/// <summary>
/// A description of the tax.
/// </summary>
public string TaxDescription { get; set; }
/// <summary>
/// The level of the authority collecting tax, e.g. federal, state, city.
/// </summary>
public string JurisdictionLevel { get; set; }
/// <summary>
/// The name of the authority collecting tax.
/// </summary>
public string JurisdictionValue { get; set; }
/// <summary>
/// ID of the ship estimate this tax applies to. Null if not a shipping tax.
/// </summary>
public string ShipEstimateID { get; set; }
}
public class OrderSummaryForTax
{
public string OrderID { get; set; }
public string CustomerCode { get; set; }
/// <summary>
/// Sum of the LineItem-level PromotionDiscounts plus the discount from all Order-level promotions.
/// </summary>
public decimal PromotionDiscount { get; set; }
public List<LineItemSummaryForTax> LineItems { get; set; }
public List<ShipEstimateSummaryForTax> ShippingCosts { get; set; }
}
public class LineItemSummaryForTax
{
public string LineItemID { get; set; }
public string ProductID { get; set; }
public string ProductName { get; set; }
public int Quantity { get; set; }
public decimal UnitPrice { get; set; }
public decimal PromotionDiscount { get; set; }
/// <summary>
/// (UnitPrice * Quantity) - PromotionDiscount
/// </summary>
public decimal LineTotal { get; set; }
public string TaxCode { get; set; }
public Address ShipTo { get; set; }
public Address ShipFrom { get; set; }
}
public class ShipEstimateSummaryForTax
{
public string ShipEstimateID { get; set; }
/// <summary>
/// E.G. "Fedex 2-day priority"
/// </summary>
public string Description { get; set; }
public decimal Cost { get; set; }
public Address ShipTo { get; set; }
public Address ShipFrom { get; set; }
}
}