Skip to content

Commit

Permalink
Add PromptPay (Thailand)
Browse files Browse the repository at this point in the history
  • Loading branch information
leshik committed Oct 28, 2018
1 parent 3239b40 commit 0b8f6c1
Show file tree
Hide file tree
Showing 11 changed files with 321 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 @@ -722,6 +722,7 @@ message PaymentAccountPayload {
WeChatPayAccountPayload we_chat_pay_account_payload = 22;
MoneyGramAccountPayload money_gram_account_payload = 23;
HalCashAccountPayload hal_cash_account_payload = 24;
PromptPayAccountPayload prompt_pay_account_payload = 25;
}
map<string, string> exclude_from_json_data = 15;
}
Expand Down Expand Up @@ -896,6 +897,10 @@ message F2FAccountPayload {
string extra_info = 3;
}

message PromptPayAccountPayload {
string prompt_pay_id = 1;
}

///////////////////////////////////////////////////////////////////////////////////////////
// PersistableEnvelope
///////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public static PaymentAccount getPaymentAccount(PaymentMethod paymentMethod) {
return new HalCashAccount();
case PaymentMethod.F2F_ID:
return new F2FAccount();
case PaymentMethod.PROMPT_PAY_ID:
return new PromptPayAccount();
default:
throw new RuntimeException("Not supported PaymentMethod: " + paymentMethod);
}
Expand Down
46 changes: 46 additions & 0 deletions core/src/main/java/bisq/core/payment/PromptPayAccount.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 bisq.core.payment;

import bisq.core.locale.FiatCurrency;
import bisq.core.payment.payload.PaymentAccountPayload;
import bisq.core.payment.payload.PaymentMethod;
import bisq.core.payment.payload.PromptPayAccountPayload;

