controller
Class BitPay

java.lang.Object
  extended by controller.BitPay

public class BitPay
extends java.lang.Object


Field Summary
static java.lang.String FACADE_MERCHANT
           
static java.lang.String FACADE_PAYROLL
           
static java.lang.String FACADE_POS
           
static java.lang.String FACADE_USER
           
static java.lang.String PUBLIC_NO_TOKEN
           
 
Constructor Summary
BitPay()
          Constructor for use if the keys and SIN are managed by this library.
BitPay(com.google.bitcoin.core.ECKey ecKey)
          Constructor for use if the keys and SIN were derived external to this library.
BitPay(com.google.bitcoin.core.ECKey ecKey, java.lang.String clientName)
          Constructor for use if the keys and SIN were derived external to this library.
BitPay(com.google.bitcoin.core.ECKey ecKey, java.lang.String clientName, java.lang.String envUrl)
          Constructor for use if the keys and SIN were derived external to this library.
BitPay(java.lang.String clientName)
          Constructor for use if the keys and SIN are managed by this library.
BitPay(java.lang.String clientName, java.lang.String envUrl)
          Constructor for use if the keys and SIN are managed by this library.
 
Method Summary
 void authorizeClient(java.lang.String pairingCode)
          Authorize this client for use with the BitPay server.
 boolean cancelRefundRequest(Invoice invoice, java.lang.String refundId)
          Cancel a previously submitted refund request on a BitPay invoice.
 boolean cancelRefundRequest(java.lang.String invoiceId, java.lang.String refundId)
          Cancel a previously submitted refund request on a BitPay invoice.
 boolean clientIsAuthorized(java.lang.String facade)
          Test whether this client is authorized for a specified level of API access.
 Invoice createInvoice(Invoice invoice)
          Create a BitPay invoice using the POS facade.
 Invoice createInvoice(Invoice invoice, java.lang.String token)
          Create a BitPay invoice.
 java.lang.String getAccessToken(java.lang.String id)
          Retrieve a token associated with a known resource.
 java.util.List<Refund> getAllRefunds(Invoice invoice)
          Retrieve all refund requests on a BitPay invoice.
 java.lang.String getIdentity()
          Get the generated client identity.
 Invoice getInvoice(java.lang.String invoiceId)
          Retrieve a BitPay invoice by invoice id using the public facade.
 Invoice getInvoice(java.lang.String invoiceId, java.lang.String token)
          Retrieve a BitPay invoice by invoice id using the specified facade.
 java.util.List<Invoice> getInvoices(java.lang.String dateStart, java.lang.String dateEnd)
          Retrieve a collection of BitPay invoices.
 Rates getRates()
          Retrieve the exchange rate table maintained by BitPay.
 Refund getRefund(Invoice invoice, java.lang.String refundId)
          Retrieve a previously made refund request on a BitPay invoice.
 java.lang.String requestClientAuthorization(java.lang.String facade)
          Request a pairing code from the BitPay server.
 RefundHelper requestRefund(Invoice invoice, java.lang.String bitcoinAddress, java.lang.Double amount, java.lang.String currency)
          Request a refund for a BitPay invoice.
 RefundHelper requestRefund(java.lang.String invoiceId, java.lang.String bitcoinAddress)
          Request a full refund for a BitPay invoice.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FACADE_MERCHANT

public static final java.lang.String FACADE_MERCHANT
See Also:
Constant Field Values

FACADE_PAYROLL

public static final java.lang.String FACADE_PAYROLL
See Also:
Constant Field Values

FACADE_POS

public static final java.lang.String FACADE_POS
See Also:
Constant Field Values

FACADE_USER

public static final java.lang.String FACADE_USER
See Also:
Constant Field Values

PUBLIC_NO_TOKEN

public static final java.lang.String PUBLIC_NO_TOKEN
See Also:
Constant Field Values
Constructor Detail

BitPay

public BitPay(java.lang.String clientName,
              java.lang.String envUrl)
       throws BitPayException
