From e757ad7758f72257c60f16c3fa18bd052dcd2a96 Mon Sep 17 00:00:00 2001 From: Arush Date: Mon, 8 Jul 2024 12:26:51 +0530 Subject: [PATCH] fix: passing customer acceptance if recurring_enabled is false in saved methods list --- src/Components/SavedMethods.res | 9 ++------- src/Types/PaymentType.res | 4 ++++ src/orca-loader/PaymentSessionMethods.res | 5 +++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Components/SavedMethods.res b/src/Components/SavedMethods.res index 7474006f8..2cfd517ad 100644 --- a/src/Components/SavedMethods.res +++ b/src/Components/SavedMethods.res @@ -54,12 +54,6 @@ let make = ( } } - let isCustomerAcceptanceRequired = useIsCustomerAcceptanceRequired( - ~displaySavedPaymentMethodsCheckbox, - ~isSaveCardsChecked, - ~isGuestCustomer, - ) - let bottomElement = { savedMethods ->Array.mapWithIndex((obj, i) => { @@ -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( @@ -235,7 +231,6 @@ let make = ( empty, complete, customerMethod, - isCustomerAcceptanceRequired, applePayToken, gPayToken, isManualRetryEnabled, diff --git a/src/Types/PaymentType.res b/src/Types/PaymentType.res index 0f682e839..a7d0f2b47 100644 --- a/src/Types/PaymentType.res +++ b/src/Types/PaymentType.res @@ -132,6 +132,7 @@ type customerMethods = { requiresCvv: bool, lastUsedAt: string, bank: bank, + recurringEnabled: bool, } type savedCardsLoadState = LoadingSavedCards | LoadedSavedCards(array, bool) | NoResult(bool) @@ -192,6 +193,7 @@ let defaultCustomerMethods = { requiresCvv: true, lastUsedAt: "", bank: {mask: ""}, + recurringEnabled: false, } let defaultLayout = { defaultCollapsed: false, @@ -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), } }) @@ -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) diff --git a/src/orca-loader/PaymentSessionMethods.res b/src/orca-loader/PaymentSessionMethods.res index a0e920454..cdfb784f6 100644 --- a/src/orca-loader/PaymentSessionMethods.res +++ b/src/orca-loader/PaymentSessionMethods.res @@ -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 }