diff --git a/src/CollectWidget.res b/src/CollectWidget.res
index ed8c65be1..52f999b72 100644
--- a/src/CollectWidget.res
+++ b/src/CollectWidget.res
@@ -152,8 +152,12 @@ let make = (
fieldName={field->getPaymentMethodDataFieldLabel(localeString)}
value
setValue={getVal => {
- let isValid = calculateValidity(field, getVal(), ~default=Some(false))
+ let updatedValue = getVal()
+ let isValid = calculateValidity(field, updatedValue, ~default=Some(false))
setValidityDictVal(key, isValid)
+ if isValid->Option.getOr(false) {
+ setFormData(key, updatedValue)
+ }
}}
options={countries->DropdownField.updateArrayOfStringToOptionsTypeArray}
disabled=false
diff --git a/src/FormViewTabs.res b/src/FormViewTabs.res
index 1ee3a44ed..28643ea19 100644
--- a/src/FormViewTabs.res
+++ b/src/FormViewTabs.res
@@ -226,8 +226,10 @@ let make = (
{payoutDynamicFields.payoutMethodData->renderPayoutMethodForm->React.array}
{payoutDynamicFields.address
->Option.map(addressFields => {
- let formFields = addressFields->renderAddressForm
- if formFields->Array.length > 0 {
+ let fieldsToCollect =
+ addressFields->Array.filter(addressField => addressField.value == None)
+ if fieldsToCollect->Array.length > 0 {
+ let formFields = addressFields->renderAddressForm
<>
{React.string(localeString.billingDetailsText)}
diff --git a/src/PaymentMethodCollectElement.res b/src/PaymentMethodCollectElement.res
index 7435fb822..f791f9ac7 100644
--- a/src/PaymentMethodCollectElement.res
+++ b/src/PaymentMethodCollectElement.res
@@ -192,7 +192,7 @@ let make = (~integrateError, ~logger) => {
let renderCollectWidget = () =>
-
+
{loader
?
: {React.null}}
diff --git a/src/Types/PaymentMethodCollectTypes.res b/src/Types/PaymentMethodCollectTypes.res
index 69b618c79..c9d78a2a0 100644
--- a/src/Types/PaymentMethodCollectTypes.res
+++ b/src/Types/PaymentMethodCollectTypes.res
@@ -252,9 +252,15 @@ let getFieldOptions = dict => {
obj
->Dict.get("options")
->Option.flatMap(JSON.Decode.array)
- ->Option.map(options => BillingAddress(
- AddressCountry(options->Array.filterMap(option => option->JSON.Decode.string)),
- ))
+ ->Option.map(options => {
+ let countries = options->Array.filterMap(option => option->JSON.Decode.string)
+ countries->Array.sort(
+ (c1, c2) =>
+ (c1->String.charCodeAt(0)->Float.toInt - c2->String.charCodeAt(0)->Float.toInt)
+ ->Int.toFloat,
+ )
+ BillingAddress(AddressCountry(countries))
+ })
)
| _ => None
}
@@ -338,7 +344,9 @@ let sortByCustomOrder = (arr: array<'a>, getKey: 'a => string, customOrder: arra
})
}
-let decodePayoutDynamicFields = (json: JSON.t): option
=>
+let decodePayoutDynamicFields = (json: JSON.t, defaultDynamicPmdFields): option<
+ payoutDynamicFields,
+> =>
json
->JSON.Decode.object
->Option.map(obj => {
@@ -382,7 +390,9 @@ let decodePayoutDynamicFields = (json: JSON.t): option =>
address: address->Array.length > 0
? Some(sortByCustomOrder(address, item => item.pmdMap, customAddressOrder))
: None,
- payoutMethodData: sortByCustomOrder(pmd, item => item.pmdMap, customPmdOrder),
+ payoutMethodData: pmd->Array.length > 0
+ ? sortByCustomOrder(pmd, item => item.pmdMap, customPmdOrder)
+ : defaultDynamicPmdFields,
}
})
@@ -427,7 +437,9 @@ let decodePaymentMethodTypeWithRequiredFields = (
let payoutDynamicFields =
obj
->Dict.get("required_fields")
- ->Option.flatMap(decodePayoutDynamicFields)
+ ->Option.flatMap(
+ json => json->decodePayoutDynamicFields(defaultDynamicPmdFields(~pmt)),
+ )
->Option.getOr({
address: None,
payoutMethodData: defaultDynamicPmdFields(~pmt),
@@ -435,7 +447,10 @@ let decodePaymentMethodTypeWithRequiredFields = (
switch pmt {
| Card(card) => {
pmta->Array.push(Card(card))
- let pmtwr: paymentMethodTypeWithDynamicFields = Card(card, payoutDynamicFields)
+ let pmtwr: paymentMethodTypeWithDynamicFields = Card(
+ card,
+ payoutDynamicFields,
+ )
pmtr->Array.push(pmtwr)
(pmta, pmtr)
}
diff --git a/src/Utilities/PaymentMethodCollectUtils.res b/src/Utilities/PaymentMethodCollectUtils.res
index 23381614d..ebf3b4501 100644
--- a/src/Utilities/PaymentMethodCollectUtils.res
+++ b/src/Utilities/PaymentMethodCollectUtils.res
@@ -289,7 +289,7 @@ let getPaymentMethodDataFieldCharacterPattern = (key): option =>
| PayoutMethodData(PaypalMobNumber) => Some(%re("/^[0-9]{1,12}$/"))
| PayoutMethodData(SepaBic) => Some(%re("/^([A-Z0-9]| ){1,8}$/"))
| PayoutMethodData(SepaIban) => Some(%re("/^([A-Z0-9]| ){1,34}$/"))
- | BillingAddress(AddressPincode) => Some(%re("/^[0-9]{1,8}$/"))
+ | BillingAddress(AddressPincode) => Some(%re("/^([0-9A-Z]| ){1,10}$/"))
| BillingAddress(PhoneNumber) => Some(%re("/^[0-9]{1,12}$/"))
| BillingAddress(PhoneCountryCode) => Some(%re("/^[0-9]{1,2}$/"))
| _ => None
@@ -521,7 +521,7 @@ let defaultPaypalFields = [
{
pmdMap: "payout_method_data.wallet.telephone_number",
displayName: "user_phone_number",
- fieldType: SepaIban,
+ fieldType: PaypalMobNumber,
value: None,
},
]
@@ -565,12 +565,12 @@ let defaultEnabledPaymentMethods: array = [
Wallet(Paypal),
]
let defaultEnabledPaymentMethodsWithDynamicFields: array = [
- Card((Credit, defaultPayoutDynamicFields())),
- Card((Debit, defaultPayoutDynamicFields())),
- BankTransfer((ACH, defaultPayoutDynamicFields())),
- BankTransfer((Bacs, defaultPayoutDynamicFields())),
- BankTransfer((Sepa, defaultPayoutDynamicFields())),
- Wallet((Paypal, defaultPayoutDynamicFields())),
+ Card((Credit, defaultPayoutDynamicFields(~pmt=Card(Credit)))),
+ Card((Debit, defaultPayoutDynamicFields(~pmt=Card(Debit)))),
+ BankTransfer((ACH, defaultPayoutDynamicFields(~pmt=BankTransfer(ACH)))),
+ BankTransfer((Bacs, defaultPayoutDynamicFields(~pmt=BankTransfer(Bacs)))),
+ BankTransfer((Sepa, defaultPayoutDynamicFields(~pmt=BankTransfer(Sepa)))),
+ Wallet((Paypal, defaultPayoutDynamicFields(~pmt=Wallet(Paypal)))),
]
let defaultPaymentMethodCollectOptions = {
enabledPaymentMethods: defaultEnabledPaymentMethods,
@@ -696,6 +696,11 @@ let calculateValidity = (key, value, ~default=None) => {
} else {
Some(false)
}
+ | PayoutMethodData(SepaIban) => Some(value->String.length > 13 && value->String.length < 34)
+
+ // Sepa BIC is optional
+ | PayoutMethodData(SepaBic) => Some(true)
+
// Defaults
| PayoutMethodData(_)
| BillingAddress(_) =>