Added support for payment processors and BitcoinPay.com payment processor

This commit is contained in:
b00lean 2014-09-09 16:37:47 +02:00
parent 70d9c9a1f6
commit 8214121450
16 changed files with 512 additions and 1 deletions

View File

@ -46,6 +46,15 @@ public interface IExtension {
*/
public IExchange createExchange(String exchangeLogin);
/**
* This method is used for creating implementation of payment processor
* @param paymentProcessorLogin
* @return
*
* @see com.generalbytes.batm.server.extensions.IPaymentProcessor
*/
public IPaymentProcessor createPaymentProcessor(String paymentProcessorLogin);
/**
* This method is used for creating implementation of coin price source
* @param sourceLogin

View File

@ -0,0 +1,50 @@
/*************************************************************************************
* Copyright (C) 2014 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
* Foundation and appearing in the file GPL2.TXT included in the packaging of
* this file. Please note that GPL2 Section 2[b] requires that all works based
* on this software must also be made publicly available under the terms of
* the GPL2 ("Copyleft").
*
* Contact information
* -------------------
*
* GENERAL BYTES s.r.o.
* Web : http://www.generalbytes.com
*
************************************************************************************/
package com.generalbytes.batm.server.extensions;
import java.math.BigDecimal;
import java.util.Set;
/**
* Classes implementing this interface are used by the server to obtain crypto address and crypto price from Payment Processor such as BitcoinPay.com based on fiat amount.
*/
public interface IPaymentProcessor {
/**
* Returns Response containing details for crypto payment
* @param amount - fiat amount
* @param currency - fiat currency
* @param settledCurrency - in which currency you want to have payment settled
* @param reference - reference such as order number
* @return
*/
public IPaymentProcessorPaymentResponse requestPayment(BigDecimal amount, String currency, String settledCurrency, String reference);
public IPaymentProcessorPaymentStatus getPaymentStatus(String paymentId);
/**
* This method returns list of supported crypto currencies
* @return
*/
public Set<String> getCryptoCurrencies();
/**
* This method returns list of supported fiat currencies
* @return
*/
public Set<String> getFiatCurrencies();
}

View File

@ -0,0 +1,33 @@
/*************************************************************************************
* Copyright (C) 2014 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
* Foundation and appearing in the file GPL2.TXT included in the packaging of
* this file. Please note that GPL2 Section 2[b] requires that all works based
* on this software must also be made publicly available under the terms of
* the GPL2 ("Copyleft").
*
* Contact information
* -------------------
*
* GENERAL BYTES s.r.o.
* Web : http://www.generalbytes.com
*
************************************************************************************/
package com.generalbytes.batm.server.extensions;
import java.math.BigDecimal;
public interface IPaymentProcessorPaymentResponse {
public String getCryptoAddress();
public BigDecimal getCryptoAmount();
public String getCryptoCurrency();
public BigDecimal getFiatAmount();
public String getFiatCurrency();
public String getId();
public String getReference();
}

View File

@ -0,0 +1,29 @@
/*************************************************************************************
* Copyright (C) 2014 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
* Foundation and appearing in the file GPL2.TXT included in the packaging of
* this file. Please note that GPL2 Section 2[b] requires that all works based
* on this software must also be made publicly available under the terms of
* the GPL2 ("Copyleft").
*
* Contact information
* -------------------
*
* GENERAL BYTES s.r.o.
* Web : http://www.generalbytes.com
*
************************************************************************************/
package com.generalbytes.batm.server.extensions;
public interface IPaymentProcessorPaymentStatus {
public static final int STATUS_PENDING = 0;
public static final int STATUS_RECEIVED = 1;
public static final int STATUS_INSUFFICIENT_AMOUNT = 2;
public static final int STATUS_INVALID = 3;
public static final int STATUS_TIMEOUT = 4;
public static final int STATUS_CONFIRMED = 5;
public int getStatus();
}

View File

@ -17,6 +17,10 @@
<param name="price" />
<cryptocurrency>BTC</cryptocurrency>
</ratesource>
<paymentprocessor prefix="bitcoinpay" name="BitcoinPay.com" >
<param name="apikey" />
<cryptocurrency>BTC</cryptocurrency>
</paymentprocessor>
<cryptologo cryptocurrency="BTC" file="btc.png"/>
</extension>
<extension class="com.generalbytes.batm.server.extensions.extra.dogecoin.DogecoinExtension">
@ -114,7 +118,7 @@
<param name="price" />
<cryptocurrency>NLG</cryptocurrency>
</ratesource>
<ratesource prefix="guldencoincom" name ="Guldencoin.com" >
<ratesource prefix="guldencoincom" name="Guldencoin.com" >
<cryptocurrency>NLG</cryptocurrency>
</ratesource>
<cryptologo cryptocurrency="NLG" file="nlg.png"/>

View File

@ -18,6 +18,7 @@
package com.generalbytes.batm.server.extensions.extra.bitcoin;
import com.generalbytes.batm.server.extensions.*;
import com.generalbytes.batm.server.extensions.extra.bitcoin.paymentprocessors.bitcoinpay.BitcoinPayPP;
import com.generalbytes.batm.server.extensions.extra.bitcoin.sources.BitcoinAverageRateSource;
import com.generalbytes.batm.server.extensions.extra.bitcoin.sources.FixPriceRateSource;
import com.generalbytes.batm.server.extensions.extra.bitcoin.wallets.bitcoind.BATMBitcoindRPCWallet;
@ -37,6 +38,21 @@ public class BitcoinExtension implements IExtension{
return null; //no BTC exchange available in open source version so far (Bitstamp is in built-in extension)
}
@Override
public IPaymentProcessor createPaymentProcessor(String paymentProcessorLogin) {
if (paymentProcessorLogin !=null && !paymentProcessorLogin.trim().isEmpty()) {
StringTokenizer st = new StringTokenizer(paymentProcessorLogin,":");
String processorType = st.nextToken();
if ("bitcoinpay".equalsIgnoreCase(processorType)) { //bitcoinpay:msciu823jes
if (st.hasMoreTokens()) {
String apiKey = st.nextToken();
return new BitcoinPayPP(apiKey);
}
}
}
return null;
}
@Override
public IWallet createWallet(String walletLogin) {
if (walletLogin !=null && !walletLogin.trim().isEmpty()) {

View File

@ -0,0 +1,185 @@
/*************************************************************************************
* Copyright (C) 2014 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
* Foundation and appearing in the file GPL2.TXT included in the packaging of
* this file. Please note that GPL2 Section 2[b] requires that all works based
* on this software must also be made publicly available under the terms of
* the GPL2 ("Copyleft").
*
* Contact information
* -------------------
*
* GENERAL BYTES s.r.o.
* Web : http://www.generalbytes.com
*
************************************************************************************/
package com.generalbytes.batm.server.extensions.extra.bitcoin.paymentprocessors.bitcoinpay;
import com.generalbytes.batm.server.extensions.ICurrencies;
import com.generalbytes.batm.server.extensions.IPaymentProcessor;
import com.generalbytes.batm.server.extensions.IPaymentProcessorPaymentResponse;
import com.generalbytes.batm.server.extensions.IPaymentProcessorPaymentStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import si.mazi.rescu.RestProxyFactory;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;
public class BitcoinPayPP implements IPaymentProcessor{
private static final Logger log = LoggerFactory.getLogger(BitcoinPayPP.class);
private String apiKey;
private IBitcoinPay api;
public BitcoinPayPP(String apiKey) {
this.apiKey = apiKey;
api = RestProxyFactory.createProxy(IBitcoinPay.class, "https://www.bitcoinpay.com/");
}
@Override
public IPaymentProcessorPaymentResponse requestPayment(BigDecimal amount, String currency, String settledCurrency, String reference) {
if (reference == null) {
reference ="Empty";
}
BitcoinPayPaymentResponseDTO r = api.createNewPaymentRequest("Token " + apiKey, new BitcoinPayPaymentRequestRequestDTO(currency, amount, settledCurrency, reference));
if (r != null) {
return new BitcoinPayPPResponse(r.getData().address,r.getData().paid_amount,r.getData().paid_currency,r.getData().settled_amount,r.getData().settled_currency,r.getData().payment_id,r.getData().reference);
}else{
log.error("Payment request call to Payment Processor failed.");
return null;
}
}
@Override
public IPaymentProcessorPaymentStatus getPaymentStatus(String paymentId) {
if (paymentId != null) {
BitcoinPayPaymentResponseDTO s = api.getPaymentStatus("Token " + apiKey, paymentId);
if (s == null) {
log.error("Payment status call to Payment Processor failed.");
}else{
String statusString = s.getData().status;
int statusInt = IPaymentProcessorPaymentStatus.STATUS_INVALID;
if ("pending".equalsIgnoreCase(statusString)) {
statusInt = IPaymentProcessorPaymentStatus.STATUS_PENDING;
}else if ("received".equalsIgnoreCase(statusString)) {
statusInt = IPaymentProcessorPaymentStatus.STATUS_RECEIVED;
}else if ("insufficient_amount".equalsIgnoreCase(statusString)) {
statusInt = IPaymentProcessorPaymentStatus.STATUS_INSUFFICIENT_AMOUNT;
}else if ("invalid".equalsIgnoreCase(statusString)) {
statusInt = IPaymentProcessorPaymentStatus.STATUS_INVALID;
}else if ("timeout".equalsIgnoreCase(statusString)) {
statusInt = IPaymentProcessorPaymentStatus.STATUS_TIMEOUT;
}else if ("confirmed".equalsIgnoreCase(statusString)) {
statusInt = IPaymentProcessorPaymentStatus.STATUS_CONFIRMED;
}
return new BitcoinPayPPStatus(statusInt);
}
}else{
log.error("Invalid payment id");
}
return null;
}
class BitcoinPayPPStatus implements IPaymentProcessorPaymentStatus {
private int status;
BitcoinPayPPStatus(int status) {
this.status = status;
}
public int getStatus() {
return status;
}
@Override
public String toString() {
return "BitcoinPayPPStatus{" +
"status=" + status +
'}';
}
}
class BitcoinPayPPResponse implements IPaymentProcessorPaymentResponse {
private String cryptoAddress;
private BigDecimal cryptoAmount;
private String cryptoCurrency;
private BigDecimal fiatAmount;
private String fiatCurrency;
private String id;
private String reference;
BitcoinPayPPResponse(String cryptoAddress, BigDecimal cryptoAmount, String cryptoCurrency, BigDecimal fiatAmount, String fiatCurrency, String id, String reference) {
this.cryptoAddress = cryptoAddress;
this.cryptoAmount = cryptoAmount;
this.cryptoCurrency = cryptoCurrency;
this.fiatAmount = fiatAmount;
this.fiatCurrency = fiatCurrency;
this.id = id;
this.reference = reference;
}
public String getCryptoAddress() {
return cryptoAddress;
}
public BigDecimal getCryptoAmount() {
return cryptoAmount;
}
public String getCryptoCurrency() {
return cryptoCurrency;
}
public BigDecimal getFiatAmount() {
return fiatAmount;
}
public String getFiatCurrency() {
return fiatCurrency;
}
public String getId() {
return id;
}
public String getReference() {
return reference;
}
@Override
public String toString() {
return "BitcoinPayPPResponse{" +
"cryptoAddress='" + cryptoAddress + '\'' +
", cryptoAmount=" + cryptoAmount +
", cryptoCurrency='" + cryptoCurrency + '\'' +
", fiatAmount=" + fiatAmount +
", fiatCurrency='" + fiatCurrency + '\'' +
", id='" + id + '\'' +
", reference='" + reference + '\'' +
'}';
}
}
@Override
public Set<String> getCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.BTC);
return result;
}
@Override
public Set<String> getFiatCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.USD);
result.add(ICurrencies.EUR);
result.add(ICurrencies.CZK);
return result;
}
}

