Skip to content

Commit

Permalink
Add payment method Cash App (#1049)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManfredKarrer committed Feb 14, 2018
1 parent ead3082 commit ad56c26
Show file tree
Hide file tree
Showing 11 changed files with 298 additions and 1 deletion.
5 changes: 5 additions & 0 deletions common/src/main/proto/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ message PaymentAccountPayload {
SwishAccountPayload swish_account_payload = 13;
USPostalMoneyOrderAccountPayload u_s_postal_money_order_account_payload = 14;
UpholdAccountPayload uphold_account_payload = 16;
CashAppAccountPayload cash_app_account_payload = 17;
}
map<string, string> exclude_from_json_data = 15;
}
Expand Down Expand Up @@ -945,6 +946,10 @@ message UpholdAccountPayload {
string account_id = 1;
}

message CashAppAccountPayload {
string account_id = 1;
}

message PerfectMoneyAccountPayload {
string account_nr = 1;
}
Expand Down
6 changes: 5 additions & 1 deletion common/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,8 @@ payment.select.altcoin=Select or search altcoin
payment.secret=Secret question:
payment.answer=Answer:
payment.wallet=Wallet ID:
payment.uphold.accountId=Account ID (username or email or tel. no):
payment.uphold.accountId=Account ID (username or email or phone. no):
payment.cashApp.accountId=Account ID ($Cashtag or email or phone. no):
payment.supported.okpay=Supported currencies:
payment.supported.uphold=Supported currencies:
payment.limitations=Limitations:
Expand Down Expand Up @@ -1704,6 +1705,7 @@ WESTERN_UNION_SHORT=Western Union
# Do not translate brand names
OK_PAY=OKPay
UPHOLD=Uphold
CASH_APP=Cash App
PERFECT_MONEY=Perfect Money
ALI_PAY=AliPay
SEPA=SEPA
Expand All @@ -1720,6 +1722,8 @@ OK_PAY_SHORT=OKPay
# suppress inspection "UnusedProperty"
UPHOLD_SHORT=Uphold
# suppress inspection "UnusedProperty"
CASH_APP_SHORT=Cash App
# suppress inspection "UnusedProperty"
PERFECT_MONEY_SHORT=Perfect Money
# suppress inspection "UnusedProperty"
ALI_PAY_SHORT=AliPay
Expand Down
46 changes: 46 additions & 0 deletions core/src/main/java/io/bisq/core/payment/CashAppAccount.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.CashAppAccountPayload;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.payment.payload.PaymentMethod;
import lombok.EqualsAndHashCode;

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

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

public void setAccountId(String accountId) {
((CashAppAccountPayload) paymentAccountPayload).setAccountId(accountId);
}

