Passed
Push — master ( fe77d5...879265 )
by Sogunle
02:02
created

com.rave.CardCharge   C

Complexity

Total Complexity 53

Size/Duplication

Total Lines 489
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 53
c 1
b 0
f 0
dl 0
loc 489
rs 6.96

59 Methods

Rating   Name   Duplication   Size   Complexity  
A chargeVisaAndIntl(boolean) 0 7 1
A chargeMasterAndVerveCard() 0 16 1
chargeMasterAndVerveCard 0 16 ?
A validateCardCharge(boolean) 0 5 1
A setDevice_fingerprint(String) 0 4 1
A getSuggested_auth() 0 2 1
validateCardChargeVB 0 6 ?
A setLastname(String) 0 4 1
A setAmount(String) 0 4 1
A getPin() 0 2 1
A chargeVisaAndIntl() 0 13 1
A setExpiryyear(String) 0 4 1
A getExpiryyear() 0 2 1
A getAmount() 0 2 1
A setCountry(String) 0 4 1
A getCardno() 0 2 1
A setCardno(String) 0 4 1
A setCvv(String) 0 4 1
A setPin(String) 0 4 1
A getRedirect_url() 0 2 1
A setEmail(String) 0 4 1
A getCharge_type() 0 2 1
A setTxRef(String) 0 4 1
A getAuthUrl() 0 2 1
A getEmail() 0 2 1
A setExpirymonth(String) 0 4 1
A setJSON() 0 23 2
A setIP(String) 0 4 1
A getTxRef() 0 2 1
chargeVisaAndIntl 0 13 ?
A getPhonenumber() 0 2 1
A chargeMasterAndVerveCard(boolean) 0 9 1
A getCountry() 0 2 1
A getCurrency() 0 2 1
A getDevice_fingerprint() 0 2 1
A setCharge_type(String) 0 4 1
getSuggested_auth 0 2 ?
A getLastname() 0 2 1
A setTransactionreference(String) 0 4 1
A setAuthUrl(String) 0 4 1
getAuthUrl 0 2 ?
A getExpirymonth() 0 2 1
A setFirstname(String) 0 4 1
A setRedirect_url(String) 0 4 1
setAuthUrl 0 4 ?
A getFirstname() 0 2 1
A getIP() 0 2 1
A setPhonenumber(String) 0 4 1
setTransactionreference 0 4 ?
A validateCardChargeVB() 0 6 3
getTransactionreference 0 2 ?
A setCurrency(String) 0 4 1
A getCvv() 0 2 1
A setOtp(String) 0 4 1
A getTransactionreference() 0 2 1
A setSuggested_auth(String) 0 4 1
A getOtp() 0 2 1
setSuggested_auth 0 4 ?
A validateCardCharge() 0 4 1

How to fix   Complexity   

Complexity

Complex classes like com.rave.CardCharge often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

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