diff --git a/src/Utilities/ApplePayHelpers.res b/src/Utilities/ApplePayHelpers.res index b481b55f2..e0ab6b8b7 100644 --- a/src/Utilities/ApplePayHelpers.res +++ b/src/Utilities/ApplePayHelpers.res @@ -128,7 +128,7 @@ 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, @@ -136,23 +136,23 @@ let startApplePaySession = ( ) let newTotal: lineItem = { label: "Net Amount", - amount: netAmount->Int.toString, + amount: netAmount->Float.toString, \"type": "final", } let newLineItems: array = [ { 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", }, ] diff --git a/src/Utilities/TaxCalculation.res b/src/Utilities/TaxCalculation.res index c48b1ae5b..8628de648 100644 --- a/src/Utilities/TaxCalculation.res +++ b/src/Utilities/TaxCalculation.res @@ -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,