1 | /* |
||
2 | * To change this license header, choose License Headers in Project Properties. |
||
3 | * To change this template file, choose Tools | Templates |
||
4 | * and open the template in the editor. |
||
5 | */ |
||
6 | package com.github.theresasogunle; |
||
7 | |||
8 | |||
9 | |||
10 | import static com.github.theresasogunle.Encryption.encryptData; |
||
11 | import org.json.JSONException; |
||
12 | import org.json.JSONObject; |
||
13 | |||
14 | |||
15 | |||
16 | /** |
||
17 | * |
||
18 | * @author Theresa |
||
19 | */ |
||
20 | public class AlternativePayment { |
||
21 | |||
22 | ApiConnection apiConnection; |
||
23 | |||
24 | Encryption e=new Encryption(); |
||
25 | |||
26 | |||
27 | private String accountnumber,accountbank,currency,country, |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
28 | amount,firstname,lastname, |
||
0 ignored issues
–
show
|
|||
29 | pin,email,IP,txRef,phonenumber,orderRef,network, |
||
0 ignored issues
–
show
|
|||
30 | flwRef; |
||
0 ignored issues
–
show
|
|||
31 | |||
32 | |||
33 | /** |
||
34 | * |
||
35 | * @throws JSONException it throws JSON exception |
||
36 | * @return JSONObject |
||
37 | */ |
||
38 | |||
39 | // charge customers using nigerian USSD for GTB and Zenith Bank,Ghana mobile money and Kenya Mpesa |
||
40 | |||
41 | public JSONObject chargeNigerianUssd () { |
||
42 | //getting charge endpoint |
||
43 | JSONObject json=new JSONObject(); |
||
44 | try{ |
||
45 | json.put("accountnumber", this.getAccountnumber()); |
||
46 | json.put("accountbank", this.getAccountbank()); |
||
47 | json.put("currency", this.getCurrency()); |
||
48 | json.put("country", this.getCountry()); |
||
49 | json.put("amount", this.getAmount()); |
||
50 | json.put("firstname", this.getFirstname()); |
||
51 | json.put("lastname", this.getLastname()); |
||
52 | json.put("pin", this.getPin()); |
||
53 | json.put("email", this.getEmail()); |
||
54 | json.put("IP", this.getIP()); |
||
55 | json.put("txRef", this.getTxRef()); |
||
56 | json.put("payment_type", "ussd"); |
||
57 | |||
58 | }catch(JSONException ex){ex.getMessage();} |
||
0 ignored issues
–
show
Ignoring an Exception may lead to hard to find bugs. Consider logging or rethrowing the original exception. If you want to throw a different exception, you can set the original exception as its cause to preserve the stacktrace.
When instantiating a new Exception, you can set another Exception as its cause. See the Oracle documentation on Throwables. Usage example throw new Exception("Exception Message", originalException);
Complete Example: class ReThrowException {
public static void throwsException() {
try {
throw new Exception("I am the original exception");
} catch (final Exception e) {
throw new RuntimeException("I am the new exception", e);
}
}
public static void main(String[] args) {
try {
throwsException();
}
catch (final RuntimeException e) {
System.out.println(e.getMessage());
System.out.println("and my cause is: " + e.getCause().getMessage());
e.printStackTrace();
}
}
}
![]() |
|||
59 | String message= json.toString(); |
||
60 | |||
61 | String encrypt_secret_key=Encryption.getKey(RaveConstant.SECRET_KEY); |
||
62 | String client= encryptData(message,encrypt_secret_key); |
||
63 | |||
64 | Charge ch=new Charge(); |
||
65 | |||
66 | return ch.charge(client); |
||
67 | |||
68 | } |
||
69 | /** |
||
70 | * |
||
71 | * @throws JSONException it throws JSON exception |
||
72 | * @return JSONObject |
||
73 | */ |
||
74 | |||
75 | |||
76 | public JSONObject chargeGhanaMobileMoney () { |
||
77 | //getting charge endpoint |
||
78 | JSONObject json=new JSONObject(); |
||
79 | try{ |
||
80 | json.put("orderRef",this.getOrderRef()); |
||
81 | json.put("network", this.getNetwork()); |
||
82 | json.put("currency", this.getCurrency()); |
||
83 | json.put("country", this.getCountry()); |
||
84 | json.put("amount", this.getAmount()); |
||
85 | json.put("firstname", this.getFirstname()); |
||
86 | json.put("lastname", this.getLastname()); |
||
87 | json.put("pin", this.getPin()); |
||
88 | json.put("email", this.getEmail()); |
||
89 | json.put("IP", this.getIP()); |
||
90 | json.put("txRef", this.getTxRef()); |
||
91 | json.put("payment_type", "mobilemoneygh"); |
||
92 | json.put("is_mobile_money_gh", "1"); |
||
93 | json.put("phonenumber",this.getPhonenumber()); |
||
94 | }catch(JSONException ex){ex.getMessage();} |
||
0 ignored issues
–
show
Ignoring an Exception may lead to hard to find bugs. Consider logging or rethrowing the original exception. If you want to throw a different exception, you can set the original exception as its cause to preserve the stacktrace.
When instantiating a new Exception, you can set another Exception as its cause. See the Oracle documentation on Throwables. Usage example throw new Exception("Exception Message", originalException);
Complete Example: class ReThrowException {
public static void throwsException() {
try {
throw new Exception("I am the original exception");
} catch (final Exception e) {
throw new RuntimeException("I am the new exception", e);
}
}
public static void main(String[] args) {
try {
throwsException();
}
catch (final RuntimeException e) {
System.out.println(e.getMessage());
System.out.println("and my cause is: " + e.getCause().getMessage());
e.printStackTrace();
}
}
}
![]() |
|||
95 | String message= json.toString(); |
||
96 | |||
97 | String encrypt_secret_key=Encryption.getKey(RaveConstant.SECRET_KEY); |
||
98 | String client= encryptData(message,encrypt_secret_key); |
||
99 | |||
100 | Charge ch=new Charge(); |
||
101 | |||
102 | return ch.charge(client); |
||
103 | |||
104 | } |
||
105 | /** |
||
106 | * |
||
107 | * @throws JSONException it throws JSON exception |
||
108 | * @return JSONObject |
||
109 | */ |
||
110 | |||
111 | public JSONObject chargeKenyaMpesa () { |
||
112 | //getting charge endpoint |
||
113 | JSONObject json=new JSONObject(); |
||
114 | try{ |
||
115 | json.put("currency", this.getCurrency()); |
||
116 | json.put("country", this.getCountry()); |
||
117 | json.put("amount", this.getAmount()); |
||
118 | json.put("firstname", this.getFirstname()); |
||
119 | json.put("lastname", this.getLastname()); |
||
120 | json.put("pin", this.getPin()); |
||
121 | json.put("email", this.getEmail()); |
||
122 | json.put("IP", this.getIP()); |
||
123 | json.put("txRef", this.getTxRef()); |
||
124 | json.put("orderRef", this.getOrderRef()); |
||
125 | json.put("phonenumber", this.getPhonenumber()); |
||
126 | json.put("payment_type", "mpesa"); |
||
127 | json.put("is_mpesa", "1"); |
||
128 | }catch(JSONException ex){ex.getMessage();} |
||
0 ignored issues
–
show
Ignoring an Exception may lead to hard to find bugs. Consider logging or rethrowing the original exception. If you want to throw a different exception, you can set the original exception as its cause to preserve the stacktrace.
When instantiating a new Exception, you can set another Exception as its cause. See the Oracle documentation on Throwables. Usage example throw new Exception("Exception Message", originalException);
Complete Example: class ReThrowException {
public static void throwsException() {
try {
throw new Exception("I am the original exception");
} catch (final Exception e) {
throw new RuntimeException("I am the new exception", e);
}
}
public static void main(String[] args) {
try {
throwsException();
}
catch (final RuntimeException e) {
System.out.println(e.getMessage());
System.out.println("and my cause is: " + e.getCause().getMessage());
e.printStackTrace();
}
}
}
![]() |
|||
129 | String message= json.toString(); |
||
130 | |||
131 | String encrypt_secret_key=Encryption.getKey(RaveConstant.SECRET_KEY); |
||
132 | String client= encryptData(message,encrypt_secret_key); |
||
133 | |||
134 | Charge ch=new Charge(); |
||
135 | |||
136 | return ch.charge(client); |
||
137 | |||
138 | } |
||
139 | |||
140 | /** |
||
141 | * |
||
142 | * @param txref |
||
143 | * @param flwref |
||
144 | * @return JSONObject |
||
145 | */ |
||
146 | //to requery transaction for ghana mobile money,kenya mpesa and nigerian ussd using xquery |
||
147 | |||
148 | /** |
||
149 | * @return the accountnumber |
||
150 | */ |
||
151 | public String getAccountnumber() { |
||
152 | return accountnumber; |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * @param accountnumber the accountnumber to set |
||
157 | * @return AlternativePayment |
||
158 | */ |
||
159 | public AlternativePayment setAccountnumber(String accountnumber) { |
||
160 | this.accountnumber = accountnumber; |
||
161 | return this; |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * @return the accountbank |
||
166 | */ |
||
167 | public String getAccountbank() { |
||
168 | return accountbank; |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * @param accountbank the accountbank to set |
||
173 | * @return AlternativePayment |
||
174 | */ |
||
175 | public AlternativePayment setAccountbank(String accountbank) { |
||
176 | this.accountbank = accountbank; |
||
177 | return this; |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * @return the currency |
||
182 | */ |
||
183 | public String getCurrency() { |
||
184 | return currency; |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * @param currency the currency to set |
||
189 | * @return AlternativePayment |
||
190 | */ |
||
191 | public AlternativePayment setCurrency(String currency) { |
||
192 | this.currency = currency; |
||
193 | return this; |
||
194 | } |
||
195 | |||
196 | /** |
||
197 | * @return the country |
||
198 | */ |
||
199 | public String getCountry() { |
||
200 | return country; |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * @param country the country to set |
||
205 | * @return AlternativePayment |
||
206 | */ |
||
207 | public AlternativePayment setCountry(String country) { |
||
208 | this.country = country; |
||
209 | return this; |
||
210 | } |
||
211 | |||
212 | /** |
||
213 | * @return the amount |
||
214 | */ |
||
215 | public String getAmount() { |
||
216 | return amount; |
||
217 | } |
||
218 | |||
219 | /** |
||
220 | * @param amount the amount to set |
||
221 | * @return AlternativePayment |
||
222 | */ |
||
223 | public AlternativePayment setAmount(String amount) { |
||
224 | this.amount = amount; |
||
225 | return this; |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * @return the firstname |
||
230 | */ |
||
231 | public String getFirstname() { |
||
232 | return firstname; |
||
233 | } |
||
234 | |||
235 | /** |
||
236 | * @param firstname the firstname to set |
||
237 | * @return AlternativePayment |
||
238 | */ |
||
239 | public AlternativePayment setFirstname(String firstname) { |
||
240 | this.firstname = firstname; |
||
241 | return this; |
||
242 | } |
||
243 | |||
244 | /** |
||
245 | * @return the lastname |
||
246 | */ |
||
247 | public String getLastname() { |
||
248 | return lastname; |
||
249 | } |
||
250 | |||
251 | /** |
||
252 | * @param lastname the lastname to set |
||
253 | * @return AlternativePayment |
||
254 | */ |
||
255 | public AlternativePayment setLastname(String lastname) { |
||
256 | this.lastname = lastname; |
||
257 | return this; |
||
258 | } |
||
259 | |||
260 | /** |
||
261 | * @return the pin |
||
262 | */ |
||
263 | public String getPin() { |
||
264 | return pin; |
||
265 | } |
||
266 | |||
267 | /** |
||
268 | * @param pin the pin to set |
||
269 | * @return AlternativePayment |
||
270 | */ |
||
271 | public AlternativePayment setPin(String pin) { |
||
272 | this.pin = pin; |
||
273 | return this; |
||
274 | } |
||
275 | |||
276 | /** |
||
277 | * @return the email |
||
278 | */ |
||
279 | public String getEmail() { |
||
280 | return email; |
||
281 | } |
||
282 | |||
283 | /** |
||
284 | * @param email the email to set |
||
285 | * @return AlternativePayment |
||
286 | */ |
||
287 | public AlternativePayment setEmail(String email) { |
||
288 | this.email = email; |
||
289 | return this; |
||
290 | } |
||
291 | |||
292 | /** |
||
293 | * @return the IP |
||
294 | */ |
||
295 | public String getIP() { |
||
296 | return IP; |
||
297 | } |
||
298 | |||
299 | /** |
||
300 | * @param IP the IP to set |
||
301 | * @return AlternativePayment |
||
302 | */ |
||
303 | public AlternativePayment setIP(String IP) { |
||
304 | this.IP = IP; |
||
305 | return this; |
||
306 | } |
||
307 | |||
308 | /** |
||
309 | * @return the txRef |
||
310 | */ |
||
311 | public String getTxRef() { |
||
312 | return txRef; |
||
313 | } |
||
314 | |||
315 | /** |
||
316 | * @param txRef the txRef to set |
||
317 | * @return AlternativePayment |
||
318 | */ |
||
319 | public AlternativePayment setTxRef(String txRef) { |
||
320 | this.txRef = txRef; |
||
321 | return this; |
||
322 | } |
||
323 | |||
324 | /** |
||
325 | * @return the phonenumber |
||
326 | */ |
||
327 | public String getPhonenumber() { |
||
328 | return phonenumber; |
||
329 | } |
||
330 | |||
331 | /** |
||
332 | * @param phonenumber the phonenumber to set |
||
333 | * @return AlternativePayment |
||
334 | */ |
||
335 | public AlternativePayment setPhonenumber(String phonenumber) { |
||
336 | this.phonenumber = phonenumber; |
||
337 | return this; |
||
338 | } |
||
339 | |||
340 | /** |
||
341 | * @return the orderRef |
||
342 | */ |
||
343 | public String getOrderRef() { |
||
344 | return orderRef; |
||
345 | } |
||
346 | |||
347 | /** |
||
348 | * @param orderRef the orderRef to set |
||
349 | * @return AlternativePayment |
||
350 | */ |
||
351 | public AlternativePayment setOrderRef(String orderRef) { |
||
352 | this.orderRef = orderRef; |
||
353 | return this; |
||
354 | } |
||
355 | |||
356 | /** |
||
357 | * @return the network |
||
358 | */ |
||
359 | public String getNetwork() { |
||
360 | return network; |
||
361 | } |
||
362 | |||
363 | /** |
||
364 | * @param network the network to set |
||
365 | * @return AlternativePayment |
||
366 | */ |
||
367 | public AlternativePayment setNetwork(String network) { |
||
368 | this.network = network; |
||
369 | return this; |
||
370 | } |
||
371 | |||
372 | /** |
||
373 | * @return the flwRef |
||
374 | */ |
||
375 | public String getFlwRef() { |
||
376 | return flwRef; |
||
377 | } |
||
378 | |||
379 | /** |
||
380 | * @param flwRef the flwRef to set |
||
381 | * @return AlternativePayment |
||
382 | */ |
||
383 | public AlternativePayment setFlwRef(String flwRef) { |
||
384 | this.flwRef = flwRef; |
||
385 | return this; |
||
386 | } |
||
387 | } |
||
388 |