Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dynamic tax calculation fix #618

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Utilities/ApplePayHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -128,31 +128,31 @@ let startApplePaySession = (
~paymentMethodType,
)
->then(response => {
let taxCalculationResponse = response->getDictFromJson->taxResponseToObjMapper
let taxCalculationResponse = response->taxResponseToObjMapper
let (netAmount, ordertaxAmount, shippingCost) = (
taxCalculationResponse.net_amount,
taxCalculationResponse.order_tax_amount,
taxCalculationResponse.shipping_cost,
)
let newTotal: lineItem = {
label: "Net Amount",
amount: netAmount->Int.toString,
amount: netAmount->Float.toString,
\"type": "final",
}
let newLineItems: array<lineItem> = [
{
label: "Bag Subtotal",
amount: (netAmount - ordertaxAmount - shippingCost)->Int.toString,
amount: (netAmount -. ordertaxAmount -. shippingCost)->Float.toString,
\"type": "final",
},
{
label: "Order Tax Amount",
amount: ordertaxAmount->Int.toString,
amount: ordertaxAmount->Float.toString,
\"type": "final",
},
{
label: "Shipping Cost",
amount: shippingCost->Int.toString,
amount: shippingCost->Float.toString,
\"type": "final",
},
]
Expand Down
28 changes: 19 additions & 9 deletions src/Utilities/TaxCalculation.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,29 @@ open Utils

type calculateTaxResponse = {
payment_id: string,
net_amount: int,
order_tax_amount: int,
shipping_cost: int,
net_amount: float,
order_tax_amount: float,
shipping_cost: float,
}

let taxResponseToObjMapper = dict => {
payment_id: dict->getString("payment_id", ""),
net_amount: dict->getInt("net_amount", 0),
order_tax_amount: dict->getInt("order_tax_amount", 0),
shipping_cost: dict->getInt("shipping_cost", 0),
let taxResponseToObjMapper = resp => {
let responseDict = resp->getDictFromJson
let displayAmountDict = responseDict->getDictFromDict("display_amount")
{
payment_id: responseDict->getString("payment_id", ""),
net_amount: displayAmountDict->getFloat("net_amount", 0.0),
order_tax_amount: displayAmountDict->getFloat("order_tax_amount", 0.0),
shipping_cost: displayAmountDict->getFloat("shipping_cost", 0.0),
}
}

let calculateTax = (~shippingAddress, ~logger, ~clientSecret, ~publishableKey, ~paymentMethodType) => {
let calculateTax = (
~shippingAddress,
~logger,
~clientSecret,
~publishableKey,
~paymentMethodType,
) => {
PaymentHelpers.calculateTax(
~clientSecret=clientSecret->JSON.Encode.string,
~apiKey=publishableKey,
Expand Down
Loading