Skip to content

Commit

Permalink
fix: invalid shipping address and taxjar api failing case handle in a…
Browse files Browse the repository at this point in the history
…pple pay

invalid shipping address and taxjar api failing case handle in apple pay
  • Loading branch information
Sagnik Mitra authored and Sagnik Mitra committed Sep 19, 2024
1 parent 4c16c6c commit dd7dec8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 36 deletions.
70 changes: 37 additions & 33 deletions src/Utilities/ApplePayHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -128,39 +128,43 @@ let startApplePaySession = (
~paymentMethodType,
)
->then(response => {
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->Float.toString,
\"type": "final",
}
let newLineItems: array<lineItem> = [
{
label: "Bag Subtotal",
amount: (netAmount -. ordertaxAmount -. shippingCost)->Float.toString,
\"type": "final",
},
{
label: "Order Tax Amount",
amount: ordertaxAmount->Float.toString,
\"type": "final",
},
{
label: "Shipping Cost",
amount: shippingCost->Float.toString,
\"type": "final",
},
]
let updatedOrderDetails: updatedOrderDetails = {
newTotal,
newLineItems,
}
ssn.completeShippingContactSelection(updatedOrderDetails)->resolve
switch response->taxResponseToObjMapper {
| Some(taxCalculationResponse) => {
let (netAmount, ordertaxAmount, shippingCost) = (
taxCalculationResponse.net_amount,
taxCalculationResponse.order_tax_amount,
taxCalculationResponse.shipping_cost,
)
let newTotal: lineItem = {
label: "Net Amount",
amount: netAmount->Float.toString,
\"type": "final",
}
let newLineItems: array<lineItem> = [
{
label: "Bag Subtotal",
amount: (netAmount -. ordertaxAmount -. shippingCost)->Float.toString,
\"type": "final",
},
{
label: "Order Tax Amount",
amount: ordertaxAmount->Float.toString,
\"type": "final",
},
{
label: "Shipping Cost",
amount: shippingCost->Float.toString,
\"type": "final",
},
]
let updatedOrderDetails: updatedOrderDetails = {
newTotal,
newLineItems,
}
ssn.completeShippingContactSelection(updatedOrderDetails)
}
| None => ssn.abort()
}->resolve
})
->ignore
}
Expand Down
8 changes: 5 additions & 3 deletions src/Utilities/TaxCalculation.res
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ type calculateTaxResponse = {

let taxResponseToObjMapper = resp => {
let responseDict = resp->getDictFromJson
let displayAmountDict = responseDict->getDictFromDict("display_amount")
{
responseDict
->Dict.get("display_amount")
->Option.flatMap(JSON.Decode.object)
->Option.map(displayAmountDict => {
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 = (
Expand Down

0 comments on commit dd7dec8

Please sign in to comment.