Skip to content

Commit

Permalink
fix: added paymentType to be passed in the confirm body (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArushKapoorJuspay authored Mar 13, 2024
1 parent 1bbc1f2 commit 4f94264
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
8 changes: 8 additions & 0 deletions src/Utilities/PaymentBody.res
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
21 changes: 12 additions & 9 deletions src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -735,10 +735,13 @@ let usePaymentIntent = (optLogger: option<OrcaLogger.loggerMake>, 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
Expand All @@ -749,9 +752,7 @@ let usePaymentIntent = (optLogger: option<OrcaLogger.loggerMake>, paymentType: p
body
->Js.Array2.concat(
bodyArr->Js.Array2.concatMany([
PaymentBody.mandateBody(
mandatePaymentType->PaymentMethodsRecord.paymentTypeToStringMapper,
),
PaymentBody.mandateBody(mandatePaymentType),
broswerInfo(),
]),
)
Expand All @@ -764,6 +765,8 @@ let usePaymentIntent = (optLogger: option<OrcaLogger.loggerMake>, 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 {
Expand All @@ -773,12 +776,12 @@ let usePaymentIntent = (optLogger: option<OrcaLogger.loggerMake>, paymentType: p
| KlarnaRedirect
| Paypal
| BankDebits =>
intentWithMandate(paymentList.payment_type)
| _ => intentWithoutMandate()
intentWithMandate(mandatePaymentType)
| _ => intentWithoutMandate(mandatePaymentType)
}
| None => intentWithoutMandate()
| None => intentWithoutMandate(mandatePaymentType)
}
| SemiLoaded => intentWithoutMandate()
| SemiLoaded => intentWithoutMandate("")
| _ => ()
}
| None =>
Expand Down

0 comments on commit 4f94264

Please sign in to comment.