Project

General

Profile

Programming Guide » History » Version 11

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