Skip to content

Commit

Permalink
fix: fix apple pay address and loading issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ImSagnik007 committed Oct 16, 2024
1 parent 64a1f03 commit 6d41782
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/Types/ApplePayTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type lineItem = {
\"type": string,
}
type shippingAddressChangeEvent = {shippingContact: JSON.t}
type updatedOrderDetails = {newTotal: lineItem, newLineItems: array<lineItem>}
type orderDetails = {newTotal: lineItem, newLineItems: array<lineItem>}
type innerSession
type session = {
begin: unit => unit,
Expand All @@ -41,8 +41,8 @@ type session = {
mutable onvalidatemerchant: event => unit,
completeMerchantValidation: JSON.t => unit,
mutable onpaymentauthorized: event => unit,
mutable onshippingcontactselected: shippingAddressChangeEvent => unit,
completeShippingContactSelection: updatedOrderDetails => unit,
mutable onshippingcontactselected: shippingAddressChangeEvent => promise<unit>,
completeShippingContactSelection: orderDetails => unit,
completePayment: JSON.t => unit,
\"STATUS_SUCCESS": string,
\"STATUS_FAILURE": string,
Expand Down
33 changes: 24 additions & 9 deletions src/Utilities/ApplePayHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,28 @@ let startApplePaySession = (
}

ssn.onshippingcontactselected = shippingAddressChangeEvent => {
let currentTotal = paymentRequest->getDictFromJson->getDictFromDict("total")
let label = currentTotal->getString("label", "apple")
let currentAmount = currentTotal->getString("amount", "0.00")
let \"type" = currentTotal->getString("type", "final")

let oldTotal: lineItem = {
label,
amount: currentAmount,
\"type",
}
let currentOrderDetails: orderDetails = {
newTotal: oldTotal,
newLineItems: [oldTotal],
}
if isTaxCalculationEnabled {
let newShippingContact =
shippingAddressChangeEvent.shippingContact
->getDictFromJson
->shippingContactItemToObjMapper
let newShippingAddress =
[
("state", newShippingContact.locality->JSON.Encode.string),
("state", newShippingContact.administrativeArea->JSON.Encode.string),
("country", newShippingContact.countryCode->JSON.Encode.string),
("zip", newShippingContact.postalCode->JSON.Encode.string),
]->getJsonFromArrayOfJson
Expand All @@ -126,8 +140,7 @@ let startApplePaySession = (
~publishableKey,
~clientSecret,
~paymentMethodType,
)
->thenResolve(response => {
)->thenResolve(response => {
switch response->taxResponseToObjMapper {
| Some(taxCalculationResponse) => {
let (netAmount, ordertaxAmount, shippingCost) = (
Expand All @@ -136,13 +149,13 @@ let startApplePaySession = (
taxCalculationResponse.shipping_cost,
)
let newTotal: lineItem = {
label: "Net Amount",
label,
amount: netAmount->minorUnitToString,
\"type": "final",
\"type",
}
let newLineItems: array<lineItem> = [
{
label: "Bag Subtotal",
label: "Subtotal",
amount: (netAmount - ordertaxAmount - shippingCost)->minorUnitToString,
\"type": "final",
},
Expand All @@ -157,16 +170,18 @@ let startApplePaySession = (
\"type": "final",
},
]
let updatedOrderDetails: updatedOrderDetails = {
let updatedOrderDetails: orderDetails = {
newTotal,
newLineItems,
}
ssn.completeShippingContactSelection(updatedOrderDetails)
}
| None => ssn.abort()
| None => ssn.completeShippingContactSelection(currentOrderDetails)
}
})
->ignore
} else {
ssn.completeShippingContactSelection(currentOrderDetails)
resolve()
}
}

Expand Down

0 comments on commit 6d41782

Please sign in to comment.