Skip to content

Commit

Permalink
support paypal, cashapp, venmo
Browse files Browse the repository at this point in the history
Co-authored-by: preland <[email protected]>
  • Loading branch information
woodser and preland committed Jun 9, 2024
1 parent 26c32a8 commit fea8040
Show file tree
Hide file tree
Showing 51 changed files with 881 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ public void testCreateRevolutAccount(TestInfo testInfo) {
assertEquals(COMPLETED_FORM_MAP.get(PROPERTY_NAME_SELECTED_TRADE_CURRENCY),
paymentAccount.getSelectedTradeCurrency().getCode());
verifyCommonFormEntries(paymentAccount);
assertEquals(COMPLETED_FORM_MAP.get(PROPERTY_NAME_USERNAME), paymentAccount.getUserName());
assertEquals(COMPLETED_FORM_MAP.get(PROPERTY_NAME_USERNAME), paymentAccount.getUsername());
print(paymentAccount);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ public enum FormId {
TRANSFERWISE,
UPHOLD,
ZELLE,
AUSTRALIA_PAYID;
AUSTRALIA_PAYID,
CASH_APP,
PAYPAL,
VENMO;

public static PaymentAccountForm.FormId fromProto(protobuf.PaymentAccountForm.FormId formId) {
return ProtoUtil.enumFromProto(PaymentAccountForm.FormId.class, formId.name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ public enum FieldId {
SPECIAL_INSTRUCTIONS,
STATE,
TRADE_CURRENCIES,
USER_NAME;
USERNAME,
EMAIL_OR_MOBILE_NR_OR_USERNAME,
EMAIL_OR_MOBILE_NR_OR_CASHTAG;

public static PaymentAccountFormField.FieldId fromProto(protobuf.PaymentAccountFormField.FieldId fieldId) {
return ProtoUtil.enumFromProto(PaymentAccountFormField.FieldId.class, fieldId.name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public void initDomainServices(Consumer<String> rejectedTxErrorMessageHandler,
revolutAccountsUpdateHandler.accept(user.getPaymentAccountsAsObservable().stream()
.filter(paymentAccount -> paymentAccount instanceof RevolutAccount)
.map(paymentAccount -> (RevolutAccount) paymentAccount)
.filter(RevolutAccount::userNameNotSet)
.filter(RevolutAccount::usernameNotSet)
.collect(Collectors.toList()));
}
if (amazonGiftCardAccountsUpdateHandler != null && user.getPaymentAccountsAsObservable() != null) {
Expand Down
25 changes: 15 additions & 10 deletions core/src/main/java/haveno/core/payment/CashAppAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,22 @@

import java.util.List;

// Removed due too high chargeback risk
// Cannot be deleted as it would break old trade history entries
@Deprecated
@EqualsAndHashCode(callSuper = true)
public final class CashAppAccount extends PaymentAccount {

public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("USD"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(
new TraditionalCurrency("USD"),
new TraditionalCurrency("GBP"));

private static final List<PaymentAccountFormField.FieldId> INPUT_FIELD_IDS = List.of(
PaymentAccountFormField.FieldId.EMAIL_OR_MOBILE_NR_OR_CASHTAG,
PaymentAccountFormField.FieldId.TRADE_CURRENCIES,
PaymentAccountFormField.FieldId.ACCOUNT_NAME,
PaymentAccountFormField.FieldId.SALT);

public CashAppAccount() {
super(PaymentMethod.CASH_APP);
setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0));
tradeCurrencies.addAll(getSupportedCurrencies());
}

@Override
Expand All @@ -53,14 +58,14 @@ protected PaymentAccountPayload createPayload() {

@Override
public @NonNull List<PaymentAccountFormField.FieldId> getInputFieldIds() {
throw new RuntimeException("Not implemented");
return INPUT_FIELD_IDS;
}

public void setCashTag(String cashTag) {
((CashAppAccountPayload) paymentAccountPayload).setCashTag(cashTag);
public void setEmailOrMobileNrOrCashtag(String emailOrMobileNrOrCashtag) {
((CashAppAccountPayload) paymentAccountPayload).setEmailOrMobileNrOrCashtag(emailOrMobileNrOrCashtag);
}

public String getCashTag() {
return ((CashAppAccountPayload) paymentAccountPayload).getCashTag();
public String getEmailOrMobileNrOrCashtag() {
return ((CashAppAccountPayload) paymentAccountPayload).getEmailOrMobileNrOrCashtag();
}
}
95 changes: 95 additions & 0 deletions core/src/main/java/haveno/core/payment/PayPalAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* This file is part of Haveno.
*
* Haveno 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.
*
* Haveno 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 Haveno. If not, see <http://www.gnu.org/licenses/>.
*/

package haveno.core.payment;

import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
import haveno.core.payment.payload.PayPalAccountPayload;
import lombok.EqualsAndHashCode;
import lombok.NonNull;

import java.util.List;

@EqualsAndHashCode(callSuper = true)
public final class PayPalAccount extends PaymentAccount {

// https://developer.paypal.com/docs/reports/reference/paypal-supported-currencies/
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(
new TraditionalCurrency("AUD"),
new TraditionalCurrency("BRL"),
new TraditionalCurrency("CAD"),
new TraditionalCurrency("CNY"),
new TraditionalCurrency("CZK"),
new TraditionalCurrency("DKK"),
new TraditionalCurrency("EUR"),
new TraditionalCurrency("HKD"),
new TraditionalCurrency("HUF"),
new TraditionalCurrency("ILS"),
new TraditionalCurrency("JPY"),
new TraditionalCurrency("MYR"),
new TraditionalCurrency("MXN"),
new TraditionalCurrency("TWD"),
new TraditionalCurrency("NZD"),
new TraditionalCurrency("NOK"),
new TraditionalCurrency("PHP"),
new TraditionalCurrency("PLN"),
new TraditionalCurrency("GBP"),
new TraditionalCurrency("SGD"),
new TraditionalCurrency("SEK"),
new TraditionalCurrency("CHF"),
new TraditionalCurrency("THB"),
new TraditionalCurrency("USD"));

private static final List<PaymentAccountFormField.FieldId> INPUT_FIELD_IDS = List.of(
PaymentAccountFormField.FieldId.EMAIL_OR_MOBILE_NR_OR_USERNAME,
PaymentAccountFormField.FieldId.TRADE_CURRENCIES,
PaymentAccountFormField.FieldId.ACCOUNT_NAME,
PaymentAccountFormField.FieldId.SALT);

public PayPalAccount() {
super(PaymentMethod.PAYPAL);
tradeCurrencies.addAll(SUPPORTED_CURRENCIES);
}

@Override
protected PaymentAccountPayload createPayload() {
return new PayPalAccountPayload(paymentMethod.getId(), id);
}

@Override
public @NonNull List<TradeCurrency> getSupportedCurrencies() {
return SUPPORTED_CURRENCIES;
}

@Override
public @NonNull List<PaymentAccountFormField.FieldId> getInputFieldIds() {
return INPUT_FIELD_IDS;
}

public void setEmailOrMobileNrOrUsername(String emailOrMobileNrOrUsername) {
((PayPalAccountPayload) paymentAccountPayload)
.setEmailOrMobileNrOrUsername(emailOrMobileNrOrUsername);
}

public String getEmailOrMobileNrOrUsername() {
return ((PayPalAccountPayload) paymentAccountPayload).getEmailOrMobileNrOrUsername();
}
}
24 changes: 21 additions & 3 deletions core/src/main/java/haveno/core/payment/PaymentAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,13 @@ public void validateFormField(PaymentAccountForm form, PaymentAccountFormField.F
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:
case USERNAME:
processValidationResult(new LengthValidator(3, 100).validate(value));
break;
case EMAIL_OR_MOBILE_NR_OR_USERNAME:
processValidationResult(new LengthValidator(3, 100).validate(value));
break;
case EMAIL_OR_MOBILE_NR_OR_CASHTAG:
processValidationResult(new LengthValidator(3, 100).validate(value));
break;
case ADDRESS:
Expand Down Expand Up @@ -768,9 +774,21 @@ protected PaymentAccountFormField getEmptyFormField(PaymentAccountFormField.Fiel
field.setSupportedCurrencies(getSupportedCurrencies());
field.setValue(String.join(",", getSupportedCurrencies().stream().map(TradeCurrency::getCode).collect(Collectors.toList())));
break;
case USER_NAME:
case USERNAME:
field.setComponent(PaymentAccountFormField.Component.TEXT);
field.setLabel(Res.get("payment.account.username"));
field.setMinLength(3);
field.setMaxLength(100);
break;
case EMAIL_OR_MOBILE_NR_OR_USERNAME:
field.setComponent(PaymentAccountFormField.Component.TEXT);
field.setLabel(Res.get("payment.email.mobile.username"));
field.setMinLength(3);
field.setMaxLength(100);
break;
case EMAIL_OR_MOBILE_NR_OR_CASHTAG:
field.setComponent(PaymentAccountFormField.Component.TEXT);
field.setLabel(Res.get("payment.account.userName"));
field.setLabel(Res.get("payment.email.mobile.cashtag"));
field.setMinLength(3);
field.setMaxLength(100);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public static PaymentAccount getPaymentAccount(PaymentMethod paymentMethod) {
return new TransferwiseAccount();
case PaymentMethod.TRANSFERWISE_USD_ID:
return new TransferwiseUsdAccount();
case PaymentMethod.PAYPAL_ID:
return new PayPalAccount();
case PaymentMethod.PAYSERA_ID:
return new PayseraAccount();
case PaymentMethod.PAXUM_ID:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import static haveno.core.payment.payload.PaymentMethod.NEFT_ID;
import static haveno.core.payment.payload.PaymentMethod.NEQUI_ID;
import static haveno.core.payment.payload.PaymentMethod.PAXUM_ID;
import static haveno.core.payment.payload.PaymentMethod.PAYPAL_ID;
import static haveno.core.payment.payload.PaymentMethod.PAYSERA_ID;
import static haveno.core.payment.payload.PaymentMethod.PAYTM_ID;
import static haveno.core.payment.payload.PaymentMethod.PERFECT_MONEY_ID;
Expand Down Expand Up @@ -214,6 +215,8 @@ public static List<TradeCurrency> getTradeCurrencies(PaymentMethod paymentMethod
return USPostalMoneyOrderAccount.SUPPORTED_CURRENCIES;
case VENMO_ID:
return VenmoAccount.SUPPORTED_CURRENCIES;
case PAYPAL_ID:
return PayPalAccount.SUPPORTED_CURRENCIES;
case JAPAN_BANK_ID:
return JapanBankAccount.SUPPORTED_CURRENCIES;
case WECHAT_PAY_ID:
Expand Down
14 changes: 7 additions & 7 deletions core/src/main/java/haveno/core/payment/RevolutAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public final class RevolutAccount extends PaymentAccount {

private static final List<PaymentAccountFormField.FieldId> INPUT_FIELD_IDS = List.of(
PaymentAccountFormField.FieldId.USER_NAME,
PaymentAccountFormField.FieldId.USERNAME,
PaymentAccountFormField.FieldId.TRADE_CURRENCIES,
PaymentAccountFormField.FieldId.ACCOUNT_NAME,
PaymentAccountFormField.FieldId.SALT
Expand Down Expand Up @@ -82,16 +82,16 @@ protected PaymentAccountPayload createPayload() {
return new RevolutAccountPayload(paymentMethod.getId(), id);
}

public void setUserName(String userName) {
revolutAccountPayload().setUserName(userName);
public void setUsername(String userame) {
revolutAccountPayload().setUserName(userame);
}

public String getUserName() {
return (revolutAccountPayload()).getUserName();
public String getUsername() {
return (revolutAccountPayload()).getUsername();
}

public boolean userNameNotSet() {
return (revolutAccountPayload()).userNameNotSet();
public boolean usernameNotSet() {
return (revolutAccountPayload()).usernameNotSet();
}

private RevolutAccountPayload revolutAccountPayload() {
Expand Down
27 changes: 11 additions & 16 deletions core/src/main/java/haveno/core/payment/VenmoAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@

import java.util.List;

// Removed due too high chargeback risk
// Cannot be deleted as it would break old trade history entries
@Deprecated
@EqualsAndHashCode(callSuper = true)
public final class VenmoAccount extends PaymentAccount {

public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("USD"));

private static final List<PaymentAccountFormField.FieldId> INPUT_FIELD_IDS = List.of(
PaymentAccountFormField.FieldId.EMAIL_OR_MOBILE_NR_OR_USERNAME,
PaymentAccountFormField.FieldId.ACCOUNT_NAME,
PaymentAccountFormField.FieldId.SALT);

public VenmoAccount() {
super(PaymentMethod.VENMO);
setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0));
Expand All @@ -53,22 +55,15 @@ protected PaymentAccountPayload createPayload() {

@Override
public @NonNull List<PaymentAccountFormField.FieldId> getInputFieldIds() {
throw new RuntimeException("Not implemented");
}

public void setVenmoUserName(String venmoUserName) {
((VenmoAccountPayload) paymentAccountPayload).setVenmoUserName(venmoUserName);
}

public String getVenmoUserName() {
return ((VenmoAccountPayload) paymentAccountPayload).getVenmoUserName();
return INPUT_FIELD_IDS;
}

public void setHolderName(String holderName) {
((VenmoAccountPayload) paymentAccountPayload).setHolderName(holderName);
public void setNameOrUsernameOrEmailOrMobileNr(String usernameOrEmailOrMobileNr) {
((VenmoAccountPayload) paymentAccountPayload)
.setEmailOrMobileNrOrUsername(usernameOrEmailOrMobileNr);
}

public String getHolderName() {
return ((VenmoAccountPayload) paymentAccountPayload).getHolderName();
public String getNameOrUsernameOrEmailOrMobileNr() {
return ((VenmoAccountPayload) paymentAccountPayload).getEmailOrMobileNrOrUsername();
}
}
Loading

0 comments on commit fea8040

Please sign in to comment.