webfunds.sox
Class AbstractPayment

java.lang.Object
  |
  +--webfunds.sox.Encodable
        |
        +--webfunds.sox.AbstractPayment
Direct Known Subclasses:
Payment, TokenPayment

public abstract class AbstractPayment
extends Encodable
implements Value

This class represents a signed payment. AbstractPayment objects are usually created using the createPayment method of an Account object, or re-constructed from a byte array which was created using the encode() method of a previous Payment object. Payments are encoded as a byte array for sending to third parties, and similarly, byte arrays are the form in which payments are received. It should be possible for classes to derive from this one, in order to have different functionality, so developers of this class should be sure to cater for derived classes.

See Also:
Serialized Form

Field Summary
protected  byte[] desc
          A description (can be anything, although very long lengths may be refused by some issuers and clients, but at least 2K is guaranteed to be supported by all SOX compatible software) Note that it can be non-ascii, and non readable.
protected  ItemId item
          The type of item (or "currency") of this payment.
protected  java.lang.String paymentId
          The identifer for this payment.
static int PF_VERSION
          The version number for this payment structure: 0: sox 2 cheque only 1: AbstractPayment / PaymentFactory {cheque; token; wagner}
protected  long qty
          The quantity of the item represented by this payment.
static int SINGLETON_VERSION
          The version number for this payment structure: 0: sox 2 cheque only 1: AbstractPayment / PaymentFactory {cheque; token; wagner}
protected  int subversion
          The sub version of the subclass.
protected  int type
          The type of payment of this class.
protected  int version
           
 
Constructor Summary
AbstractPayment(byte[] paymentData)
          Construct a payment object from a byte array that was previously returned from the encode() method of a payment object.
AbstractPayment(java.io.InputStream is)
          Construct a payment object from data in an input stream, where the data was previously returned from the encode() method of a payment object.
AbstractPayment(int version, int type, int subversion, ItemId item, long qty, byte[] desc)
          Create a basic payment, a constructor for subclasses
 
Method Summary
abstract  void decode(java.io.InputStream is)
          Update this payment object with the values from a payment encoded as a byte array (such as previously returned from the encode() method of a payment object).
abstract  void encode(java.io.OutputStream os)
          Encode a payment as a byte array, suitable for sending to third parties for depositing.
 boolean equals(java.lang.Object obj)
           
 byte[] getDesc()
          A description (can be anything, although very long lengths may be refused by some issuers and clients, but at least 2K is guaranteed to be supported by all SOX compatible software) Note that it can be non-ascii, and non readable.
 java.lang.String getId()
          Get the Payment Id.
 ItemId getItem()
          The type of item (or "currency") of this payment.
 long getQty()
          The quantity of the item to be transferred between accounts
 AccountId getSource()
          Get the account from which the transaction is drawn, should be overridden for sourced payments.
 int getSubVersion()
          The sub version of the subclass.
 AccountId getTarget()
          Get the account to which the payment is made, should be overridden for targetted payments.
 int getType()
          The type of payment of this class.
 long getValidFrom()
          Get the date from which the payment is valid.
 long getValidTill()
          Get the date to which the payment is valid
 int getVersion()
          The version number for the encoded form.
 boolean isBearer()
           
 java.lang.String toString()
           
 java.lang.String vString()
           
 
Methods inherited from class webfunds.sox.Encodable
decode, encode, main, readByteArray, readCertificate, readProperties, readString, writeByteArray, writeCertificate, writeProperties, writeString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SINGLETON_VERSION

public static final int SINGLETON_VERSION
The version number for this payment structure: 0: sox 2 cheque only 1: AbstractPayment / PaymentFactory {cheque; token; wagner}

PF_VERSION

public static final int PF_VERSION
The version number for this payment structure: 0: sox 2 cheque only 1: AbstractPayment / PaymentFactory {cheque; token; wagner}

version

protected int version

type

protected int type
The type of payment of this class. See PaymentFactory for types.

subversion

protected int subversion
The sub version of the subclass.

paymentId

protected java.lang.String paymentId
The identifer for this payment. This is used locally for storage and uniqueness, and may be used by the extending payment for idempotency, or stripped off as desired.

