Skip to content

Commit

Permalink
Merge pull request #1127 from namloan/payment_methods
Browse files Browse the repository at this point in the history
Add Interac e-Transfer and Amazon Gift Card payment methods
  • Loading branch information
alvasw authored Aug 14, 2023
2 parents 5a5326f + 0c04a02 commit cdf02f8
Show file tree
Hide file tree
Showing 17 changed files with 351 additions and 3 deletions.
3 changes: 3 additions & 0 deletions account/src/main/java/bisq/account/accounts/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ protected bisq.account.protobuf.Account.Builder getAccountBuilder() {
case CASHBYMAILACCOUNT: {
return CashByMailAccount.fromProto(proto);
}
case INTERACETRANSFERACCOUNT: {
return InteracETransferAccount.fromProto(proto);
}
case MESSAGE_NOT_SET: {
throw new UnresolvableProtobufMessageException(proto);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public static AccountPayload fromProto(bisq.account.protobuf.AccountPayload prot
case CASHBYMAILACCOUNTPAYLOAD: {
return CashByMailAccountPayload.fromProto(proto);
}
case INTERACETRANSFERACCOUNTPAYLOAD: {
return InteracETransferAccountPayload.fromProto(proto);
}
case MESSAGE_NOT_SET: {
throw new UnresolvableProtobufMessageException(proto);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package bisq.account.accounts;

import bisq.account.payment_method.FiatPaymentMethod;
import bisq.account.payment_method.FiatPaymentRail;
import bisq.account.protobuf.Account;
import bisq.common.locale.Country;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

@Getter
@Slf4j
@ToString
@EqualsAndHashCode(callSuper = true)
public final class AmazonGiftCardAccount extends CountryBasedAccount<AmazonGiftCardAccountPayload, FiatPaymentMethod> {

private static final FiatPaymentMethod PAYMENT_METHOD = FiatPaymentMethod.fromPaymentRail(FiatPaymentRail.AMAZON_GIFT_CARD);

public AmazonGiftCardAccount(String accountName, AmazonGiftCardAccountPayload payload, Country country) {
super(accountName, PAYMENT_METHOD, payload, country);
}

@Override
public Account toProto() {
return getAccountBuilder()
.setCountryBasedAccount(getCountryBasedAccountBuilder()
.setAmazonGiftCardAccount(bisq.account.protobuf.AmazonGiftCardAccount.newBuilder()))
.build();
}

public static AmazonGiftCardAccount fromProto(bisq.account.protobuf.Account proto) {
return new AmazonGiftCardAccount(proto.getAccountName(),
AmazonGiftCardAccountPayload.fromProto(proto.getAccountPayload()),
Country.fromProto(proto.getCountryBasedAccount().getCountry()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package bisq.account.accounts;

import bisq.account.protobuf.AccountPayload;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

@Getter
@Slf4j
@ToString
@EqualsAndHashCode(callSuper = true)
public final class AmazonGiftCardAccountPayload extends CountryBasedAccountPayload {

private final String emailOrMobileNr;

public AmazonGiftCardAccountPayload(String id, String paymentMethodName,
String countryCode, String emailOrMobileNr) {
super(id, paymentMethodName, countryCode);
this.emailOrMobileNr = emailOrMobileNr;
}

@Override
public AccountPayload toProto() {
return getAccountPayloadBuilder().setCountryBasedAccountPayload(
getCountryBasedAccountPayloadBuilder()
.setAmazonGiftCardAccountPayload(
bisq.account.protobuf.AmazonGiftCardAccountPayload.newBuilder()
.setEmailOrMobileNr(emailOrMobileNr)
))
.build();
}

public static AmazonGiftCardAccountPayload fromProto(AccountPayload proto) {
bisq.account.protobuf.CountryBasedAccountPayload countryBasedAccountPayload =
proto.getCountryBasedAccountPayload();
bisq.account.protobuf.AmazonGiftCardAccountPayload amazonGiftCardAccountPayload =
countryBasedAccountPayload.getAmazonGiftCardAccountPayload();
return new AmazonGiftCardAccountPayload(
proto.getId(),
proto.getPaymentMethodName(),
countryBasedAccountPayload.getCountryCode(),
amazonGiftCardAccountPayload.getEmailOrMobileNr()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ protected bisq.account.protobuf.CountryBasedAccount.Builder getCountryBasedAccou
case STRIKEACCOUNT: {
return StrikeAccount.fromProto(proto);
}
case AMAZONGIFTCARDACCOUNT: {
return AmazonGiftCardAccount.fromProto(proto);
}
case MESSAGE_NOT_SET: {
throw new UnresolvableProtobufMessageException(proto);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public static CountryBasedAccountPayload fromProto(bisq.account.protobuf.Account
case STRIKEACCOUNTPAYLOAD: {
return StrikeAccountPayload.fromProto(proto);
}
case AMAZONGIFTCARDACCOUNTPAYLOAD: {
return AmazonGiftCardAccountPayload.fromProto(proto);
}
case MESSAGE_NOT_SET: {
throw new UnresolvableProtobufMessageException(proto);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package bisq.account.accounts;

import bisq.account.payment_method.FiatPaymentMethod;
import bisq.account.payment_method.FiatPaymentRail;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

@Getter
@Slf4j
@ToString
@EqualsAndHashCode(callSuper = true)
public final class InteracETransferAccount extends Account<InteracETransferAccountPayload, FiatPaymentMethod> {

private static final FiatPaymentMethod PAYMENT_METHOD = FiatPaymentMethod.fromPaymentRail(FiatPaymentRail.INTERAC_E_TRANSFER);

public InteracETransferAccount(long creationDate, String accountName, InteracETransferAccountPayload accountPayload) {
super(creationDate, accountName, PAYMENT_METHOD, accountPayload);
}

@Override
public bisq.account.protobuf.Account toProto() {
return getAccountBuilder()
.setInteracETransferAccount(
bisq.account.protobuf.InteracETransferAccount.newBuilder()
)
.build();
}

public static InteracETransferAccount fromProto(bisq.account.protobuf.Account proto) {
return new InteracETransferAccount(
proto.getCreationDate(),
proto.getAccountName(),
InteracETransferAccountPayload.fromProto(proto.getAccountPayload())
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package bisq.account.accounts;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

@Getter
@Slf4j
@ToString
@EqualsAndHashCode(callSuper = true)
public final class InteracETransferAccountPayload extends AccountPayload {

private final String email;
private final String holderName;
private final String question;
private final String answer;

public InteracETransferAccountPayload(String id, String paymentMethodName, String email, String holderName, String question, String answer) {
super(id, paymentMethodName);
this.email = email;
this.holderName = holderName;
this.question = question;
this.answer = answer;
}

@Override
public bisq.account.protobuf.AccountPayload toProto() {
return getAccountPayloadBuilder()
.setInteracETransferAccountPayload(
bisq.account.protobuf.InteracETransferAccountPayload.newBuilder()
.setEmail(email)
.setHolderName(holderName)
.setQuestion(question)
.setAnswer(answer)
.build()
)
.build();
}

public static InteracETransferAccountPayload fromProto(bisq.account.protobuf.AccountPayload proto) {
var interactETransferAccountPayload = proto.getInteracETransferAccountPayload();
return new InteracETransferAccountPayload(
proto.getId(),
proto.getPaymentMethodName(),
interactETransferAccountPayload.getEmail(),
interactETransferAccountPayload.getHolderName(),
interactETransferAccountPayload.getQuestion(),
interactETransferAccountPayload.getAnswer()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ public enum FiatPaymentRail implements PaymentRail {
PAY_ID(List.of("AU"), List.of("AUD")),
US_POSTAL_MONEY_ORDER(List.of("US"), List.of("USD")),
CASH_BY_MAIL(),
STRIKE(List.of("US", "SV"), List.of("USD"));
STRIKE(List.of("US", "SV"), List.of("USD")),
INTERAC_E_TRANSFER(new ArrayList<>(), List.of("CAD")),
AMAZON_GIFT_CARD(
new ArrayList<>(),
List.of("AUD", "CAD", "EUR", "GBP", "INR", "JPY", "SAR", "SEK", "SGD", "TRY", "USD"));

@Getter
@EqualsAndHashCode.Exclude
Expand Down Expand Up @@ -124,7 +128,6 @@ public boolean supportsCurrency(String currencyCode) {
SEPA_INSTANT=SEPA Instant Payments
SWISH=Swish
CHASE_QUICK_PAY=Chase QuickPay
INTERAC_E_TRANSFER=Interac e-Transfer
HAL_CASH=HalCash
PROMPT_PAY=PromptPay
ADVANCED_CASH=Advanced Cash
Expand All @@ -138,7 +141,6 @@ public boolean supportsCurrency(String currencyCode) {
PAYTM=India/PayTM
NEQUI=Nequi
BIZUM=Bizum
AMAZON_GIFT_CARD=Amazon eGift Card
CAPITUAL=Capitual
CELPAY=CelPay
MONESE=Monese
Expand Down
21 changes: 21 additions & 0 deletions account/src/main/proto/account.proto
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ message AccountPayload {
PayIDAccountPayload payIDAccountPayload = 24;
USPostalMoneyOrderAccountPayload usPostalMoneyOrderAccountPayload = 25;
CashByMailAccountPayload cashByMailAccountPayload = 26;
InteracETransferAccountPayload interacETransferAccountPayload = 27;
}
}
message UserDefinedFiatAccountPayload {
Expand All @@ -92,6 +93,7 @@ message CountryBasedAccountPayload {
F2FAccountPayload f2fAccountPayload = 11;
PixAccountPayload pixAccountPayload = 12;
StrikeAccountPayload strikeAccountPayload = 13;
AmazonGiftCardAccountPayload amazonGiftCardAccountPayload = 14;
}
}
message SepaAccountPayload {
Expand Down Expand Up @@ -163,6 +165,17 @@ message StrikeAccountPayload {
string holderName = 1;
}

message InteracETransferAccountPayload {
string email = 1;
string holder_name = 2;
string question = 3;
string answer = 4;
}

message AmazonGiftCardAccountPayload {
string email_or_mobile_nr = 1;
}

// Account
message Account {
sint64 creationDate = 1;
Expand All @@ -180,6 +193,7 @@ message Account {
PayIDAccount payIDAccount = 24;
USPostalMoneyOrderAccount usPostalMoneyOrderAccount = 25;
CashByMailAccount cashByMailAccount = 26;
InteracETransferAccount interacETransferAccount = 27;
}
}

Expand All @@ -195,6 +209,7 @@ message CountryBasedAccount {
F2FAccount f2fAccount = 21;
PixAccount pixAccount = 22;
StrikeAccount strikeAccount = 23;
AmazonGiftCardAccount amazonGiftCardAccount = 24;
}
}
message SepaAccount {
Expand Down Expand Up @@ -237,6 +252,12 @@ message CashByMailAccount {
message StrikeAccount {
}

message InteracETransferAccount {
}

message AmazonGiftCardAccount {
}

message AccountStore {
map<string, Account> accountByName = 1;
optional Account selectedAccount = 2;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package bisq.account.accounts;

import bisq.account.protobuf.Account;
import bisq.account.protobuf.AccountPayload;
import bisq.account.protobuf.AmazonGiftCardAccount;
import bisq.account.protobuf.AmazonGiftCardAccountPayload;
import bisq.account.protobuf.CountryBasedAccount;
import bisq.account.protobuf.CountryBasedAccountPayload;
import bisq.account.protobuf.FiatPaymentMethod;
import bisq.account.protobuf.PaymentMethod;
import bisq.common.protobuf.Country;
import bisq.common.protobuf.Region;
import org.junit.jupiter.api.Test;

import static java.lang.System.currentTimeMillis;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.data.Offset.offset;

class AmazonGiftCardAccountTest {

private static final Account PROTO = Account.newBuilder()
.setAccountName("accountName")
.setCreationDate(123)
.setPaymentMethod(PaymentMethod.newBuilder()
.setName("AMAZON_GIFT_CARD")
.setFiatPaymentMethod(FiatPaymentMethod.newBuilder().build())
.build())
.setAccountPayload(AccountPayload.newBuilder()
.setId("id")
.setPaymentMethodName("AMAZON_GIFT_CARD")
.setCountryBasedAccountPayload(CountryBasedAccountPayload.newBuilder()
.setCountryCode("countryCode")
.setAmazonGiftCardAccountPayload(AmazonGiftCardAccountPayload.newBuilder()
.setEmailOrMobileNr("emailOrMobileNr")
))
)
.setCountryBasedAccount(CountryBasedAccount.newBuilder()
.setCountry(Country.newBuilder()
.setCode("countryCode")
.setName("countryName")
.setRegion(Region.newBuilder()
.setCode("regionCode")
.setName("regionName")))
.setAmazonGiftCardAccount(AmazonGiftCardAccount.newBuilder())
)
.build();

private static final bisq.account.accounts.AmazonGiftCardAccount ACCOUNT =
new bisq.account.accounts.AmazonGiftCardAccount(
"accountName",
new bisq.account.accounts.AmazonGiftCardAccountPayload("id", "AMAZON_GIFT_CARD", "countryCode", "emailOrMobileNr"),
new bisq.common.locale.Country(
"countryCode",
"countryName",
new bisq.common.locale.Region("regionCode", "regionName")));

@Test
void toProto() {
var result = ACCOUNT.toProto();
assertThat(result)
.usingRecursiveComparison()
.ignoringFields("accountPayload_.memoizedHashCode", "memoizedHashCode", "creationDate_")
.isEqualTo(PROTO);
assertThat(result.getCreationDate()).isCloseTo(currentTimeMillis(), offset(1000L));
}

@Test
void fromProto() {
var result = bisq.account.accounts.AmazonGiftCardAccount.fromProto(PROTO);
assertThat(result)
.usingRecursiveComparison()
.ignoringFields("creationDate")
.isEqualTo(ACCOUNT);
assertThat(result.getCreationDate()).isCloseTo(System.currentTimeMillis(), offset(1000L));
}
}
Loading

0 comments on commit cdf02f8

Please sign in to comment.