psoft.epayment
Class GenericMerchantGateway

java.lang.Object
  extended bypsoft.epayment.GenericMerchantGateway
All Implemented Interfaces:
MerchantGateway

public abstract class GenericMerchantGateway
extends java.lang.Object
implements MerchantGateway

This is a support class for all merchant gateway classes. Each merchant gateway must be represented by a GenericMerchantGateway subclass.


Field Summary
protected static java.util.HashMap defaultValues
           
protected  int id
           
protected  MerchantGatewayLog log
           
 
Fields inherited from interface psoft.epayment.MerchantGateway
AUTH, CAPTURE, CHARGE, REFUND, VOID
 
Constructor Summary
GenericMerchantGateway()
           
 
Method Summary
abstract  java.util.HashMap authorize(long id, java.lang.String description, double amount, CreditCard cc)
          Verifies that the credit card is valid and has enough balance for the transaction and sets aside the required amount.
 java.util.HashMap authorize(long id, java.lang.String description, double amount, PaymentInstrument pi)
          Authorizes to charge provided amount from the PaymentInstrument using Merchant Gateway.
 java.util.HashMap authorize(java.lang.String description, double amount, PaymentInstrument pi)
          Authorizes to charge provided amount from the PaymentInstrument using Merchant Gateway.
abstract  java.util.HashMap capture(long id, java.lang.String description, java.util.HashMap data, CreditCard cc)
          Charges the set-aside amount to the credit card.
 java.util.HashMap capture(long id, java.lang.String description, java.util.HashMap data, PaymentInstrument pi)
          Captures pre-authorized amount from the PaymentInstrument
 java.util.HashMap capture(java.lang.String description, java.util.HashMap data, PaymentInstrument pi)
          Captures pre-authorized amount from the PaymentInstrument
abstract  java.util.HashMap charge(long id, java.lang.String description, double amount, CreditCard cc)
          Immediately verifies and charges the credit card.
 java.util.HashMap charge(long id, java.lang.String description, double amount, PaymentInstrument pi)
          Charges PaymentInstrument using Merchant Gateway.
 java.util.HashMap charge(java.lang.String description, double amount, PaymentInstrument pi)
          Charges PaymentInstrument using Merchant Gateway.
 java.util.HashMap checkCC(long acctid, CreditCard cc)
          This method should be overridden for gateways that support CVV validation to check CVV value immediately after the credit card info is passed to the hsphere database
 java.util.HashMap checkCCCVV(long acctid, CreditCard cc)
          This method can be used in the checkCC(...) method implementation for merchant gateways that support CVV validation.
 java.util.HashMap checkCVV(long acctid, PaymentInstrument pi)
          This method is called by hsphere to check CVV value when the credit card details are entered.
protected  java.lang.String formatAmount(double amount)
          Although the system locale can differ from american, most payment systems use the "12.34" format to process transactions using the dot as the decimal delimiter
static java.util.Map getDefaultValues()
          Returns default MerchantGateway configuration parameters as a HashMap
 int getId()
          Returns the ID of the Merchant Gateway in H-Sphere
static java.lang.String getTrDescription(int id)
          Returns description of the transaction
protected  java.lang.String getValue(java.util.HashMap values, java.lang.String key)
          Returns a value from the hashmap as String
abstract  java.util.Map getValues()
          Returns configuration of MerchantGateway as key/value pairs
abstract  void init(int id, java.util.HashMap values)
          Initializes MerchantGateway with default values
protected  void sendEmail(java.lang.String email, int trtype, java.lang.String description, long id, java.lang.String mess)
          Sends email notificaton about necessity to manually void/capture a transaction if there is no possibility to do it automatically
 void setLog(MerchantGatewayLog log)
          Sets log object where all that transactions will be written
abstract  java.util.HashMap voidAuthorize(long id, java.lang.String description, java.util.HashMap data, CreditCard cc)
          Cancels the transaction that has not yet been settled.
 java.util.HashMap voidAuthorize(long id, java.lang.String description, java.util.HashMap data, PaymentInstrument pi)
          Voids pre-authorized amount from the PaymentInstrument
 java.util.HashMap voidAuthorize(java.lang.String description, java.util.HashMap data, PaymentInstrument pi)
          Voids pre-authorized amount from the PaymentInstrument
protected  void writeAuthorize(double amount)
          writes to the log if the card was authorized successfully
