FileDocCategorySizeDatePackage
Transaction.javaAPI DocphoneME MR2 API (J2ME)12076Wed May 02 18:00:44 BST 2007com.sun.j2me.payment

Transaction

public class Transaction extends Object
A transaction holds the state and information about payment. It's state is updated by the associated transaction processor.

There are the following predefined states:

  • ENTERED - the payment has been initiated by the application
  • UPDATE - the transaction should be updated from the update URL
  • ASSIGNED - the transaction has been assigned to the payment adapter instance associated with the user selected provider
  • SUCCESSFUL - the payment has been successfully finished
  • FAILED - the payment failed because of errors
  • REJECTED - the payment has been rejected by the user
  • DISCARDED - the transaction should be silently discarded by the payment module

The Transaction class can be extended by some adapter specific subclass, which can hold more information about payment and can define some adapter specific states. For this purpose, there is a special constructor which initiates the transaction from the information provided by the transaction given as a parameter. There is also defined the ADAPTER_SPECIFIC constant, which should be used to number adapter specific states (ADAPTER_SPECIFIC, ADAPTER_SPECIFIC + 1, ADAPTER_SPECIFIC + 2...).

version
1.7

Fields Summary
public static final int
ENTERED
A predefined transaction state.
public static final int
UPDATE
A predefined transaction state.
public static final int
ASSIGNED
A predefined transaction state.
public static final int
SUCCESSFUL
A predefined transaction state.
public static final int
FAILED
A predefined transaction state.
public static final int
REJECTED
A predefined transaction state.
public static final int
DISCARDED
A predefined transaction state.
protected static final int
ADAPTER_SPECIFIC
The starting value of adapter specific states.
private int
transactionID
private int
featureID
private String
featureTitle
private String
featureDescription
private byte[]
payload
private TransactionModuleImpl
transactionModule
private String
providerName
private String
currency
private double
price
private String
specificPriceInfo
private int
state
private boolean
waiting
private boolean
needsUI
private TransactionProcessor
processor
Constructors Summary
Transaction(TransactionProcessor processor, TransactionModuleImpl module, int featureID, String featureTitle, String featureDescription, byte[] payload)
Creates a new instance of Transaction.

param
processor the initial transaction processor responsible for processing of this transaction
param
module the transaction module associated with the transaction
param
featureID the identifier of the feature to be paid for
param
featureTitle the title of the feature
param
featureDescription the description of the feature
param
payload the payload to be transfered as a part of the payment or null if no such payload required

  
    
                                                                                             
     
             
              
             
             
              

        this.transactionModule = module;
        
        this.featureID = featureID;
        this.featureTitle = featureTitle;
        this.featureDescription = featureDescription;
        this.payload = payload;
        
        this.processor = processor;
        this.needsUI = true;
    
public Transaction(Transaction templ)
Creates a new instance of Transaction with the fields initialized from the given original transaction.

param
templ the original transaction

        transactionID = templ.transactionID;
        
        featureID = templ.featureID;
        featureTitle = templ.featureTitle;
        featureDescription = templ.featureDescription;
        payload = templ.payload;
        transactionModule = templ.transactionModule;

        providerName = templ.providerName;
        currency = templ.currency;
        price = templ.price;
        specificPriceInfo = templ.specificPriceInfo;
        
        state = templ.state;
        
        waiting = templ.waiting;
        needsUI = templ.needsUI;

        processor = templ.processor;
    
Methods Summary
public final java.lang.StringgetCurrency()
Returns the currency of the payment.

return
the currency of the payment

        return currency;
    
public final java.lang.StringgetFeatureDescription()
Returns the description of the feature, which is paid for by this transaction.

return
the description of the feature

        return featureDescription;
    
public final intgetFeatureID()
Returns the id of the paid feature.

return
the feature id

        return featureID;
    
public final java.lang.StringgetFeatureTitle()
Returns the title of the feature, which is paid for by this transaction.

return
the title of the feature

        return featureTitle;
    
public final byte[]getPayload()
Returns the payload which is a part of the payment or null if it's undefined.

return
the payload or null

        return payload;
    
public final doublegetPrice()
Returns the price of the feature, which is paid.

return
the price of the feature

        return price;
    
public final java.lang.StringgetProviderName()
Returns the payload which is a part of the payment or null if it's undefined.

return
the payload or null

        return providerName;
    
public final java.lang.StringgetSpecificPriceInfo()
Returns the provider specific price information associated with the paid feature.

return
the provider specific price information

        return specificPriceInfo;
    
public final intgetState()
Returns the current state of the transaction.

return
the current state
see
#setState

        return state;
    
public final intgetTransactionID()
Returns the transaction ID value.

return
the transaction ID

        return transactionID;
    
public final TransactionModuleImplgetTransactionModule()
Returns the associated transaction module.

return
the transaction module

        return transactionModule;
    
public final booleanisWaiting()
Indicates if the transaction is waiting for some event.

return
true if the transaction is waiting

        return waiting;
    
public final booleanneedsUI()
Indicates if the transaction needs or will need an user response to be finished.

return
true if the transaction needs an user response

        return needsUI;
    
final com.sun.j2me.payment.Transactionprocess()
Processes the transaction. Delegates the call to the associated transaction processor.

return
the fully or partially processed transaction.

        return processor.process(this);
    
final voidsetCurrency(java.lang.String value)
Sets the currency of the payment.

param
value the currency

        currency = value;
    
public final voidsetNeedsUI(boolean value)
Sets the value which indicates if the transaction needs or will need some user response to be finished. Setting this value to true can block this or other transactions that also need user response from processing (only one such transaction can be processed at a time). Initialy this value is set to true and is an adapter responsibility to set it to false at the right time.

param
value true if the transaction needs or will need an user response to be finished

        needsUI = value;
    
final voidsetPrice(double value)
Sets the price of the paid feature.

param
value the price

        price = value;
    
final voidsetProviderName(java.lang.String value)
Sets the name of the selected provider.

param
value the new provider name

        providerName = value;
    
final voidsetSpecificPriceInfo(java.lang.String value)
Sets the provider specific price information.

param
value the provider specific price information

        specificPriceInfo = value;
    
public final voidsetState(int newState)
Sets the state of the transaction to the new value.

param
newState the new state
see
#getState

        state = newState;
    
final voidsetTransactionID(int value)
Sets the transaction ID for the transaction.

param
value the new transaction ID value

        transactionID = value;
    
public voidsetTransactionProcessor(TransactionProcessor processor)
Sets the transaction processor of the transaction.

param
processor the new transaction processor

        this.processor = processor;
    
public final voidsetWaiting(boolean value)
Puts the transaction into or resumes it from the waiting. A transaction which is waiting is not processed by the transaction processing thread of the payment module (its state doesn't change). A transaction can wait for some user response or the end of some adapter specific thread.

param
value if true the transaction is entering the waiting, if false the transaction is ending its waiting

        // should be synchronized?
        if (waiting == value) {
            return;
        }
        if (waiting) {
            waiting = false;
            // notify the payment module
            PaymentModule.getInstance().continueProcessing();
            return;
        }
        waiting = true;