diff --git a/src/Payments/PaypalSDKHelpers.res b/src/Payments/PaypalSDKHelpers.res index 7738c4236..50f2be048 100644 --- a/src/Payments/PaypalSDKHelpers.res +++ b/src/Payments/PaypalSDKHelpers.res @@ -76,8 +76,16 @@ let loadPaypalSDK = ( ->Option.flatMap(JSON.Decode.object) ->Option.getOr(Dict.make()) let details = purchaseUnit->paypalShippingDetails + let payerDetails = + val + ->Utils.getDictFromJson + ->Dict.get("payer") + ->Option.flatMap(JSON.Decode.object) + ->Option.getOr(Dict.make()) + ->PaymentType.itemToPayerDetailsObjectMapper let requiredFieldsBody = DynamicFieldsUtils.getPaypalRequiredFields( ~details, + ~payerDetails, ~paymentMethodTypes, ~statesList=stateJson, ) diff --git a/src/Types/PaymentType.res b/src/Types/PaymentType.res index 5eb0d9065..2737249dc 100644 --- a/src/Types/PaymentType.res +++ b/src/Types/PaymentType.res @@ -173,6 +173,12 @@ type options = { displayDefaultSavedPaymentIcon: bool, hideCardNicknameField: bool, } + +type payerDetails = { + email: option, + phone: option, +} + let defaultCardDetails = { scheme: None, last4Digits: "", @@ -311,6 +317,12 @@ let defaultOptions = { displayDefaultSavedPaymentIcon: true, hideCardNicknameField: false, } + +let defaultPayerDetails = { + email: None, + phone: None, +} + let getLayout = (str, logger) => { switch str { | "tabs" => Tabs @@ -1061,3 +1073,14 @@ type loadType = Loading | Loaded(JSON.t) | SemiLoaded | LoadError(JSON.t) let getIsStoredPaymentMethodHasName = (savedMethod: customerMethods) => { savedMethod.card.cardHolderName->Option.getOr("")->String.length > 0 } + +let itemToPayerDetailsObjectMapper = dict => { + email: dict->Dict.get("email_address")->Option.flatMap(JSON.Decode.string), + phone: dict + ->Dict.get("phone") + ->Option.flatMap(JSON.Decode.object) + ->Option.flatMap(Dict.get(_, "phone_number")) + ->Option.flatMap(JSON.Decode.object) + ->Option.flatMap(Dict.get(_, "national_number")) + ->Option.flatMap(JSON.Decode.string), +} diff --git a/src/Utilities/DynamicFieldsUtils.res b/src/Utilities/DynamicFieldsUtils.res index 8c3d70b9f..7025f9756 100644 --- a/src/Utilities/DynamicFieldsUtils.res +++ b/src/Utilities/DynamicFieldsUtils.res @@ -1051,6 +1051,7 @@ let getGooglePayRequiredFields = ( let getPaypalRequiredFields = ( ~details: PaypalSDKTypes.details, + ~payerDetails: PaymentType.payerDetails=PaymentType.defaultPayerDetails, ~paymentMethodTypes: PaymentMethodsRecord.paymentMethodTypes, ~statesList, ) => { @@ -1072,12 +1073,23 @@ let getPaypalRequiredFields = ( } | ShippingAddressCountry(_) => details.shippingAddress.countryCode->Option.getOr("") | ShippingAddressPincode => details.shippingAddress.postalCode->Option.getOr("") - | Email => details.email + | Email => + switch item.required_field { + | "payment_method_data.billing.email" + | "shipping.email" => + payerDetails.email->Option.getOr("") + | _ => details.email + } | PhoneNumber => - switch (details.phone->Option.getOr(""), details.shippingAddress.phone->Option.getOr("")) { - | (phone, "") => phone - | ("", phone) => phone - | _ => "" + switch item.required_field { + | "payment_method_data.billing.phone.number" | "shipping.phone.number" => + payerDetails.phone->Option.getOr("") + | _ => + switch (details.phone, details.shippingAddress.phone) { + | (Some(phone), None) => phone + | (None, Some(phone)) => phone + | _ => "" + } } | _ => "" }