webfunds.sox
Class Payment

java.lang.Object
  |
  +--webfunds.sox.Encodable
        |
        +--webfunds.sox.AbstractPayment
              |
              +--webfunds.sox.Payment

public class Payment
extends AbstractPayment

This class represents a signed payment. Payment 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.

See Also:
Serialized Form

Field Summary
protected  boolean changekey
          this boolean indicated wether the account has to rollover to a new key.
protected  byte[] sig
          The signature of the other payment fields (made by the owner of the source account)
protected  AccountId source
          The account from which the payment is drawn
static int SUB_VERSION
          The sub version of the original cheque payment.
protected  AccountId target
          The account to which the payment is made out.
static int TYPE
          The type of payment of this class There is currently only one defined, but future payment types may include things such as bearer payments, coins, bank transfers and hash chain payments
protected  long validFrom
          The date from which the payment is valid
protected  long validTill
          The date to which the payment is valid
 
Fields inherited from class webfunds.sox.AbstractPayment
desc, item, paymentId, PF_VERSION, qty, SINGLETON_VERSION, subversion, type, version
 
Constructor Summary
Payment(byte[] paymentData)
          Construct a payment object from a byte array that was previously returned from the encode() method of a payment object.
Payment(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.
Payment(java.lang.String paymentId, AccountId source, AccountId target, ItemId item, long qty, byte[] desc, boolean changekey, long validFrom, long validTill)
          Create an unsigned payment
 
Method Summary
protected static void cycle()
           
 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).
 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)
           
static Payment example()
           
 boolean getChangeKey()
           
 byte[] getSignature()
          Get the signature of the payment
 AccountId getSource()
          Get the account from which the transaction is drawn
 AccountId getTarget()
          Get the account to which the payment is made
 long getValidFrom()
          Get the date from which the payment is valid
 long getValidTill()
          Get the date to which the payment is valid
protected static void input()
           
 boolean isBearer()
           
 boolean isSigned()
          Check to see if this payment is signed NOTE: This does not check the validity of the signature, only that this payment has one.
static void main(java.lang.String[] args)
           
protected static void output()
           
protected static void readWrite()
           
 void setSignature(byte[] sig)
          Define the signature for this payment
 java.lang.String toString()
           
 boolean verify(java.security.PublicKey pk)
          Verify the signature on the payment with the given public key
 
Methods inherited from class webfunds.sox.AbstractPayment
getDesc, getId, getItem, getQty, getSubVersion, getType, getVersion, vString
 
Methods inherited from class webfunds.sox.Encodable
decode, encode, 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

TYPE

public static final int TYPE
The type of payment of this class There is currently only one defined, but future payment types may include things such as bearer payments, coins, bank transfers and hash chain payments

SUB_VERSION

public static final int SUB_VERSION
The sub version of the original cheque payment. The original is imputed as one (from VERSION==0), and the newer subclass version as 1, implying a subclass. Version 0 payments do not have a subversion.

source

protected AccountId source
The account from which the payment is drawn

target

protected AccountId target
The account to which the payment is made out.

validFrom

protected long validFrom
The date from which the payment is valid

validTill

protected long validTill
The date to which the payment is valid

sig

protected byte[] sig
The signature of the other payment fields (made by the owner of the source account)

changekey

protected boolean changekey
this boolean indicated wether the account has to rollover to a new key.
Constructor Detail

Payment

public Payment(java.lang.String paymentId,
               AccountId source,
               AccountId target,
               ItemId item,
               long qty,
               byte[] desc,
               boolean changekey,
               long validFrom,
               long validTill)
Create an unsigned payment
Parameters:
paymentId - the payment identifier
source - the source account
target - the target account
item - the item for which the payment is for
desc - a description of what this payment is for (optional)
qty - the number of items of which the payment is for
validFrom - the Java time from which the payment is valid
validTill - the Java time till which the payment is valid
changekey - boolean specifying if the account needs to be rolled over.

Payment

public Payment(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

Payment

public Payment(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

getSource

public AccountId getSource()
Get the account from which the transaction is drawn
Overrides:
getSource in class AbstractPayment

getTarget

public AccountId getTarget()
Get the account to which the payment is made
Overrides:
getTarget in class AbstractPayment

isBearer

public boolean isBearer()
Overrides:
isBearer in class AbstractPayment
Returns:
true if the payment is made out to BEARER

getValidFrom

public long getValidFrom()
Get the date from which the payment is valid
Overrides:
getValidFrom in class AbstractPayment

getValidTill

public long getValidTill()
Get the date to which the payment is valid
Overrides:
getValidTill in class AbstractPayment

getSignature

public byte[] getSignature()
Get the signature of the payment

getChangeKey

public boolean getChangeKey()

isSigned

public boolean isSigned()
Check to see if this payment is signed NOTE: This does not check the validity of the signature, only that this payment has one.
Returns:
boolean true if this payment has a signature

setSignature

public void setSignature(byte[] sig)
Define the signature for this payment
Parameters:
sig - the signature to place on the payment, or if null or empty, then the signature (if any) is removed.

verify

public boolean verify(java.security.PublicKey pk)
Verify the signature on the payment with the given public key
Parameters:
pk - The publickey to verify the signature with
Returns:
boolean true if payment is signed correctly

decode

public 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 AbstractPayment
Parameters:
paymentData - the previosly encoded payment

encode

public 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 AbstractPayment
Returns:
byte[] the payment in encoded form

toString

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

equals

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

example

public static Payment example()

main

public static void main(java.lang.String[] args)

cycle

protected static void cycle()
                     throws java.lang.Exception

output

protected static void output()
                      throws java.lang.Exception

readWrite

protected static void readWrite()
                         throws java.lang.Exception

input

protected static void input()
                     throws java.lang.Exception