protected  void writeCapture(double amount)
          writes to the log if the transaction was completed
protected  void writeCharge(double amount)
          writes charge transaction to the log
protected  long writeLog(long accid, double amount, int trtype)
          writes transaction to the log
protected  long writeLog(long trid, long accid, double amount, int trtype, java.lang.String dataOut, java.lang.String dataIn, java.lang.String error, boolean success)
          writes transaction to the log
protected  long writeLog(long accid, java.lang.String dataOut, java.lang.String dataIn, java.lang.String error)
          writes transaction to the log
protected  void writeVoid(double amount)
          writes to the log if the transaction was canceled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface psoft.epayment.MerchantGateway
getDescription
 

Field Detail

defaultValues

protected static java.util.HashMap defaultValues

id

protected int id

log

protected MerchantGatewayLog log
Constructor Detail

GenericMerchantGateway

public GenericMerchantGateway()
Method Detail

getDefaultValues

public static java.util.Map getDefaultValues()
Returns default MerchantGateway configuration parameters as a HashMap

Returns:
Default MerchantGateway configuration parameters as a HashMap

getValues

public abstract java.util.Map getValues()
Returns configuration of MerchantGateway as key/value pairs

Specified by:
getValues in interface MerchantGateway
Returns:
key/value pairs as a HashMap

init

public abstract void init(int id,
                          java.util.HashMap values)
                   throws java.lang.Exception
Initializes MerchantGateway with default values

Specified by:
init in interface MerchantGateway
Parameters:
id - merchant account id
values - bundle values needed to initialize the MerchantGateway usually login, password, merchant account number
Throws:
java.lang.Exception - in case initialization fails

getId

public int getId()
Returns the ID of the Merchant Gateway in H-Sphere

Specified by:
getId in interface MerchantGateway
Returns:
id Merchant Gateway ID in H-Sphere

setLog

public void setLog(MerchantGatewayLog log)
Sets log object where all that transactions will be written

Specified by:
setLog in interface MerchantGateway
Parameters:
log - MerchantGatewayLog

getValue

protected java.lang.String getValue(java.util.HashMap values,
                                    java.lang.String key)
Returns a value from the hashmap as String

Parameters:
values - HashMap
key - String
Returns:
String

formatAmount

protected java.lang.String formatAmount(double amount)
Although the system locale can differ from american, most payment systems use the "12.34" format to process transactions using the dot as the decimal delimiter

Parameters:
amount - amount to be taken off the account
Returns:
formatted amount

checkCVV

public java.util.HashMap checkCVV(long acctid,
                                  PaymentInstrument pi)
                           throws java.lang.Exception
Description copied from interface: MerchantGateway
This method is called by hsphere to check CVV value when the credit card details are entered.

Specified by:
checkCVV in interface MerchantGateway
Parameters:
acctid - - hsphere account/signup ID
pi - - PaymentInstrument, e.g. CreditCard
Returns:
response from gateway as key/value pairs
Throws:
java.lang.Exception

checkCC

public java.util.HashMap checkCC(long acctid,
                                 CreditCard cc)
                          throws java.lang.Exception
This method should be overridden for gateways that support CVV validation to check CVV value immediately after the credit card info is passed to the hsphere database

Parameters:
acctid - - hsphere account/signup ID
cc - - CreditCard that represents user's credit card
Throws:
java.lang.Exception

checkCCCVV

public java.util.HashMap checkCCCVV(long acctid,
                                    CreditCard cc)
                             throws java.lang.Exception
This method can be used in the checkCC(...) method implementation for merchant gateways that support CVV validation. Credit card exp. date will be validated locally and then an authorization on $1 will be run to check CVV, then $1 authorization will be cancelled

Parameters:
acctid - - hsphere account/signup ID
cc - - CreditCard implementation that represents user's credit card
Throws:
java.lang.Exception

charge

public java.util.HashMap charge(java.lang.String description,
                                double amount,
                                PaymentInstrument pi)
                         throws java.lang.Exception
Description copied from interface: MerchantGateway
Charges PaymentInstrument using Merchant Gateway.

Specified by:
charge in interface MerchantGateway
Parameters:
description - description for the gateway
amount - amount to charge
pi - PaymentInstrument information
Returns:
response from gateway as key/value pairs
Throws:
java.lang.Exception - In case of the error
See Also:
PaymentInstrument

charge

