Skip to content

Commit

Permalink
Merge pull request #5672 from jmacxx/swift_payment_method
Browse files Browse the repository at this point in the history
Add SWIFT payment method
  • Loading branch information
ripcurlx authored Sep 13, 2021
2 parents e8f417f + 51eca30 commit 90b2f9e
Show file tree
Hide file tree
Showing 16 changed files with 850 additions and 4 deletions.
4 changes: 4 additions & 0 deletions common/src/main/java/bisq/common/util/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -591,4 +591,8 @@ public static String formatDurationAsWords(long durationMillis) {
}
return result;
}

public static String cleanString(String string) {
return string.replaceAll("[\\t\\n\\r]+", " ");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public static PaymentAccount getPaymentAccount(PaymentMethod paymentMethod) {
return new InstantCryptoCurrencyAccount();
case PaymentMethod.CAPITUAL_ID:
return new CapitualAccount();
case PaymentMethod.SWIFT_ID:
return new SwiftAccount();

// Cannot be deleted as it would break old trade history entries
case PaymentMethod.OK_PAY_ID:
Expand Down
54 changes: 54 additions & 0 deletions core/src/main/java/bisq/core/payment/SwiftAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.payment;

import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.FiatCurrency;
import bisq.core.locale.TradeCurrency;
import bisq.core.payment.payload.SwiftAccountPayload;
import bisq.core.payment.payload.PaymentAccountPayload;
import bisq.core.payment.payload.PaymentMethod;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
public final class SwiftAccount extends PaymentAccount {
public SwiftAccount() {
super(PaymentMethod.SWIFT);
}

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

public SwiftAccountPayload getPayload() {
return ((SwiftAccountPayload) this.paymentAccountPayload);
}

public void selectAllTradeCurrencies() {
List<FiatCurrency> currencyCodesSorted = CurrencyUtil.getAllSortedFiatCurrencies().stream()
.sorted(Comparator.comparing(TradeCurrency::getCode))
.collect(Collectors.toList());
tradeCurrencies.addAll(currencyCodesSorted);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
public static final String BLOCK_CHAINS_INSTANT_ID = "BLOCK_CHAINS_INSTANT";
public static final String CASH_BY_MAIL_ID = "CASH_BY_MAIL";
public static final String CAPITUAL_ID = "CAPITUAL";
public static final String SWIFT_ID = "SWIFT";

// Cannot be deleted as it would break old trade history entries
@Deprecated
Expand Down Expand Up @@ -146,6 +147,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
public static PaymentMethod BLOCK_CHAINS_INSTANT;
public static PaymentMethod CASH_BY_MAIL;
public static PaymentMethod CAPITUAL;
public static PaymentMethod SWIFT;

// Cannot be deleted as it would break old trade history entries
@Deprecated
Expand Down Expand Up @@ -200,7 +202,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
PAYSERA = new PaymentMethod(PAYSERA_ID, DAY, DEFAULT_TRADE_LIMIT_HIGH_RISK),
PAXUM = new PaymentMethod(PAXUM_ID, DAY, DEFAULT_TRADE_LIMIT_HIGH_RISK),
CAPITUAL = new PaymentMethod(CAPITUAL_ID, DAY, DEFAULT_TRADE_LIMIT_HIGH_RISK),

SWIFT = new PaymentMethod(SWIFT_ID, 7 * DAY, DEFAULT_TRADE_LIMIT_MID_RISK),

// Japan
JAPAN_BANK = new PaymentMethod(JAPAN_BANK_ID, DAY, DEFAULT_TRADE_LIMIT_LOW_RISK),
Expand Down
184 changes: 184 additions & 0 deletions core/src/main/java/bisq/core/payment/payload/SwiftAccountPayload.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.payment.payload;

import bisq.core.locale.Res;

import com.google.protobuf.Message;

import java.nio.charset.StandardCharsets;

import java.util.HashMap;
import java.util.Map;

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

@EqualsAndHashCode(callSuper = true)
@ToString
@Setter
@Getter
@Slf4j
public final class SwiftAccountPayload extends PaymentAccountPayload {
// payload data elements
private String bankSwiftCode = "";
private String bankCountryCode = "";
private String bankName = "";
private String bankBranch = "";
private String bankAddress = "";
private String beneficiaryName = "";
private String beneficiaryAccountNr = "";
private String beneficiaryAddress = "";
private String beneficiaryCity = "";
private String beneficiaryPhone = "";
private String specialInstructions = "";
private String intermediarySwiftCode = "";
private String intermediaryCountryCode = "";
private String intermediaryName = "";
private String intermediaryBranch = "";
private String intermediaryAddress = "";

// constants
public static final String BANKPOSTFIX = ".bank";
public static final String INTERMEDIARYPOSTFIX = ".intermediary";
public static final String BENEFICIARYPOSTFIX = ".beneficiary";
public static final String SWIFT_CODE = "payment.swift.swiftCode";
public static final String COUNTRY = "payment.swift.country";
public static final String SWIFT_ACCOUNT = "payment.swift.account";
public static final String SNAME = "payment.swift.name";
public static final String BRANCH = "payment.swift.branch";
public static final String ADDRESS = "payment.swift.address";
public static final String PHONE = "payment.swift.phone";

public SwiftAccountPayload(String paymentMethod, String id) {
super(paymentMethod, id);
}

private SwiftAccountPayload(String paymentMethod,
String id,
String bankSwiftCode,
String bankCountryCode,
String bankName,
String bankBranch,
String bankAddress,
String beneficiaryName,
String beneficiaryAccountNr,
String beneficiaryAddress,
String beneficiaryCity,
String beneficiaryPhone,
String specialInstructions,
String intermediarySwiftCode,
String intermediaryCountryCode,
String intermediaryName,
String intermediaryBranch,
String intermediaryAddress,
long maxTradePeriod,
Map<String, String> excludeFromJsonDataMap) {
super(paymentMethod,
id,
maxTradePeriod,
excludeFromJsonDataMap);

this.bankSwiftCode = bankSwiftCode;
this.bankCountryCode = bankCountryCode;
this.bankName = bankName;
this.bankBranch = bankBranch;
this.bankAddress = bankAddress;
this.beneficiaryName = beneficiaryName;
this.beneficiaryAccountNr = beneficiaryAccountNr;
this.beneficiaryAddress = beneficiaryAddress;
this.beneficiaryCity = beneficiaryCity;
this.beneficiaryPhone = beneficiaryPhone;
this.specialInstructions = specialInstructions;
this.intermediarySwiftCode = intermediarySwiftCode;
this.intermediaryCountryCode = intermediaryCountryCode;
this.intermediaryName = intermediaryName;
this.intermediaryBranch = intermediaryBranch;
this.intermediaryAddress = intermediaryAddress;
}

@Override
public Message toProtoMessage() {
return getPaymentAccountPayloadBuilder()
.setSwiftAccountPayload(protobuf.SwiftAccountPayload.newBuilder()
.setBankSwiftCode(bankSwiftCode)
.setBankCountryCode(bankCountryCode)
.setBankName(bankName)
.setBankBranch(bankBranch)
.setBankAddress(bankAddress)
.setBeneficiaryName(beneficiaryName)
.setBeneficiaryAccountNr(beneficiaryAccountNr)
.setBeneficiaryAddress(beneficiaryAddress)
.setBeneficiaryCity(beneficiaryCity)
.setBeneficiaryPhone(beneficiaryPhone)
.setSpecialInstructions(specialInstructions)
.setIntermediarySwiftCode(intermediarySwiftCode)
.setIntermediaryCountryCode(intermediaryCountryCode)
.setIntermediaryName(intermediaryName)
.setIntermediaryBranch(intermediaryBranch)
.setIntermediaryAddress(intermediaryAddress)
)
.build();
}

public static SwiftAccountPayload fromProto(protobuf.PaymentAccountPayload proto) {
protobuf.SwiftAccountPayload x = proto.getSwiftAccountPayload();
return new SwiftAccountPayload(proto.getPaymentMethodId(),
proto.getId(),
x.getBankSwiftCode(),
x.getBankCountryCode(),
x.getBankName(),
x.getBankBranch(),
x.getBankAddress(),
x.getBeneficiaryName(),
x.getBeneficiaryAccountNr(),
x.getBeneficiaryAddress(),
x.getBeneficiaryCity(),
x.getBeneficiaryPhone(),
x.getSpecialInstructions(),
x.getIntermediarySwiftCode(),
x.getIntermediaryCountryCode(),
x.getIntermediaryName(),
x.getIntermediaryBranch(),
x.getIntermediaryAddress(),
proto.getMaxTradePeriod(),
new HashMap<>(proto.getExcludeFromJsonDataMap()));
}

@Override
public String getPaymentDetails() {
return Res.get(paymentMethodId) + " - " + beneficiaryName;
}

@Override
public String getPaymentDetailsForTradePopup() {
return getPaymentDetails();
}

@Override
public byte[] getAgeWitnessInputData() {
return super.getAgeWitnessInputData(beneficiaryAccountNr.getBytes(StandardCharsets.UTF_8));
}

public boolean usesIntermediaryBank() {
return (intermediarySwiftCode != null && intermediarySwiftCode.length() > 0);
}
}
3 changes: 3 additions & 0 deletions core/src/main/java/bisq/core/proto/CoreProtoResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import bisq.core.payment.payload.SepaAccountPayload;
import bisq.core.payment.payload.SepaInstantAccountPayload;
import bisq.core.payment.payload.SpecificBanksAccountPayload;
import bisq.core.payment.payload.SwiftAccountPayload;
import bisq.core.payment.payload.SwishAccountPayload;
import bisq.core.payment.payload.TransferwiseAccountPayload;
import bisq.core.payment.payload.USPostalMoneyOrderAccountPayload;
Expand Down Expand Up @@ -168,6 +169,8 @@ public PaymentAccountPayload fromProto(protobuf.PaymentAccountPayload proto) {
return InstantCryptoCurrencyPayload.fromProto(proto);
case CAPITUAL_ACCOUNT_PAYLOAD:
return CapitualAccountPayload.fromProto(proto);
case SWIFT_ACCOUNT_PAYLOAD:
return SwiftAccountPayload.fromProto(proto);

// Cannot be deleted as it would break old trade history entries
case O_K_PAY_ACCOUNT_PAYLOAD:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ private enum PaymentMethodMapper {
CASH_BY_MAIL,
CAPITUAL,
PAYSERA,
PAXUM
PAXUM,
SWIFT
}

@Getter
Expand Down
50 changes: 50 additions & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,9 @@ portfolio.pending.step2_buyer.refTextWarn=Important: when making the payment, le
# suppress inspection "TrailingSpacesInProperty"
portfolio.pending.step2_buyer.fees=If your bank charges you any fees to make the transfer, you are responsible for paying those fees.
# suppress inspection "TrailingSpacesInProperty"
portfolio.pending.step2_buyer.fees.swift=Make sure to use the SHA (shared fee model) to send the SWIFT payment. \
See more details at [HYPERLINK:https://bisq.wiki/SWIFT#Use_the_correct_fee_option].
# suppress inspection "TrailingSpacesInProperty"
portfolio.pending.step2_buyer.altcoin=Please transfer from your external {0} wallet\n{1} to the BTC seller.\n\n
# suppress inspection "TrailingSpacesInProperty"
portfolio.pending.step2_buyer.cash=Please go to a bank and pay {0} to the BTC seller.\n\n
Expand Down Expand Up @@ -3280,6 +3283,27 @@ payment.secret=Secret question
payment.answer=Answer
payment.wallet=Wallet ID
payment.capitual.cap=CAP Code

# suppress inspection "UnusedProperty"
payment.swift.headline=International SWIFT Wire Transfer
payment.swift.title.bank=Receiving Bank
payment.swift.title.intermediary=Intermediary Bank (click to expand)
payment.swift.country.bank=Receiving Bank Country
payment.swift.country.intermediary=Intermediary Bank Country
payment.swift.swiftCode.bank=Receiving Bank SWIFT Code
payment.swift.swiftCode.intermediary=Intermediary Bank SWIFT Code
payment.swift.name.bank=Receiving Bank name
payment.swift.name.intermediary=Intermediary Bank name
payment.swift.branch.bank=Receiving Bank branch
payment.swift.branch.intermediary=Intermediary Bank branch
payment.swift.address.bank=Receiving Bank address
payment.swift.address.intermediary=Intermediary Bank address
payment.swift.address.beneficiary=Beneficiary address
payment.swift.phone.beneficiary=Beneficiary phone number
payment.swift.account=Account No. (or IBAN)
payment.swift.use.intermediary=Use Intermediary Bank
payment.swift.showPaymentInfo=Show Payment Information...

payment.amazon.site=Buy giftcard at
payment.ask=Ask in Trader Chat
payment.uphold.accountId=Username or email or phone no.
Expand Down Expand Up @@ -3411,6 +3435,28 @@ payment.account.amazonGiftCard.addCountryInfo={0}\n\
This will not affect your account age status.
payment.amazonGiftCard.upgrade.headLine=Update Amazon Gift Card account

payment.swift.info=Carefully review the core guidelines for using SWIFT on Bisq:\n\
\n\
- fill all fields completely and accurately \n\
- buyer must send payment in currency specified by the offer maker \n\
- buyer must use the shared fee model (SHA) \n\
- buyer and seller may incur fees, so they should check their bank's fee schedules beforehand \n\
\n\
SWIFT is more sophisticated than other payment methods, so please take a moment to review full guidance on the wiki [HYPERLINK:https://bisq.wiki/SWIFT].

payment.swift.info.buyer=To buy bitcoin with SWIFT, you must:\n\
\n\
- send payment in the currency specified by the offer maker \n\
- use the shared fee model (SHA) to send payment\n\
\n\
Please review further guidance on the wiki to avoid penalties and ensure smooth trades [HYPERLINK:https://bisq.wiki/SWIFT].

payment.swift.info.seller=SWIFT senders are required to use the shared payment model (SHA) to send payments.\n\
\n\
If you receive a SWIFT payment that does not use SHA, open a mediation ticket.\n\
\n\
Please review further guidance on the wiki to avoid penalties and ensure smooth trades [HYPERLINK:https://bisq.wiki/SWIFT].

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 Expand Up @@ -3581,6 +3627,8 @@ AMAZON_GIFT_CARD=Amazon eGift Card
BLOCK_CHAINS_INSTANT=Altcoins Instant
# suppress inspection "UnusedProperty"
CAPITUAL=Capitual
# suppress inspection "UnusedProperty"
SWIFT=SWIFT International Wire Transfer

# Deprecated: Cannot be deleted as it would break old trade history entries
# suppress inspection "UnusedProperty"
Expand Down Expand Up @@ -3639,6 +3687,8 @@ AMAZON_GIFT_CARD_SHORT=Amazon eGift Card
BLOCK_CHAINS_INSTANT_SHORT=Altcoins Instant
# suppress inspection "UnusedProperty"
CAPITUAL_SHORT=Capitual
# suppress inspection "UnusedProperty"
SWIFT_SHORT=SWIFT

# Deprecated: Cannot be deleted as it would break old trade history entries
# suppress inspection "UnusedProperty"
Expand Down
Loading

0 comments on commit 90b2f9e

Please sign in to comment.