Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pix and Faster Payments payment methods #1115

Merged
merged 2 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -83,6 +83,9 @@ protected bisq.account.protobuf.Account.Builder getAccountBuilder() {
case COUNTRYBASEDACCOUNT: {
return CountryBasedAccount.fromProto(proto);
}
case FASTERPAYMENTSACCOUNT: {
return FasterPaymentsAccount.fromProto(proto);
}
case MESSAGE_NOT_SET: {
throw new UnresolvableProtobufMessageException(proto);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public static AccountPayload fromProto(bisq.account.protobuf.AccountPayload prot
case USERDEFINEDFIATACCOUNTPAYLOAD: {
return UserDefinedFiatAccountPayload.fromProto(proto);
}
case FASTERPAYMENTSACCOUNTPAYLOAD: {
return FasterPaymentsAccountPayload.fromProto(proto);
}
case MESSAGE_NOT_SET: {
throw new UnresolvableProtobufMessageException(proto);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ protected bisq.account.protobuf.CountryBasedAccount.Builder getCountryBasedAccou
case F2FACCOUNT: {
return F2FAccount.fromProto(proto);
}
case PIXACCOUNT: {
return PixAccount.fromProto(proto);
}
case MESSAGE_NOT_SET: {
throw new UnresolvableProtobufMessageException(proto);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public static CountryBasedAccountPayload fromProto(bisq.account.protobuf.Account
case F2FACCOUNTPAYLOAD: {
return F2FAccountPayload.fromProto(proto);
}
case PIXACCOUNTPAYLOAD: {
return PixAccountPayload.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,36 @@
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 FasterPaymentsAccount extends Account<FasterPaymentsAccountPayload, FiatPaymentMethod> {

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


public FasterPaymentsAccount(long creationDate, String accountName, FasterPaymentsAccountPayload accountPayload) {
super(creationDate, accountName, PAYMENT_METHOD, accountPayload);
}

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

public static FasterPaymentsAccount fromProto(bisq.account.protobuf.Account proto) {
return new FasterPaymentsAccount(
proto.getCreationDate(),
proto.getAccountName(),
FasterPaymentsAccountPayload.fromProto(proto.getAccountPayload()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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 FasterPaymentsAccountPayload extends AccountPayload {

private final String sortCode;
private final String accountNr;

public FasterPaymentsAccountPayload(String id, String paymentMethodName, String sortCode, String accountNr) {
super(id, paymentMethodName);
this.sortCode = sortCode;
this.accountNr = accountNr;
}

@Override
public bisq.account.protobuf.AccountPayload toProto() {
return getAccountPayloadBuilder()
.setFasterPaymentsAccountPayload(bisq.account.protobuf.FasterPaymentsAccountPayload.newBuilder()
.setSortCode(sortCode)
.setAccountNr(accountNr))
.build();
}

public static FasterPaymentsAccountPayload fromProto(bisq.account.protobuf.AccountPayload account) {
var fasterPaymentsPayload = account.getFasterPaymentsAccountPayload();
return new FasterPaymentsAccountPayload(
account.getId(),
account.getPaymentMethodName(),
fasterPaymentsPayload.getSortCode(),
fasterPaymentsPayload.getAccountNr());
}
}
37 changes: 37 additions & 0 deletions account/src/main/java/bisq/account/accounts/PixAccount.java
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 PixAccount extends CountryBasedAccount<PixAccountPayload, FiatPaymentMethod> {

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

public PixAccount(String accountName, PixAccountPayload payload, Country country) {
super(accountName, PAYMENT_METHOD, payload, country);
}

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

public static PixAccount fromProto(bisq.account.protobuf.Account proto) {
return new PixAccount(proto.getAccountName(),
PixAccountPayload.fromProto(proto.getAccountPayload()),
Country.fromProto(proto.getCountryBasedAccount().getCountry()));
}
}
41 changes: 41 additions & 0 deletions account/src/main/java/bisq/account/accounts/PixAccountPayload.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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 PixAccountPayload extends CountryBasedAccountPayload {

private final String pixKey;

public PixAccountPayload(String id, String paymentMethodName, String countryCode, String pixKey) {
super(id, paymentMethodName, countryCode);
this.pixKey = pixKey;
}

@Override
public AccountPayload toProto() {
return getAccountPayloadBuilder().setCountryBasedAccountPayload(
getCountryBasedAccountPayloadBuilder().setPixAccountPayload(
bisq.account.protobuf.PixAccountPayload.newBuilder()
.setPixKey(pixKey)))
.build();
}

public static PixAccountPayload fromProto(AccountPayload proto) {
bisq.account.protobuf.CountryBasedAccountPayload countryBasedAccountPayload = proto.getCountryBasedAccountPayload();
bisq.account.protobuf.PixAccountPayload pixAccountPayload = countryBasedAccountPayload.getPixAccountPayload();
return new PixAccountPayload(
proto.getId(),
proto.getPaymentMethodName(),
countryBasedAccountPayload.getCountryCode(),
pixAccountPayload.getPixKey()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
import lombok.Getter;

import javax.annotation.Nullable;
import java.util.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
Expand All @@ -42,7 +46,9 @@ public enum FiatPaymentRail implements PaymentRail {
NATIONAL_BANK(new ArrayList<>(), new ArrayList<>()),
SWIFT(),
F2F(),
ACH_TRANSFER(List.of("US"), List.of("USD"));
ACH_TRANSFER(List.of("US"), List.of("USD")),
PIX(List.of("BR"), List.of("BRL")),
FASTER_PAYMENTS(List.of("GB"), List.of("GBP"));

@Getter
@EqualsAndHashCode.Exclude
Expand Down Expand Up @@ -119,7 +125,6 @@ public boolean supportsCurrency(String currencyCode) {
WECHAT_PAY=WeChat Pay
SEPA=SEPA
SEPA_INSTANT=SEPA Instant Payments
FASTER_PAYMENTS=Faster Payments
SWISH=Swish
ZELLE=Zelle
CHASE_QUICK_PAY=Chase QuickPay
Expand All @@ -138,7 +143,6 @@ public boolean supportsCurrency(String currencyCode) {
PAYTM=India/PayTM
NEQUI=Nequi
BIZUM=Bizum
PIX=Pix
AMAZON_GIFT_CARD=Amazon eGift Card
CAPITUAL=Capitual
CELPAY=CelPay
Expand Down
18 changes: 18 additions & 0 deletions account/src/main/proto/account.proto
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ message AccountPayload {
UserDefinedFiatAccountPayload userDefinedFiatAccountPayload = 20;
RevolutAccountPayload RevolutAccountPayload = 21;
CountryBasedAccountPayload countryBasedAccountPayload = 22;
FasterPaymentsAccountPayload fasterPaymentsAccountPayload = 23;
}
}
message UserDefinedFiatAccountPayload {
Expand All @@ -86,6 +87,7 @@ message CountryBasedAccountPayload {
BankAccountPayload bankAccountPayload = 2;
SepaAccountPayload sepaAccountPayload = 10;
F2FAccountPayload f2fAccountPayload = 11;
PixAccountPayload pixAccountPayload = 12;
}
}
message SepaAccountPayload {
Expand Down Expand Up @@ -128,6 +130,14 @@ message ZelleAccountPayload {
string emailOrMobileNr = 2;
}

message PixAccountPayload {
string pix_key = 1;
}

message FasterPaymentsAccountPayload {
string sort_code = 1;
string account_nr = 2;
}

// Account
message Account {
Expand All @@ -142,6 +152,7 @@ message Account {
UserDefinedFiatAccount userDefinedFiatAccount = 20;
RevolutAccount revolutAccount = 21;
CountryBasedAccount countryBasedAccount = 22;
FasterPaymentsAccount fasterPaymentsAccount = 23;
}
}

Expand All @@ -155,6 +166,7 @@ message CountryBasedAccount {
BankAccount bankAccount = 19;
SepaAccount sepaAccount = 20;
F2FAccount f2fAccount = 21;
PixAccount pixAccount = 22;
}
}
message SepaAccount {
Expand All @@ -179,6 +191,12 @@ message ZelleAccount {
message NationalBankAccount {
}

message PixAccount {
}

message FasterPaymentsAccount {
}

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,53 @@
package bisq.account.accounts;

import bisq.account.protobuf.Account;
import bisq.account.protobuf.AccountPayload;
import bisq.account.protobuf.FasterPaymentsAccount;
import bisq.account.protobuf.FasterPaymentsAccountPayload;
import bisq.account.protobuf.FiatPaymentMethod;
import bisq.account.protobuf.PaymentMethod;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class FasterPaymentsAccountTest {

private static final bisq.account.protobuf.Account PROTO = Account.newBuilder()
.setAccountName("accountName")
.setCreationDate(123)
.setPaymentMethod(
PaymentMethod.newBuilder()
.setName("FASTER_PAYMENTS")
.setFiatPaymentMethod(
FiatPaymentMethod.newBuilder()))
.setAccountPayload(AccountPayload.newBuilder()
.setId("id")
.setPaymentMethodName("FASTER_PAYMENTS")
.setFasterPaymentsAccountPayload(FasterPaymentsAccountPayload.newBuilder()
.setSortCode("sortCode")
.setAccountNr("accountNr")))
.setFasterPaymentsAccount(FasterPaymentsAccount.newBuilder())
.build();

private static final bisq.account.accounts.FasterPaymentsAccount ACCOUNT = new bisq.account.accounts.FasterPaymentsAccount(
123,
"accountName",
new bisq.account.accounts.FasterPaymentsAccountPayload("id", "FASTER_PAYMENTS", "sortCode", "accountNr")
);

@Test
void toProto() {
var result = ACCOUNT.toProto();
assertThat(result)
.usingRecursiveComparison()
.isEqualTo(PROTO);
}

@Test
void fromProto() {
var result = bisq.account.accounts.FasterPaymentsAccount.fromProto(PROTO);
assertThat(result)
.usingRecursiveComparison()
.isEqualTo(ACCOUNT);
}
}
Loading