Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: HS-187: Added Pix Bank Transfer #129

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Components/DynamicFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ let make = (
PaymentMethodsRecord.getPaymentMethodTypeFromList(
~list,
~paymentMethod,
~paymentMethodType,
~paymentMethodType=PaymentUtils.getPaymentMethodName(
~paymentMethodType=paymentMethod,
~paymentMethodName=paymentMethodType,
),
)->Belt.Option.getWithDefault(PaymentMethodsRecord.defaultPaymentMethodType)

let requiredFieldsWithBillingDetails = if paymentMethod === "card" {
Expand Down
5 changes: 4 additions & 1 deletion src/Components/Surcharge.res
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ let make = (
PaymentMethodsRecord.getPaymentMethodTypeFromList(
~list,
~paymentMethod,
~paymentMethodType,
~paymentMethodType=PaymentUtils.getPaymentMethodName(
~paymentMethodType=paymentMethod,
~paymentMethodName=paymentMethodType,
),
)->Belt.Option.getWithDefault(PaymentMethodsRecord.defaultPaymentMethodType)
}

Expand Down
8 changes: 8 additions & 0 deletions src/Payments/PaymentMethodsRecord.res
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,13 @@ let paymentMethodsFields = [
fields: [InfoElement],
miniIcon: Some(icon("cashtocode", ~size=19)),
},
{
paymentMethodName: "pix_transfer",
fields: [InfoElement],
icon: Some(icon("pix", ~size=26, ~width=40)),
displayName: "Pix",
miniIcon: None,
},
]

type required_fields = {
Expand Down Expand Up @@ -560,6 +567,7 @@ let dynamicFieldsEnabledPaymentMethods = [
"eps",
"ideal",
"sofort",
"pix_transfer",
]

let getIsBillingField = requiredFieldType => {
Expand Down
7 changes: 5 additions & 2 deletions src/Payments/PaymentMethodsWrapper.res
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ let make = (
let optionPaymentMethodDetails =
list
->PaymentMethodsRecord.buildFromPaymentList
->Js.Array2.find(x => x.paymentMethodName === paymentMethodName)
->Js.Array2.find(x =>
x.paymentMethodName ===
PaymentUtils.getPaymentMethodName(~paymentMethodType=x.methodType, ~paymentMethodName)
)
let paymentMethodDetails =
optionPaymentMethodDetails->Belt.Option.getWithDefault(
PaymentMethodsRecord.defaultPaymentMethodContent,
Expand Down Expand Up @@ -120,7 +123,7 @@ let make = (
paymentType
list
paymentMethod=paymentMethodDetails.methodType
paymentMethodType=paymentMethodDetails.paymentMethodName
paymentMethodType=paymentMethodName
setRequiredFieldsBody
/>
</div>
Expand Down
9 changes: 8 additions & 1 deletion src/Payments/QRCodeDisplay.res
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ let make = () => {
let (x, val) = entries
Js.Dict.set(headers, x, val->Js.Json.decodeString->Belt.Option.getWithDefault(""))
})
let _timeExpiry = metaDataDict->getString("expiryTime", "")
let timeExpiry =
metaDataDict
->getString("expiryTime", "")
->Belt.Float.fromString
->Belt.Option.getWithDefault(0.0)
if timeExpiry > 0.0 && timeExpiry < 900000.0 {
setExpiryTime(_ => timeExpiry)
}
open Promise
setHeaders(_ => headers->Js.Dict.entries)
PaymentHelpers.pollRetrievePaymentIntent(
Expand Down
3 changes: 3 additions & 0 deletions src/Types/PaymentConfirmTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type nextAction = {
bank_transfer_steps_and_charges_details: option<Js.Json.t>,
session_token: option<Js.Json.t>,
image_data_url: option<string>,
display_to_timestamp: option<string>,
}
type intent = {
nextAction: nextAction,
Expand All @@ -56,6 +57,7 @@ let defaultNextAction = {
bank_transfer_steps_and_charges_details: None,
session_token: None,
image_data_url: None,
display_to_timestamp: None,
}
let defaultIntent = {
nextAction: defaultNextAction,
Expand Down Expand Up @@ -123,6 +125,7 @@ let getNextAction = (dict, str) => {
getJsonObjFromDict(json, "session_token", Js.Dict.empty())->Js.Json.object_,
),
image_data_url: Some(json->getString("image_data_url", "")),
display_to_timestamp: Some(json->getString("display_to_timestamp", ""))
}
})
->Belt.Option.getWithDefault(defaultNextAction)
Expand Down
19 changes: 19 additions & 0 deletions src/Utilities/PaymentBody.res
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,24 @@ let openBankingUKBody = () => {
]
}

let pixTransferBody = () => {
[
("payment_method", "bank_transfer"->Js.Json.string),
("payment_method_type", "pix"->Js.Json.string),
(
"payment_method_data",
[
(
"bank_transfer",
[("pix", Js.Dict.empty()->Js.Json.object_)]->Js.Dict.fromArray->Js.Json.object_,
),
]
->Js.Dict.fromArray
->Js.Json.object_,
),
]
}

let getPaymentBody = (
~paymentMethod,
~fullName,
Expand Down Expand Up @@ -1513,6 +1531,7 @@ let getPaymentBody = (
| "card_redirect" => cardRedirectBody()
| "open_banking_uk" => openBankingUKBody()
| "evoucher" => rewardBody(~paymentMethodType=paymentMethod)
| "pix_transfer" => pixTransferBody()
| _ => []
}
}
3 changes: 2 additions & 1 deletion src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ let intentCall = (
])
} else if intent.nextAction.type_ === "qr_code_information" {
let qrData = intent.nextAction.image_data_url->Belt.Option.getWithDefault("")
let expiryTime = intent.nextAction.display_to_timestamp->Belt.Option.getWithDefault("")
let headerObj = Js.Dict.empty()
headers->Js.Array2.forEach(entries => {
let (x, val) = entries
Expand All @@ -263,7 +264,7 @@ let intentCall = (
("qrData", qrData->Js.Json.string),
("paymentIntentId", clientSecret->Js.Json.string),
("headers", headerObj->Js.Json.object_),
("expiryTime", Js.Json.null),
("expiryTime", expiryTime->Js.Json.string),
("url", url.href->Js.Json.string),
]->Js.Dict.fromArray
handleLogging(
Expand Down
10 changes: 10 additions & 0 deletions src/Utilities/PaymentUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,13 @@ let getDisplayNameAndIcon = (
| None => (defaultName, defaultIcon)
}
}

let getPaymentMethodName = (~paymentMethodType, ~paymentMethodName) => {
if paymentMethodType == "bank_debit" {
paymentMethodName->Js.String2.replace("_debit", "")
} else if paymentMethodType == "bank_transfer" {
paymentMethodName->Js.String2.replace("_transfer", "")
} else {
paymentMethodName
}
}