From 2579e6baad815000de19af8156adc4c048ecbef3 Mon Sep 17 00:00:00 2001 From: Arush Date: Wed, 13 Mar 2024 19:55:58 +0530 Subject: [PATCH] fix: added paymentType to be passed in the confirm body --- src/Utilities/PaymentBody.res | 8 ++++++++ src/Utilities/PaymentHelpers.res | 21 ++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Utilities/PaymentBody.res b/src/Utilities/PaymentBody.res index a3904f0f3..f366efcb6 100644 --- a/src/Utilities/PaymentBody.res +++ b/src/Utilities/PaymentBody.res @@ -111,6 +111,14 @@ let mandateBody = paymentType => { ] } +let paymentTypeBody = paymentType => { + if paymentType != "" { + [("payment_type", paymentType->Js.Json.string)] + } else { + [] + } +} + let confirmPayloadForSDKButton = (sdkHandleConfirmPayment: PaymentType.sdkHandleConfirmPayment) => [ ("redirect", "always"->JSON.Encode.string), diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index 9f76ddf1e..51faf60f7 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -735,10 +735,13 @@ let usePaymentIntent = (optLogger: option, paymentType: p } let broswerInfo = BrowserSpec.broswerInfo - let intentWithoutMandate = () => { + let intentWithoutMandate = mandatePaymentType => { let bodyStr = body - ->Js.Array2.concat(bodyArr->Js.Array2.concat(broswerInfo())) + ->Js.Array2.concatMany([ + bodyArr->Js.Array2.concat(broswerInfo()), + mandatePaymentType->PaymentBody.paymentTypeBody, + ]) ->Js.Dict.fromArray ->Js.Json.object_ ->Js.Json.stringify @@ -749,9 +752,7 @@ let usePaymentIntent = (optLogger: option, paymentType: p body ->Js.Array2.concat( bodyArr->Js.Array2.concatMany([ - PaymentBody.mandateBody( - mandatePaymentType->PaymentMethodsRecord.paymentTypeToStringMapper, - ), + PaymentBody.mandateBody(mandatePaymentType), broswerInfo(), ]), ) @@ -764,6 +765,8 @@ let usePaymentIntent = (optLogger: option, paymentType: p switch list { | Loaded(data) => let paymentList = data->getDictFromJson->PaymentMethodsRecord.itemToObjMapper + let mandatePaymentType = + paymentList.payment_type->PaymentMethodsRecord.paymentTypeToStringMapper switch paymentList.mandate_payment { | Some(_) => switch paymentType { @@ -773,12 +776,12 @@ let usePaymentIntent = (optLogger: option, paymentType: p | KlarnaRedirect | Paypal | BankDebits => - intentWithMandate(paymentList.payment_type) - | _ => intentWithoutMandate() + intentWithMandate(mandatePaymentType) + | _ => intentWithoutMandate(mandatePaymentType) } - | None => intentWithoutMandate() + | None => intentWithoutMandate(mandatePaymentType) } - | SemiLoaded => intentWithoutMandate() + | SemiLoaded => intentWithoutMandate("") | _ => () } | None =>