Skip to content

Commit

Permalink
fix: passing customer acceptance if recurring_enabled is false in sav…
Browse files Browse the repository at this point in the history
…ed methods list
  • Loading branch information
ArushKapoorJuspay committed Jul 8, 2024
1 parent 45a71e3 commit e757ad7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/Components/SavedMethods.res
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ let make = (
}
}

let isCustomerAcceptanceRequired = useIsCustomerAcceptanceRequired(
~displaySavedPaymentMethodsCheckbox,
~isSaveCardsChecked,
~isGuestCustomer,
)

let bottomElement = {
savedMethods
->Array.mapWithIndex((obj, i) => {
Expand Down Expand Up @@ -126,6 +120,8 @@ let make = (
let json = ev.data->JSON.parseExn
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper

let isCustomerAcceptanceRequired = customerMethod.recurringEnabled->not

let savedPaymentMethodBody = switch customerMethod.paymentMethod {
| "card" =>
PaymentBody.savedCardBody(
Expand Down Expand Up @@ -235,7 +231,6 @@ let make = (
empty,
complete,
customerMethod,
isCustomerAcceptanceRequired,
applePayToken,
gPayToken,
isManualRetryEnabled,
Expand Down
4 changes: 4 additions & 0 deletions src/Types/PaymentType.res
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ type customerMethods = {
requiresCvv: bool,
lastUsedAt: string,
bank: bank,
recurringEnabled: bool,
}
type savedCardsLoadState =
LoadingSavedCards | LoadedSavedCards(array<customerMethods>, bool) | NoResult(bool)
Expand Down Expand Up @@ -192,6 +193,7 @@ let defaultCustomerMethods = {
requiresCvv: true,
lastUsedAt: "",
bank: {mask: ""},
recurringEnabled: false,
}
let defaultLayout = {
defaultCollapsed: false,
Expand Down Expand Up @@ -883,6 +885,7 @@ let itemToCustomerObjMapper = customerDict => {
requiresCvv: getBool(dict, "requires_cvv", true),
lastUsedAt: getString(dict, "last_used_at", ""),
bank: dict->getBank,
recurringEnabled: getBool(dict, "recurring_enabled", false),
}
})

Expand Down Expand Up @@ -919,6 +922,7 @@ let getCustomerMethods = (dict, str) => {
requiresCvv: getBool(dict, "requires_cvv", true),
lastUsedAt: getString(dict, "last_used_at", ""),
bank: dict->getBank,
recurringEnabled: getBool(dict, "recurring_enabled", false),
}
})
LoadedSavedCards(customerPaymentMethods, false)
Expand Down
5 changes: 5 additions & 0 deletions src/orca-loader/PaymentSessionMethods.res
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,17 @@ let getCustomerSavedPaymentMethods = (
let paymentMethod = lastUsedPaymentMethod.paymentMethod
let paymentMethodType = lastUsedPaymentMethod.paymentMethodType->Option.getOr("")
let paymentType = paymentMethodType->PaymentHelpers.getPaymentType
let isCustomerAcceptanceRequired = lastUsedPaymentMethod.recurringEnabled->not

let body = [
("payment_method", paymentMethod->JSON.Encode.string),
("payment_token", paymentToken->JSON.Encode.string),
]

if isCustomerAcceptanceRequired {
body->Array.push(("customer_acceptance", PaymentBody.customerAcceptanceBody))->ignore
}

if paymentMethodType !== "" {
body->Array.push(("payment_method_type", paymentMethodType->JSON.Encode.string))->ignore
}
Expand Down

0 comments on commit e757ad7

Please sign in to comment.