item

protected ItemId item
The type of item (or "currency") of this payment. E.g. "airmiles", "chips", ... In pure SOX protocol form, this can be any byte array as encoded in ItemId. In extant implementations, this will be the message digest of the Ricardian Contract. In a SOX / practical context this turns out to be more or less mandatory, so included here?

qty

protected long qty
The quantity of the item represented by this payment.

desc

protected byte[] desc
A description (can be anything, although very long lengths may be refused by some issuers and clients, but at least 2K is guaranteed to be supported by all SOX compatible software) Note that it can be non-ascii, and non readable. That's up to the client software to deal with. Null is not actually supported, it will be promoted to an empty byte array.
Constructor Detail

AbstractPayment

public AbstractPayment(int version,
                       int type,
                       int subversion,
                       ItemId item,
                       long qty,
                       byte[] desc)
Create a basic payment, a constructor for subclasses
Parameters:
item - the item for which the payment is for
desc - a description of what this payment is for (optional)

AbstractPayment

public AbstractPayment(byte[] paymentData)
                throws SOXPacketException
Construct a payment object from a byte array that was previously returned from the encode() method of a payment object. If the signature is not present in the encoded data, the created payment will be unsigned.
Parameters:
paymentData - the previously encoded payment

AbstractPayment

public AbstractPayment(java.io.InputStream is)
                throws SOXPacketException
Construct a payment object from data in an input stream, where the data was previously returned from the encode() method of a payment object. If the signature is not present in the encoded data, the created payment will be unsigned.
Parameters:
is - the input stream from which to read the payment data
Method Detail

getVersion

public int getVersion()
Description copied from interface: Value
The version number for the encoded form. 0: sox 2 cheque only 1: AbstractPayment / PaymentFactory {cheque; token; wagner}
Specified by:
getVersion in interface Value

getType

public int getType()
Description copied from interface: Value
The type of payment of this class. See PaymentFactory for types.
Specified by:
getType in interface Value

getSubVersion

public int getSubVersion()
Description copied from interface: Value
The sub version of the subclass.
Specified by:
getSubVersion in interface Value

getSource

public AccountId getSource()
Get the account from which the transaction is drawn, should be overridden for sourced payments.

getTarget

public AccountId getTarget()
Get the account to which the payment is made, should be overridden for targetted payments.

isBearer

public boolean isBearer()

getId

public java.lang.String getId()
Get the Payment Id. should be overridden for identified payments.

getValidFrom

public long getValidFrom()
Get the date from which the payment is valid.

getValidTill

public long getValidTill()
Get the date to which the payment is valid

getItem

public ItemId getItem()
Description copied from interface: Value
The type of item (or "currency") of this payment. E.g. "airmiles", "chips", ... In pure SOX protocol form, this can be any byte array as encoded in ItemId. In extant implementations, this will be the message digest of the Ricardian Contract. In a SOX / practical context this turns out to be more or less mandatory, so included here?
Specified by:
getItem in interface Value

getQty

public long getQty()
Description copied from interface: Value
The quantity of the item to be transferred between accounts
Specified by:
getQty in interface Value

getDesc

public byte[] getDesc()
Description copied from interface: Value
A description (can be anything, although very long lengths may be refused by some issuers and clients, but at least 2K is guaranteed to be supported by all SOX compatible software) Note that it can be non-ascii, and non readable. That's up to the client software to deal with.
Specified by:
getDesc in interface Value

decode

public abstract void decode(java.io.InputStream is)
                     throws java.io.IOException,
                            SOXPacketException
Update this payment object with the values from a payment encoded as a byte array (such as previously returned from the encode() method of a payment object). If the signature is not present in the encoded data, the current signature (if any) will be removed.
Overrides:
decode in class Encodable
Parameters:
paymentData - the previosly encoded payment

encode

public abstract void encode(java.io.OutputStream os)
                     throws java.io.IOException
Encode a payment as a byte array, suitable for sending to third parties for depositing. If the signature is not present, an unsigned payment will be encoded.
Overrides:
encode in class Encodable
Returns:
byte[] the payment in encoded form

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

vString

public java.lang.String vString()

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object