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

PaymentAdapter

public abstract class PaymentAdapter extends Object implements TransactionProcessor
This class represents an adapter which is responsible for handling of transactions with an assigned provider. Each instance should be responsible for some provider specific payment method (one instance of premium priced SMS adapter for each PPSMS provider).
version
1.3

Fields Summary
Constructors Summary
Methods Summary
public abstract java.lang.StringgetDisplayName()
Returns a display name for this particular adapter. It should represent a payment method (premium priced sms, credit card...).

return
the display name

public java.lang.StringgetPaymentQuestion(java.lang.String provider, double price, java.lang.String currency)
Returns a question which is used for this adapter instance when the user chooses between providers for the particular payment.

param
provider the application supplied provider name
param
price the price to pay when using the provider
param
currency the currency of the payment
return
the question to ask (Are you sure, you want to buy this feature...)

        int multiplied = (int)(price * 100 + 0.5);
        String priceString = Integer.toString(multiplied);
        int length = priceString.length();

        String[] values = {
            currency,
            priceString.substring(0, length - 2),
            priceString.substring(length - 2),
            getDisplayName(),
            provider
        };

        return PaymentModule.getInstance().getUtilities().
                getString(Utils.PAYMENT_UPDATE_DLG_QUESTION, values);
    
protected final voidpreemptDisplay(SecurityToken token, javax.microedition.lcdui.Displayable nextDisplayable)
Replaces the current Displayable with the new one if the nextDisplayable is not null or it recovers the previous Displayable if the nextDisplayable is null.

param
token a security token, which allows preempting
param
nextDisplayable the Displayable to show or null if the recovery of the old Displayable is requested

        PaymentModule.getInstance().preemptDisplay(token, nextDisplayable);
    
public Transactionprocess(Transaction transaction)
Processes the given transaction, updates its state and returns the same transaction instance or a new one (an instance of a Transaction subclass), which is based on the old transaction, but adds more (adapter specific) information to it. The current implementation fails any transaction with the Transaction.ASSIGNED state, so it has to be overriden to work properly. It also sets the transaction processor of the given transaction to the payment module instance. It's recomended to call this method from the overriden one for every unhandled transaction (with the state, which can't be further processed in the adapter). It ensures that the control over the transaction will return to the payment module.

param
transaction the transaction to be processed
return
the transaction after processing

        if (transaction.getState() == Transaction.ASSIGNED) {
            // was not processed by the child adapter class
            transaction.setState(Transaction.FAILED);
            transaction.setNeedsUI(false);
        }

        // return any transaction which was not processed by the payment
        // adapter back to the payment module
        transaction.setTransactionProcessor(PaymentModule.getInstance());
        return transaction;
    
public voidvalidatePriceInfo(double price, java.lang.String paySpecificPriceInfo)
Validates the price information which are specified in the application manifest file for the provider handled by this adapter. It throws an PaymentException if the parameters are incorrect.

param
price the price to pay when using this provider
param
paySpecificPriceInfo the specific price information string from the manifest
throws
PaymentException if the provided information is correct