Skip to content

Commit

Permalink
Polish WeChat payment method support
Browse files Browse the repository at this point in the history
 - Remove dependency on bisq-common from build.gradle
 - Use camel case spelling of 'WeChat' consistently
 - Organize imports with common layout (bisq-network/style#2)
  • Loading branch information
cbeams committed Apr 10, 2018
1 parent 599d8fd commit 4a7afa1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 27 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ repositories {

dependencies {
compile 'network.bisq:bisq-p2p:-SNAPSHOT'
compile 'network.bisq:bisq-common:-SNAPSHOT'
compile 'net.sf.jopt-simple:jopt-simple:5.0.3'
compile('network.bisq.btcd-cli4j:btcd-cli4j-core:29f99be') {
exclude(module: 'slf4j-api')
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/bisq/core/payment/PaymentAccountFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static PaymentAccount getPaymentAccount(PaymentMethod paymentMethod) {
case PaymentMethod.ALI_PAY_ID:
return new AliPayAccount();
case PaymentMethod.WECHAT_PAY_ID:
return new WechatPayAccount();
return new WeChatPayAccount();
case PaymentMethod.SWISH_ID:
return new SwishAccount();
case PaymentMethod.CLEAR_X_CHANGE_ID:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,28 @@
import bisq.core.locale.FiatCurrency;
import bisq.core.payment.payload.PaymentAccountPayload;
import bisq.core.payment.payload.PaymentMethod;
import bisq.core.payment.payload.WechatPayAccountPayload;
import bisq.core.payment.payload.WeChatPayAccountPayload;

import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
public final class WechatPayAccount extends PaymentAccount {
public WechatPayAccount() {
public final class WeChatPayAccount extends PaymentAccount {

public WeChatPayAccount() {
super(PaymentMethod.WECHAT_PAY);
setSingleTradeCurrency(new FiatCurrency("CNY"));
}

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

public void setAccountNr(String accountNr) {
((WechatPayAccountPayload) paymentAccountPayload).setAccountNr(accountNr);
((WeChatPayAccountPayload) paymentAccountPayload).setAccountNr(accountNr);
}

public String getAccountNr() {
return ((WechatPayAccountPayload) paymentAccountPayload).getAccountNr();
return ((WeChatPayAccountPayload) paymentAccountPayload).getAccountNr();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,32 @@

package bisq.core.payment.payload;

import com.google.protobuf.Message;
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 org.springframework.util.CollectionUtils;

import javax.annotation.Nullable;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;

@EqualsAndHashCode(callSuper = true)
@Getter
@Setter
@ToString
public final class WechatPayAccountPayload extends PaymentAccountPayload {
public final class WeChatPayAccountPayload extends PaymentAccountPayload {
private String accountNr = "";

public WechatPayAccountPayload(String paymentMethod, String id) {
public WeChatPayAccountPayload(String paymentMethod, String id) {
super(paymentMethod, id);
}

Expand All @@ -46,7 +51,7 @@ public WechatPayAccountPayload(String paymentMethod, String id) {
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////

private WechatPayAccountPayload(String paymentMethod,
private WeChatPayAccountPayload(String paymentMethod,
String id,
String accountNr,
long maxTradePeriod,
Expand All @@ -61,15 +66,15 @@ private WechatPayAccountPayload(String paymentMethod,
@Override
public Message toProtoMessage() {
return getPaymentAccountPayloadBuilder()
.setWechatPayAccountPayload(PB.WechatPayAccountPayload.newBuilder()
.setWeChatPayAccountPayload(PB.WeChatPayAccountPayload.newBuilder()
.setAccountNr(accountNr))
.build();
}

public static WechatPayAccountPayload fromProto(PB.PaymentAccountPayload proto) {
return new WechatPayAccountPayload(proto.getPaymentMethodId(),
public static WeChatPayAccountPayload fromProto(PB.PaymentAccountPayload proto) {
return new WeChatPayAccountPayload(proto.getPaymentMethodId(),
proto.getId(),
proto.getWechatPayAccountPayload().getAccountNr(),
proto.getWeChatPayAccountPayload().getAccountNr(),
proto.getMaxTradePeriod(),
CollectionUtils.isEmpty(proto.getExcludeFromJsonDataMap()) ? null : new HashMap<>(proto.getExcludeFromJsonDataMap()));
}
Expand All @@ -81,7 +86,7 @@ public static WechatPayAccountPayload fromProto(PB.PaymentAccountPayload proto)

@Override
public String getPaymentDetails() {
return "WechatPay - Account no.: " + accountNr;
return "WeChat Pay - Account no.: " + accountNr;
}

@Override
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/bisq/core/proto/CoreProtoResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

package bisq.core.proto;

import bisq.common.proto.ProtoResolver;
import bisq.common.proto.ProtobufferException;
import bisq.common.proto.persistable.PersistableEnvelope;
import bisq.core.payment.AccountAgeWitness;
import bisq.core.payment.payload.AliPayAccountPayload;
import bisq.core.payment.payload.CashAppAccountPayload;
Expand All @@ -44,10 +41,16 @@
import bisq.core.payment.payload.USPostalMoneyOrderAccountPayload;
import bisq.core.payment.payload.UpholdAccountPayload;
import bisq.core.payment.payload.VenmoAccountPayload;
import bisq.core.payment.payload.WechatPayAccountPayload;
import bisq.core.payment.payload.WeChatPayAccountPayload;
import bisq.core.payment.payload.WesternUnionAccountPayload;
import bisq.core.trade.statistics.TradeStatistics2;

import bisq.common.proto.ProtoResolver;
import bisq.common.proto.ProtobufferException;
import bisq.common.proto.persistable.PersistableEnvelope;

import io.bisq.generated.protobuffer.PB;

import lombok.extern.slf4j.Slf4j;

@Slf4j
Expand All @@ -59,8 +62,8 @@ public PaymentAccountPayload fromProto(PB.PaymentAccountPayload proto) {
switch (messageCase) {
case ALI_PAY_ACCOUNT_PAYLOAD:
return AliPayAccountPayload.fromProto(proto);
case WECHAT_PAY_ACCOUNT_PAYLOAD:
return WechatPayAccountPayload.fromProto(proto);
case WE_CHAT_PAY_ACCOUNT_PAYLOAD:
return WeChatPayAccountPayload.fromProto(proto);
case CHASE_QUICK_PAY_ACCOUNT_PAYLOAD:
return ChaseQuickPayAccountPayload.fromProto(proto);
case CLEAR_XCHANGE_ACCOUNT_PAYLOAD:
Expand Down

0 comments on commit 4a7afa1

Please sign in to comment.