diff --git a/server_extensions_extra/res/batm-extensions.xml b/server_extensions_extra/res/batm-extensions.xml index 3ecd8a1..3fd3869 100644 --- a/server_extensions_extra/res/batm-extensions.xml +++ b/server_extensions_extra/res/batm-extensions.xml @@ -31,6 +31,11 @@ BTC + + + + BTC + diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtension.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtension.java index 6f0e18b..0e88dbc 100644 --- a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtension.java +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtension.java @@ -20,6 +20,7 @@ package com.generalbytes.batm.server.extensions.extra.bitcoin; import com.generalbytes.batm.server.extensions.*; import com.generalbytes.batm.server.extensions.extra.bitcoin.exchanges.bitfinex.BitfinexExchange; import com.generalbytes.batm.server.extensions.extra.bitcoin.paymentprocessors.bitcoinpay.BitcoinPayPP; +import com.generalbytes.batm.server.extensions.extra.bitcoin.paymentprocessors.coinofsale.CoinOfSalePP; 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; @@ -61,6 +62,10 @@ public class BitcoinExtension implements IExtension{ String apiKey = st.nextToken(); return new BitcoinPayPP(apiKey); } + }else if ("coinofsale".equalsIgnoreCase(processorType)) { //coinofsale:token:pin + String token = st.nextToken(); + String pin = st.nextToken(); + return new CoinOfSalePP(token,pin); } } return null; diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/paymentprocessors/coinofsale/CoSPaymentResponseDTO.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/paymentprocessors/coinofsale/CoSPaymentResponseDTO.java new file mode 100644 index 0000000..384799b --- /dev/null +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/paymentprocessors/coinofsale/CoSPaymentResponseDTO.java @@ -0,0 +1,78 @@ +/************************************************************************************* + * Copyright (C) 2015 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.coinofsale; + +import java.math.BigDecimal; + +public class CoSPaymentResponseDTO { + private String address; + private BigDecimal bitcoin_price; + private BigDecimal fiat_price; + private String fiat_currency; + private String uri; + private boolean determined; + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public BigDecimal getBitcoin_price() { + return bitcoin_price; + } + + public void setBitcoin_price(BigDecimal bitcoin_price) { + this.bitcoin_price = bitcoin_price; + } + + public String getUri() { + return uri; + } + + public void setUri(String uri) { + this.uri = uri; + } + + public boolean isDetermined() { + return determined; + } + + public void setDetermined(boolean determined) { + this.determined = determined; + } + + public BigDecimal getFiat_price() { + return fiat_price; + } + + public void setFiat_price(BigDecimal fiat_price) { + this.fiat_price = fiat_price; + } + + public String getFiat_currency() { + return fiat_currency; + } + + public void setFiat_currency(String fiat_currency) { + this.fiat_currency = fiat_currency; + } +} + diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/paymentprocessors/coinofsale/CoSStatusResponseDTO.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/paymentprocessors/coinofsale/CoSStatusResponseDTO.java new file mode 100644 index 0000000..7aac009 --- /dev/null +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/paymentprocessors/coinofsale/CoSStatusResponseDTO.java @@ -0,0 +1,34 @@ +package com.generalbytes.batm.server.extensions.extra.bitcoin.paymentprocessors.coinofsale; + +/** + * Created by b00lean on 3/8/15. + */ +public class CoSStatusResponseDTO { + private String address; + private String txid; + private String status; // paid/unpaid/error + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getTxid() { + return txid; + } + + public void setTxid(String txid) { + this.txid = txid; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } +} diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/paymentprocessors/coinofsale/CoinOfSalePP.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/paymentprocessors/coinofsale/CoinOfSalePP.java new file mode 100644 index 0000000..49a1b26 --- /dev/null +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/paymentprocessors/coinofsale/CoinOfSalePP.java @@ -0,0 +1,162 @@ +/************************************************************************************* + * Copyright (C) 2015 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.coinofsale; + +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 si.mazi.rescu.RestProxyFactory; + +import java.math.BigDecimal; +import java.util.HashSet; +import java.util.Set; + +public class CoinOfSalePP implements IPaymentProcessor { + private String token; + private String pin; + + private ICoinOfSaleAPI api; + + public CoinOfSalePP(String token, String pin) { + this.token = token; + this.pin = pin; + + api = RestProxyFactory.createProxy(ICoinOfSaleAPI.class, "https://coinofsale.com"); + } + + @Override + public Set getCryptoCurrencies() { + Set result = new HashSet(); + result.add(ICurrencies.BTC); + return result; + } + + @Override + public Set getFiatCurrencies() { + Set result = new HashSet(); + result.add(ICurrencies.USD); + result.add(ICurrencies.EUR); + result.add(ICurrencies.CZK); + return result; + } + + @Override + public IPaymentProcessorPaymentResponse requestPayment(BigDecimal amount, String currency, String settledCurrency, String reference) { + CoSPaymentResponseDTO res = api.createPayment(token, pin, amount, currency); + if (res != null) { + return new COSPPResponse(res.getAddress(),res.getBitcoin_price(),ICurrencies.BTC,res.getFiat_price(),res.getFiat_currency(),res.getAddress(),reference); + } + return null; + } + + @Override + public IPaymentProcessorPaymentStatus getPaymentStatus(String paymentId) { + CoSStatusResponseDTO res = api.getPaymentStatus(paymentId, token, true); + if (res != null) { + if ("unpaid".equalsIgnoreCase(res.getStatus())) { + return new COSPPStatus(IPaymentProcessorPaymentStatus.STATUS_PENDING); + }else if ("paid".equalsIgnoreCase(res.getStatus())) { + return new COSPPStatus(IPaymentProcessorPaymentStatus.STATUS_RECEIVED); + }else if ("error".equalsIgnoreCase(res.getStatus())) { + return new COSPPStatus(IPaymentProcessorPaymentStatus.STATUS_INVALID); + } + } + return null; + } + + class COSPPStatus implements IPaymentProcessorPaymentStatus { + private int status; + + COSPPStatus(int status) { + this.status = status; + } + + public int getStatus() { + return status; + } + + @Override + public String toString() { + return "COSPPStatus{" + + "status=" + status + + '}'; + } + } + + class COSPPResponse implements IPaymentProcessorPaymentResponse { + private String cryptoAddress; + private BigDecimal cryptoAmount; + private String cryptoCurrency; + private BigDecimal fiatAmount; + private String fiatCurrency; + private String id; + private String reference; + + COSPPResponse(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 "COSPPResponse{" + + "cryptoAddress='" + cryptoAddress + '\'' + + ", cryptoAmount=" + cryptoAmount + + ", cryptoCurrency='" + cryptoCurrency + '\'' + + ", fiatAmount=" + fiatAmount + + ", fiatCurrency='" + fiatCurrency + '\'' + + ", id='" + id + '\'' + + ", reference='" + reference + '\'' + + '}'; + } + } +} diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/paymentprocessors/coinofsale/ICoinOfSaleAPI.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/paymentprocessors/coinofsale/ICoinOfSaleAPI.java new file mode 100644 index 0000000..4cd28bb --- /dev/null +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/paymentprocessors/coinofsale/ICoinOfSaleAPI.java @@ -0,0 +1,39 @@ +/************************************************************************************* + * Copyright (C) 2015 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.coinofsale; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import java.math.BigDecimal; + + +@Path("/payment/api") +@Produces(MediaType.APPLICATION_JSON) +public interface ICoinOfSaleAPI { + + @GET + @Path("/uri") + public CoSPaymentResponseDTO createPayment(@QueryParam("token") String token, @QueryParam("pin") String pin, @QueryParam("price") BigDecimal fiatPrice, @QueryParam("fiat_currency") String fiatCurrency); + + @GET + @Path("/status") + public CoSStatusResponseDTO getPaymentStatus(@QueryParam("address") String address, @QueryParam("token") String token, @QueryParam("determined") boolean determined); +}