public java.util.HashMap charge(long id,
                                java.lang.String description,
                                double amount,
                                PaymentInstrument pi)
                         throws java.lang.Exception
Description copied from interface: MerchantGateway
Charges PaymentInstrument using Merchant Gateway.

Specified by:
charge in interface MerchantGateway
Parameters:
id - internal transaction id
description - description for the gateway
amount - amount to charge
pi - PaymentInstrument information
Returns:
response from gateway as key/value pairs
Throws:
java.lang.Exception - In case of the error
See Also:
PaymentInstrument

charge

public abstract java.util.HashMap charge(long id,
                                         java.lang.String description,
                                         double amount,
                                         CreditCard cc)
                                  throws java.lang.Exception
Immediately verifies and charges the credit card. This method is called when the credit card is expected to be valid and to have sufficient balance for the transaction.

Parameters:
id - internal id of transaction
description - description of transaction
amount - amount to be taken off the account
cc - - CreditCard implementation that represents user's credit card
Throws:
java.lang.Exception

authorize

public java.util.HashMap authorize(java.lang.String description,
                                   double amount,
                                   PaymentInstrument pi)
                            throws java.lang.Exception
Description copied from interface: MerchantGateway
Authorizes to charge provided amount from the PaymentInstrument using Merchant Gateway.

Specified by:
authorize in interface MerchantGateway
Parameters:
description - description for the gateway
amount - amount to authorize
pi - PaymentInstrument information
Returns:
response from gateway as key/value pairs
Throws:
java.lang.Exception - In case of the error
See Also:
PaymentInstrument

authorize

public java.util.HashMap authorize(long id,
                                   java.lang.String description,
                                   double amount,
                                   PaymentInstrument pi)
                            throws java.lang.Exception
Description copied from interface: MerchantGateway
Authorizes to charge provided amount from the PaymentInstrument using Merchant Gateway.

Specified by:
authorize in interface MerchantGateway
Parameters:
id - internal transaction id
description - description for the gateway
amount - amount to authorize
pi - PaymentInstrument information
Returns:
response from gateway as key/value pairs
Throws:
java.lang.Exception - In case of the error
See Also:
PaymentInstrument

authorize

public abstract java.util.HashMap authorize(long id,
                                            java.lang.String description,
                                            double amount,
                                            CreditCard cc)
                                     throws java.lang.Exception
Verifies that the credit card is valid and has enough balance for the transaction and sets aside the required amount.

Parameters:
id - internal id of transaction
description - description of transaction
amount - amount to be taken off the account
cc - - CreditCard implementation that represents user's credit card
Throws:
java.lang.Exception

capture

public java.util.HashMap capture(java.lang.String description,
                                 java.util.HashMap data,
                                 PaymentInstrument pi)
                          throws java.lang.Exception
Description copied from interface: MerchantGateway
Captures pre-authorized amount from the PaymentInstrument

Specified by:
capture in interface MerchantGateway
Parameters:
description - description for the gateway
data - data return by authorize method
pi - PaymentInstrument information
Returns:
response from gateway as key/value pairs
Throws:
java.lang.Exception - In case of the error
See Also:
PaymentInstrument, MerchantGateway.authorize, MerchantGateway.void

capture

public java.util.HashMap capture(long id,
                                 java.lang.String description,
                                 java.util.HashMap data,
                                 PaymentInstrument pi)
                          throws java.lang.Exception
Description copied from interface: MerchantGateway
Captures pre-authorized amount from the PaymentInstrument

Specified by:
capture in interface MerchantGateway
Parameters:
id - internal transaction id
description - description for the gateway
data - data return by authorize method
pi - PaymentInstrument information
Returns:
response from gateway as key/value pairs
Throws:
java.lang.Exception - In case of the error
See Also:
PaymentInstrument, MerchantGateway.authorize, MerchantGateway.void

capture

public abstract java.util.HashMap capture(long id,
                                          java.lang.String description,
                                          java.util.HashMap data,
                                          CreditCard cc)
                                   throws java.lang.Exception
Charges the set-aside amount to the credit card. Requires to authorize the transaction first.

Parameters:
id - internal id of transaction
description - description of transaction
cc - - CreditCard implementation that represents user's credit card
Throws:
java.lang.Exception

voidAuthorize

public java.util.HashMap voidAuthorize(java.lang.String description,
                                       java.util.HashMap data,
                                       PaymentInstrument pi)
                                throws java.lang.Exception
