diff --git a/common/src/main/proto/pb.proto b/common/src/main/proto/pb.proto index a028dec6412..08cfda1d890 100644 --- a/common/src/main/proto/pb.proto +++ b/common/src/main/proto/pb.proto @@ -901,6 +901,7 @@ message PaymentAccountPayload { AdvancedCashAccountPayload advanced_cash_account_payload = 26; InstantCryptoCurrencyAccountPayload instant_crypto_currency_account_payload = 27; JapanBankAccountPayload japan_bank_account_payload = 28; + AustraliaPayIDPayload australia_payid_payload = 29; } map exclude_from_json_data = 15; } @@ -968,6 +969,11 @@ message JapanBankAccountPayload { string bank_account_number = 7; } +message AustraliaPayIDPayload { + string bank_account_name = 1; + string payid = 2; +} + message SpecificBanksAccountPayload { repeated string accepted_banks = 1; } diff --git a/core/src/main/java/bisq/core/payment/AustraliaPayID.java b/core/src/main/java/bisq/core/payment/AustraliaPayID.java new file mode 100644 index 00000000000..8e9f2edf348 --- /dev/null +++ b/core/src/main/java/bisq/core/payment/AustraliaPayID.java @@ -0,0 +1,69 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.core.payment; + +import bisq.core.payment.payload.AustraliaPayIDPayload; +import bisq.core.payment.payload.PaymentAccountPayload; +import bisq.core.payment.payload.PaymentMethod; +import bisq.core.payment.payload.AustraliaPayIDPayload; + +import org.jetbrains.annotations.NotNull; + +import lombok.Getter; +import lombok.Setter; + +import bisq.core.locale.Country; +import bisq.core.locale.FiatCurrency; +import bisq.core.payment.payload.AustraliaPayIDPayload; + +public final class AustraliaPayID extends PaymentAccount +{ + public AustraliaPayID() + { + super(PaymentMethod.AUSTRALIA_PAYID); + setSingleTradeCurrency(new FiatCurrency("AUD")); + } + + @Override + protected PaymentAccountPayload createPayload() + { + return new AustraliaPayIDPayload(paymentMethod.getId(), id); + } + + // payid + public String getPayID() + { + return ((AustraliaPayIDPayload) paymentAccountPayload).getPayid(); + } + public void setPayID(String payid) + { + if (payid == null) payid = ""; + ((AustraliaPayIDPayload) paymentAccountPayload).setPayid(payid); + } + + // bankAccount name + public String getBankAccountName() + { + return ((AustraliaPayIDPayload) paymentAccountPayload).getBankAccountName(); + } + public void setBankAccountName(String bankAccountName) + { + if (bankAccountName == null) bankAccountName = ""; + ((AustraliaPayIDPayload) paymentAccountPayload).setBankAccountName(bankAccountName); + } +} diff --git a/core/src/main/java/bisq/core/payment/PaymentAccountFactory.java b/core/src/main/java/bisq/core/payment/PaymentAccountFactory.java index e858e01e3b0..2a35128a16f 100644 --- a/core/src/main/java/bisq/core/payment/PaymentAccountFactory.java +++ b/core/src/main/java/bisq/core/payment/PaymentAccountFactory.java @@ -46,6 +46,8 @@ public static PaymentAccount getPaymentAccount(PaymentMethod paymentMethod) { return new SpecificBanksAccount(); case PaymentMethod.JAPAN_BANK_ID: return new JapanBankAccount(); + case PaymentMethod.AUSTRALIA_PAYID_ID: + return new AustraliaPayID(); case PaymentMethod.ALI_PAY_ID: return new AliPayAccount(); case PaymentMethod.WECHAT_PAY_ID: diff --git a/core/src/main/java/bisq/core/payment/payload/AustraliaPayIDPayload.java b/core/src/main/java/bisq/core/payment/payload/AustraliaPayIDPayload.java new file mode 100644 index 00000000000..4e110200cc7 --- /dev/null +++ b/core/src/main/java/bisq/core/payment/payload/AustraliaPayIDPayload.java @@ -0,0 +1,116 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.core.payment.payload; + +import bisq.core.locale.Res; + +import bisq.common.util.CollectionUtils; + +import com.google.protobuf.Message; + +import java.nio.charset.Charset; + +import java.util.HashMap; +import java.util.Map; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.extern.slf4j.Slf4j; + +@EqualsAndHashCode(callSuper = true) +@ToString +@Setter +@Getter +@Slf4j +public final class AustraliaPayIDPayload extends PaymentAccountPayload { + // payid + private String payid = ""; + private String bankAccountName = ""; + + public AustraliaPayIDPayload(String paymentMethod, String id) { + super(paymentMethod, id); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // PROTO BUFFER + /////////////////////////////////////////////////////////////////////////////////////////// + + private AustraliaPayIDPayload(String paymentMethod, + String id, + String payid, + String bankAccountName, + long maxTradePeriod, + Map excludeFromJsonDataMap) { + super(paymentMethod, + id, + maxTradePeriod, + excludeFromJsonDataMap); + + this.payid = payid; + this.bankAccountName = bankAccountName; + } + + @Override + public Message toProtoMessage() { + return getPaymentAccountPayloadBuilder() + .setAustraliaPayidPayload( + protobuf.AustraliaPayIDPayload.newBuilder() + .setPayid(payid) + .setBankAccountName(bankAccountName) + ).build(); + } + + public static AustraliaPayIDPayload fromProto(protobuf.PaymentAccountPayload proto) { + protobuf.AustraliaPayIDPayload AustraliaPayIDPayload = proto.getAustraliaPayidPayload(); + return new AustraliaPayIDPayload(proto.getPaymentMethodId(), + proto.getId(), + AustraliaPayIDPayload.getPayid(), + AustraliaPayIDPayload.getBankAccountName(), + proto.getMaxTradePeriod(), + CollectionUtils.isEmpty(proto.getExcludeFromJsonDataMap()) ? null : new HashMap<>(proto.getExcludeFromJsonDataMap())); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // API + /////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public String getPaymentDetails() + { + return Res.get(paymentMethodId) + " - " + getPaymentDetailsForTradePopup().replace("\n", ", "); + } + + @Override + public String getPaymentDetailsForTradePopup() + { + return + Res.get("payment.australia.payid") + ": " + payid + "\n" + + Res.get("payment.account.owner") + ": " + bankAccountName; + } + + + @Override + public byte[] getAgeWitnessInputData() { + String all = this.payid + this.bankAccountName; + return super.getAgeWitnessInputData(all.getBytes(Charset.forName("UTF-8"))); + } +} 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 a1935faf16b..16cba695732 100644 --- a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java +++ b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java @@ -74,6 +74,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable. + */ + +package bisq.desktop.components.paymentmethods; + +import bisq.desktop.components.InputTextField; +import bisq.desktop.util.FormBuilder; +import bisq.desktop.util.Layout; +import bisq.desktop.util.validation.AustraliaPayIDValidator; + +import bisq.core.account.witness.AccountAgeWitnessService; +import bisq.core.locale.Res; +import bisq.core.locale.TradeCurrency; +import bisq.core.payment.AustraliaPayID; +import bisq.core.payment.PaymentAccount; +import bisq.core.payment.payload.AustraliaPayIDPayload; +import bisq.core.payment.payload.PaymentAccountPayload; +import bisq.core.util.coin.CoinFormatter; +import bisq.core.util.validation.InputValidator; + +import javafx.scene.control.TextField; +import javafx.scene.layout.GridPane; + +import static bisq.desktop.util.FormBuilder.addCompactTopLabelTextField; +import static bisq.desktop.util.FormBuilder.addTopLabelTextField; + +public class AustraliaPayIDForm extends PaymentMethodForm { + private final AustraliaPayID australiaPayID; + private final AustraliaPayIDValidator australiaPayIDValidator; + private InputTextField mobileNrInputTextField; + + public static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountPayload paymentAccountPayload) { + addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.account.owner"), + ((AustraliaPayIDPayload) paymentAccountPayload).getBankAccountName()); + addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.payid"), + ((AustraliaPayIDPayload) paymentAccountPayload).getPayid()); + return gridRow; + } + + public AustraliaPayIDForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAgeWitnessService, AustraliaPayIDValidator australiaPayIDValidator, + InputValidator inputValidator, GridPane gridPane, int gridRow, CoinFormatter formatter) { + super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter); + this.australiaPayID = (AustraliaPayID) paymentAccount; + this.australiaPayIDValidator = australiaPayIDValidator; + } + + @Override + public void addFormForAddAccount() { + gridRowFrom = gridRow + 1; + + InputTextField holderNameInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, + Res.get("payment.account.owner")); + holderNameInputTextField.setValidator(inputValidator); + holderNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { + australiaPayID.setBankAccountName(newValue); + updateFromInputs(); + }); + + mobileNrInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, Res.get("payment.payid")); + mobileNrInputTextField.setValidator(australiaPayIDValidator); + mobileNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { + australiaPayID.setPayID(newValue); + updateFromInputs(); + }); + + TradeCurrency singleTradeCurrency = australiaPayID.getSingleTradeCurrency(); + String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "null"; + addTopLabelTextField(gridPane, ++gridRow, Res.get("shared.currency"), nameAndCode); + addLimitations(false); + addAccountNameTextFieldWithAutoFillToggleButton(); + } + + @Override + protected void autoFillNameTextField() { + setAccountNameWithString(mobileNrInputTextField.getText()); + } + + @Override + public void addFormForDisplayAccount() { + gridRowFrom = gridRow; + addTopLabelTextField(gridPane, gridRow, Res.get("payment.account.name"), + australiaPayID.getAccountName(), Layout.FIRST_ROW_AND_GROUP_DISTANCE); + addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("shared.paymentMethod"), + Res.get(australiaPayID.getPaymentMethod().getId())); + addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.payid"), + australiaPayID.getPayID()); + TextField field = addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.account.owner"), + australiaPayID.getBankAccountName()).second; + field.setMouseTransparent(false); + TradeCurrency singleTradeCurrency = australiaPayID.getSingleTradeCurrency(); + String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "null"; + addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("shared.currency"), nameAndCode); + addLimitations(true); + } + + @Override + public void updateAllInputsValid() { + allInputsValid.set(isAccountNameValid() + && australiaPayIDValidator.validate(australiaPayID.getPayID()).isValid + && inputValidator.validate(australiaPayID.getBankAccountName()).isValid + && australiaPayID.getTradeCurrencies().size() > 0); + } +} diff --git a/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java b/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java index a3a0088579c..f8423229b55 100644 --- a/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java +++ b/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java @@ -29,6 +29,7 @@ import bisq.desktop.components.paymentmethods.HalCashForm; import bisq.desktop.components.paymentmethods.InteracETransferForm; import bisq.desktop.components.paymentmethods.JapanBankTransferForm; +import bisq.desktop.components.paymentmethods.AustraliaPayIDForm; import bisq.desktop.components.paymentmethods.MoneyBeamForm; import bisq.desktop.components.paymentmethods.MoneyGramForm; import bisq.desktop.components.paymentmethods.NationalBankForm; @@ -53,6 +54,7 @@ import bisq.desktop.util.Layout; import bisq.desktop.util.validation.AdvancedCashValidator; import bisq.desktop.util.validation.AliPayValidator; +import bisq.desktop.util.validation.AustraliaPayIDValidator; import bisq.desktop.util.validation.BICValidator; import bisq.desktop.util.validation.ChaseQuickPayValidator; import bisq.desktop.util.validation.ClearXchangeValidator; @@ -61,6 +63,7 @@ import bisq.desktop.util.validation.IBANValidator; import bisq.desktop.util.validation.InteracETransferValidator; import bisq.desktop.util.validation.JapanBankTransferValidator; +import bisq.desktop.util.validation.AustraliaPayIDValidator; import bisq.desktop.util.validation.MoneyBeamValidator; import bisq.desktop.util.validation.PerfectMoneyValidator; import bisq.desktop.util.validation.PopmoneyValidator; @@ -74,6 +77,7 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.Res; import bisq.core.offer.OfferRestrictions; +import bisq.core.payment.AustraliaPayID; import bisq.core.payment.CashDepositAccount; import bisq.core.payment.ClearXchangeAccount; import bisq.core.payment.F2FAccount; @@ -137,6 +141,7 @@ public class FiatAccountsView extends PaymentAccountsView doSaveNewAccount(paymentAccount)) .show(); + } else if (paymentAccount instanceof AustraliaPayID) { + new Popup().information(Res.get("payment.payid.info", currencyName, currencyName)) + .width(900) + .closeButtonText(Res.get("shared.cancel")) + .actionButtonText(Res.get("shared.iConfirm")) + .onAction(() -> doSaveNewAccount(paymentAccount)) + .show(); } else { doSaveNewAccount(paymentAccount); } @@ -452,6 +466,8 @@ private PaymentMethodForm getPaymentMethodForm(PaymentMethod paymentMethod, Paym return new SpecificBankForm(paymentAccount, accountAgeWitnessService, inputValidator, root, gridRow, formatter); case PaymentMethod.JAPAN_BANK_ID: return new JapanBankTransferForm(paymentAccount, accountAgeWitnessService, japanBankTransferValidator, inputValidator, root, gridRow, formatter); + case PaymentMethod.AUSTRALIA_PAYID_ID: + return new AustraliaPayIDForm(paymentAccount, accountAgeWitnessService, australiapayidValidator, inputValidator, root, gridRow, formatter); case PaymentMethod.ALI_PAY_ID: return new AliPayForm(paymentAccount, accountAgeWitnessService, aliPayValidator, inputValidator, root, gridRow, formatter); case PaymentMethod.WECHAT_PAY_ID: diff --git a/desktop/src/main/java/bisq/desktop/util/validation/AustraliaPayIDValidator.java b/desktop/src/main/java/bisq/desktop/util/validation/AustraliaPayIDValidator.java new file mode 100644 index 00000000000..e96cb059e8f --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/util/validation/AustraliaPayIDValidator.java @@ -0,0 +1,56 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.desktop.util.validation; + +import bisq.core.util.validation.InputValidator; + +public final class AustraliaPayIDValidator extends InputValidator { + + private final EmailValidator emailValidator; + + /////////////////////////////////////////////////////////////////////////////////////////// + // Public methods + /////////////////////////////////////////////////////////////////////////////////////////// + + public AustraliaPayIDValidator() { + emailValidator = new EmailValidator(); + } + + @Override + public ValidationResult validate(String input) { + ValidationResult result = validateIfNotEmpty(input); + if (!result.isValid) { + return result; + } else { + ValidationResult emailResult = emailValidator.validate(input); + if (emailResult.isValid) + return emailResult; + else + return validatePhoneNumber(input); + } + } + + /////////////////////////////////////////////////////////////////////////////////////////// + // Private methods + /////////////////////////////////////////////////////////////////////////////////////////// + + // TODO not impl yet -> see InteracETransferValidator + private ValidationResult validatePhoneNumber(String input) { + return super.validate(input); + } +} diff --git a/desktop/src/main/java/bisq/desktop/util/validation/AustraliaPayidAccountNameValidator.java b/desktop/src/main/java/bisq/desktop/util/validation/AustraliaPayidAccountNameValidator.java new file mode 100644 index 00000000000..e8a50445e7c --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/util/validation/AustraliaPayidAccountNameValidator.java @@ -0,0 +1,49 @@ + +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.desktop.util.validation; + +import bisq.core.util.validation.InputValidator; +import javax.inject.Inject; + +public final class AustraliaPayidAccountNameValidator extends InputValidator { + @Override + public ValidationResult validate(String input) { + ValidationResult result = super.validate(input); + + if (result.isValid) + result = lengthValidator.validate(input); + if (result.isValid) + result = regexValidator.validate(input); + + return result; + } + + private LengthValidator lengthValidator; + private RegexValidator regexValidator; + + @Inject + public AustraliaPayidAccountNameValidator(LengthValidator lengthValidator, RegexValidator regexValidator) { + + lengthValidator.setMinLength(1); + lengthValidator.setMaxLength(40); + this.lengthValidator = lengthValidator; + + this.regexValidator = regexValidator; + } +}