anon.pay
Class BIConnection

java.lang.Object
  extended by anon.pay.BIConnection
All Implemented Interfaces:
ICaptchaSender

public class BIConnection
extends java.lang.Object
implements ICaptchaSender


Field Summary
private  boolean m_bFirstCaptcha
           
private  java.util.Vector m_biConnectionListeners
           
private  boolean m_bSendNewCaptcha
           
private  byte[] m_captchaSolution
           
private  HttpClient m_httpClient
           
private  java.net.Socket m_socket
           
private  PaymentInstanceDBEntry m_theBI
           
private static int ms_connectionTimeout
           
private static IMutableProxyInterface ms_proxyInterface
          A proxy interface that is used for all connections and may change over time.
static int TIMEOUT_DEFAULT
           
static int TIMEOUT_MAX
           
static int TIMEOUT_MIN
           
static java.lang.String XML_ATTR_CONNECTION_TIMEOUT
           
 
Constructor Summary
BIConnection(PaymentInstanceDBEntry theBI)
          Constructor
 
Method Summary
 void addConnectionListener(IBIConnectionListener a_listener)
          Adds an IBIConnectionListener
 void authenticate(XMLAccountCertificate accountCert, IMyPrivateKey a_privateKey)
          performs challenge-response authentication
 XMLErrorMessage buyFlatrate(long accountnumber)
           
 XMLTransCert charge(XMLGenericStrings parameters)
          Fetches a transfer certificate from the BI.
 boolean checkCouponCode(java.lang.String couponCode)
           
private  void connect_internal(ImmutableProxyInterface a_proxy, int a_connectionTimeout)
           
 void connect()
           
 void connect(int a_connectionTimeout)
          Connects to the Payment Instance via TCP and inits the HttpClient.
 void disconnect()
          Closes the connection.
 IXMLEncodable fetchPaymentData(java.lang.String transfernumber)
           
 XMLPaymentOptions fetchPaymentOptions()
          Gets the payment options the PI provides.
 XMLTransactionOverview fetchTransactionOverview(XMLTransactionOverview a_overview)
          Asks the PI to fill an XMLTransactionOverview
