support faster payments

This commit is contained in:
woodser 2022-06-22 13:16:43 -04:00
parent d0c02acba1
commit 6dbd1660e5
7 changed files with 36 additions and 28 deletions

View file

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

View file

@ -32,6 +32,14 @@ import lombok.NonNull;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public final class FasterPaymentsAccount extends PaymentAccount { public final class FasterPaymentsAccount extends PaymentAccount {
private static final List<PaymentAccountFormField.FieldId> INPUT_FIELD_IDS = List.of(
PaymentAccountFormField.FieldId.ACCOUNT_NAME,
PaymentAccountFormField.FieldId.HOLDER_NAME,
PaymentAccountFormField.FieldId.SORT_CODE,
PaymentAccountFormField.FieldId.ACCOUNT_NR,
PaymentAccountFormField.FieldId.SALT
);
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("GBP")); public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("GBP"));
public FasterPaymentsAccount() { public FasterPaymentsAccount() {
@ -51,7 +59,7 @@ public final class FasterPaymentsAccount extends PaymentAccount {
@Override @Override
public @NonNull List<PaymentAccountFormField.FieldId> getInputFieldIds() { public @NonNull List<PaymentAccountFormField.FieldId> getInputFieldIds() {
throw new RuntimeException("Not implemented"); return INPUT_FIELD_IDS;
} }
public void setHolderName(String value) { public void setHolderName(String value) {

View file

@ -27,7 +27,9 @@ import bisq.core.locale.Res;
import bisq.core.locale.TradeCurrency; import bisq.core.locale.TradeCurrency;
import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload;
import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.PaymentMethod;
import bisq.core.payment.validation.AccountNrValidator;
import bisq.core.payment.validation.BICValidator; import bisq.core.payment.validation.BICValidator;
import bisq.core.payment.validation.BranchIdValidator;
import bisq.core.payment.validation.EmailOrMobileNrValidator; import bisq.core.payment.validation.EmailOrMobileNrValidator;
import bisq.core.payment.validation.EmailValidator; import bisq.core.payment.validation.EmailValidator;
import bisq.core.payment.validation.IBANValidator; import bisq.core.payment.validation.IBANValidator;
@ -313,7 +315,8 @@ public abstract class PaymentAccount implements PersistablePayload {
processValidationResult(new LengthValidator(2, 100).validate(value)); processValidationResult(new LengthValidator(2, 100).validate(value));
break; break;
case ACCOUNT_NR: case ACCOUNT_NR:
throw new IllegalArgumentException("Not implemented"); processValidationResult(new AccountNrValidator("GB").validate(value));
break;
case ACCOUNT_OWNER: case ACCOUNT_OWNER:
throw new IllegalArgumentException("Not implemented"); throw new IllegalArgumentException("Not implemented");
case ACCOUNT_TYPE: case ACCOUNT_TYPE:
@ -437,15 +440,13 @@ public abstract class PaymentAccount implements PersistablePayload {
if (!value.equals("")) throw new IllegalArgumentException("Salt must be empty"); if (!value.equals("")) throw new IllegalArgumentException("Salt must be empty");
break; break;
case SORT_CODE: case SORT_CODE:
throw new IllegalArgumentException("Not implemented"); processValidationResult(new BranchIdValidator("GB").validate(value));
break;
case SPECIAL_INSTRUCTIONS: case SPECIAL_INSTRUCTIONS:
break; break;
case STATE: case STATE:
String countryCode = form.getValue(PaymentAccountFormField.FieldId.COUNTRY); String countryCode = form.getValue(PaymentAccountFormField.FieldId.COUNTRY);
System.out.println("BACKEND RECEIVED STATE COUNTRY CODE: " + countryCode);
System.out.println("BACKEND RECEIVED STATE: " + value);
boolean isStateRequired = BankUtil.isStateRequired(countryCode); boolean isStateRequired = BankUtil.isStateRequired(countryCode);
System.out.println("IS STATE REQUIRED :" + isStateRequired);
if (value == null || value.isEmpty()) { if (value == null || value.isEmpty()) {
if (isStateRequired) throw new IllegalArgumentException("Must provide state for country " + countryCode); if (isStateRequired) throw new IllegalArgumentException("Must provide state for country " + countryCode);
} else { } else {
@ -494,7 +495,9 @@ public abstract class PaymentAccount implements PersistablePayload {
field.setMaxLength(100); field.setMaxLength(100);
break; break;
case ACCOUNT_NR: case ACCOUNT_NR:
throw new IllegalArgumentException("Not implemented"); field.setComponent(PaymentAccountFormField.Component.TEXT);
field.setLabel("Account number");
break;
case ACCOUNT_OWNER: case ACCOUNT_OWNER:
throw new IllegalArgumentException("Not implemented"); throw new IllegalArgumentException("Not implemented");
case ACCOUNT_TYPE: case ACCOUNT_TYPE:
@ -646,7 +649,9 @@ public abstract class PaymentAccount implements PersistablePayload {
field.setLabel("Salt"); field.setLabel("Salt");
break; break;
case SORT_CODE: case SORT_CODE:
throw new IllegalArgumentException("Not implemented"); field.setComponent(PaymentAccountFormField.Component.TEXT);
field.setLabel("UK sort code");
break;
case SPECIAL_INSTRUCTIONS: case SPECIAL_INSTRUCTIONS:
field.setComponent(PaymentAccountFormField.Component.TEXT); field.setComponent(PaymentAccountFormField.Component.TEXT);
field.setLabel("Special instructions"); field.setLabel("Special instructions");

View file

@ -41,11 +41,12 @@ import lombok.extern.slf4j.Slf4j;
@Getter @Getter
@Slf4j @Slf4j
public final class FasterPaymentsAccountPayload extends PaymentAccountPayload { public final class FasterPaymentsAccountPayload extends PaymentAccountPayload {
@Setter
private String holderName = "";
@Setter @Setter
private String sortCode = ""; private String sortCode = "";
@Setter @Setter
private String accountNr = ""; private String accountNr = "";
private String email = "";// not used anymore but need to keep it for backward compatibility, must not be null but empty string, otherwise hash check fails for contract
public FasterPaymentsAccountPayload(String paymentMethod, String id) { public FasterPaymentsAccountPayload(String paymentMethod, String id) {
super(paymentMethod, id); super(paymentMethod, id);
@ -58,36 +59,36 @@ public final class FasterPaymentsAccountPayload extends PaymentAccountPayload {
private FasterPaymentsAccountPayload(String paymentMethod, private FasterPaymentsAccountPayload(String paymentMethod,
String id, String id,
String holderName,
String sortCode, String sortCode,
String accountNr, String accountNr,
String email,
long maxTradePeriod, long maxTradePeriod,
Map<String, String> excludeFromJsonDataMap) { Map<String, String> excludeFromJsonDataMap) {
super(paymentMethod, super(paymentMethod,
id, id,
maxTradePeriod, maxTradePeriod,
excludeFromJsonDataMap); excludeFromJsonDataMap);
this.holderName = holderName;
this.sortCode = sortCode; this.sortCode = sortCode;
this.accountNr = accountNr; this.accountNr = accountNr;
this.email = email;
} }
@Override @Override
public Message toProtoMessage() { public Message toProtoMessage() {
return getPaymentAccountPayloadBuilder() return getPaymentAccountPayloadBuilder()
.setFasterPaymentsAccountPayload(protobuf.FasterPaymentsAccountPayload.newBuilder() .setFasterPaymentsAccountPayload(protobuf.FasterPaymentsAccountPayload.newBuilder()
.setHolderName(holderName)
.setSortCode(sortCode) .setSortCode(sortCode)
.setAccountNr(accountNr) .setAccountNr(accountNr))
.setEmail(email))
.build(); .build();
} }
public static FasterPaymentsAccountPayload fromProto(protobuf.PaymentAccountPayload proto) { public static FasterPaymentsAccountPayload fromProto(protobuf.PaymentAccountPayload proto) {
return new FasterPaymentsAccountPayload(proto.getPaymentMethodId(), return new FasterPaymentsAccountPayload(proto.getPaymentMethodId(),
proto.getId(), proto.getId(),
proto.getFasterPaymentsAccountPayload().getHolderName(),
proto.getFasterPaymentsAccountPayload().getSortCode(), proto.getFasterPaymentsAccountPayload().getSortCode(),
proto.getFasterPaymentsAccountPayload().getAccountNr(), proto.getFasterPaymentsAccountPayload().getAccountNr(),
proto.getFasterPaymentsAccountPayload().getEmail(),
proto.getMaxTradePeriod(), proto.getMaxTradePeriod(),
new HashMap<>(proto.getExcludeFromJsonDataMap())); new HashMap<>(proto.getExcludeFromJsonDataMap()));
} }
@ -97,14 +98,6 @@ public final class FasterPaymentsAccountPayload extends PaymentAccountPayload {
// API // API
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public String getHolderName() {
return excludeFromJsonDataMap.getOrDefault(HOLDER_NAME, "");
}
public void setHolderName(String holderName) {
excludeFromJsonDataMap.compute(HOLDER_NAME, (k, v) -> Strings.emptyToNull(holderName));
}
@Override @Override
public String getPaymentDetails() { public String getPaymentDetails() {
return Res.get(paymentMethodId) + " - " + getPaymentDetailsForTradePopup().replace("\n", ", "); return Res.get(paymentMethodId) + " - " + getPaymentDetailsForTradePopup().replace("\n", ", ");

View file

@ -50,7 +50,6 @@ public abstract class PaymentAccountPayload implements NetworkPayload, UsedForTr
// Keys for excludeFromJsonDataMap // Keys for excludeFromJsonDataMap
public static final String SALT = "salt"; public static final String SALT = "salt";
public static final String HOLDER_NAME = "holderName";
protected final String paymentMethodId; protected final String paymentMethodId;
protected final String id; protected final String id;

View file

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

View file

@ -1226,9 +1226,9 @@ message InstantCryptoCurrencyAccountPayload {
} }
message FasterPaymentsAccountPayload { message FasterPaymentsAccountPayload {
string sort_code = 1; string holder_name = 1;
string account_nr = 2; string sort_code = 2;
string email = 3 [deprecated = true]; string account_nr = 3;
} }
message InteracETransferAccountPayload { message InteracETransferAccountPayload {
@ -2083,6 +2083,7 @@ message PaymentAccountForm {
F2F = 6; F2F = 6;
STRIKE = 7; STRIKE = 7;
MONEY_GRAM = 8; MONEY_GRAM = 8;
FASTER_PAYMENTS = 9;
} }
FormId id = 1; FormId id = 1;
repeated PaymentAccountFormField fields = 2; repeated PaymentAccountFormField fields = 2;