Programming Guide » History » Version 13
Soh Keong, 02/05/2013 09:00 AM
1 | 2 | chin-yeh | {{toc}} |
---|---|---|---|
2 | |||
3 | 1 | chin-yeh | h1. Programming Guide |
4 | 2 | chin-yeh | |
5 | 3 | chin-yeh | There are number of APIs provided by VP. All of these APIs are wrapped and exposed through a client application, [[documentation#list-of-components|vp-client]]. Refer to the following sub sections for more information. |
6 | 1 | chin-yeh | |
7 | 3 | chin-yeh | The Javadoc of *vp-client*: |
8 | > http://192.168.2.13:50000/vp_client_apidocs/ |
||
9 | |||
10 | 4 | chin-yeh | The binary or source files of *vp-client*: |
11 | > [[wiki#SCM|SCM]] |
||
12 | |||
13 | 3 | chin-yeh | Demo application of *vp-client*: |
14 | 13 | Soh Keong | URL : http://192.168.2.68:8080/TestPage/page/point/tw_vp.jsp |
15 | Query : http://192.168.2.68:8080/TestPage/page/point/tw_vp.jsp |
||
16 | Registration : http://192.168.2.68:8080/TestPage/page/point/tw_vp_reg.jsp |
||
17 | Renewal : http://192.168.2.68:8080/TestPage/page/point/tw_vp_renew.jsp |
||
18 | 3 | chin-yeh | |
19 | 2 | chin-yeh | h2. VP Registration |
20 | 1 | chin-yeh | |
21 | 3 | chin-yeh | This method is only applicable for *new registration*, which means the member/shopper ID *is not yet registered* with VP before. |
22 | 1 | chin-yeh | |
23 | 11 | chin-yeh | _Method Signature:_ |
24 | <pre> |
||
25 | <code class="JAVA"> |
||
26 | public static TransactionResponse performRegistration(java.sql.Connection connection, |
||
27 | java.lang.String trxId, |
||
28 | java.lang.String countryId, |
||
29 | java.lang.String memberId, |
||
30 | java.lang.String memberName, |
||
31 | java.math.BigDecimal vpAmount, |
||
32 | java.util.Date trxDate, |
||
33 | java.util.Date regDate, |
||
34 | java.util.Date expDate) |
||
35 | throws java.rmi.RemoteException, |
||
36 | java.sql.SQLException |
||
37 | </code> |
||
38 | </pre> |
||
39 | |||
40 | |||
41 | 3 | chin-yeh | h3. Input Parameters |
42 | |||
43 | 5 | chin-yeh | See "performRegistration":http://192.168.2.13:50000/vp_client_apidocs/com/ecosway/vp_client/VPServicesUtils.html#performRegistration%28java.sql.Connection,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.math.BigDecimal,%20java.util.Date,%20java.util.Date,%20java.util.Date%29 |
44 | 3 | chin-yeh | |
45 | h3. Output Parameters |
||
46 | |||
47 | The return object, *TransactionResponse* consists of the following fields value: |
||
48 | * *process* - For registration, the possible value is *VRegister* |
||
49 | * *transactionId* - The unique reference that passed in by the caller |
||
50 | * *countryId* - The country ID/code that passed in by the caller |
||
51 | * *centerId* - To differentiate if the caller are from POS system or online |
||
52 | * *memberId* - The member/shopper ID |
||
53 | * *status* - The status of the transaction. If success, returns *0000* |
||
54 | ** _refer to document:"VP Web Service Format" for other possible status_ |
||
55 | * *errorCode* - the error code of the transaction. if success, returns *00000* |
||
56 | ** _refer to document:"VP Web Service Format" for other possible error code_ |
||
57 | * *errorMessage* - the detailed description of the error code |
||
58 | ** _refer to document:"VP Web Service Format" for other possible description_ |
||
59 | |||
60 | h3. Code Snippet |
||
61 | |||
62 | *Important note:* One should modify the following code to cater existing program so do not copy & paste it directly. |
||
63 | |||
64 | <pre> |
||
65 | <code class="JAVA"> |
||
66 | Connection dbConnection = DBConnectionFactory.createDbConnection("java:/DB2DS2"); |
||
67 | TransactionResponse vpResponse = new TransactionResponse(); |
||
68 | |||
69 | try { |
||
70 | vpResponse = VPServicesUtils.performRegistration(dbConnection, trxId, |
||
71 | 7 | chin-yeh | countryId, memberId, memberName, vpAmount, trxDate, regDate, expDate); |
72 | 3 | chin-yeh | |
73 | } catch (RemoteException ex) { |
||
74 | // do not ignore. either log the full stack trace or handle it |
||
75 | 12 | chin-yeh | LOGGER.error("Error in connecting to VP web services", ex); |
76 | 3 | chin-yeh | } catch (SQLException ex) { |
77 | // do not ignore. either log the full stack trace or handle it |
||
78 | 12 | chin-yeh | LOGGER.error("Error in persisting the event", ex); |
79 | 3 | chin-yeh | } finally { |
80 | if (dbConnection != null) { |
||
81 | dbConnection.close(); |
||
82 | } |
||
83 | } |
||
84 | </code> |
||
85 | </pre> |
||
86 | |||
87 | 1 | chin-yeh | h2. VP Renewal |
88 | 4 | chin-yeh | |
89 | 9 | chin-yeh | This method is only applicable for renewal. If the member is not exist, VP will create the record in the background. |
90 | 11 | chin-yeh | |
91 | _Method Signature:_ |
||
92 | <pre> |
||
93 | <code class="JAVA"> |
||
94 | public static TransactionResponse performRenewal(java.sql.Connection connection, |
||
95 | java.lang.String trxId, |
||
96 | java.lang.String countryId, |
||
97 | java.lang.String memberId, |
||
98 | java.lang.String memberName, |
||
99 | java.math.BigDecimal vpAmount, |
||
100 | java.util.Date trxDate, |
||
101 | java.util.Date regDate, |
||
102 | java.util.Date expDate) |
||
103 | throws java.rmi.RemoteException, |
||
104 | java.sql.SQLException |
||
105 | </code> |
||
106 | </pre> |
||
107 | |||
108 | 4 | chin-yeh | |
109 | h3. Input Parameters |
||
110 | |||
111 | 6 | chin-yeh | See "performRenewal":http://192.168.2.13:50000/vp_client_apidocs/com/ecosway/vp_client/VPServicesUtils.html#performRenewal(java.sql.Connection,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.math.BigDecimal,%20java.util.Date,%20java.util.Date,%20java.util.Date) |
112 | 4 | chin-yeh | |
113 | h3. Output Parameters |
||
114 | |||
115 | The return object, *TransactionResponse* consists of the following fields value: |
||
116 | * *process* - For registration/renewal, the possible value is *VRegister* |
||
117 | * *transactionId* - The unique reference that passed in by the caller |
||
118 | * *countryId* - The country ID/code that passed in by the caller |
||
119 | * *centerId* - To differentiate if the caller are from POS system or online |
||
120 | * *memberId* - The member/shopper ID |
||
121 | * *status* - The status of the transaction. If success, returns *0000* |
||
122 | ** _refer to document:"VP Web Service Format" for other possible status_ |
||
123 | * *errorCode* - the error code of the transaction. if success, returns *00000* |
||
124 | ** _refer to document:"VP Web Service Format" for other possible error code_ |
||
125 | * *errorMessage* - the detailed description of the error code |
||
126 | ** _refer to document:"VP Web Service Format" for other possible description_ |
||
127 | |||
128 | h3. Code Snippet |
||
129 | |||
130 | *Important note:* One should modify the following code to cater existing program so do not copy & paste it directly. |
||
131 | |||
132 | <pre> |
||
133 | <code class="JAVA"> |
||
134 | Connection dbConnection = DBConnectionFactory.createDbConnection("java:/DB2DS2"); |
||
135 | TransactionResponse vpResponse = new TransactionResponse(); |
||
136 | |||
137 | try { |
||
138 | vpResponse = VPServicesUtils.performRenewal(dbConnection, trxId, |
||
139 | 7 | chin-yeh | countryId, memberId, memberName, vpAmount, trxDate, regDate, expDate); |
140 | 4 | chin-yeh | |
141 | } catch (RemoteException ex) { |
||
142 | // do not ignore. either log the full stack trace or handle it |
||
143 | 12 | chin-yeh | LOGGER.error("Error in connecting to VP web services", ex); |
144 | 4 | chin-yeh | } catch (SQLException ex) { |
145 | // do not ignore. either log the full stack trace or handle it |
||
146 | 12 | chin-yeh | LOGGER.error("Error in persisting the event", ex); |
147 | 4 | chin-yeh | } finally { |
148 | 1 | chin-yeh | if (dbConnection != null) { |
149 | 4 | chin-yeh | dbConnection.close(); |
150 | } |
||
151 | } |
||
152 | </code> |
||
153 | </pre> |
||
154 | |||
155 | |||
156 | 10 | chin-yeh | h2. Exception Handling Strategies |
157 | 4 | chin-yeh | |
158 | 10 | chin-yeh | The APIs would throw the following exceptions: |
159 | 4 | chin-yeh | * *RemoteException* - if there's any issue in communicating with VP |
160 | * *SQLException* - if there's any issue in persisting or updating the event |
||
161 | * *unchecked exception* - e.g. NullPointerException. This is more like a programming errors so do not catch it for whatever reasons. |
||
162 | 8 | chin-yeh | ** _note: catch the *Exception* will catch both checked & unchecked exception_ |
163 | 4 | chin-yeh | |
164 | The above exceptions should never be ignored, at least, the full error stack trace should be logged. |