Skip to content

Commit

Permalink
Merge pull request #5117 from jmacxx/add_country_amazon_account
Browse files Browse the repository at this point in the history
Specify Amazon eGift Card country
  • Loading branch information
ripcurlx authored Feb 12, 2021
2 parents de57900 + f89e418 commit 31b7292
Show file tree
Hide file tree
Showing 11 changed files with 316 additions and 21 deletions.
5 changes: 5 additions & 0 deletions core/src/main/java/bisq/core/app/BisqSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import bisq.core.dao.state.unconfirmed.UnconfirmedBsqChangeOutputListService;
import bisq.core.locale.Res;
import bisq.core.offer.OpenOfferManager;
import bisq.core.payment.AmazonGiftCardAccount;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.RevolutAccount;
import bisq.core.payment.payload.PaymentMethod;
Expand Down Expand Up @@ -179,6 +180,9 @@ default void onRequestWalletPassword() {
private Consumer<List<RevolutAccount>> revolutAccountsUpdateHandler;
@Setter
@Nullable
private Consumer<List<AmazonGiftCardAccount>> amazonGiftCardAccountsUpdateHandler;
@Setter
@Nullable
private Runnable osxKeyLoggerWarningHandler;
@Setter
@Nullable
Expand Down Expand Up @@ -456,6 +460,7 @@ private void initDomainServices() {
filterWarningHandler,
voteResultExceptionHandler,
revolutAccountsUpdateHandler,
amazonGiftCardAccountsUpdateHandler,
daoRequiresRestartHandler);

if (walletsSetup.downloadPercentageProperty().get() == 1) {
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/bisq/core/app/DomainInitialisation.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import bisq.core.notifications.alerts.price.PriceAlert;
import bisq.core.offer.OpenOfferManager;
import bisq.core.offer.TriggerPriceService;
import bisq.core.payment.AmazonGiftCardAccount;
import bisq.core.payment.RevolutAccount;
import bisq.core.payment.TradeLimits;
import bisq.core.provider.fee.FeeService;
Expand Down Expand Up @@ -189,6 +190,7 @@ public void initDomainServices(Consumer<String> rejectedTxErrorMessageHandler,
Consumer<String> filterWarningHandler,
Consumer<VoteResultException> voteResultExceptionHandler,
Consumer<List<RevolutAccount>> revolutAccountsUpdateHandler,
Consumer<List<AmazonGiftCardAccount>> amazonGiftCardAccountsUpdateHandler,
Runnable daoRequiresRestartHandler) {
clockWatcher.start();

Expand Down Expand Up @@ -267,5 +269,12 @@ public void initDomainServices(Consumer<String> rejectedTxErrorMessageHandler,
.filter(RevolutAccount::userNameNotSet)
.collect(Collectors.toList()));
}
if (amazonGiftCardAccountsUpdateHandler != null) {
amazonGiftCardAccountsUpdateHandler.accept(user.getPaymentAccountsAsObservable().stream()
.filter(paymentAccount -> paymentAccount instanceof AmazonGiftCardAccount)
.map(paymentAccount -> (AmazonGiftCardAccount) paymentAccount)
.filter(AmazonGiftCardAccount::countryNotSet)
.collect(Collectors.toList()));
}
}
}
12 changes: 12 additions & 0 deletions core/src/main/java/bisq/core/locale/CountryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ public static List<Country> getAllRevolutCountries() {
return list;
}

public static List<Country> getAllAmazonGiftCardCountries() {
List<Country> list = new ArrayList<>();
String[] codes = {"AU", "CA", "FR", "DE", "IT", "NL", "ES", "GB", "IN", "JP",
"SA", "SE", "SG", "TR", "US"};
populateCountryListByCodes(list, codes);
list.sort((a, b) -> a.name.compareTo(b.name));

return list;
}

public static List<Country> getAllSepaInstantEuroCountries() {
return getAllSepaEuroCountries();
}
Expand Down Expand Up @@ -133,6 +143,8 @@ public static String getNameByCode(String countryCode) {
}

