From 984a26977686504d4c89f0b92af9fd731e1927f4 Mon Sep 17 00:00:00 2001 From: jmacxx <47253594+jmacxx@users.noreply.github.com> Date: Wed, 25 Aug 2021 13:38:54 -0500 Subject: [PATCH] Add Payment Methods: Paysera and Paxum --- .../java/bisq/core/locale/CurrencyUtil.java | 68 ++++++++++ .../java/bisq/core/payment/PaxumAccount.java | 44 +++++++ .../core/payment/PaymentAccountFactory.java | 4 + .../bisq/core/payment/PayseraAccount.java | 44 +++++++ .../payment/payload/PaxumAccountPayload.java | 99 +++++++++++++++ .../core/payment/payload/PaymentMethod.java | 6 + .../payload/PayseraAccountPayload.java | 99 +++++++++++++++ .../bisq/core/proto/CoreProtoResolver.java | 6 + .../trade/statistics/TradeStatistics3.java | 4 +- .../resources/i18n/displayStrings.properties | 8 ++ .../components/paymentmethods/PaxumForm.java | 118 ++++++++++++++++++ .../paymentmethods/PayseraForm.java | 118 ++++++++++++++++++ .../fiataccounts/FiatAccountsView.java | 6 + .../steps/buyer/BuyerStep2View.java | 8 ++ proto/src/main/proto/pb.proto | 10 ++ 15 files changed, 641 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/bisq/core/payment/PaxumAccount.java create mode 100644 core/src/main/java/bisq/core/payment/PayseraAccount.java create mode 100644 core/src/main/java/bisq/core/payment/payload/PaxumAccountPayload.java create mode 100644 core/src/main/java/bisq/core/payment/payload/PayseraAccountPayload.java create mode 100644 desktop/src/main/java/bisq/desktop/components/paymentmethods/PaxumForm.java create mode 100644 desktop/src/main/java/bisq/desktop/components/paymentmethods/PayseraForm.java diff --git a/core/src/main/java/bisq/core/locale/CurrencyUtil.java b/core/src/main/java/bisq/core/locale/CurrencyUtil.java index b7275ddf4a8..2e89df8a5d1 100644 --- a/core/src/main/java/bisq/core/locale/CurrencyUtil.java +++ b/core/src/main/java/bisq/core/locale/CurrencyUtil.java @@ -330,6 +330,74 @@ public static List getAllTransferwiseCurrencies() { return currencies; } + // https://github.com/bisq-network/growth/issues/233 + public static List getAllPayseraCurrencies() { + ArrayList currencies = new ArrayList<>(Arrays.asList( + new FiatCurrency("AUD"), + new FiatCurrency("BGN"), + new FiatCurrency("BYN"), + new FiatCurrency("CAD"), + new FiatCurrency("CHF"), + new FiatCurrency("CNY"), + new FiatCurrency("CZK"), + new FiatCurrency("DKK"), + new FiatCurrency("EUR"), + new FiatCurrency("GBP"), + new FiatCurrency("GEL"), + new FiatCurrency("HKD"), + new FiatCurrency("HRK"), + new FiatCurrency("HUF"), + new FiatCurrency("ILS"), + new FiatCurrency("INR"), + new FiatCurrency("JPY"), + new FiatCurrency("KZT"), + new FiatCurrency("MXN"), + new FiatCurrency("NOK"), + new FiatCurrency("NZD"), + new FiatCurrency("PHP"), + new FiatCurrency("PLN"), + new FiatCurrency("RON"), + new FiatCurrency("RSD"), + new FiatCurrency("RUB"), + new FiatCurrency("SEK"), + new FiatCurrency("SGD"), + new FiatCurrency("THB"), + new FiatCurrency("TRY"), + new FiatCurrency("USD"), + new FiatCurrency("ZAR") + )); + + currencies.sort(Comparator.comparing(TradeCurrency::getCode)); + return currencies; + } + + // https://github.com/bisq-network/growth/issues/235 + public static List getAllPaxumCurrencies() { + ArrayList currencies = new ArrayList<>(Arrays.asList( + new FiatCurrency("USD"), + new FiatCurrency("CAD"), + new FiatCurrency("EUR"), + new FiatCurrency("DKK"), + new FiatCurrency("CZK"), + new FiatCurrency("AUD"), + new FiatCurrency("ZAR"), + new FiatCurrency("THB"), + new FiatCurrency("CHF"), + new FiatCurrency("SEK"), + new FiatCurrency("RON"), + new FiatCurrency("PLN"), + new FiatCurrency("NZD"), + new FiatCurrency("NOK"), + new FiatCurrency("INR"), + new FiatCurrency("IDR"), + new FiatCurrency("HUF"), + new FiatCurrency("GBP") + )); + + currencies.sort(Comparator.comparing(TradeCurrency::getCode)); + return currencies; + } + public static List getAllAmazonGiftCardCurrencies() { List currencies = new ArrayList<>(Arrays.asList( new FiatCurrency("AUD"), diff --git a/core/src/main/java/bisq/core/payment/PaxumAccount.java b/core/src/main/java/bisq/core/payment/PaxumAccount.java new file mode 100644 index 00000000000..e95111f47ad --- /dev/null +++ b/core/src/main/java/bisq/core/payment/PaxumAccount.java @@ -0,0 +1,44 @@ +/* + * 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.PaymentAccountPayload; +import bisq.core.payment.payload.PaymentMethod; +import bisq.core.payment.payload.PaxumAccountPayload; + +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +public final class PaxumAccount extends PaymentAccount { + public PaxumAccount() { + super(PaymentMethod.PAXUM); + } + + @Override + protected PaymentAccountPayload createPayload() { + return new PaxumAccountPayload(paymentMethod.getId(), id); + } + + public void setEmail(String accountId) { + ((PaxumAccountPayload) paymentAccountPayload).setEmail(accountId); + } + + public String getEmail() { + return ((PaxumAccountPayload) paymentAccountPayload).getEmail(); + } +} diff --git a/core/src/main/java/bisq/core/payment/PaymentAccountFactory.java b/core/src/main/java/bisq/core/payment/PaymentAccountFactory.java index 0cceb0cb865..345702623e6 100644 --- a/core/src/main/java/bisq/core/payment/PaymentAccountFactory.java +++ b/core/src/main/java/bisq/core/payment/PaymentAccountFactory.java @@ -82,6 +82,10 @@ public static PaymentAccount getPaymentAccount(PaymentMethod paymentMethod) { return new AdvancedCashAccount(); case PaymentMethod.TRANSFERWISE_ID: return new TransferwiseAccount(); + case PaymentMethod.PAYSERA_ID: + return new PayseraAccount(); + case PaymentMethod.PAXUM_ID: + return new PaxumAccount(); case PaymentMethod.AMAZON_GIFT_CARD_ID: return new AmazonGiftCardAccount(); case PaymentMethod.BLOCK_CHAINS_INSTANT_ID: diff --git a/core/src/main/java/bisq/core/payment/PayseraAccount.java b/core/src/main/java/bisq/core/payment/PayseraAccount.java new file mode 100644 index 00000000000..0f943a1c1d8 --- /dev/null +++ b/core/src/main/java/bisq/core/payment/PayseraAccount.java @@ -0,0 +1,44 @@ +/* + * 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.PaymentAccountPayload; +import bisq.core.payment.payload.PaymentMethod; +import bisq.core.payment.payload.PayseraAccountPayload; + +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +public final class PayseraAccount extends PaymentAccount { + public PayseraAccount() { + super(PaymentMethod.PAYSERA); + } + + @Override + protected PaymentAccountPayload createPayload() { + return new PayseraAccountPayload(paymentMethod.getId(), id); + } + + public void setEmail(String accountId) { + ((PayseraAccountPayload) paymentAccountPayload).setEmail(accountId); + } + + public String getEmail() { + return ((PayseraAccountPayload) paymentAccountPayload).getEmail(); + } +} diff --git a/core/src/main/java/bisq/core/payment/payload/PaxumAccountPayload.java b/core/src/main/java/bisq/core/payment/payload/PaxumAccountPayload.java new file mode 100644 index 00000000000..ae416a6da93 --- /dev/null +++ b/core/src/main/java/bisq/core/payment/payload/PaxumAccountPayload.java @@ -0,0 +1,99 @@ +/* + * 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 com.google.protobuf.Message; + +import java.nio.charset.StandardCharsets; + +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 PaxumAccountPayload extends PaymentAccountPayload { + private String email = ""; + + public PaxumAccountPayload(String paymentMethod, String id) { + super(paymentMethod, id); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // PROTO BUFFER + /////////////////////////////////////////////////////////////////////////////////////////// + + private PaxumAccountPayload(String paymentMethod, + String id, + String email, + long maxTradePeriod, + Map excludeFromJsonDataMap) { + super(paymentMethod, + id, + maxTradePeriod, + excludeFromJsonDataMap); + + this.email = email; + } + + @Override + public Message toProtoMessage() { + return getPaymentAccountPayloadBuilder() + .setPaxumAccountPayload(protobuf.PaxumAccountPayload.newBuilder().setEmail(email)) + .build(); + } + + public static PaxumAccountPayload fromProto(protobuf.PaymentAccountPayload proto) { + return new PaxumAccountPayload(proto.getPaymentMethodId(), + proto.getId(), + proto.getPaxumAccountPayload().getEmail(), + proto.getMaxTradePeriod(), + new HashMap<>(proto.getExcludeFromJsonDataMap())); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // API + /////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public String getPaymentDetails() { + return Res.get(paymentMethodId) + " - " + Res.getWithCol("payment.email") + " " + email; + } + + @Override + public String getPaymentDetailsForTradePopup() { + return getPaymentDetails(); + } + + @Override + public byte[] getAgeWitnessInputData() { + return super.getAgeWitnessInputData(email.getBytes(StandardCharsets.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 0a6072e69dd..dd6fe31db01 100644 --- a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java +++ b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java @@ -96,6 +96,8 @@ public final class PaymentMethod implements PersistablePayload, Comparable. + */ + +package bisq.core.payment.payload; + +import bisq.core.locale.Res; + +import com.google.protobuf.Message; + +import java.nio.charset.StandardCharsets; + +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 PayseraAccountPayload extends PaymentAccountPayload { + private String email = ""; + + public PayseraAccountPayload(String paymentMethod, String id) { + super(paymentMethod, id); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // PROTO BUFFER + /////////////////////////////////////////////////////////////////////////////////////////// + + private PayseraAccountPayload(String paymentMethod, + String id, + String email, + long maxTradePeriod, + Map excludeFromJsonDataMap) { + super(paymentMethod, + id, + maxTradePeriod, + excludeFromJsonDataMap); + + this.email = email; + } + + @Override + public Message toProtoMessage() { + return getPaymentAccountPayloadBuilder() + .setPayseraAccountPayload(protobuf.PayseraAccountPayload.newBuilder().setEmail(email)) + .build(); + } + + public static PayseraAccountPayload fromProto(protobuf.PaymentAccountPayload proto) { + return new PayseraAccountPayload(proto.getPaymentMethodId(), + proto.getId(), + proto.getPayseraAccountPayload().getEmail(), + proto.getMaxTradePeriod(), + new HashMap<>(proto.getExcludeFromJsonDataMap())); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // API + /////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public String getPaymentDetails() { + return Res.get(paymentMethodId) + " - " + Res.getWithCol("payment.email") + " " + email; + } + + @Override + public String getPaymentDetailsForTradePopup() { + return getPaymentDetails(); + } + + @Override + public byte[] getAgeWitnessInputData() { + return super.getAgeWitnessInputData(email.getBytes(StandardCharsets.UTF_8)); + } +} diff --git a/core/src/main/java/bisq/core/proto/CoreProtoResolver.java b/core/src/main/java/bisq/core/proto/CoreProtoResolver.java index dd37ec3f3b4..d51503a15c8 100644 --- a/core/src/main/java/bisq/core/proto/CoreProtoResolver.java +++ b/core/src/main/java/bisq/core/proto/CoreProtoResolver.java @@ -42,7 +42,9 @@ import bisq.core.payment.payload.MoneyGramAccountPayload; import bisq.core.payment.payload.NationalBankAccountPayload; import bisq.core.payment.payload.OKPayAccountPayload; +import bisq.core.payment.payload.PaxumAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; +import bisq.core.payment.payload.PayseraAccountPayload; import bisq.core.payment.payload.PerfectMoneyAccountPayload; import bisq.core.payment.payload.PopmoneyAccountPayload; import bisq.core.payment.payload.PromptPayAccountPayload; @@ -156,6 +158,10 @@ public PaymentAccountPayload fromProto(protobuf.PaymentAccountPayload proto) { return AdvancedCashAccountPayload.fromProto(proto); case TRANSFERWISE_ACCOUNT_PAYLOAD: return TransferwiseAccountPayload.fromProto(proto); + case PAYSERA_ACCOUNT_PAYLOAD: + return PayseraAccountPayload.fromProto(proto); + case PAXUM_ACCOUNT_PAYLOAD: + return PaxumAccountPayload.fromProto(proto); case AMAZON_GIFT_CARD_ACCOUNT_PAYLOAD: return AmazonGiftCardAccountPayload.fromProto(proto); case INSTANT_CRYPTO_CURRENCY_ACCOUNT_PAYLOAD: diff --git a/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java b/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java index 0454985364e..fcc57d6f89d 100644 --- a/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java +++ b/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java @@ -153,7 +153,9 @@ private enum PaymentMethodMapper { TRANSFERWISE, AMAZON_GIFT_CARD, CASH_BY_MAIL, - CAPITUAL + CAPITUAL, + PAYSERA, + PAXUM } @Getter diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 95378f141be..f1452c309f0 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -3572,6 +3572,10 @@ ADVANCED_CASH=Advanced Cash # suppress inspection "UnusedProperty" TRANSFERWISE=TransferWise # suppress inspection "UnusedProperty" +PAYSERA=Paysera +# suppress inspection "UnusedProperty" +PAXUM=Paxum +# suppress inspection "UnusedProperty" AMAZON_GIFT_CARD=Amazon eGift Card # suppress inspection "UnusedProperty" BLOCK_CHAINS_INSTANT=Altcoins Instant @@ -3626,6 +3630,10 @@ ADVANCED_CASH_SHORT=Advanced Cash # suppress inspection "UnusedProperty" TRANSFERWISE_SHORT=TransferWise # suppress inspection "UnusedProperty" +PAYSERA_SHORT=Paysera +# suppress inspection "UnusedProperty" +PAXUM_SHORT=Paxum +# suppress inspection "UnusedProperty" AMAZON_GIFT_CARD_SHORT=Amazon eGift Card # suppress inspection "UnusedProperty" BLOCK_CHAINS_INSTANT_SHORT=Altcoins Instant diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaxumForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaxumForm.java new file mode 100644 index 00000000000..40c6349f320 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaxumForm.java @@ -0,0 +1,118 @@ +/* + * 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.components.paymentmethods; + +import bisq.desktop.components.InputTextField; +import bisq.desktop.util.FormBuilder; +import bisq.desktop.util.Layout; +import bisq.desktop.util.validation.EmailValidator; + +import bisq.core.account.witness.AccountAgeWitnessService; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.Res; +import bisq.core.payment.PaymentAccount; +import bisq.core.payment.PaxumAccount; +import bisq.core.payment.payload.PaymentAccountPayload; +import bisq.core.payment.payload.PaxumAccountPayload; +import bisq.core.util.coin.CoinFormatter; +import bisq.core.util.validation.InputValidator; + +import javafx.scene.control.TextField; +import javafx.scene.layout.FlowPane; +import javafx.scene.layout.GridPane; + +import static bisq.desktop.util.FormBuilder.addCompactTopLabelTextField; +import static bisq.desktop.util.FormBuilder.addCompactTopLabelTextFieldWithCopyIcon; +import static bisq.desktop.util.FormBuilder.addTopLabelTextField; + +public class PaxumForm extends PaymentMethodForm { + private final PaxumAccount account; + private InputTextField emailInputTextField; + private EmailValidator validator = new EmailValidator(); + + public static int addFormForBuyer(GridPane gridPane, int gridRow, + PaymentAccountPayload paymentAccountPayload) { + addCompactTopLabelTextFieldWithCopyIcon(gridPane, ++gridRow, Res.get("payment.email"), + ((PaxumAccountPayload) paymentAccountPayload).getEmail()); + return gridRow; + } + + public PaxumForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAgeWitnessService, + InputValidator inputValidator, GridPane gridPane, + int gridRow, CoinFormatter formatter) { + super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter); + this.account = (PaxumAccount) paymentAccount; + } + + @Override + public void addFormForAddAccount() { + gridRowFrom = gridRow + 1; + + emailInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, Res.get("payment.email")); + emailInputTextField.setValidator(validator); + emailInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { + account.setEmail(newValue.trim()); + updateFromInputs(); + }); + + addCurrenciesGrid(true); + addLimitations(false); + addAccountNameTextFieldWithAutoFillToggleButton(); + } + + private void addCurrenciesGrid(boolean isEditable) { + FlowPane flowPane = FormBuilder.addTopLabelFlowPane(gridPane, ++gridRow, + Res.get("payment.supportedCurrenciesForReceiver"), 20, 20).second; + + if (isEditable) { + flowPane.setId("flow-pane-checkboxes-bg"); + } else { + flowPane.setId("flow-pane-checkboxes-non-editable-bg"); + } + + CurrencyUtil.getAllPaxumCurrencies().forEach(currency -> + fillUpFlowPaneWithCurrencies(isEditable, flowPane, currency, account)); + } + + @Override + protected void autoFillNameTextField() { + setAccountNameWithString(emailInputTextField.getText()); + } + + @Override + public void addFormForDisplayAccount() { + gridRowFrom = gridRow; + addTopLabelTextField(gridPane, gridRow, Res.get("payment.account.name"), + account.getAccountName(), Layout.FIRST_ROW_AND_GROUP_DISTANCE); + addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("shared.paymentMethod"), + Res.get(account.getPaymentMethod().getId())); + TextField field = addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.email"), + account.getEmail()).second; + field.setMouseTransparent(false); + addLimitations(true); + addCurrenciesGrid(false); + } + + @Override + public void updateAllInputsValid() { + allInputsValid.set(isAccountNameValid() + && account.getEmail() != null + && validator.validate(account.getEmail()).isValid + && account.getTradeCurrencies().size() > 0); + } +} diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/PayseraForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PayseraForm.java new file mode 100644 index 00000000000..9759b2a5b69 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PayseraForm.java @@ -0,0 +1,118 @@ +/* + * 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.components.paymentmethods; + +import bisq.desktop.components.InputTextField; +import bisq.desktop.util.FormBuilder; +import bisq.desktop.util.Layout; +import bisq.desktop.util.validation.EmailValidator; + +import bisq.core.account.witness.AccountAgeWitnessService; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.Res; +import bisq.core.payment.PaymentAccount; +import bisq.core.payment.PayseraAccount; +import bisq.core.payment.payload.PaymentAccountPayload; +import bisq.core.payment.payload.PayseraAccountPayload; +import bisq.core.util.coin.CoinFormatter; +import bisq.core.util.validation.InputValidator; + +import javafx.scene.control.TextField; +import javafx.scene.layout.FlowPane; +import javafx.scene.layout.GridPane; + +import static bisq.desktop.util.FormBuilder.addCompactTopLabelTextField; +import static bisq.desktop.util.FormBuilder.addCompactTopLabelTextFieldWithCopyIcon; +import static bisq.desktop.util.FormBuilder.addTopLabelTextField; + +public class PayseraForm extends PaymentMethodForm { + private final PayseraAccount account; + private InputTextField emailInputTextField; + private EmailValidator validator = new EmailValidator(); + + public static int addFormForBuyer(GridPane gridPane, int gridRow, + PaymentAccountPayload paymentAccountPayload) { + addCompactTopLabelTextFieldWithCopyIcon(gridPane, ++gridRow, Res.get("payment.email"), + ((PayseraAccountPayload) paymentAccountPayload).getEmail()); + return gridRow; + } + + public PayseraForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAgeWitnessService, + InputValidator inputValidator, GridPane gridPane, + int gridRow, CoinFormatter formatter) { + super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter); + this.account = (PayseraAccount) paymentAccount; + } + + @Override + public void addFormForAddAccount() { + gridRowFrom = gridRow + 1; + + emailInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, Res.get("payment.email")); + emailInputTextField.setValidator(validator); + emailInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { + account.setEmail(newValue.trim()); + updateFromInputs(); + }); + + addCurrenciesGrid(true); + addLimitations(false); + addAccountNameTextFieldWithAutoFillToggleButton(); + } + + private void addCurrenciesGrid(boolean isEditable) { + FlowPane flowPane = FormBuilder.addTopLabelFlowPane(gridPane, ++gridRow, + Res.get("payment.supportedCurrenciesForReceiver"), 20, 20).second; + + if (isEditable) { + flowPane.setId("flow-pane-checkboxes-bg"); + } else { + flowPane.setId("flow-pane-checkboxes-non-editable-bg"); + } + + CurrencyUtil.getAllPayseraCurrencies().forEach(currency -> + fillUpFlowPaneWithCurrencies(isEditable, flowPane, currency, account)); + } + + @Override + protected void autoFillNameTextField() { + setAccountNameWithString(emailInputTextField.getText()); + } + + @Override + public void addFormForDisplayAccount() { + gridRowFrom = gridRow; + addTopLabelTextField(gridPane, gridRow, Res.get("payment.account.name"), + account.getAccountName(), Layout.FIRST_ROW_AND_GROUP_DISTANCE); + addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("shared.paymentMethod"), + Res.get(account.getPaymentMethod().getId())); + TextField field = addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.email"), + account.getEmail()).second; + field.setMouseTransparent(false); + addLimitations(true); + addCurrenciesGrid(false); + } + + @Override + public void updateAllInputsValid() { + allInputsValid.set(isAccountNameValid() + && account.getEmail() != null + && validator.validate(account.getEmail()).isValid + && account.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 eb86ac98e25..d94b4b18728 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 @@ -47,6 +47,8 @@ import bisq.desktop.components.paymentmethods.SpecificBankForm; import bisq.desktop.components.paymentmethods.SwishForm; import bisq.desktop.components.paymentmethods.TransferwiseForm; +import bisq.desktop.components.paymentmethods.PayseraForm; +import bisq.desktop.components.paymentmethods.PaxumForm; import bisq.desktop.components.paymentmethods.USPostalMoneyOrderForm; import bisq.desktop.components.paymentmethods.UpholdForm; import bisq.desktop.components.paymentmethods.WeChatPayForm; @@ -533,6 +535,10 @@ private PaymentMethodForm getPaymentMethodForm(PaymentMethod paymentMethod, Paym return new AdvancedCashForm(paymentAccount, accountAgeWitnessService, advancedCashValidator, inputValidator, root, gridRow, formatter); case PaymentMethod.TRANSFERWISE_ID: return new TransferwiseForm(paymentAccount, accountAgeWitnessService, transferwiseValidator, inputValidator, root, gridRow, formatter); + case PaymentMethod.PAYSERA_ID: + return new PayseraForm(paymentAccount, accountAgeWitnessService, inputValidator, root, gridRow, formatter); + case PaymentMethod.PAXUM_ID: + return new PaxumForm(paymentAccount, accountAgeWitnessService, inputValidator, root, gridRow, formatter); case PaymentMethod.AMAZON_GIFT_CARD_ID: return new AmazonGiftCardForm(paymentAccount, accountAgeWitnessService, inputValidator, root, gridRow, formatter); case PaymentMethod.CAPITUAL_ID: diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java index dc051613f62..167b9140f6f 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java @@ -38,6 +38,8 @@ import bisq.desktop.components.paymentmethods.MoneyBeamForm; import bisq.desktop.components.paymentmethods.MoneyGramForm; import bisq.desktop.components.paymentmethods.NationalBankForm; +import bisq.desktop.components.paymentmethods.PaxumForm; +import bisq.desktop.components.paymentmethods.PayseraForm; import bisq.desktop.components.paymentmethods.PerfectMoneyForm; import bisq.desktop.components.paymentmethods.PopmoneyForm; import bisq.desktop.components.paymentmethods.PromptPayForm; @@ -321,6 +323,12 @@ protected void addContent() { case PaymentMethod.TRANSFERWISE_ID: gridRow = TransferwiseForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload); break; + case PaymentMethod.PAYSERA_ID: + gridRow = PayseraForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload); + break; + case PaymentMethod.PAXUM_ID: + gridRow = PaxumForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload); + break; case PaymentMethod.AMAZON_GIFT_CARD_ID: gridRow = AmazonGiftCardForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload); break; diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index cc833037170..0b19e1c7e31 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -997,6 +997,8 @@ message PaymentAccountPayload { AmazonGiftCardAccountPayload amazon_gift_card_account_payload = 31; CashByMailAccountPayload cash_by_mail_account_payload = 32; CapitualAccountPayload capitual_account_payload = 33; + PayseraAccountPayload Paysera_account_payload = 34; + PaxumAccountPayload Paxum_account_payload = 35; } map exclude_from_json_data = 15; } @@ -1218,6 +1220,14 @@ message TransferwiseAccountPayload { string email = 1; } +message PayseraAccountPayload { + string email = 1; +} + +message PaxumAccountPayload { + string email = 1; +} + message CapitualAccountPayload { string account_nr = 1; }