Project

General

Profile

Actions

Programming Guide » History » Revision 11

« Previous | Revision 11/21 (diff) | Next »
chin-yeh, 08/26/2011 10:08 AM


Programming Guide

There are number of APIs provided by DP. All of these APIs are wrapped and exposed through a client application, dp-client. Refer to the following sub sections for more information.

The Javadoc of dp-client:

http://192.168.2.13:50000/dp_client_apidocs/

The binary or source files of dp-client:

SCM

Demo application of dp-client:

http://192.168.2.66:8080/dp-test/index.html

Query DP balance

Queries the available DP balance.

Input Parameters

See queryBalance

Output Parameters

The return object, TransactionResponse consists of:
  • process - Sales1
  • transactionId - the unique reference that passed in by the caller
  • countryId - the country ID that passed in by the caller
  • centerId - possible value is ONLINE. It's used to differentiate if the caller are from POS system or online mall.
  • memberId - the member/shopper ID
  • status - the status of the transaction. If success, returns 0000
  • balance - the available DP balance
  • errorCode - the error code of the transaction. if success, returns 00000
  • errorMessage - the detailed description of the error code

Code Snippet

TransactionResponse dpResponse;
try {
  dpResponse = DPServicesUtils.queryBalance(countryCode, shopperId); 

} catch (RemoteException ex) {
  LOGGER.error("Error in connecting to web services", ex);
}

Impose Sales Lock

Imposes the Sales Lock on the particular member ID. This method is usually to be used conjunction with Commit Sales. Without sales lock, the Commit Sales won't succeed.

Input Parameters

See imposeSalesLock

Output Parameters

The return object, TransactionResponse consists of:
  • process - Sales1
  • transactionId - the unique reference that passed in by the caller
  • countryId - the country ID that passed in by the caller
  • centerId - possible value is ONLINE. It's used to differentiate if the caller are from POS system or online mall.
  • memberId - the member/shopper ID
  • status - the status of the transaction. If success, returns 0000
  • balance - the available DP balance
  • errorCode - the error code of the transaction. if success, returns 00000
  • errorMessage - the detailed description of the error code

Code Snippet

TransactionResponse dpResponse;
try {
  dpResponse = DPServicesUtils.imposeSalesLock(trxId, countryCode, shopperId);

} catch (RemoteException ex) {
  LOGGER.error("Error in connecting to web services", ex);
}

Release Sales Lock

To be able to release the Sales Lock, one must provide the same transaction ID, which being used to impose the Sales Lock.

And, this method will return success status regardless if there's Sales Lock or not.

Input Parameters

See releaseSalesLock

Output Parameters

  • process - Sales1
  • transactionId - the unique reference that passed in by the caller
  • countryId - the country ID that passed in by the caller
  • centerId - possible value is ONLINE. It's used to differentiate if the caller are from POS system or online mall.
  • memberId - the member/shopper ID
  • status - the status of the transaction. If success, returns 0000
  • balance - the available DP balance
  • errorCode - the error code of the transaction. if success, returns 00000
  • errorMessage - the detailed description of the error code

Code Snippet

TransactionResponse dpResponse;
try {
  dpResponse = DPServicesUtils.releaseSalesLock(trxId, countryCode, shopperId);

} catch (RemoteException ex) {
  LOGGER.error("Error in connecting web services", ex);
}

Commit Sales

This method is used to deduct DP balance according to the provided amount. The Impose Sales Lock must be invoked prior that.

The Commit Sales and Impose Sales Lock could be invoked by 2 separate processes but both must use the same transaction ID.

This method will persist the transaction details into database.

Input Parameters

See performSalesCommit

Output Parameters

  • process - Sales2
  • transactionId - the unique reference that passed in by the caller
  • countryId - the country ID that passed in by the caller
  • centerId - possible value is ONLINE. It's used to differentiate if the caller are from POS system or online mall.
  • memberId - the member/shopper ID
  • status - the status of the transaction. If success, returns 0000
  • balance - the available DP balance
  • errorCode - the error code of the transaction. if success, returns 00000
  • errorMessage - the detailed description of the error code

Code Snippet

Connection dbConnection = DBConnectionFactory.createDbConnection("java:/DB2DS2");
TransactionResponse dpResponse = new TransactionResponse();
try {
    // impose sales lock before commit
    dpResponse = DPServicesUtils.imposeSalesLock(trxId, countryCode, shopperId);

    dpResponse = DPServicesUtils.performSalesCommit(dbConnection,
                trxId, countryCode, shopperId,
                trxDate, dpAmount, invoiceAmount);
} catch (RemoteException ex) {
    LOGGER.error("Error in connecting to web service", ex);
} catch (SQLException ex) {
    LOGGER.error("Error in persisting the event", ex);
} finally {        
    if (dbConnection != null) {
       dbConnection.close();
    }
}

// release the Sales Lock in the event of exception 
if (dpResponse == null || !"0000".equals(dpResponse.getStatus())) {
   DPServicesUtils.releaseSalesLock(trxId, countryCode, shopperId);
}


Sales Return / Cancel Sales

This method is used to adjust the DP balance. There's no need to impose the Sales Lock.

Input Parameters

See performSalesReturn

Output Parameters

  • process - SReturn
  • transactionId - the unique reference that passed in by the caller
  • countryId - the country ID that passed in by the caller
  • centerId - possible value is ONLINE. It's used to differentiate if the caller are from POS system or online mall.
  • memberId - the member/shopper ID
  • status - the status of the transaction. If success, returns 0000
  • balance - the available DP balance
  • errorCode - the error code of the transaction. if success, returns 00000
  • errorMessage - the detailed description of the error code

Code Snippet

Connection dbConnection = DBConnectionFactory.createDbConnection("java:/DB2DS2");

TransactionResponse dpResponse = new TransactionResponse();

try {
    dpResponse = DPServicesUtils.performSalesReturn(dbConnection, trxId, countryCode, 
            shopperId,trxDate, dpAmount, invoiceAmount);    

} catch (RemoteException ex) {
    LOGGER.error("Error in connecting to web service", ex);
} catch (SQLException ex) {
    LOGGER.error("Error in persisting the event", ex);
} finally {
    if (dbConnection != null) {
        dbConnection.close();
    }
}


VIP Upgrade to BO

Input Parameters

See performVipUpgrade

Output Parameters

Code Snippet

Generate the redirect URL for VIP Details page

Input Parameters

See vipDetailsPage

Output Parameters

Code Snippet

Exception Handling Strategies

The APIs would throw the following exceptions:
  • RemoteException - if there's any issue in communicating with the DP
  • SQLException - if there's any issue in persisting or updating the event
  • unchecked exception - e.g. NullPointerException. This is more like a programming errors so do not catch it for whatever reasons.
    • note: catch the Exception will catch both checked & unchecked exception

The above exceptions should never be ignored, at least, the full error stack trace should be logged.

Updated by chin-yeh about 13 years ago · 11 revisions