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 | |||
11 | import static com.github.theresasogunle.Encryption.encryptData; |
||
12 | import static com.github.theresasogunle.Encryption.getKey; |
||
13 | import java.awt.Desktop; |
||
14 | import java.io.IOException; |
||
15 | import java.net.URI; |
||
16 | import java.net.URISyntaxException; |
||
17 | import org.json.JSONException; |
||
18 | |||
19 | import org.json.JSONObject; |
||
20 | |||
21 | /** |
||
22 | * |
||
23 | * @author Theresa |
||
24 | */ |
||
25 | public class CardCharge { |
||
26 | JSONObject api=new JSONObject(); |
||
27 | Endpoints ed=new Endpoints(); |
||
28 | ApiConnection apiConnection; |
||
29 | |||
30 | Encryption e=new Encryption(); |
||
31 | private String cardno,cvv,expirymonth,expiryyear,currency,country,pin,suggested_auth, |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
32 | amount,email,phonenumber,firstname,lastname,txRef,redirect_url,device_fingerprint,IP, |
||
0 ignored issues
–
show
|
|||
33 | charge_type; |
||
0 ignored issues
–
show
|
|||
34 | |||
35 | private String transactionreference,otp, authUrl; |
||
0 ignored issues
–
show
|
|||
36 | /** |
||
37 | * |
||
38 | |||
39 | * |
||
40 | * @return JSONObject |
||
41 | */ |
||
42 | |||
43 | public JSONObject setJSON() { |
||
44 | JSONObject json=new JSONObject(); |
||
45 | try{ |
||
46 | |||
47 | json.put("cardno", this.getCardno()); |
||
48 | json.put("cvv", this.getCvv()); |
||
49 | json.put("currency", this.getCurrency()); |
||
50 | json.put("country", this.getCountry()); |
||
51 | json.put("amount", this.getAmount()); |
||
52 | json.put("expiryyear", this.getExpiryyear()); |
||
53 | json.put("expirymonth", this.getExpirymonth()); |
||
54 | json.put("email", this.getEmail()); |
||
55 | json.put("IP", this.getIP()); |
||
56 | json.put("txRef", this.getTxRef()); |
||
57 | json.put("device_fingerprint", this.getDevice_fingerprint()); |
||
58 | // json.put("pin", this.getPin()); |
||
59 | //json.put("suggested_auth", this.getSuggested_auth()); |
||
60 | json.put("firstname", this.getFirstname()); |
||
61 | json.put("lastname", this.getLastname()); |
||
62 | json.put("redirect_url", this.getRedirect_url()); |
||
63 | json.put("charge_type", this.getCharge_type()); |
||
64 | }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();
}
}
}
![]() |
|||
65 | return json; |
||
66 | } |
||
67 | |||
68 | |||
69 | public JSONObject chargeMasterAndVerveCard() throws JSONException{ |
||
70 | JSONObject json= setJSON(); |
||
71 | |||
72 | json.put("PBFPubKey",RaveConstant.PUBLIC_KEY); |
||
73 | json.put("pin",this.getPin() ); |
||
74 | json.put("suggested_auth",this.getSuggested_auth() ); |
||
75 | |||
76 | |||
77 | String message= json.toString(); |
||
78 | |||
79 | String encrypt_secret_key=getKey(RaveConstant.SECRET_KEY); |
||
80 | String client= encryptData(message,encrypt_secret_key); |
||
81 | |||
82 | Charge ch=new Charge(); |
||
83 | |||
84 | return ch.charge(client); |
||
85 | |||
86 | } |
||
87 | public JSONObject chargeMasterAndVerveCard(boolean polling) { |
||
0 ignored issues
–
show
|
|||
88 | JSONObject json= setJSON(); |
||
89 | |||
90 | json.put("PBFPubKey",RaveConstant.PUBLIC_KEY); |
||
91 | json.put("pin",this.getPin() ); |
||
92 | json.put("suggested_auth",this.getSuggested_auth() ); |
||
93 | Polling p=new Polling(); |
||
94 | |||
95 | return p.handleTimeoutCharge(json); |
||
96 | |||
97 | } |
||
98 | public JSONObject chargeVisaAndIntl() throws JSONException{ |
||
99 | JSONObject json= setJSON(); |
||
100 | json.put("PBFPubKey",RaveConstant.PUBLIC_KEY); |
||
101 | json.put("redirect_url", this.getRedirect_url() ); |
||
102 | |||
103 | String message= json.toString(); |
||
104 | |||
105 | String encrypt_secret_key=getKey(RaveConstant.SECRET_KEY); |
||
106 | String client= encryptData(message,encrypt_secret_key); |
||
107 | |||
108 | Charge ch=new Charge(); |
||
109 | |||
110 | return ch.charge(client); |
||
111 | |||
112 | } |
||
113 | |||
114 | public JSONObject chargeVisaAndIntl(boolean polling) throws JSONException{ |
||
0 ignored issues
–
show
|
|||
115 | JSONObject json= setJSON(); |
||
116 | json.put("PBFPubKey",RaveConstant.PUBLIC_KEY); |
||
117 | json.put("redirect_url", this.getRedirect_url() ); |
||
118 | Polling p=new Polling(); |
||
119 | |||
120 | return p.handleTimeoutCharge(json); |
||
121 | |||
122 | } |
||
123 | |||
124 | |||
125 | /* |
||
126 | if AuthMode::"PIN" |
||
127 | @params transaction reference(flwRef),OTP |
||
128 | * @return JSONObject |
||
129 | */ |
||
130 | |||
131 | public JSONObject validateCardCharge(){ |
||
132 | Charge vch= new Charge(); |
||
133 | |||
134 | return vch.validateCardCharge(this.getTransactionreference(), this.getOtp()); |
||
135 | } |
||
136 | //if timeout |
||
137 | public JSONObject validateCardCharge(boolean polling){ |
||
0 ignored issues
–
show
|
|||
138 | |||
139 | Polling p=new Polling(); |
||
140 | |||
141 | return p.validateCardChargeTimeout(this.getTransactionreference(), this.getOtp()); |
||
142 | } |
||
143 | |||
144 | /* |
||
145 | if AuthMode::"VBSECURE"or "AVS_VBVSECURECODE" |
||
146 | @params authUrl This requires that you copy the authurl returned in the response |
||
147 | and paste it in the argument and it opens a small window for card validation |
||
148 | */ |
||
149 | public void validateCardChargeVB(){ |
||
150 | |||
151 | if (Desktop.isDesktopSupported()) { |
||
152 | try{ |
||
153 | Desktop.getDesktop().browse(new URI(this.getAuthUrl())); |
||
154 | }catch(URISyntaxException | IOException ex){} |
||
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();
}
}
}
![]() |
|||
155 | } |
||
156 | } |
||
157 | |||
158 | |||
159 | /** |
||
160 | * @return the cardno |
||
161 | */ |
||
162 | public String getCardno() { |
||
163 | return cardno; |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * @param cardno the cardno to set |
||
168 | * @return CardCharge |
||
169 | */ |
||
170 | public CardCharge setCardno(String cardno) { |
||
171 | this.cardno = cardno; |
||
172 | |||
173 | return this; |
||
174 | } |
||
175 | |||
176 | /** |
||
177 | * @return the cvv |
||
178 | */ |
||
179 | public String getCvv() { |
||
180 | return cvv; |
||
181 | } |
||
182 | |||
183 | /** |
||
184 | * @param cvv the cvv to set |
||
185 | * @return CardCharge |
||
186 | */ |
||
187 | public CardCharge setCvv(String cvv) { |
||
188 | this.cvv = cvv; |
||
189 | |||
190 | return this; |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * @return the expirymonth |
||
195 | */ |
||
196 | public String getExpirymonth() { |
||
197 | return expirymonth; |
||
198 | } |
||
199 | |||
200 | /** |
||
201 | * @param expirymonth the expirymonth to set |
||
202 | * @return CardCharge |
||
203 | */ |
||
204 | public CardCharge setExpirymonth(String expirymonth) { |
||
205 | this.expirymonth = expirymonth; |
||
206 | |||
207 | return this; |
||
208 | } |
||
209 | |||
210 | /** |
||
211 | * @return the expiryyear |
||
212 | */ |
||
213 | public String getExpiryyear() { |
||
214 | return expiryyear; |
||
215 | } |
||
216 | |||
217 | /** |
||
218 | * @param expiryyear the expiryyear to set |
||
219 | * @return CardCharge |
||
220 | */ |
||
221 | public CardCharge setExpiryyear(String expiryyear) { |
||
222 | this.expiryyear = expiryyear; |
||
223 | |||
224 | return this; |
||
225 | } |
||
226 | |||
227 | /** |
||
228 | * @return the currency |
||
229 | */ |
||
230 | public String getCurrency() { |
||
231 | return currency; |
||
232 | } |
||
233 | |||
234 | /** |
||
235 | * @param currency the currency to set |
||
236 | * @return CardCharge |
||
237 | */ |
||
238 | public CardCharge setCurrency(String currency) { |
||
239 | this.currency = currency; |
||
240 | |||
241 | return this; |
||
242 | } |
||
243 | |||
244 | /** |
||
245 | * @return the country |
||
246 | */ |
||
247 | public String getCountry() { |
||
248 | return country; |
||
249 | } |
||
250 | |||
251 | /** |
||
252 | * @param country the country to set |
||
253 | * @return CardCharge |
||
254 | */ |
||
255 | public CardCharge setCountry(String country) { |
||
256 | this.country = country; |
||
257 | |||
258 | return this; |
||
259 | } |
||
260 | |||
261 | /** |
||
262 | * @return the pin |
||
263 | */ |
||
264 | public String getPin() { |
||
265 | return pin; |
||
266 | } |
||
267 | |||
268 | /** |
||
269 | * @param pin the pin to set |
||
270 | * @return CardCharge |
||
271 | */ |
||
272 | public CardCharge setPin(String pin) { |
||
273 | this.pin = pin; |
||
274 | |||
275 | return this; |
||
276 | } |
||
277 | |||
278 | /** |
||
279 | * @return the suggested_auth |
||
280 | */ |
||
281 | public String getSuggested_auth() { |
||
282 | return suggested_auth; |
||
283 | } |
||
284 | |||
285 | /** |
||
286 | * @param suggested_auth the suggested_auth to set |
||
287 | * @return CardCharge |
||
288 | */ |
||
289 | public CardCharge setSuggested_auth(String suggested_auth) { |
||
290 | this.suggested_auth = suggested_auth; |
||
291 | |||
292 | return this; |
||
293 | } |
||
294 | |||
295 | /** |
||
296 | * @return the amount |
||
297 | */ |
||
298 | public String getAmount() { |
||
299 | return amount; |
||
300 | } |
||
301 | |||
302 | /** |
||
303 | * @param amount the amount to set |
||
304 | * @return CardCharge |
||
305 | */ |
||
306 | public CardCharge setAmount(String amount) { |
||
307 | this.amount = amount; |
||
308 | |||
309 | return this; |
||
310 | } |
||
311 | |||
312 | /** |
||
313 | * @return the email |
||
314 | */ |
||
315 | public String getEmail() { |
||
316 | return email; |
||
317 | } |
||
318 | |||
319 | /** |
||
320 | * @param email the email to set |
||
321 | * @return CardCharge |
||
322 | */ |
||
323 | public CardCharge setEmail(String email) { |
||
324 | this.email = email; |
||
325 | |||
326 | return this; |
||
327 | } |
||
328 | |||
329 | /** |
||
330 | * @return the phonenumber |
||
331 | */ |
||
332 | public String getPhonenumber() { |
||
333 | return phonenumber; |
||
334 | } |
||
335 | |||
336 | /** |
||
337 | * @param phonenumber the phonenumber to set |
||
338 | * @return CardCharge |
||
339 | */ |
||
340 | public CardCharge setPhonenumber(String phonenumber) { |
||
341 | this.phonenumber = phonenumber; |
||
342 | |||
343 | return this; |
||
344 | } |
||
345 | |||
346 | /** |
||
347 | * @return the firstname |
||
348 | */ |
||
349 | public String getFirstname() { |
||
350 | return firstname; |
||
351 | } |
||
352 | |||
353 | /** |
||
354 | * @param firstname the firstname to set |
||
355 | * @return CardCharge |
||
356 | */ |
||
357 | public CardCharge setFirstname(String firstname) { |
||
358 | this.firstname = firstname; |
||
359 | |||
360 | return this; |
||
361 | } |
||
362 | |||
363 | /** |
||
364 | * @return the lastname |
||
365 | */ |
||
366 | public String getLastname() { |
||
367 | return lastname; |
||
368 | } |
||
369 | |||
370 | /** |
||
371 | * @param lastname the lastname to set |
||
372 | * @return CardCharge |
||
373 | */ |
||
374 | public CardCharge setLastname(String lastname) { |
||
375 | this.lastname = lastname; |
||
376 | |||
377 | return this; |
||
378 | } |
||
379 | |||
380 | /** |
||
381 | * @return the IP |
||
382 | */ |
||
383 | public String getIP() { |
||
384 | return IP; |
||
385 | } |
||
386 | |||
387 | /** |
||
388 | * @param IP the IP to set |
||
389 | * @return CardCharge |
||
390 | */ |
||
391 | public CardCharge setIP(String IP) { |
||
392 | this.IP = IP; |
||
393 | |||
394 | return this; |
||
395 | } |
||
396 | |||
397 | /** |
||
398 | * @return the txRef |
||
399 | */ |
||
400 | public String getTxRef() { |
||
401 | return txRef; |
||
402 | } |
||
403 | |||
404 | /** |
||
405 | * @param txRef the txRef to set |
||
406 | * @return CardCharge |
||
407 | */ |
||
408 | public CardCharge setTxRef(String txRef) { |
||
409 | this.txRef = txRef; |
||
410 | |||
411 | return this; |
||
412 | } |
||
413 | |||
414 | /** |
||
415 | * @return the redirect_url |
||
416 | */ |
||
417 | public String getRedirect_url() { |
||
418 | return redirect_url; |
||
419 | } |
||
420 | |||
421 | /** |
||
422 | * @param redirect_url the redirect_url to set |
||
423 | * @return CardCharge |
||
424 | */ |
||
425 | public CardCharge setRedirect_url(String redirect_url) { |
||
426 | this.redirect_url = redirect_url; |
||
427 | |||
428 | return this; |
||
429 | } |
||
430 | |||
431 | /** |
||
432 | * @return the device_fingerprint |
||
433 | */ |
||
434 | public String getDevice_fingerprint() { |
||
435 | return device_fingerprint; |
||
436 | } |
||
437 | |||
438 | /** |
||
439 | * @param device_fingerprint the device_fingerprint to set |
||
440 | * @return CardCharge |
||
441 | */ |
||
442 | public CardCharge setDevice_fingerprint(String device_fingerprint) { |
||
443 | this.device_fingerprint = device_fingerprint; |
||
444 | |||
445 | return this; |
||
446 | } |
||
447 | |||
448 | /** |
||
449 | * @return the charge_type |
||
450 | */ |
||
451 | public String getCharge_type() { |
||
452 | return charge_type; |
||
453 | } |
||
454 | |||
455 | /** |
||
456 | * @param charge_type the charge_type to set |
||
457 | * @return CardCharge |
||
458 | */ |
||
459 | public CardCharge setCharge_type(String charge_type) { |
||
460 | this.charge_type = charge_type; |
||
461 | |||
462 | return this; |
||
463 | } |
||
464 | |||
465 | /** |
||
466 | * @return the transaction_reference |
||
467 | */ |
||
468 | public String getTransactionreference() { |
||
469 | return transactionreference; |
||
470 | } |
||
471 | |||
472 | /** |
||
473 | * @param transaction_reference the transaction_reference to set |
||
474 | * @return CardCharge |
||
475 | */ |
||
476 | public CardCharge setTransactionreference(String transaction_reference) { |
||
477 | this.transactionreference= transaction_reference; |
||
478 | |||
479 | return this; |
||
480 | } |
||
481 | |||
482 | /** |
||
483 | * @return the otp |
||
484 | */ |
||
485 | public String getOtp() { |
||
486 | return otp; |
||
487 | } |
||
488 | |||
489 | /** |
||
490 | * @param otp the otp to set |
||
491 | * @return CardCharge |
||
492 | */ |
||
493 | public CardCharge setOtp(String otp) { |
||
494 | this.otp = otp; |
||
495 | |||
496 | return this; |
||
497 | } |
||
498 | |||
499 | /** |
||
500 | * @return the authUrl |
||
501 | */ |
||
502 | public String getAuthUrl() { |
||
503 | return authUrl; |
||
504 | } |
||
505 | |||
506 | /** |
||
507 | * @param authUrl the authUrl to set |
||
508 | * @return CardCharge |
||
509 | */ |
||
510 | public CardCharge setAuthUrl(String authUrl) { |
||
511 | this.authUrl = authUrl; |
||
512 | |||
513 | return this; |
||
514 | } |
||
515 | } |
||
516 |