Skip to content

Commit

Permalink
Add payment method Venmo (#1347)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManfredKarrer committed Feb 19, 2018
1 parent beaaf59 commit 7654a5d
Show file tree
Hide file tree
Showing 11 changed files with 297 additions and 0 deletions.
5 changes: 5 additions & 0 deletions common/src/main/proto/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ message PaymentAccountPayload {
UpholdAccountPayload uphold_account_payload = 16;
CashAppAccountPayload cash_app_account_payload = 17;
MoneyBeamAccountPayload money_beam_account_payload = 18;
VenmoAccountPayload venmo_account_payload = 19;
}
map<string, string> exclude_from_json_data = 15;
}
Expand Down Expand Up @@ -955,6 +956,10 @@ message MoneyBeamAccountPayload {
string account_id = 1;
}

message VenmoAccountPayload {
string venmo_user_name = 1;
}

message PerfectMoneyAccountPayload {
string account_nr = 1;
}
Expand Down
4 changes: 4 additions & 0 deletions common/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,7 @@ payment.wallet=Wallet ID:
payment.uphold.accountId=Username or email or phone no.:
payment.cashApp.accountId=$Cashtag or email or phone no.:
payment.moneyBeam.accountId=Email or phone no.:
payment.venmo.venmoUserName=Venmo username:
payment.supported.okpay=Supported currencies:
payment.supported.uphold=Supported currencies:
payment.limitations=Limitations:
Expand Down Expand Up @@ -1712,6 +1713,7 @@ OK_PAY=OKPay
UPHOLD=Uphold
CASH_APP=Cash App
MONEY_BEAM=MoneyBeam
VENMO=Venmo
PERFECT_MONEY=Perfect Money
ALI_PAY=AliPay
SEPA=SEPA
Expand All @@ -1732,6 +1734,8 @@ CASH_APP_SHORT=Cash App
# suppress inspection "UnusedProperty"
MONEY_BEAM_SHORT=MoneyBeam
# suppress inspection "UnusedProperty"
VENMO_SHORT=Venmo
# suppress inspection "UnusedProperty"
PERFECT_MONEY_SHORT=Perfect Money
# suppress inspection "UnusedProperty"
ALI_PAY_SHORT=AliPay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public static PaymentAccount getPaymentAccount(PaymentMethod paymentMethod) {
return new CashAppAccount();
case PaymentMethod.MONEY_BEAM_ID:
return new MoneyBeamAccount();
case PaymentMethod.VENMO_ID:
return new VenmoAccount();
case PaymentMethod.PERFECT_MONEY_ID:
return new PerfectMoneyAccount();
case PaymentMethod.SEPA_ID:
Expand Down
46 changes: 46 additions & 0 deletions core/src/main/java/io/bisq/core/payment/VenmoAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/

package io.bisq.core.payment;

import io.bisq.common.locale.FiatCurrency;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.payment.payload.PaymentMethod;
import io.bisq.core.payment.payload.VenmoAccountPayload;
import lombok.EqualsAndHashCode;

//TODO missing support for selected trade currency
@EqualsAndHashCode(callSuper = true)
public final class VenmoAccount extends PaymentAccount {
public VenmoAccount() {
super(PaymentMethod.VENMO);
setSingleTradeCurrency(new FiatCurrency("USD"));
}

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

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

public String getVenmoUserName() {
return ((VenmoAccountPayload) paymentAccountPayload).getVenmoUserName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable {
public static final String UPHOLD_ID = "UPHOLD";
public static final String CASH_APP_ID = "CASH_APP";
public static final String MONEY_BEAM_ID = "MONEY_BEAM";
public static final String VENMO_ID = "VENMO";
public static final String PERFECT_MONEY_ID = "PERFECT_MONEY";
public static final String SEPA_ID = "SEPA";
public static final String SEPA_INSTANT_ID = "SEPA_INSTANT";
Expand All @@ -71,6 +72,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable {
public static PaymentMethod UPHOLD;
public static PaymentMethod CASH_APP;
public static PaymentMethod MONEY_BEAM;
public static PaymentMethod VENMO;
public static PaymentMethod PERFECT_MONEY;
public static PaymentMethod SEPA;
public static PaymentMethod SEPA_INSTANT;
Expand Down Expand Up @@ -176,6 +178,7 @@ public static List<PaymentMethod> getAllValues() {
// US
CLEAR_X_CHANGE = new PaymentMethod(CLEAR_X_CHANGE_ID, 4 * DAY, maxTradeLimitMidRisk),
CASH_APP = new PaymentMethod(CASH_APP_ID, DAY, maxTradeLimitMidRisk),
VENMO = new PaymentMethod(VENMO_ID, DAY, maxTradeLimitMidRisk),
CHASE_QUICK_PAY = new PaymentMethod(CHASE_QUICK_PAY_ID, DAY, maxTradeLimitMidRisk),
US_POSTAL_MONEY_ORDER = new PaymentMethod(US_POSTAL_MONEY_ORDER_ID, 8 * DAY, maxTradeLimitMidRisk),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/

package io.bisq.core.payment.payload;

import com.google.protobuf.Message;
import io.bisq.generated.protobuffer.PB;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;

import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;

@EqualsAndHashCode(callSuper = true)
@ToString
@Setter
@Getter
@Slf4j
public final class VenmoAccountPayload extends PaymentAccountPayload {
private String venmoUserName = "";

public VenmoAccountPayload(String paymentMethod, String id) {
super(paymentMethod, id);
}


///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////

private VenmoAccountPayload(String paymentMethod,
String id,
String venmoUserName,
long maxTradePeriod,
Map<String, String> excludeFromJsonDataMap) {
super(paymentMethod,
id,
maxTradePeriod,
excludeFromJsonDataMap);

this.venmoUserName = venmoUserName;
}

@Override
public Message toProtoMessage() {
return getPaymentAccountPayloadBuilder()
.setVenmoAccountPayload(PB.VenmoAccountPayload.newBuilder()
.setVenmoUserName(venmoUserName))
.build();
}

public static VenmoAccountPayload fromProto(PB.PaymentAccountPayload proto) {
return new VenmoAccountPayload(proto.getPaymentMethodId(),
proto.getId(),
proto.getVenmoAccountPayload().getVenmoUserName(),
proto.getMaxTradePeriod(),
CollectionUtils.isEmpty(proto.getExcludeFromJsonDataMap()) ? null : new HashMap<>(proto.getExcludeFromJsonDataMap()));
}


///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////

@Override
public String getPaymentDetails() {
return "Venmo - Account: " + venmoUserName;
}

@Override
public String getPaymentDetailsForTradePopup() {
return getPaymentDetails();
}

@Override
public byte[] getAgeWitnessInputData() {
return super.getAgeWitnessInputData(venmoUserName.getBytes(Charset.forName("UTF-8")));
}
}
2 changes: 2 additions & 0 deletions core/src/main/java/io/bisq/core/proto/CoreProtoResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public PaymentAccountPayload fromProto(PB.PaymentAccountPayload proto) {
return CashAppAccountPayload.fromProto(proto);
case MONEY_BEAM_ACCOUNT_PAYLOAD:
return MoneyBeamAccountPayload.fromProto(proto);
case VENMO_ACCOUNT_PAYLOAD:
return VenmoAccountPayload.fromProto(proto);
case PERFECT_MONEY_ACCOUNT_PAYLOAD:
return PerfectMoneyAccountPayload.fromProto(proto);
case SWISH_ACCOUNT_PAYLOAD:
Expand Down
101 changes: 101 additions & 0 deletions gui/src/main/java/io/bisq/gui/components/paymentmethods/VenmoForm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/

package io.bisq.gui.components.paymentmethods;

import io.bisq.common.locale.Res;
import io.bisq.common.locale.TradeCurrency;
import io.bisq.core.payment.AccountAgeWitnessService;
import io.bisq.core.payment.PaymentAccount;
import io.bisq.core.payment.VenmoAccount;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.payment.payload.VenmoAccountPayload;
import io.bisq.gui.components.InputTextField;
import io.bisq.gui.util.BSFormatter;
import io.bisq.gui.util.Layout;
import io.bisq.gui.util.validation.InputValidator;
import io.bisq.gui.util.validation.VenmoValidator;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import org.apache.commons.lang3.StringUtils;

import static io.bisq.gui.util.FormBuilder.*;

public class VenmoForm extends PaymentMethodForm {
private final VenmoAccount account;
private final VenmoValidator validator;
private InputTextField accountIdInputTextField;

public static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountPayload paymentAccountPayload) {
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, Res.get("payment.venmo.venmoUserName"), ((VenmoAccountPayload) paymentAccountPayload).getVenmoUserName());
return gridRow;
}

public VenmoForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAgeWitnessService, VenmoValidator aliPayValidator, InputValidator inputValidator, GridPane gridPane, int gridRow, BSFormatter formatter) {
super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter);
this.account = (VenmoAccount) paymentAccount;
this.validator = aliPayValidator;
}

@Override
public void addFormForAddAccount() {
gridRowFrom = gridRow + 1;

accountIdInputTextField = addLabelInputTextField(gridPane, ++gridRow, Res.get("payment.venmo.venmoUserName")).second;
accountIdInputTextField.setValidator(validator);
accountIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
account.setVenmoUserName(newValue);
updateFromInputs();
});

final TradeCurrency singleTradeCurrency = account.getSingleTradeCurrency();
final String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "";
addLabelTextField(gridPane, ++gridRow, Res.getWithCol("shared.currency"), nameAndCode);
addLimitations();
addAccountNameTextFieldWithAutoFillCheckBox();
}

@Override
protected void autoFillNameTextField() {
if (useCustomAccountNameCheckBox != null && !useCustomAccountNameCheckBox.isSelected()) {
String accountNr = accountIdInputTextField.getText();
accountNr = StringUtils.abbreviate(accountNr, 9);
String method = Res.get(paymentAccount.getPaymentMethod().getId());
accountNameTextField.setText(method.concat(": ").concat(accountNr));
}
}

@Override
public void addFormForDisplayAccount() {
gridRowFrom = gridRow;
addLabelTextField(gridPane, gridRow, Res.get("payment.account.name"), account.getAccountName(), Layout.FIRST_ROW_AND_GROUP_DISTANCE);
addLabelTextField(gridPane, ++gridRow, Res.getWithCol("shared.paymentMethod"), Res.get(account.getPaymentMethod().getId()));
TextField field = addLabelTextField(gridPane, ++gridRow, Res.get("payment.venmo.venmoUserName"), account.getVenmoUserName()).second;
field.setMouseTransparent(false);
final TradeCurrency singleTradeCurrency = account.getSingleTradeCurrency();
final String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "";
addLabelTextField(gridPane, ++gridRow, Res.getWithCol("shared.currency"), nameAndCode);
addLimitations();
}

@Override
public void updateAllInputsValid() {
allInputsValid.set(isAccountNameValid()
&& validator.validate(account.getVenmoUserName()).isValid
&& account.getTradeCurrencies().size() > 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class FiatAccountsView extends ActivatableViewAndModel<GridPane, FiatAcco
private final UpholdValidator upholdValidator;
private final CashAppValidator cashAppValidator;
private final MoneyBeamValidator moneyBeamValidator;
private final VenmoValidator venmoValidator;
private final AliPayValidator aliPayValidator;
private final PerfectMoneyValidator perfectMoneyValidator;
private final SwishValidator swishValidator;
Expand All @@ -91,6 +92,7 @@ public FiatAccountsView(FiatAccountsViewModel model,
UpholdValidator upholdValidator,
CashAppValidator cashAppValidator,
MoneyBeamValidator moneyBeamValidator,
VenmoValidator venmoValidator,
AliPayValidator aliPayValidator,
PerfectMoneyValidator perfectMoneyValidator,
SwishValidator swishValidator,
Expand All @@ -109,6 +111,7 @@ public FiatAccountsView(FiatAccountsViewModel model,
this.upholdValidator = upholdValidator;
this.cashAppValidator = cashAppValidator;
this.moneyBeamValidator = moneyBeamValidator;
this.venmoValidator = venmoValidator;
this.aliPayValidator = aliPayValidator;
this.perfectMoneyValidator = perfectMoneyValidator;
this.swishValidator = swishValidator;
Expand Down Expand Up @@ -354,6 +357,8 @@ private PaymentMethodForm getPaymentMethodForm(PaymentMethod paymentMethod, Paym
return new CashAppForm(paymentAccount, accountAgeWitnessService, cashAppValidator, inputValidator, root, gridRow, formatter);
case PaymentMethod.MONEY_BEAM_ID:
return new MoneyBeamForm(paymentAccount, accountAgeWitnessService, moneyBeamValidator, inputValidator, root, gridRow, formatter);
case PaymentMethod.VENMO_ID:
return new VenmoForm(paymentAccount, accountAgeWitnessService, venmoValidator, inputValidator, root, gridRow, formatter);
case PaymentMethod.PERFECT_MONEY_ID:
return new PerfectMoneyForm(paymentAccount, accountAgeWitnessService, perfectMoneyValidator, inputValidator, root, gridRow, formatter);
case PaymentMethod.SEPA_ID:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ protected void addContent() {
case PaymentMethod.MONEY_BEAM_ID:
gridRow = MoneyBeamForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.VENMO_ID:
gridRow = VenmoForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.PERFECT_MONEY_ID:
gridRow = PerfectMoneyForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
Expand Down
Loading

0 comments on commit 7654a5d

Please sign in to comment.