import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
public final class PromptPayAccount extends PaymentAccount {
public PromptPayAccount() {
super(PaymentMethod.PROMPT_PAY);
setSingleTradeCurrency(new FiatCurrency("THB"));
}

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

public void setPromptPayId(String promptPayId) {
((PromptPayAccountPayload) paymentAccountPayload).setPromptPayId(promptPayId);
}

public String getPromptPayId() {
return ((PromptPayAccountPayload) paymentAccountPayload).getPromptPayId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable {
public static final String HAL_CASH_ID = "HAL_CASH";
public static final String F2F_ID = "F2F";
public static final String BLOCK_CHAINS_ID = "BLOCK_CHAINS";
public static final String PROMPT_PAY_ID = "PROMPT_PAY";

@Deprecated
public static PaymentMethod OK_PAY;
Expand Down Expand Up @@ -112,6 +113,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable {
public static PaymentMethod F2F;
public static PaymentMethod HAL_CASH;
public static PaymentMethod BLOCK_CHAINS;
public static PaymentMethod PROMPT_PAY;

private static List<PaymentMethod> ALL_VALUES;

Expand Down Expand Up @@ -227,6 +229,9 @@ public static List<PaymentMethod> getAllValues() {
ALI_PAY = new PaymentMethod(ALI_PAY_ID, DAY, maxTradeLimitLowRisk),
WECHAT_PAY = new PaymentMethod(WECHAT_PAY_ID, DAY, maxTradeLimitLowRisk),

// Thailand
PROMPT_PAY = new PaymentMethod(PROMPT_PAY_ID, DAY, maxTradeLimitLowRisk),

// Altcoins
BLOCK_CHAINS = new PaymentMethod(BLOCK_CHAINS_ID, DAY, maxTradeLimitVeryLowRisk)
));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* 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 bisq.core.payment.payload;

import io.bisq.generated.protobuffer.PB;

import com.google.protobuf.Message;

import org.springframework.util.CollectionUtils;

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;

import javax.annotation.Nullable;

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

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


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

private PromptPayAccountPayload(String paymentMethod, String id,
String promptPayId,
long maxTradePeriod,
@Nullable Map<String, String> excludeFromJsonDataMap) {
super(paymentMethod,
id,
maxTradePeriod,
excludeFromJsonDataMap);

this.promptPayId = promptPayId;
}

@Override
public Message toProtoMessage() {
return getPaymentAccountPayloadBuilder()
.setPromptPayAccountPayload(PB.PromptPayAccountPayload.newBuilder()
.setPromptPayId(promptPayId))
.build();
}

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


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

@Override
public String getPaymentDetails() {
return "PromptPay ID: " + promptPayId;
}

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

@Override
public byte[] getAgeWitnessInputData() {
return super.getAgeWitnessInputData(promptPayId.getBytes(Charset.forName("UTF-8")));
}
}
3 changes: 3 additions & 0 deletions core/src/main/java/bisq/core/proto/CoreProtoResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import bisq.core.payment.payload.PaymentAccountPayload;
import bisq.core.payment.payload.PerfectMoneyAccountPayload;
import bisq.core.payment.payload.PopmoneyAccountPayload;
import bisq.core.payment.payload.PromptPayAccountPayload;
import bisq.core.payment.payload.RevolutAccountPayload;
import bisq.core.payment.payload.SameBankAccountPayload;
import bisq.core.payment.payload.SepaAccountPayload;
Expand Down Expand Up @@ -135,6 +136,8 @@ public PaymentAccountPayload fromProto(PB.PaymentAccountPayload proto) {
return HalCashAccountPayload.fromProto(proto);
case U_S_POSTAL_MONEY_ORDER_ACCOUNT_PAYLOAD:
return USPostalMoneyOrderAccountPayload.fromProto(proto);
case PROMPT_PAY_ACCOUNT_PAYLOAD:
return PromptPayAccountPayload.fromProto(proto);
default:
throw new ProtobufferRuntimeException("Unknown proto message case(PB.PaymentAccountPayload). messageCase=" + messageCase);
}
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,7 @@ payment.moneyBeam.accountId=Email or phone no.:
payment.venmo.venmoUserName=Venmo username:
payment.popmoney.accountId=Email or phone no.:
payment.revolut.accountId=Email or phone no.:
payment.promptPay.promptPayId=Citizen ID/Tax ID or phone no.:
payment.supportedCurrencies=Supported currencies:
payment.limitations=Limitations:
payment.salt=Salt for account age verification:
Expand Down Expand Up @@ -2305,6 +2306,8 @@ INTERAC_E_TRANSFER=Interac e-Transfer
HAL_CASH=HalCash
# suppress inspection "UnusedProperty"
BLOCK_CHAINS=Altcoins
# suppress inspection "UnusedProperty"
PROMPT_PAY=PromptPay

# suppress inspection "UnusedProperty"
OK_PAY_SHORT=OKPay
Expand Down Expand Up @@ -2344,6 +2347,8 @@ INTERAC_E_TRANSFER_SHORT=Interac e-Transfer
HAL_CASH_SHORT=HalCash
# suppress inspection "UnusedProperty"
BLOCK_CHAINS_SHORT=Altcoins
# suppress inspection "UnusedProperty"
PROMPT_PAY_SHORT=PromptPay


####################################################################
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* 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 bisq.desktop.components.paymentmethods;

import bisq.desktop.components.InputTextField;
import bisq.desktop.util.Layout;
import bisq.desktop.util.validation.PromptPayValidator;

import bisq.core.locale.Res;
import bisq.core.locale.TradeCurrency;
import bisq.core.payment.AccountAgeWitnessService;
import bisq.core.payment.PromptPayAccount;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.payload.PromptPayAccountPayload;
import bisq.core.payment.payload.PaymentAccountPayload;
import bisq.core.util.BSFormatter;
import bisq.core.util.validation.InputValidator;

import org.apache.commons.lang3.StringUtils;

import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;

import static bisq.desktop.util.FormBuilder.addLabelInputTextField;
import static bisq.desktop.util.FormBuilder.addLabelTextField;

public class PromptPayForm extends PaymentMethodForm {
private final PromptPayAccount promptPayAccount;
private final PromptPayValidator promptPayValidator;
private InputTextField promptPayIdInputTextField;

public static int addFormForBuyer(GridPane gridPane, int gridRow,
PaymentAccountPayload paymentAccountPayload) {
addLabelTextField(gridPane, ++gridRow, Res.get("payment.promptPay.promptPayId"),
((PromptPayAccountPayload) paymentAccountPayload).getPromptPayId());
return gridRow;
}

public PromptPayForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAgeWitnessService, PromptPayValidator promptPayValidator,
InputValidator inputValidator, GridPane gridPane, int gridRow, BSFormatter formatter) {
super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter);
this.promptPayAccount = (PromptPayAccount) paymentAccount;
this.promptPayValidator = promptPayValidator;
}

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

promptPayIdInputTextField = addLabelInputTextField(gridPane, ++gridRow,
Res.get("payment.promptPay.promptPayId")).second;
promptPayIdInputTextField.setValidator(promptPayValidator);
promptPayIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
promptPayAccount.setPromptPayId(newValue);
updateFromInputs();
});

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

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

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

@Override
public void updateAllInputsValid() {
allInputsValid.set(isAccountNameValid()
&& promptPayValidator.validate(promptPayAccount.getPromptPayId()).isValid
&& promptPayAccount.getTradeCurrencies().size() > 0);
}
}
Loading

0 comments on commit 0b8f6c1

Please sign in to comment.