Constructor for use if the keys and SIN are managed by this library.

Parameters:
clientName - The label for this client.
envUrl - The target server URL.
Throws:
BitPayException

BitPay

public BitPay(java.lang.String clientName)
       throws BitPayException
Constructor for use if the keys and SIN are managed by this library. Use BitPay production server.

Parameters:
clientName - The label for this client.
Throws:
BitPayException

BitPay

public BitPay()
       throws BitPayException
Constructor for use if the keys and SIN are managed by this library. Use BitPay production server. Default client name.

Throws:
BitPayException

BitPay

public BitPay(com.google.bitcoin.core.ECKey ecKey,
              java.lang.String clientName,
              java.lang.String envUrl)
       throws BitPayException
Constructor for use if the keys and SIN were derived external to this library.

Parameters:
ecKey - An elliptical curve key.
clientName - The label for this client.
envUrl - The target server URL.
Throws:
BitPayException

BitPay

public BitPay(com.google.bitcoin.core.ECKey ecKey,
              java.lang.String clientName)
       throws BitPayException
Constructor for use if the keys and SIN were derived external to this library. Use BitPay production server.

Parameters:
ecKey - An elliptical curve key.
clientName - The label for this client.
Throws:
BitPayException

BitPay

public BitPay(com.google.bitcoin.core.ECKey ecKey)
       throws BitPayException
Constructor for use if the keys and SIN were derived external to this library. Use BitPay production server. Default client name.

Parameters:
ecKey - An elliptical curve key.
Throws:
BitPayException
Method Detail

getIdentity

public java.lang.String getIdentity()
Get the generated client identity.

Returns:
Client identify as a string

authorizeClient

public void authorizeClient(java.lang.String pairingCode)
                     throws BitPayException
Authorize this client for use with the BitPay server.

Parameters:
pairingCode - A pairing code generated at https://bitpay.com/dashboard/merchant/api-tokens.
Throws:
BitPayException

requestClientAuthorization

public java.lang.String requestClientAuthorization(java.lang.String facade)
                                            throws BitPayException
Request a pairing code from the BitPay server.

Parameters:
facade - Defines the level of API access being requested
Returns:
A pairing code for claim at https://bitpay.com/dashboard/merchant/api-tokens.
Throws:
BitPayException

clientIsAuthorized

public boolean clientIsAuthorized(java.lang.String facade)
Test whether this client is authorized for a specified level of API access.

Parameters:
facade - Defines the level of API access being requested.
Returns:
True if this client is authorized, false otherwise.
Throws:
BitPayException

getAccessToken

public java.lang.String getAccessToken(java.lang.String id)
                                throws BitPayException
Retrieve a token associated with a known resource. The token is used to access other related resources.

Parameters:
id - The identifier for the desired resource.
Returns:
The token associated with resource.
Throws:
BitPayException

createInvoice

public Invoice createInvoice(Invoice invoice,
                             java.lang.String token)
                      throws BitPayException
Create a BitPay invoice.

Parameters:
invoice - An Invoice object with request parameters defined.
token - The resource access token for the request.
Returns:
A BitPay generated Invoice object.
Throws:
BitPayException

createInvoice

public Invoice createInvoice(Invoice invoice)
                      throws BitPayException
Create a BitPay invoice using the POS facade.

Parameters:
invoice - An Invoice object with request parameters defined.
Returns:
A BitPay generated Invoice object.
Throws:
BitPayException

getInvoice

public Invoice getInvoice(java.lang.String invoiceId)
                   throws BitPayException
Retrieve a BitPay invoice by invoice id using the public facade.

Parameters:
invoiceId - The id of the invoice to retrieve.
Returns:
A BitPay Invoice object.
Throws:
BitPayException

getInvoice

public Invoice getInvoice(java.lang.String invoiceId,
                          java.lang.String token)
                   throws BitPayException
