diff --git a/src/Payments/PaymentMethodsRecord.res b/src/Payments/PaymentMethodsRecord.res index 1d3855e32..ce9a72dfd 100644 --- a/src/Payments/PaymentMethodsRecord.res +++ b/src/Payments/PaymentMethodsRecord.res @@ -479,7 +479,7 @@ let paymentMethodsFields = [ miniIcon: None, }, { - paymentMethodName: "multibanco", + paymentMethodName: "multibanco_transfer", icon: Some(icon("multibanco", ~size=19)), displayName: "Multibanco", fields: [Email, InfoElement], diff --git a/src/Utilities/DynamicFieldsUtils.res b/src/Utilities/DynamicFieldsUtils.res index 02bf1ae1d..34a27478b 100644 --- a/src/Utilities/DynamicFieldsUtils.res +++ b/src/Utilities/DynamicFieldsUtils.res @@ -42,12 +42,12 @@ let isBillingAddressFieldType = (fieldType: PaymentMethodsRecord.paymentMethodsF let getBillingAddressPathFromFieldType = (fieldType: PaymentMethodsRecord.paymentMethodsFields) => { switch fieldType { - | AddressLine1 => "billing.address.line1" - | AddressLine2 => "billing.address.line2" - | AddressCity => "billing.address.city" - | AddressState => "billing.address.state" - | AddressCountry(_) => "billing.address.country" - | AddressPincode => "billing.address.zip" + | AddressLine1 => "payment_method_data.billing.address.line1" + | AddressLine2 => "payment_method_data.billing.address.line2" + | AddressCity => "payment_method_data.billing.address.city" + | AddressState => "payment_method_data.billing.address.state" + | AddressCountry(_) => "payment_method_data.billing.address.country" + | AddressPincode => "payment_method_data.billing.address.zip" | _ => "" } } @@ -552,11 +552,11 @@ let useRequiredFieldsBody = ( if item === BillingName { let arr = value->String.split(" ") acc->Dict.set( - "billing.address.first_name", + "payment_method_data.billing.address.first_name", arr->Array.get(0)->Option.getOr("")->JSON.Encode.string, ) acc->Dict.set( - "billing.address.last_name", + "payment_method_data.billing.address.last_name", arr->Array.get(1)->Option.getOr("")->JSON.Encode.string, ) } else { diff --git a/src/Utilities/PaymentBody.res b/src/Utilities/PaymentBody.res index 46d53d3a9..00f827a4b 100644 --- a/src/Utilities/PaymentBody.res +++ b/src/Utilities/PaymentBody.res @@ -7,24 +7,29 @@ let billingDetailsTuple = ( ~state, ~postalCode, ~country, -) => ( - "billing_details", - [ - ("name", fullName->JSON.Encode.string), - ("email", email->JSON.Encode.string), - ( - "address", - [ - ("line1", line1->JSON.Encode.string), - ("line2", line2->JSON.Encode.string), - ("city", city->JSON.Encode.string), - ("state", state->JSON.Encode.string), - ("zip", postalCode->JSON.Encode.string), - ("country", country->JSON.Encode.string), - ]->Utils.getJsonFromArrayOfJson, - ), - ]->Utils.getJsonFromArrayOfJson, -) +) => { + let (firstName, lastName) = fullName->Utils.getFirstAndLastNameFromFullName + + ( + "billing", + [ + ("email", email->JSON.Encode.string), + ( + "address", + [ + ("first_name", firstName), + ("last_name", lastName), + ("line1", line1->JSON.Encode.string), + ("line2", line2->JSON.Encode.string), + ("city", city->JSON.Encode.string), + ("state", state->JSON.Encode.string), + ("zip", postalCode->JSON.Encode.string), + ("country", country->JSON.Encode.string), + ]->Utils.getJsonFromArrayOfJson, + ), + ]->Utils.getJsonFromArrayOfJson, + ) +} let cardPaymentBody = ( ~cardNumber, @@ -192,22 +197,22 @@ let achBankDebitBody = ( ( "payment_method_data", [ + billingDetailsTuple( + ~fullName=cardHolderName, + ~email, + ~line1, + ~line2, + ~city, + ~state, + ~postalCode, + ~country, + ), ( "bank_debit", [ ( "ach_bank_debit", [ - billingDetailsTuple( - ~fullName=cardHolderName, - ~email, - ~line1, - ~line2, - ~city, - ~state, - ~postalCode, - ~country, - ), ("account_number", bank.accountNumber->JSON.Encode.string), ("bank_account_holder_name", bank.accountHolderName->JSON.Encode.string), ("routing_number", bank.routingNumber->JSON.Encode.string), @@ -235,22 +240,22 @@ let sepaBankDebitBody = ( ( "payment_method_data", [ + billingDetailsTuple( + ~fullName, + ~email, + ~line1, + ~line2, + ~city, + ~state, + ~postalCode, + ~country, + ), ( "bank_debit", [ ( "sepa_bank_debit", [ - billingDetailsTuple( - ~fullName, - ~email, - ~line1, - ~line2, - ~city, - ~state, - ~postalCode, - ~country, - ), ("iban", data.iban->JSON.Encode.string), ("bank_account_holder_name", data.accountHolderName->JSON.Encode.string), ]->Utils.getJsonFromArrayOfJson, @@ -277,22 +282,22 @@ let bacsBankDebitBody = ( ( "payment_method_data", [ + billingDetailsTuple( + ~fullName=bankAccountHolderName, + ~email, + ~line1, + ~line2, + ~city, + ~state, + ~postalCode=zip, + ~country, + ), ( "bank_debit", [ ( "bacs_bank_debit", [ - billingDetailsTuple( - ~fullName=bankAccountHolderName, - ~email, - ~line1, - ~line2, - ~city, - ~state, - ~postalCode=zip, - ~country, - ), ("bank_account_holder_name", bankAccountHolderName->JSON.Encode.string), ("sort_code", sortCode->JSON.Encode.string), ("account_number", accNum->JSON.Encode.string), @@ -319,22 +324,22 @@ let becsBankDebitBody = ( ( "payment_method_data", [ + billingDetailsTuple( + ~fullName, + ~email, + ~line1, + ~line2, + ~city, + ~state, + ~postalCode, + ~country, + ), ( "bank_debit", [ ( "becs_bank_debit", [ - billingDetailsTuple( - ~fullName, - ~email, - ~line1, - ~line2, - ~city, - ~state, - ~postalCode, - ~country, - ), ("bsb_number", data.sortCode->JSON.Encode.string), ("account_number", data.accountNumber->JSON.Encode.string), ("bank_account_holder_name", data.accountHolderName->JSON.Encode.string), @@ -698,78 +703,75 @@ let achBankTransferBody = (~email, ~connectors) => [ ( "payment_method_data", [ + ("billing", [("email", email->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson), ( "bank_transfer", - [ - ( - "ach_bank_transfer", - [ - ( - "billing_details", - [("email", email->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson, - ), - ]->Utils.getJsonFromArrayOfJson, - ), - ]->Utils.getJsonFromArrayOfJson, - ), - ]->Utils.getJsonFromArrayOfJson, - ), -] -let bacsBankTransferBody = (~email, ~name, ~connectors) => [ - ("payment_method", "bank_transfer"->JSON.Encode.string), - ("connector", connectors->Utils.getArrofJsonString->JSON.Encode.array), - ("payment_method_type", "bacs"->JSON.Encode.string), - ( - "payment_method_data", - [ - ( - "bank_transfer", - [ - ( - "bacs_bank_transfer", - [ - ( - "billing_details", - [ - ("email", email->JSON.Encode.string), - ("name", name->JSON.Encode.string), - ]->Utils.getJsonFromArrayOfJson, - ), - ]->Utils.getJsonFromArrayOfJson, - ), - ]->Utils.getJsonFromArrayOfJson, - ), - ]->Utils.getJsonFromArrayOfJson, - ), -] -let sepaBankTransferBody = (~email, ~name, ~country, ~connectors) => [ - ("payment_method", "bank_transfer"->JSON.Encode.string), - ("connector", connectors->Utils.getArrofJsonString->JSON.Encode.array), - ("payment_method_type", "sepa"->JSON.Encode.string), - ( - "payment_method_data", - [ - ( - "bank_transfer", - [ - ( - "sepa_bank_transfer", - [ - ( - "billing_details", - [ - ("email", email->JSON.Encode.string), - ("name", name->JSON.Encode.string), - ]->Utils.getJsonFromArrayOfJson, - ), - ("country", country->JSON.Encode.string), - ]->Utils.getJsonFromArrayOfJson, - ), - ]->Utils.getJsonFromArrayOfJson, + [("ach_bank_transfer", Dict.make()->JSON.Encode.object)]->Utils.getJsonFromArrayOfJson, ), ]->Utils.getJsonFromArrayOfJson, ), ] +let bacsBankTransferBody = (~email, ~name, ~connectors) => { + let (firstName, lastName) = name->Utils.getFirstAndLastNameFromFullName + + [ + ("payment_method", "bank_transfer"->JSON.Encode.string), + ("connector", connectors->Utils.getArrofJsonString->JSON.Encode.array), + ("payment_method_type", "bacs"->JSON.Encode.string), + ( + "payment_method_data", + [ + ( + "billing", + [ + ("email", email->JSON.Encode.string), + ( + "address", + [("first_name", firstName), ("last_name", lastName)]->Utils.getJsonFromArrayOfJson, + ), + ]->Utils.getJsonFromArrayOfJson, + ), + ( + "bank_transfer", + [("bacs_bank_transfer", Dict.make()->JSON.Encode.object)]->Utils.getJsonFromArrayOfJson, + ), + ]->Utils.getJsonFromArrayOfJson, + ), + ] +} + +let sepaBankTransferBody = (~email, ~name, ~country, ~connectors) => { + let (firstName, lastName) = name->Utils.getFirstAndLastNameFromFullName + + [ + ("payment_method", "bank_transfer"->JSON.Encode.string), + ("connector", connectors->Utils.getArrofJsonString->JSON.Encode.array), + ("payment_method_type", "sepa"->JSON.Encode.string), + ( + "payment_method_data", + [ + ( + "billing", + [ + ("email", email->JSON.Encode.string), + ( + "address", + [ + ("first_name", firstName), + ("last_name", lastName), + ("country", country->JSON.Encode.string), + ]->Utils.getJsonFromArrayOfJson, + ), + ]->Utils.getJsonFromArrayOfJson, + ), + ( + "bank_transfer", + [("sepa_bank_transfer", Dict.make()->JSON.Encode.object)]->Utils.getJsonFromArrayOfJson, + ), + ]->Utils.getJsonFromArrayOfJson, + ), + ] +} let blikBody = (~blikCode) => [ ("payment_method", "bank_redirect"->JSON.Encode.string), ("payment_method_type", "blik"->JSON.Encode.string), @@ -792,19 +794,10 @@ let p24Body = (~email) => [ ( "payment_method_data", [ + ("billing", [("email", email->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson), ( "bank_redirect", - [ - ( - "przelewy24", - [ - ( - "billing_details", - [("email", email->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson, - ), - ]->Utils.getJsonFromArrayOfJson, - ), - ]->Utils.getJsonFromArrayOfJson, + [("przelewy24", Dict.make()->JSON.Encode.object)]->Utils.getJsonFromArrayOfJson, ), ]->Utils.getJsonFromArrayOfJson, ), @@ -973,18 +966,11 @@ let multibancoBody = (~email) => [ ( "payment_method_data", [ + ("billing", [("email", email->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson), ( "bank_transfer", [ - ( - "multibanco_bank_transfer", - [ - ( - "billing_details", - [("email", email->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson, - ), - ]->Utils.getJsonFromArrayOfJson, - ), + ("multibanco_bank_transfer", Dict.make()->JSON.Encode.object), ]->Utils.getJsonFromArrayOfJson, ), ]->Utils.getJsonFromArrayOfJson, @@ -1099,7 +1085,7 @@ let getPaymentBody = ( | "przelewy24" => p24Body(~email) | "online_banking_fpx" => fpxOBBody(~bank) | "online_banking_thailand" => thailandOBBody(~bank) - | "multibanco" => multibancoBody(~email) + | "multibanco_transfer" => multibancoBody(~email) | "classic" | "evoucher" => rewardBody(~paymentMethodType) diff --git a/src/Utilities/Utils.res b/src/Utilities/Utils.res index 305df1d28..5ff6c7c2e 100644 --- a/src/Utilities/Utils.res +++ b/src/Utilities/Utils.res @@ -1355,3 +1355,16 @@ let checkIs18OrAbove = dateOfBirth => { let compareDate = Date.makeWithYMD(~year, ~month, ~date) dateOfBirth <= compareDate } + +let getFirstAndLastNameFromFullName = fullName => { + let nameStrings = fullName->String.split(" ") + let firstName = + nameStrings + ->Array.get(0) + ->Option.flatMap(x => Some(x->JSON.Encode.string)) + ->Option.getOr(JSON.Encode.null) + let lastNameStr = nameStrings->Array.sliceToEnd(~start=1)->Array.joinWith(" ")->String.trim + let lastNameJson = lastNameStr === "" ? JSON.Encode.null : lastNameStr->JSON.Encode.string + + (firstName, lastNameJson) +}