View File

@ -0,0 +1,42 @@
/*************************************************************************************
* Copyright (C) 2014 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
* Foundation and appearing in the file GPL2.TXT included in the packaging of
* this file. Please note that GPL2 Section 2[b] requires that all works based
* on this software must also be made publicly available under the terms of
* the GPL2 ("Copyleft").
*
* Contact information
* -------------------
*
* GENERAL BYTES s.r.o.
* Web : http://www.generalbytes.com
*
************************************************************************************/
package com.generalbytes.batm.server.extensions.extra.bitcoin.paymentprocessors.bitcoinpay;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.math.BigDecimal;
public class BitcoinPayPaymentRequestRequestDTO {
@JsonProperty("currency")
String currency;
@JsonProperty("price")
BigDecimal price;
@JsonProperty("settled_currency")
String settled_currency;
@JsonProperty("reference")
String reference;
public BitcoinPayPaymentRequestRequestDTO(String currency, BigDecimal price, String settled_currency, String reference) {
this.currency = currency;
this.price = price;
this.settled_currency = settled_currency;
this.reference = reference;
}
}

View File

@ -0,0 +1,70 @@
/*************************************************************************************
* Copyright (C) 2014 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
* Foundation and appearing in the file GPL2.TXT included in the packaging of
* this file. Please note that GPL2 Section 2[b] requires that all works based
* on this software must also be made publicly available under the terms of
* the GPL2 ("Copyleft").
*
* Contact information
* -------------------
*
* GENERAL BYTES s.r.o.
* Web : http://www.generalbytes.com
*
************************************************************************************/
package com.generalbytes.batm.server.extensions.extra.bitcoin.paymentprocessors.bitcoinpay;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.math.BigDecimal;
public class BitcoinPayPaymentResponseDTO {
public class Data {
@JsonProperty("address")
String address;
@JsonProperty("confirmations")
int confirmations;
@JsonProperty("create_time")
long create_time;
@JsonProperty("currency")
String currency;
@JsonProperty("paid_amount")
BigDecimal paid_amount;
@JsonProperty("paid_currency")
String paid_currency;
@JsonProperty("payment_id")
String payment_id;
@JsonProperty("payment_url")
String payment_url;
@JsonProperty("price")
BigDecimal price;
@JsonProperty("reference")
String reference;
@JsonProperty("server_time")
long server_time;
@JsonProperty("settled_amount")
BigDecimal settled_amount;
@JsonProperty("settled_currency")
String settled_currency;
@JsonProperty("status")
String status;
@JsonProperty("timeout_time")
long timeout_time;
@JsonProperty("txid")
String txid;
}
private Data data;
public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}
}