public String getAccountId() {
return ((CashAppAccountPayload) paymentAccountPayload).getAccountId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public static PaymentAccount getPaymentAccount(PaymentMethod paymentMethod) {
return new OKPayAccount();
case PaymentMethod.UPHOLD_ID:
return new UpholdAccount();
case PaymentMethod.CASH_APP_ID:
return new CashAppAccount();
case PaymentMethod.PERFECT_MONEY_ID:
return new PerfectMoneyAccount();
case PaymentMethod.SEPA_ID:
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 CashAppAccountPayload extends PaymentAccountPayload {
private String accountId = "";

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


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

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

this.accountId = accountId;
}

@Override
public Message toProtoMessage() {
return getPaymentAccountPayloadBuilder()
.setCashAppAccountPayload(PB.CashAppAccountPayload.newBuilder()
.setAccountId(accountId))
.build();
}

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


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

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

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

@Override
public byte[] getAgeWitnessInputData() {
return super.getAgeWitnessInputData(accountId.getBytes(Charset.forName("UTF-8")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable {

public static final String OK_PAY_ID = "OK_PAY";
public static final String UPHOLD_ID = "UPHOLD";
public static final String CASH_APP_ID = "CASH_APP";
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 @@ -67,6 +68,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable {

public static PaymentMethod OK_PAY;
public static PaymentMethod UPHOLD;
public static PaymentMethod CASH_APP;
public static PaymentMethod PERFECT_MONEY;
public static PaymentMethod SEPA;
public static PaymentMethod SEPA_INSTANT;
Expand Down Expand Up @@ -170,6 +172,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),
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
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 @@ -62,6 +62,8 @@ public PaymentAccountPayload fromProto(PB.PaymentAccountPayload proto) {
return OKPayAccountPayload.fromProto(proto);
case UPHOLD_ACCOUNT_PAYLOAD:
return UpholdAccountPayload.fromProto(proto);
case CASH_APP_ACCOUNT_PAYLOAD:
return CashAppAccountPayload.fromProto(proto);
case PERFECT_MONEY_ACCOUNT_PAYLOAD:
return PerfectMoneyAccountPayload.fromProto(proto);
case SWISH_ACCOUNT_PAYLOAD:
Expand Down
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.CashAppAccount;
import io.bisq.core.payment.PaymentAccount;
import io.bisq.core.payment.payload.CashAppAccountPayload;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.gui.components.InputTextField;
import io.bisq.gui.util.BSFormatter;
import io.bisq.gui.util.Layout;
import io.bisq.gui.util.validation.CashAppValidator;
import io.bisq.gui.util.validation.InputValidator;
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 CashAppForm extends PaymentMethodForm {
private final CashAppAccount account;
private final CashAppValidator validator;
private InputTextField accountIdInputTextField;

public static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountPayload paymentAccountPayload) {
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, Res.get("payment.cashApp.accountId"), ((CashAppAccountPayload) paymentAccountPayload).getAccountId());
return gridRow;
}

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

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

accountIdInputTextField = addLabelInputTextField(gridPane, ++gridRow, Res.get("payment.cashApp.accountId")).second;
accountIdInputTextField.setValidator(validator);
accountIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
account.setAccountId(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.cashApp.accountId"), account.getAccountId()).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.getAccountId()).isValid
&& account.getTradeCurrencies().size() > 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class FiatAccountsView extends ActivatableViewAndModel<GridPane, FiatAcco
private final InputValidator inputValidator;
private final OKPayValidator okPayValidator;
private final UpholdValidator upholdValidator;
private final CashAppValidator cashAppValidator;
private final AliPayValidator aliPayValidator;
private final PerfectMoneyValidator perfectMoneyValidator;
private final SwishValidator swishValidator;
Expand All @@ -87,6 +88,7 @@ public FiatAccountsView(FiatAccountsViewModel model,
InputValidator inputValidator,
OKPayValidator okPayValidator,
UpholdValidator upholdValidator,
CashAppValidator cashAppValidator,
AliPayValidator aliPayValidator,
PerfectMoneyValidator perfectMoneyValidator,
SwishValidator swishValidator,
Expand All @@ -103,6 +105,7 @@ public FiatAccountsView(FiatAccountsViewModel model,
this.inputValidator = inputValidator;
this.okPayValidator = okPayValidator;
this.upholdValidator = upholdValidator;
this.cashAppValidator = cashAppValidator;
this.aliPayValidator = aliPayValidator;
this.perfectMoneyValidator = perfectMoneyValidator;
this.swishValidator = swishValidator;
Expand Down Expand Up @@ -344,6 +347,8 @@ private PaymentMethodForm getPaymentMethodForm(PaymentMethod paymentMethod, Paym
return new OKPayForm(paymentAccount, accountAgeWitnessService, okPayValidator, inputValidator, root, gridRow, formatter);
case PaymentMethod.UPHOLD_ID:
return new UpholdForm(paymentAccount, accountAgeWitnessService, upholdValidator, inputValidator, root, gridRow, formatter);
case PaymentMethod.CASH_APP_ID:
return new CashAppForm(paymentAccount, accountAgeWitnessService, cashAppValidator, 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 @@ -160,6 +160,9 @@ protected void addContent() {
case PaymentMethod.UPHOLD_ID:
gridRow = UpholdForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.CASH_APP_ID:
gridRow = CashAppForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.PERFECT_MONEY_ID:
gridRow = PerfectMoneyForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
Expand Down
Loading

0 comments on commit ad56c26

Please sign in to comment.