public static String getNameAndCode(String countryCode) {
if (countryCode.isEmpty())
return "";
return getNameByCode(countryCode) + " (" + countryCode + ")";
}

Expand Down
27 changes: 27 additions & 0 deletions core/src/main/java/bisq/core/payment/AmazonGiftCardAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@

package bisq.core.payment;

import bisq.core.locale.Country;
import bisq.core.locale.CountryUtil;
import bisq.core.payment.payload.AmazonGiftCardAccountPayload;
import bisq.core.payment.payload.PaymentAccountPayload;
import bisq.core.payment.payload.PaymentMethod;

import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;

public final class AmazonGiftCardAccount extends PaymentAccount {

@Nullable
private Country country;

public AmazonGiftCardAccount() {
super(PaymentMethod.AMAZON_GIFT_CARD);
}
Expand All @@ -40,6 +49,24 @@ public void setEmailOrMobileNr(String emailOrMobileNr) {
getAmazonGiftCardAccountPayload().setEmailOrMobileNr(emailOrMobileNr);
}

public boolean countryNotSet() {
return (getAmazonGiftCardAccountPayload()).countryNotSet();
}

@Nullable
public Country getCountry() {
if (country == null) {
final String countryCode = getAmazonGiftCardAccountPayload().getCountryCode();
CountryUtil.findCountryByCode(countryCode).ifPresent(c -> this.country = c);
}
return country;
}

public void setCountry(@NotNull Country country) {
this.country = country;
getAmazonGiftCardAccountPayload().setCountryCode(country.code);
}

private AmazonGiftCardAccountPayload getAmazonGiftCardAccountPayload() {
return (AmazonGiftCardAccountPayload) paymentAccountPayload;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package bisq.core.payment.payload;

import bisq.core.locale.Res;
import bisq.common.util.JsonExclude;

import com.google.protobuf.Message;

Expand All @@ -39,6 +40,10 @@
@Slf4j
public class AmazonGiftCardAccountPayload extends PaymentAccountPayload {
private String emailOrMobileNr;
// For backward compatibility we need to exclude the new field for the contract json.
// We can remove that after a while when risk that users with pre 1.5.5 version is very low.
@JsonExclude
private String countryCode = "";

public AmazonGiftCardAccountPayload(String paymentMethod, String id) {
super(paymentMethod, id);
Expand All @@ -52,19 +57,22 @@ public AmazonGiftCardAccountPayload(String paymentMethod, String id) {
private AmazonGiftCardAccountPayload(String paymentMethodName,
String id,
String emailOrMobileNr,
String countryCode,
long maxTradePeriod,
Map<String, String> excludeFromJsonDataMap) {
super(paymentMethodName,
id,
maxTradePeriod,
excludeFromJsonDataMap);
this.emailOrMobileNr = emailOrMobileNr;
this.countryCode = countryCode;
}

@Override
public Message toProtoMessage() {
protobuf.AmazonGiftCardAccountPayload.Builder builder =
protobuf.AmazonGiftCardAccountPayload.newBuilder()
.setCountryCode(countryCode)
.setEmailOrMobileNr(emailOrMobileNr);
return getPaymentAccountPayloadBuilder()
.setAmazonGiftCardAccountPayload(builder)
Expand All @@ -76,6 +84,7 @@ public static PaymentAccountPayload fromProto(protobuf.PaymentAccountPayload pro
return new AmazonGiftCardAccountPayload(proto.getPaymentMethodId(),
proto.getId(),
amazonGiftCardAccountPayload.getEmailOrMobileNr(),
amazonGiftCardAccountPayload.getCountryCode(),
proto.getMaxTradePeriod(),
new HashMap<>(proto.getExcludeFromJsonDataMap()));
}
Expand All @@ -100,4 +109,8 @@ public byte[] getAgeWitnessInputData() {
String data = "AmazonGiftCard" + emailOrMobileNr;
return super.getAgeWitnessInputData(data.getBytes(StandardCharsets.UTF_8));
}

public boolean countryNotSet() {
return countryCode.isEmpty();
}
}
13 changes: 9 additions & 4 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -653,10 +653,6 @@ portfolio.pending.step2_buyer.moneyGram.extra=IMPORTANT REQUIREMENT:\nAfter you
portfolio.pending.step2_buyer.westernUnion=Please pay {0} to the BTC seller by using Western Union.\n\n
portfolio.pending.step2_buyer.westernUnion.extra=IMPORTANT REQUIREMENT:\nAfter you have done the payment send the MTCN (tracking number) and a photo of the receipt by email to the BTC seller.\n\
The receipt must clearly show the seller''s full name, city, country and the amount. The seller''s email is: {0}.
# suppress inspection "TrailingSpacesInProperty"
portfolio.pending.step2_buyer.amazonGiftCard=Please purchase an Amazon eGift Card for {0} at your Amazon account and \
use the BTC seller''s email or mobile number as receiver. \
In case the trade amount exceeds the permitted amount send multiple cards.\n\n

# suppress inspection "TrailingSpacesInProperty"
portfolio.pending.step2_buyer.postal=Please send {0} by \"US Postal Money Order\" to the BTC seller.\n\n
Expand Down Expand Up @@ -3203,6 +3199,8 @@ payment.select.altcoin=Select or search Altcoin
payment.secret=Secret question
payment.answer=Answer
payment.wallet=Wallet ID
payment.amazon.site=Buy giftcard at
payment.ask=Ask in Trader Chat
payment.uphold.accountId=Username or email or phone no.
payment.moneyBeam.accountId=Email or phone no.
payment.venmo.venmoUserName=Venmo username
Expand Down Expand Up @@ -3313,6 +3311,13 @@ payment.account.revolut.addUserNameInfo={0}\n\
This will not affect your account age signing status.
payment.revolut.addUserNameInfo.headLine=Update Revolut account

payment.amazonGiftCard.upgrade=Amazon gift cards payment method requires the country to be specified.
payment.account.amazonGiftCard.addCountryInfo={0}\n\
Your existing Amazon Gift Card account ({1}) does not have a Country specified.\n\
Please enter your Amazon Gift Card Country to update your account data.\n\
This will not affect your account age status.
payment.amazonGiftCard.upgrade.headLine=Update Amazon Gift Card account

payment.usPostalMoneyOrder.info=Trading using US Postal Money Orders (USPMO) on Bisq requires that you understand the following:\n\
\n\
- BTC buyers must write the BTC Seller’s name in both the Payer and the Payee’s fields & take a high-resolution photo of the USPMO and envelope with proof of tracking before sending.\n\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
package bisq.desktop.components.paymentmethods;

import bisq.desktop.components.InputTextField;
import bisq.desktop.util.FormBuilder;
import bisq.desktop.util.Layout;

import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.locale.Country;
import bisq.core.locale.CountryUtil;
import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.Res;
import bisq.core.locale.TradeCurrency;
Expand All @@ -33,25 +34,41 @@
import bisq.core.util.coin.CoinFormatter;
import bisq.core.util.validation.InputValidator;

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

import javafx.collections.FXCollections;

import javafx.util.StringConverter;

import java.util.HashMap;

import lombok.extern.slf4j.Slf4j;

import static bisq.desktop.util.FormBuilder.addCompactTopLabelTextField;
import static bisq.desktop.util.FormBuilder.addInputTextField;
import static bisq.desktop.util.FormBuilder.addTopLabelTextField;
import static bisq.desktop.util.FormBuilder.*;

@Slf4j
public class AmazonGiftCardForm extends PaymentMethodForm {
private InputTextField accountNrInputTextField;
ComboBox<Country> countryCombo;
private final AmazonGiftCardAccount amazonGiftCardAccount;

public static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountPayload paymentAccountPayload) {
FormBuilder.addCompactTopLabelTextFieldWithCopyIcon(gridPane, ++gridRow, Res.get("payment.email.mobile"),
((AmazonGiftCardAccountPayload) paymentAccountPayload).getEmailOrMobileNr());
AmazonGiftCardAccountPayload amazonGiftCardAccountPayload = (AmazonGiftCardAccountPayload) paymentAccountPayload;

addTopLabelTextFieldWithCopyIcon(gridPane, gridRow, 1, Res.get("payment.amazon.site"),
countryToAmazonSite(amazonGiftCardAccountPayload.getCountryCode()),
Layout.COMPACT_FIRST_ROW_AND_GROUP_DISTANCE);
addCompactTopLabelTextFieldWithCopyIcon(gridPane, ++gridRow, Res.get("payment.email.mobile"),
amazonGiftCardAccountPayload.getEmailOrMobileNr());
String countryText = CountryUtil.getNameAndCode(amazonGiftCardAccountPayload.getCountryCode());
if (countryText.isEmpty()) {
countryText = Res.get("payment.ask");
}
addCompactTopLabelTextFieldWithCopyIcon(gridPane, gridRow, 1,
Res.get("shared.country"),
countryText);
return gridRow;
}

Expand All @@ -66,11 +83,6 @@ public AmazonGiftCardForm(PaymentAccount paymentAccount,
this.amazonGiftCardAccount = (AmazonGiftCardAccount) paymentAccount;
}

public void addTradeCurrency() {
addTradeCurrencyComboBox();
currencyComboBox.setItems(FXCollections.observableArrayList(CurrencyUtil.getAllAmazonGiftCardCurrencies()));
}

@Override
public void addFormForAddAccount() {
gridRowFrom = gridRow + 1;
Expand All @@ -82,13 +94,33 @@ public void addFormForAddAccount() {
updateFromInputs();
});

addTradeCurrency();
countryCombo = addComboBox(gridPane, ++gridRow, Res.get("shared.country"));
countryCombo.setPromptText(Res.get("payment.select.country"));
countryCombo.setItems(FXCollections.observableArrayList(CountryUtil.getAllAmazonGiftCardCountries()));
TextField ccyField = addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("shared.currency"), "").second;
countryCombo.setConverter(new StringConverter<>() {
@Override
public String toString(Country country) {
return country.name + " (" + country.code + ")";
}
@Override
public Country fromString(String s) {
return null;
}
});
countryCombo.setOnAction(e -> {
Country countryCode = countryCombo.getValue();
amazonGiftCardAccount.setCountry(countryCode);
TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(countryCode.code);
paymentAccount.setSingleTradeCurrency(currency);
ccyField.setText(currency.getNameAndCode());
updateFromInputs();
});

addLimitations(false);
addAccountNameTextFieldWithAutoFillToggleButton();
}


@Override
protected void autoFillNameTextField() {
setAccountNameWithString(accountNrInputTextField.getText());
Expand Down Expand Up @@ -121,9 +153,33 @@ private void addFormForAccountNumberDisplayAccount(String accountName,
Res.get("payment.email.mobile"), accountNr).second;
field.setMouseTransparent(false);

addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.country"),
amazonGiftCardAccount.getCountry() != null ? amazonGiftCardAccount.getCountry().name : "");
String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "";
addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("shared.currency"), nameAndCode);

addLimitations(true);
}

private static String countryToAmazonSite(String countryCode) {
HashMap<String, String> mapCountryToSite = new HashMap<>() {{
put("AU", "https://www.amazon.au");
put("CA", "https://www.amazon.ca");
put("FR", "https://www.amazon.fr");
put("DE", "https://www.amazon.de");
put("IT", "https://www.amazon.it");
put("NL", "https://www.amazon.nl");
put("ES", "https://www.amazon.es");
put("UK", "https://www.amazon.co.uk");
put("IN", "https://www.amazon.in");
put("JP", "https://www.amazon.co.jp");
put("SA", "https://www.amazon.sa");
put("SE", "https://www.amazon.se");
put("SG", "https://www.amazon.sg");
put("TR", "https://www.amazon.tr");
put("US", "https://www.amazon.com");
put("", Res.get("payment.ask"));
}};
return mapCountryToSite.get(countryCode);
}
}
Loading

0 comments on commit 31b7292

Please sign in to comment.