support uphold

This commit is contained in:
woodser 2022-06-23 10:46:52 -04:00
parent 6dbd1660e5
commit 27f4b18330
6 changed files with 27 additions and 19 deletions

View file

@ -74,7 +74,8 @@ public final class PaymentAccountForm implements PersistablePayload {
F2F,
STRIKE,
MONEY_GRAM,
FASTER_PAYMENTS;
FASTER_PAYMENTS,
UPHOLD;
public static PaymentAccountForm.FormId fromProto(protobuf.PaymentAccountForm.FormId formId) {
return ProtoUtil.enumFromProto(PaymentAccountForm.FormId.class, formId.name());

View file

@ -35,6 +35,7 @@ import bisq.core.payment.validation.EmailValidator;
import bisq.core.payment.validation.IBANValidator;
import bisq.core.payment.validation.LengthValidator;
import bisq.core.proto.CoreProtoResolver;
import bisq.core.util.validation.InputValidator;
import bisq.core.util.validation.InputValidator.ValidationResult;
import bisq.common.proto.ProtoUtil;
import bisq.common.proto.persistable.PersistablePayload;
@ -310,7 +311,8 @@ public abstract class PaymentAccount implements PersistablePayload {
break;
}
case ACCOUNT_ID:
throw new IllegalArgumentException("Not implemented");
processValidationResult(new InputValidator().validate(value));
break;
case ACCOUNT_NAME:
processValidationResult(new LengthValidator(2, 100).validate(value));
break;
@ -318,7 +320,8 @@ public abstract class PaymentAccount implements PersistablePayload {
processValidationResult(new AccountNrValidator("GB").validate(value));
break;
case ACCOUNT_OWNER:
throw new IllegalArgumentException("Not implemented");
processValidationResult(new LengthValidator(2, 100).validate(value));
break;
case ACCOUNT_TYPE:
throw new IllegalArgumentException("Not implemented");
case ANSWER:
@ -380,7 +383,7 @@ public abstract class PaymentAccount implements PersistablePayload {
processValidationResult(new LengthValidator(2, 34).validate(value));
break;
case CONTACT:
checkNotEmpty(value);
processValidationResult(new InputValidator().validate(value));
break;
case COUNTRY:
if (this instanceof CountryBasedPaymentAccount) {
@ -394,11 +397,9 @@ public abstract class PaymentAccount implements PersistablePayload {
if (!CountryUtil.findCountryByCode(value).isPresent()) throw new IllegalArgumentException("Invalid country code: " + value);
break;
case EMAIL:
checkNotEmpty(value);
processValidationResult(new EmailValidator().validate(value));
break;
case EMAIL_OR_MOBILE_NR:
checkNotEmpty(value);
processValidationResult(new EmailOrMobileNrValidator().validate(value));
break;
case EXTRA_INFO:
@ -454,13 +455,12 @@ public abstract class PaymentAccount implements PersistablePayload {
}
break;
case TRADE_CURRENCIES:
checkNotEmpty(value);
processValidationResult(new InputValidator().validate(value));
List<String> currencyCodes = commaDelimitedCodesToList.apply(value);
Optional<List<TradeCurrency>> tradeCurrencies = CurrencyUtil.getTradeCurrenciesInList(currencyCodes, getSupportedCurrencies());
if (!tradeCurrencies.isPresent()) throw new IllegalArgumentException("No trade currencies were found in the " + getPaymentMethod().getDisplayString() + " account form");
break;
case USER_NAME:
checkNotEmpty(value);
processValidationResult(new LengthValidator(3, 100).validate(value));
break;
case VIRTUAL_PAYMENT_ADDRESS:
@ -470,10 +470,6 @@ public abstract class PaymentAccount implements PersistablePayload {
}
}
protected void checkNotEmpty(String input) {
if (input == null || "".equals(input)) throw new IllegalArgumentException("Field must not be empty");
}
protected void processValidationResult(ValidationResult result) {
if (!result.isValid) throw new IllegalArgumentException(result.errorMessage);
}
@ -487,7 +483,9 @@ public abstract class PaymentAccount implements PersistablePayload {
field.setSupportedCountries(((CountryBasedPaymentAccount) this).getSupportedCountries());
break;
case ACCOUNT_ID:
throw new IllegalArgumentException("Not implemented");
field.setComponent(PaymentAccountFormField.Component.TEXT);
field.setLabel("Username or email or phone no.");
break;
case ACCOUNT_NAME:
field.setComponent(PaymentAccountFormField.Component.TEXT);
field.setLabel("Account name"); // TODO: pull all labels from language file
@ -499,7 +497,9 @@ public abstract class PaymentAccount implements PersistablePayload {
field.setLabel("Account number");
break;
case ACCOUNT_OWNER:
throw new IllegalArgumentException("Not implemented");
field.setComponent(PaymentAccountFormField.Component.TEXT);
field.setLabel("Account owner full name");
break;
case ACCOUNT_TYPE:
throw new IllegalArgumentException("Not implemented");
case ANSWER:

View file

@ -34,6 +34,14 @@ import org.jetbrains.annotations.NotNull;
@EqualsAndHashCode(callSuper = true)
public final class UpholdAccount extends PaymentAccount {
private static final List<PaymentAccountFormField.FieldId> INPUT_FIELD_IDS = List.of(
PaymentAccountFormField.FieldId.ACCOUNT_NAME,
PaymentAccountFormField.FieldId.ACCOUNT_OWNER,
PaymentAccountFormField.FieldId.ACCOUNT_ID,
PaymentAccountFormField.FieldId.TRADE_CURRENCIES,
PaymentAccountFormField.FieldId.SALT
);
// https://support.uphold.com/hc/en-us/articles/202473803-Supported-currencies
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(
new FiatCurrency("AED"),
@ -78,7 +86,7 @@ public final class UpholdAccount extends PaymentAccount {
@Override
public @NotNull List<PaymentAccountFormField.FieldId> getInputFieldIds() {
throw new RuntimeException("Not implemented");
return INPUT_FIELD_IDS;
}
public void setAccountId(String accountId) {

View file

@ -337,7 +337,8 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
F2F_ID,
STRIKE_ID,
MONEY_GRAM_ID,
FASTER_PAYMENTS_ID);
FASTER_PAYMENTS_ID,
UPHOLD_ID);
return paymentMethods.stream().filter(paymentMethod -> paymentMethodIds.contains(paymentMethod.getId())).collect(Collectors.toList());
}

View file

@ -41,9 +41,6 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public final class UpholdAccountPayload extends PaymentAccountPayload {
private String accountId = "";
// For backward compatibility we need to exclude the new field from the contract json.
@JsonExclude
private String accountOwner = "";
public UpholdAccountPayload(String paymentMethod, String id) {

View file

@ -2084,6 +2084,7 @@ message PaymentAccountForm {
STRIKE = 7;
MONEY_GRAM = 8;
FASTER_PAYMENTS = 9;
UPHOLD = 10;
}
FormId id = 1;
repeated PaymentAccountFormField fields = 2;