From 6dbd1660e58d1fbe2c036e55461cf46ccb941341 Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 22 Jun 2022 13:16:43 -0400 Subject: [PATCH] support faster payments --- .../core/api/model/PaymentAccountForm.java | 3 ++- .../core/payment/FasterPaymentsAccount.java | 10 ++++++++- .../bisq/core/payment/PaymentAccount.java | 19 ++++++++++------- .../payload/FasterPaymentsAccountPayload.java | 21 +++++++------------ .../payload/PaymentAccountPayload.java | 1 - .../core/payment/payload/PaymentMethod.java | 3 ++- proto/src/main/proto/pb.proto | 7 ++++--- 7 files changed, 36 insertions(+), 28 deletions(-) diff --git a/core/src/main/java/bisq/core/api/model/PaymentAccountForm.java b/core/src/main/java/bisq/core/api/model/PaymentAccountForm.java index 9a741adc1f..cf6febb245 100644 --- a/core/src/main/java/bisq/core/api/model/PaymentAccountForm.java +++ b/core/src/main/java/bisq/core/api/model/PaymentAccountForm.java @@ -73,7 +73,8 @@ public final class PaymentAccountForm implements PersistablePayload { SWIFT, F2F, STRIKE, - MONEY_GRAM; + MONEY_GRAM, + FASTER_PAYMENTS; public static PaymentAccountForm.FormId fromProto(protobuf.PaymentAccountForm.FormId formId) { return ProtoUtil.enumFromProto(PaymentAccountForm.FormId.class, formId.name()); diff --git a/core/src/main/java/bisq/core/payment/FasterPaymentsAccount.java b/core/src/main/java/bisq/core/payment/FasterPaymentsAccount.java index 77ed108085..dd36a83813 100644 --- a/core/src/main/java/bisq/core/payment/FasterPaymentsAccount.java +++ b/core/src/main/java/bisq/core/payment/FasterPaymentsAccount.java @@ -32,6 +32,14 @@ import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class FasterPaymentsAccount extends PaymentAccount { + private static final List 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 SUPPORTED_CURRENCIES = List.of(new FiatCurrency("GBP")); public FasterPaymentsAccount() { @@ -51,7 +59,7 @@ public final class FasterPaymentsAccount extends PaymentAccount { @Override public @NonNull List getInputFieldIds() { - throw new RuntimeException("Not implemented"); + return INPUT_FIELD_IDS; } public void setHolderName(String value) { diff --git a/core/src/main/java/bisq/core/payment/PaymentAccount.java b/core/src/main/java/bisq/core/payment/PaymentAccount.java index 2d23702e6c..b97d4f54a3 100644 --- a/core/src/main/java/bisq/core/payment/PaymentAccount.java +++ b/core/src/main/java/bisq/core/payment/PaymentAccount.java @@ -27,7 +27,9 @@ import bisq.core.locale.Res; import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import bisq.core.payment.validation.AccountNrValidator; import bisq.core.payment.validation.BICValidator; +import bisq.core.payment.validation.BranchIdValidator; import bisq.core.payment.validation.EmailOrMobileNrValidator; import bisq.core.payment.validation.EmailValidator; import bisq.core.payment.validation.IBANValidator; @@ -313,7 +315,8 @@ public abstract class PaymentAccount implements PersistablePayload { processValidationResult(new LengthValidator(2, 100).validate(value)); break; case ACCOUNT_NR: - throw new IllegalArgumentException("Not implemented"); + processValidationResult(new AccountNrValidator("GB").validate(value)); + break; case ACCOUNT_OWNER: throw new IllegalArgumentException("Not implemented"); case ACCOUNT_TYPE: @@ -437,15 +440,13 @@ public abstract class PaymentAccount implements PersistablePayload { if (!value.equals("")) throw new IllegalArgumentException("Salt must be empty"); break; case SORT_CODE: - throw new IllegalArgumentException("Not implemented"); + processValidationResult(new BranchIdValidator("GB").validate(value)); + break; case SPECIAL_INSTRUCTIONS: break; case STATE: 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); - System.out.println("IS STATE REQUIRED :" + isStateRequired); if (value == null || value.isEmpty()) { if (isStateRequired) throw new IllegalArgumentException("Must provide state for country " + countryCode); } else { @@ -494,7 +495,9 @@ public abstract class PaymentAccount implements PersistablePayload { field.setMaxLength(100); break; case ACCOUNT_NR: - throw new IllegalArgumentException("Not implemented"); + field.setComponent(PaymentAccountFormField.Component.TEXT); + field.setLabel("Account number"); + break; case ACCOUNT_OWNER: throw new IllegalArgumentException("Not implemented"); case ACCOUNT_TYPE: @@ -646,7 +649,9 @@ public abstract class PaymentAccount implements PersistablePayload { field.setLabel("Salt"); break; case SORT_CODE: - throw new IllegalArgumentException("Not implemented"); + field.setComponent(PaymentAccountFormField.Component.TEXT); + field.setLabel("UK sort code"); + break; case SPECIAL_INSTRUCTIONS: field.setComponent(PaymentAccountFormField.Component.TEXT); field.setLabel("Special instructions"); diff --git a/core/src/main/java/bisq/core/payment/payload/FasterPaymentsAccountPayload.java b/core/src/main/java/bisq/core/payment/payload/FasterPaymentsAccountPayload.java index a6ea20899e..920d47fe31 100644 --- a/core/src/main/java/bisq/core/payment/payload/FasterPaymentsAccountPayload.java +++ b/core/src/main/java/bisq/core/payment/payload/FasterPaymentsAccountPayload.java @@ -41,11 +41,12 @@ import lombok.extern.slf4j.Slf4j; @Getter @Slf4j public final class FasterPaymentsAccountPayload extends PaymentAccountPayload { + @Setter + private String holderName = ""; @Setter private String sortCode = ""; @Setter 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) { super(paymentMethod, id); @@ -58,36 +59,36 @@ public final class FasterPaymentsAccountPayload extends PaymentAccountPayload { private FasterPaymentsAccountPayload(String paymentMethod, String id, + String holderName, String sortCode, String accountNr, - String email, long maxTradePeriod, Map excludeFromJsonDataMap) { super(paymentMethod, id, maxTradePeriod, excludeFromJsonDataMap); + this.holderName = holderName; this.sortCode = sortCode; this.accountNr = accountNr; - this.email = email; } @Override public Message toProtoMessage() { return getPaymentAccountPayloadBuilder() .setFasterPaymentsAccountPayload(protobuf.FasterPaymentsAccountPayload.newBuilder() + .setHolderName(holderName) .setSortCode(sortCode) - .setAccountNr(accountNr) - .setEmail(email)) + .setAccountNr(accountNr)) .build(); } public static FasterPaymentsAccountPayload fromProto(protobuf.PaymentAccountPayload proto) { return new FasterPaymentsAccountPayload(proto.getPaymentMethodId(), proto.getId(), + proto.getFasterPaymentsAccountPayload().getHolderName(), proto.getFasterPaymentsAccountPayload().getSortCode(), proto.getFasterPaymentsAccountPayload().getAccountNr(), - proto.getFasterPaymentsAccountPayload().getEmail(), proto.getMaxTradePeriod(), new HashMap<>(proto.getExcludeFromJsonDataMap())); } @@ -97,14 +98,6 @@ public final class FasterPaymentsAccountPayload extends PaymentAccountPayload { // API /////////////////////////////////////////////////////////////////////////////////////////// - public String getHolderName() { - return excludeFromJsonDataMap.getOrDefault(HOLDER_NAME, ""); - } - - public void setHolderName(String holderName) { - excludeFromJsonDataMap.compute(HOLDER_NAME, (k, v) -> Strings.emptyToNull(holderName)); - } - @Override public String getPaymentDetails() { return Res.get(paymentMethodId) + " - " + getPaymentDetailsForTradePopup().replace("\n", ", "); diff --git a/core/src/main/java/bisq/core/payment/payload/PaymentAccountPayload.java b/core/src/main/java/bisq/core/payment/payload/PaymentAccountPayload.java index 8da65120c5..19bd133b2f 100644 --- a/core/src/main/java/bisq/core/payment/payload/PaymentAccountPayload.java +++ b/core/src/main/java/bisq/core/payment/payload/PaymentAccountPayload.java @@ -50,7 +50,6 @@ public abstract class PaymentAccountPayload implements NetworkPayload, UsedForTr // Keys for excludeFromJsonDataMap public static final String SALT = "salt"; - public static final String HOLDER_NAME = "holderName"; protected final String paymentMethodId; protected final String id; diff --git a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java index 673a672bed..c92a620ed7 100644 --- a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java +++ b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java @@ -336,7 +336,8 @@ public final class PaymentMethod implements PersistablePayload, Comparable paymentMethodIds.contains(paymentMethod.getId())).collect(Collectors.toList()); } diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index 1671b9407a..0aebdb3cb7 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -1226,9 +1226,9 @@ message InstantCryptoCurrencyAccountPayload { } message FasterPaymentsAccountPayload { - string sort_code = 1; - string account_nr = 2; - string email = 3 [deprecated = true]; + string holder_name = 1; + string sort_code = 2; + string account_nr = 3; } message InteracETransferAccountPayload { @@ -2083,6 +2083,7 @@ message PaymentAccountForm { F2F = 6; STRIKE = 7; MONEY_GRAM = 8; + FASTER_PAYMENTS = 9; } FormId id = 1; repeated PaymentAccountFormField fields = 2;