Added support for CoinOfSale.com payment processor

This commit is contained in:
b00lean 2015-03-08 22:26:23 +01:00
parent b7ca47b9e9
commit 43a8be8fcc
6 changed files with 323 additions and 0 deletions

View File

@ -31,6 +31,11 @@
<param name="apikey" />
<cryptocurrency>BTC</cryptocurrency>
</paymentprocessor>
<paymentprocessor prefix="coinofsale" name="CoinOfSale.com" >
<param name="token" />
<param name="pin" />
<cryptocurrency>BTC</cryptocurrency>
</paymentprocessor>
<!-- Bitfinex extension by Orillia BVBA -->
<exchange prefix="bitfinex" name="Bitfinex.com Exchange">
<param name="apikey" />

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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<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;
}
@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 + '\'' +
'}';
}
}
}

View File

@ -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);
}