Retrieve a BitPay invoice by invoice id using the specified facade. The client must have been previously authorized for the specified facade (the public facade requires no authorization).

Parameters:
invoiceId - The id of the invoice to retrieve.
token - The facade/invoice token (e.g., pos/invoice) for the invoice.
Returns:
A BitPay Invoice object.
Throws:
BitPayException

getInvoices

public java.util.List<Invoice> getInvoices(java.lang.String dateStart,
                                           java.lang.String dateEnd)
                                    throws BitPayException
Retrieve a collection of BitPay invoices.

Parameters:
dateStart - The first date for the query filter.
dateEnd - The last date for the query filter.
Returns:
A list of BitPay Invoice objects.
Throws:
BitPayException

requestRefund

public RefundHelper requestRefund(java.lang.String invoiceId,
                                  java.lang.String bitcoinAddress)
                           throws BitPayException
Request a full refund for a BitPay invoice. The invoice full price and currency type are used in the request.

Parameters:
invoiceId - The id of the BitPay invoice for which a refund request should be made.
bitcoinAddress - The bitcoin address to which the refund should will be made. If left empty ("") and the invoice contains a refund address then the request may success, otherwise it will fail.
Returns:
A BitPay RefundRequest object with the new Refund object.
Throws:
BitPayException

requestRefund

public RefundHelper requestRefund(Invoice invoice,
                                  java.lang.String bitcoinAddress,
                                  java.lang.Double amount,
                                  java.lang.String currency)
                           throws BitPayException
Request a refund for a BitPay invoice.

Parameters:
invoice - A BitPay invoice object for which a refund request should be made. Must have been obtained using the merchant facade.
bitcoinAddress - The bitcoin address to which the refund should will be made. If left empty ("") and the invoice contains a refund address then the request may success, otherwise it will fail.
amount - The amount of money to refund. If zero then a request for 100% of the invoice value is created.
currency - The three digit currency code specifying the exchange rate to use when calculating the refund bitcoin amount. If this value is "BTC" then no exchange rate calculation is performed.
Returns:
A BitPay RefundRequest object with the new Refund object.
Throws:
BitPayException

cancelRefundRequest

public boolean cancelRefundRequest(java.lang.String invoiceId,
                                   java.lang.String refundId)
                            throws BitPayException
Cancel a previously submitted refund request on a BitPay invoice.

Parameters:
invoiceId - The BitPay invoiceId having the associated refund to be canceled.
refundId - The refund id for the refund to be canceled.
Returns:
True if the refund was successfully canceled, false otherwise.
Throws:
BitPayException

cancelRefundRequest

public boolean cancelRefundRequest(Invoice invoice,
                                   java.lang.String refundId)
                            throws BitPayException
Cancel a previously submitted refund request on a BitPay invoice.

Parameters:
invoice - The BitPay invoice having the associated refund to be canceled. Must have been obtained using the merchant facade.
refundId - The refund id for the refund to be canceled.
Returns:
True if the refund was successfully canceled, false otherwise.
Throws:
BitPayException

getRefund

public Refund getRefund(Invoice invoice,
                        java.lang.String refundId)
                 throws BitPayException
Retrieve a previously made refund request on a BitPay invoice.

Parameters:
invoice - The BitPay invoice having the associated refund.
refundId - The refund id for the refund to be updated with new status.
Returns:
A BitPay invoice object with the associated Refund object updated.
Throws:
BitPayException

getAllRefunds

public java.util.List<Refund> getAllRefunds(Invoice invoice)
                                     throws BitPayException
Retrieve all refund requests on a BitPay invoice.

Parameters:
invoice - The BitPay invoice object having the associated refunds.
Returns:
A BitPay invoice object with the associated Refund objects updated.
Throws:
BitPayException

getRates

public Rates getRates()
               throws BitPayException
Retrieve the exchange rate table maintained by BitPay. See https://bitpay.com/bitcoin-exchange-rates.

Returns:
A Rates object populated with the BitPay exchange rate table.
Throws:
BitPayException