private  void fireGotCaptcha(IImageEncodedCaptcha a_captcha)
          Signals a received captcha to all registered IBICOnnectionListeners.
 XMLAccountInfo getAccountInfo()
          Fetches an account statement (balance cert.
 XMLGenericText getCancellationPolicy(java.lang.String lang)
           
static int getConnectionTimeout()
           
 void getNewCaptcha()
          Notifies the CaptchaSender that it should send a new captcha
 XMLPaymentOptions getPaymentOptions()
          Fetches payment options.
 XMLPaymentSettings getPaymentSettings()
           
 XMLGenericText getTerms(java.lang.String lang)
           
 XMLVolumePlans getVolumePlans()
           
 XMLAccountCertificate registerNewAccount(XMLJapPublicKey pubKey, IMyPrivateKey a_privateKey)
          Registers a new account using the specified keypair.
 boolean sendPassivePayment(XMLPassivePayment a_passivePayment)
          Sends data the user has entered for a passive payment to the payment instance.
 void setCaptchaSolution(byte[] a_solution)
          Sets the solution of a captcha for registering an account.
static void setConnectionTimeout(int a_timeout)
           
static void setMutableProxyInterface(IMutableProxyInterface a_proxyInterface)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIMEOUT_DEFAULT

public static final int TIMEOUT_DEFAULT
See Also:
Constant Field Values

TIMEOUT_MAX

public static final int TIMEOUT_MAX
See Also:
Constant Field Values

TIMEOUT_MIN

public static final int TIMEOUT_MIN
See Also:
Constant Field Values

XML_ATTR_CONNECTION_TIMEOUT

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

ms_connectionTimeout

private static int ms_connectionTimeout

m_theBI

private PaymentInstanceDBEntry m_theBI

m_socket

private java.net.Socket m_socket

m_httpClient

private HttpClient m_httpClient

m_biConnectionListeners

private java.util.Vector m_biConnectionListeners

m_captchaSolution

private byte[] m_captchaSolution

m_bSendNewCaptcha

private boolean m_bSendNewCaptcha

m_bFirstCaptcha

private boolean m_bFirstCaptcha

ms_proxyInterface

private static IMutableProxyInterface ms_proxyInterface
A proxy interface that is used for all connections and may change over time.

Constructor Detail

BIConnection

public BIConnection(PaymentInstanceDBEntry theBI)
Constructor

Parameters:
BI - the BI to which we connect
Method Detail

setConnectionTimeout

public static void setConnectionTimeout(int a_timeout)

getConnectionTimeout

public static int getConnectionTimeout()

setMutableProxyInterface

public static void setMutableProxyInterface(IMutableProxyInterface a_proxyInterface)

connect

public void connect()
             throws java.io.IOException
Throws:
java.io.IOException

connect

public void connect(int a_connectionTimeout)
             throws java.io.IOException
Connects to the Payment Instance via TCP and inits the HttpClient.

Throws:
java.io.IOException - if an error occured while connection
HTTPClient.ForbiddenIOException - if it is assumed that the local provider forbids the connection

connect_internal

private void connect_internal(ImmutableProxyInterface a_proxy,
                              int a_connectionTimeout)
                       throws java.io.IOException
Throws:
java.io.IOException

disconnect

public void disconnect()
                throws java.io.IOException,
                       XMLParseException
Closes the connection.

Throws:
java.io.IOException
XMLParseException

charge

public XMLTransCert charge(XMLGenericStrings parameters)
                    throws java.lang.Exception
Fetches a transfer certificate from the BI.

Returns:
XMLTransCert the transfer certificate
Throws:
java.lang.Exception

buyFlatrate

public XMLErrorMessage buyFlatrate(long accountnumber)
                            throws java.lang.Exception
Throws:
java.lang.Exception

getAccountInfo

public XMLAccountInfo getAccountInfo()
                              throws java.lang.Exception
Fetches an account statement (balance cert. + costconfirmations) from the BI.

Returns:
the statement in XMLAccountInfo format
Throws:
java.io.IOException
java.lang.Exception

getPaymentOptions

public XMLPaymentOptions getPaymentOptions()
                                    throws java.lang.Exception
Fetches payment options.

Returns:
XMLPaymentOptions
Throws:
java.lang.Exception

getVolumePlans

public XMLVolumePlans getVolumePlans()
                              throws java.lang.Exception
Throws:
java.lang.Exception

getTerms

public XMLGenericText getTerms(java.lang.String lang)
                        throws java.lang.Exception
Throws:
java.lang.Exception

getCancellationPolicy

public XMLGenericText getCancellationPolicy(java.lang.String lang)
                                     throws java.lang.Exception
Throws:
java.lang.Exception

getPaymentSettings

public XMLPaymentSettings getPaymentSettings()
                                      throws java.lang.Exception
Throws:
java.lang.Exception

authenticate

public void authenticate(XMLAccountCertificate accountCert,
                         IMyPrivateKey a_privateKey)
                  throws java.lang.Exception
performs challenge-response authentication

Throws:
java.lang.Exception

registerNewAccount

public XMLAccountCertificate registerNewAccount(XMLJapPublicKey pubKey,
                                                IMyPrivateKey a_privateKey)
                                         throws java.lang.Exception
Registers a new account using the specified keypair. Checks the signature and the public key of the accountCertificate that is received.

Parameters:
pubKey - public key
privKey - private key
Returns:
XMLAccountCertificate the certificate issued by the BI
Throws:
java.lang.Exception - if an error occurs or the signature or public key is wrong

fetchPaymentOptions

public XMLPaymentOptions fetchPaymentOptions()
                                      throws java.lang.Exception
Gets the payment options the PI provides.

Returns:
XMLPaymentOptions
Throws:
java.lang.Exception

fetchPaymentData

public IXMLEncodable fetchPaymentData(java.lang.String transfernumber)
                               throws java.lang.Exception
Throws:
java.lang.Exception

fetchTransactionOverview

public XMLTransactionOverview fetchTransactionOverview(XMLTransactionOverview a_overview)
                                                throws java.lang.Exception
Asks the PI to fill an XMLTransactionOverview

Parameters:
a_overview - XMLTransactionOverview
Returns:
XMLTransactionOverview
Throws:
java.lang.Exception

sendPassivePayment

public boolean sendPassivePayment(XMLPassivePayment a_passivePayment)
Sends data the user has entered for a passive payment to the payment instance.

Parameters:
a_passivePayment - XMLPassivePayment
Throws:
java.lang.Exception

checkCouponCode

public boolean checkCouponCode(java.lang.String couponCode)

addConnectionListener

public void addConnectionListener(IBIConnectionListener a_listener)
Adds an IBIConnectionListener

Parameters:
a_listener - IBIConnectionListener

fireGotCaptcha

private void fireGotCaptcha(IImageEncodedCaptcha a_captcha)
Signals a received captcha to all registered IBICOnnectionListeners.

Parameters:
a_captcha - IImageEncodedCaptcha

setCaptchaSolution

public void setCaptchaSolution(byte[] a_solution)
Sets the solution of a captcha for registering an account.

Specified by:
setCaptchaSolution in interface ICaptchaSender
Parameters:
a_solution - byte[]

getNewCaptcha

public void getNewCaptcha()
Description copied from interface: ICaptchaSender
Notifies the CaptchaSender that it should send a new captcha

Specified by:
getNewCaptcha in interface ICaptchaSender