View File

@ -0,0 +1,40 @@
/*************************************************************************************
* Copyright (C) 2014 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
* Foundation and appearing in the file GPL2.TXT included in the packaging of
* this file. Please note that GPL2 Section 2[b] requires that all works based
* on this software must also be made publicly available under the terms of
* the GPL2 ("Copyleft").
*
* Contact information
* -------------------
*
* GENERAL BYTES s.r.o.
* Web : http://www.generalbytes.com
*
************************************************************************************/
package com.generalbytes.batm.server.extensions.extra.bitcoin.paymentprocessors.bitcoinpay;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
@Path("/api/v1")
@Produces(MediaType.APPLICATION_JSON)
public interface IBitcoinPay {
@POST
@Path("/payment/btc")
@Consumes(MediaType.APPLICATION_JSON)
BitcoinPayPaymentResponseDTO createNewPaymentRequest(@HeaderParam("Authorization") String token, BitcoinPayPaymentRequestRequestDTO request);
@GET
@Path("/payment/btc/{payment_id}")
BitcoinPayPaymentResponseDTO getPaymentStatus(@HeaderParam("Authorization") String token, @PathParam("payment_id") String paymentId);
}

View File

@ -37,6 +37,11 @@ public class DogecoinExtension implements IExtension{
return null;
}
@Override
public IPaymentProcessor createPaymentProcessor(String paymentProcessorLogin) {
return null; //no payment processors available
}
@Override
public IWallet createWallet(String walletLogin) {
if (walletLogin !=null && !walletLogin.trim().isEmpty()) {

View File

@ -105,6 +105,12 @@ public class GuldencoinExtension implements IExtension{
}
return null;
}
@Override
public IPaymentProcessor createPaymentProcessor(String paymentProcessorLogin) {
return null; //no payment processors available
}
@Override
public Set<String> getSupportedCryptoCurrencies() {
Set<String> result = new HashSet<String>();

View File

@ -108,4 +108,8 @@ public class GuldencoinTickerRateSource implements IRateSource{
return result;
}
public static void main(String[] args) {
BigDecimal exchangeRateLast = (new GuldencoinTickerRateSource()).getExchangeRateLast("NLG", "EUR");
System.out.println("exchangeRateLast = " + exchangeRateLast);
}
}

View File

@ -99,6 +99,13 @@ public class LeocoinExtension implements IExtension{
}
return null;
}
@Override
public IPaymentProcessor createPaymentProcessor(String paymentProcessorLogin) {
return null; //no payment processors available
}
@Override
public Set<String> getSupportedCryptoCurrencies() {
Set<String> result = new HashSet<String>();

View File

@ -78,6 +78,11 @@ public class LitecoinExtension implements IExtension{
return null;
}
@Override
public IPaymentProcessor createPaymentProcessor(String paymentProcessorLogin) {
return null; //no payment processors available
}
@Override
public IRateSource createRateSource(String sourceLogin) {
if (sourceLogin != null && !sourceLogin.trim().isEmpty()) {

View File

@ -102,6 +102,12 @@ public class MaxcoinExtension implements IExtension{
}
return null;
}
@Override
public IPaymentProcessor createPaymentProcessor(String paymentProcessorLogin) {
return null; //no payment processors available
}
@Override
public Set<String> getSupportedCryptoCurrencies() {
Set<String> result = new HashSet<String>();