Description copied from interface: MerchantGateway
Voids pre-authorized amount from the PaymentInstrument

Specified by:
voidAuthorize in interface MerchantGateway
Parameters:
description - description for the gateway
data - data return by authorize method
pi - PaymentInstrument information
Returns:
response from gateway as key/value pairs
Throws:
java.lang.Exception - In case of the error
See Also:
PaymentInstrument, MerchantGateway.authorize, MerchantGateway.void

voidAuthorize

public java.util.HashMap voidAuthorize(long id,
                                       java.lang.String description,
                                       java.util.HashMap data,
                                       PaymentInstrument pi)
                                throws java.lang.Exception
Description copied from interface: MerchantGateway
Voids pre-authorized amount from the PaymentInstrument

Specified by:
voidAuthorize in interface MerchantGateway
Parameters:
id - internal transaction id
description - description for the gateway
data - data return by authorize method
pi - PaymentInstrument information
Returns:
response from gateway as key/value pairs
Throws:
java.lang.Exception - In case of the error
See Also:
PaymentInstrument, MerchantGateway.authorize, MerchantGateway.void

voidAuthorize

public abstract java.util.HashMap voidAuthorize(long id,
                                                java.lang.String description,
                                                java.util.HashMap data,
                                                CreditCard cc)
                                         throws java.lang.Exception
Cancels the transaction that has not yet been settled. Requires to authorize the transaction first.

Parameters:
id - internal id of transaction
description - description of transaction
cc - - CreditCard implementation that represents user's credit card
Throws:
java.lang.Exception

writeLog

protected long writeLog(long trid,
                        long accid,
                        double amount,
                        int trtype,
                        java.lang.String dataOut,
                        java.lang.String dataIn,
                        java.lang.String error,
                        boolean success)
writes transaction to the log

Parameters:
trid - - internal id of the transaction
accid - - hsphere account/signup ID
amount - - amount charged to the credit card
dataOut - - data returned by merchant gateway
dataIn - - data submitted to merchant gateway
error - - error string returned by merchant gateway
success - - 0 if the transaction was successsful, 1 if the transaction failed
Returns:
0 (zero) if the method completes successfully

writeLog

protected long writeLog(long accid,
                        double amount,
                        int trtype)
writes transaction to the log

Parameters:
accid - - hsphere account/signup ID
amount - - amount charged to the credit card
trtype - - transaction type: CHARGE = 0, AUTH = 1, REFUND = 2, VOID = 3, CAPTURE = 4.
Returns:
log entry id

writeLog

protected long writeLog(long accid,
                        java.lang.String dataOut,
                        java.lang.String dataIn,
                        java.lang.String error)
writes transaction to the log

Parameters:
accid - - hsphere account ID
dataOut - - data returned by merchant gateway
dataIn - - data submitted to the merchant gateway
error - - error string returned by merchant gateway
Returns:
log entry id

writeCharge

protected void writeCharge(double amount)
                    throws java.lang.Exception
writes charge transaction to the log

Parameters:
amount - - amount charged to the credit card
Throws:
java.lang.Exception

writeVoid

protected void writeVoid(double amount)
                  throws java.lang.Exception
writes to the log if the transaction was canceled

Parameters:
amount - - amount of the canceled transaction
Throws:
java.lang.Exception

writeCapture

protected void writeCapture(double amount)
                     throws java.lang.Exception
writes to the log if the transaction was completed

Parameters:
amount - - amount of the completed transaction
Throws:
java.lang.Exception

writeAuthorize

protected void writeAuthorize(double amount)
                       throws java.lang.Exception
writes to the log if the card was authorized successfully

Parameters:
amount - - amount of the transaction
Throws:
java.lang.Exception

getTrDescription

public static java.lang.String getTrDescription(int id)
Returns description of the transaction

Parameters:
id - -transaction type
Returns:
text transaction description

sendEmail

protected void sendEmail(java.lang.String email,
                         int trtype,
                         java.lang.String description,
                         long id,
                         java.lang.String mess)
                  throws java.lang.Exception
Sends email notificaton about necessity to manually void/capture a transaction if there is no possibility to do it automatically

Parameters:
email - - email address of notification recipient
trtype - - transaction type
description - - problem description
id - - hsphere account ID
mess - - Message text
Throws:
java.lang.Exception


Copyright © 2005 Positive Software Corporation. All Rights Reserved.