-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1127 from namloan/payment_methods
Add Interac e-Transfer and Amazon Gift Card payment methods
- Loading branch information
Showing
17 changed files
with
351 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
account/src/main/java/bisq/account/accounts/AmazonGiftCardAccount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
account/src/main/java/bisq/account/accounts/AmazonGiftCardAccountPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
account/src/main/java/bisq/account/accounts/InteracETransferAccount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
account/src/main/java/bisq/account/accounts/InteracETransferAccountPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
account/src/test/java/bisq/account/accounts/AmazonGiftCardAccountTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
Oops, something went wrong.