theresasogunle /
Rave-Java-Library
| 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 | import static com.github.theresasogunle.Encryption.encryptData; |
||
| 10 | import java.net.InetAddress; |
||
| 11 | import java.net.UnknownHostException; |
||
| 12 | import org.json.JSONException; |
||
| 13 | import org.json.JSONObject; |
||
| 14 | |||
| 15 | |||
| 16 | |||
| 17 | /** |
||
| 18 | * |
||
| 19 | * @author Theresa |
||
| 20 | */ |
||
| 21 | public class PreAuthorization { |
||
| 22 | ApiConnection apiConnection; |
||
| 23 | Endpoints end=new Endpoints(); |
||
| 24 | Encryption e=new Encryption(); |
||
| 25 | private String flwref; |
||
| 26 | private String action; |
||
| 27 | RaveConstant key=new RaveConstant(); |
||
| 28 | private String cardno,cvv,expirymonth,expiryyear,currency,country; |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 29 | private String amount,email,phonenumber,firstname,lastname,IP; |
||
|
0 ignored issues
–
show
|
|||
| 30 | private String txRef,redirect_url,device_fingerprint,charge_type; |
||
|
0 ignored issues
–
show
|
|||
| 31 | /* |
||
| 32 | NB: For Preauth payment please use the keys below: |
||
| 33 | | Public Key | FLWPUBK-8cd258c49f38e05292e5472b2b15906e-X | |
||
| 34 | | Secret Key | FLWSECK-c51891678d48c39eff3701ff686bdb69-X | |
||
| 35 | |||
| 36 | Preauth payments is based on approval per merchant, |
||
| 37 | and is not open to accounts except approval to use these payment method is given. |
||
| 38 | */ |
||
| 39 | /** |
||
| 40 | * @return JSONObject |
||
| 41 | * @throws JSONException |
||
| 42 | */ |
||
| 43 | public JSONObject setJSON(){ |
||
| 44 | JSONObject json= new JSONObject(); |
||
| 45 | try{ |
||
| 46 | InetAddress inetAddress = InetAddress.getLocalHost(); |
||
| 47 | IP= inetAddress.getHostAddress(); |
||
| 48 | String public_key="FLWPUBK-8cd258c49f38e05292e5472b2b15906e-X "; |
||
| 49 | json.put("PBFPubKey",public_key); |
||
| 50 | json.put("cardno", this.getCardno()); |
||
| 51 | json.put("charge_type",this.getCharge_type()); |
||
| 52 | json.put("cvv", this.getCvv()); |
||
| 53 | json.put("expirymonth", this.getExpirymonth()); |
||
| 54 | json.put("expiryyear",this.getExpiryyear()); |
||
| 55 | json.put( "currency", this.getCurrency()); |
||
| 56 | json.put("country", this.getCountry()); |
||
| 57 | json.put("amount",this.getAmount()); |
||
| 58 | json.put("email", this.getEmail()); |
||
| 59 | json.put("phonenumber", this.getPhonenumber()); |
||
| 60 | json.put("firstname", this.getFirstname()); |
||
| 61 | json.put("lastname", this.getLastname()); |
||
| 62 | json.put("IP", IP); |
||
| 63 | json.put("txRef", this.getTxRef()); |
||
| 64 | json.put("redirect_url", this.getRedirect_url()); |
||
| 65 | json.put("device_fingerprint", this.getDevice_fingerprint()); |
||
| 66 | }catch(UnknownHostException | 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();
}
}
}
Loading history...
|
|||
| 67 | return json; |
||
| 68 | |||
| 69 | } |
||
| 70 | /** |
||
| 71 | * @return JSONObject |
||
| 72 | * @throws JSONException |
||
| 73 | */ |
||
| 74 | public JSONObject preAuthorizeCard()throws JSONException{ |
||
| 75 | |||
| 76 | this.apiConnection = new ApiConnection(end.getChargeEndPoint()); |
||
| 77 | JSONObject json= setJSON(); |
||
| 78 | String public_key="FLWPUBK-8cd258c49f38e05292e5472b2b15906e-X "; |
||
| 79 | //preauthorization requires special public key |
||
| 80 | |||
| 81 | |||
| 82 | //else us the normal public key |
||
| 83 | // String public_key=key.getPublicKey(); |
||
| 84 | |||
| 85 | |||
| 86 | //preauthorization requires special public key |
||
| 87 | |||
| 88 | String message= json.toString(); |
||
| 89 | String secret_key="FLWSECK-c51891678d48c39eff3701ff686bdb69-X"; |
||
| 90 | |||
| 91 | String encrypt_secret_key=Encryption.getKey(secret_key); |
||
| 92 | String client= encryptData(message,encrypt_secret_key); |
||
| 93 | String alg="3DES-24"; |
||
| 94 | |||
| 95 | ApiQuery api=new ApiQuery(); |
||
| 96 | |||
| 97 | api.putParams("PBFPubKey", public_key); |
||
| 98 | api.putParams("client", client); |
||
| 99 | api.putParams("alg", alg); |
||
| 100 | System.out.println("Succesful"); |
||
| 101 | |||
| 102 | |||
| 103 | return this.apiConnection.connectAndQuery(api); |
||
| 104 | } |
||
| 105 | /** |
||
| 106 | * @return the JSONObject |
||
| 107 | */ |
||
| 108 | public JSONObject capture(){ |
||
| 109 | this.apiConnection = new ApiConnection(end.getCaptureEndPoint()); |
||
| 110 | ApiQuery api= new ApiQuery(); |
||
| 111 | |||
| 112 | String secret_key="FLWSECK-c51891678d48c39eff3701ff686bdb69-X"; |
||
| 113 | |||
| 114 | // String secret_key=key.getSecretKey(); |
||
| 115 | api.putParams("flwRef", this.getFlwref()); |
||
| 116 | api.putParams("SECKEY", secret_key); |
||
| 117 | |||
| 118 | |||
| 119 | return this.apiConnection.connectAndQuery(api); |
||
| 120 | } |
||
| 121 | /** |
||
| 122 | * @return JSONObject |
||
| 123 | */ |
||
| 124 | |||
| 125 | public JSONObject refundOrVoid(){ |
||
| 126 | this.apiConnection = new ApiConnection(end.getRefundOrVoidEndPoint()); |
||
| 127 | ApiQuery api= new ApiQuery(); |
||
| 128 | String secret_key="FLWSECK-c51891678d48c39eff3701ff686bdb69-X"; |
||
| 129 | // String secret_key=key.getSecretKey(); |
||
| 130 | api.putParams("ref", this.getFlwref()); |
||
| 131 | api.putParams("action", this.getAction()); |
||
| 132 | api.putParams("SECKEY", secret_key); |
||
| 133 | |||
| 134 | return this.apiConnection.connectAndQuery(api); |
||
| 135 | |||
| 136 | } |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @return the flwref |
||
| 140 | */ |
||
| 141 | public String getFlwref() { |
||
| 142 | return flwref; |
||
| 143 | } |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @param flwref the flwref to set |
||
| 147 | * @return PreAuthorization |
||
| 148 | */ |
||
| 149 | public PreAuthorization setFlwref(String flwref) { |
||
| 150 | this.flwref = flwref; |
||
| 151 | return this; |
||
| 152 | } |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @return the action |
||
| 156 | */ |
||
| 157 | public String getAction() { |
||
| 158 | return action; |
||
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @param action the action to set |
||
| 163 | * @return PreAuthorization |
||
| 164 | */ |
||
| 165 | public PreAuthorization setAction(String action) { |
||
| 166 | this.action = action; |
||
| 167 | return this; |
||
| 168 | } |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @return the cardno |
||
| 172 | */ |
||
| 173 | public String getCardno() { |
||
| 174 | return cardno; |
||
| 175 | } |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @param cardno the cardno to set |
||
| 179 | * @return PreAuthorization |
||
| 180 | */ |
||
| 181 | public PreAuthorization setCardno(String cardno) { |
||
| 182 | this.cardno = cardno; |
||
| 183 | return this; |
||
| 184 | } |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @return the cvv |
||
| 188 | */ |
||
| 189 | public String getCvv() { |
||
| 190 | return cvv; |
||
| 191 | } |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @param cvv the cvv to set |
||
| 195 | * @return PreAuthorization |
||
| 196 | */ |
||
| 197 | public PreAuthorization setCvv(String cvv) { |
||
| 198 | this.cvv = cvv; |
||
| 199 | return this; |
||
| 200 | } |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @return the expirymonth |
||
| 204 | */ |
||
| 205 | public String getExpirymonth() { |
||
| 206 | return expirymonth; |
||
| 207 | } |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @param expirymonth the expirymonth to set |
||
| 211 | * @return PreAuthorization |
||
| 212 | */ |
||
| 213 | public PreAuthorization setExpirymonth(String expirymonth) { |
||
| 214 | this.expirymonth = expirymonth; |
||
| 215 | return this; |
||
| 216 | } |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @return the expiryyear |
||
| 220 | */ |
||
| 221 | public String getExpiryyear() { |
||
| 222 | return expiryyear; |
||
| 223 | } |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @param expiryyear the expiryyear to set |
||
| 227 | * @return PreAuthorization |
||
| 228 | */ |
||
| 229 | public PreAuthorization setExpiryyear(String expiryyear) { |
||
| 230 | this.expiryyear = expiryyear; |
||
| 231 | return this; |
||
| 232 | } |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @return the currency |
||
| 236 | */ |
||
| 237 | public String getCurrency() { |
||
| 238 | return currency; |
||
| 239 | } |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @param currency the currency to set |
||
| 243 | * @return PreAuthorization |
||
| 244 | */ |
||
| 245 | public PreAuthorization setCurrency(String currency) { |
||
| 246 | this.currency = currency; |
||
| 247 | return this; |
||
| 248 | } |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @return the country |
||
| 252 | */ |
||
| 253 | public String getCountry() { |
||
| 254 | return country; |
||
| 255 | } |
||
| 256 | |||
| 257 | /** |
||
| 258 | * @param country the country to set |
||
| 259 | * @return PreAuthorization |
||
| 260 | */ |
||
| 261 | public PreAuthorization setCountry(String country) { |
||
| 262 | this.country = country; |
||
| 263 | return this; |
||
| 264 | } |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @return the amount |
||
| 268 | */ |
||
| 269 | public String getAmount() { |
||
| 270 | return amount; |
||
| 271 | } |
||
| 272 | |||
| 273 | /** |
||
| 274 | * @param amount the amount to set |
||
| 275 | * @return PreAuthorization |
||
| 276 | */ |
||
| 277 | public PreAuthorization setAmount(String amount) { |
||
| 278 | this.amount = amount; |
||
| 279 | return this; |
||
| 280 | } |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @return the email |
||
| 284 | */ |
||
| 285 | public String getEmail() { |
||
| 286 | return email; |
||
| 287 | } |
||
| 288 | |||
| 289 | /** |
||
| 290 | * @param email the email to set |
||
| 291 | * @return PreAuthorization |
||
| 292 | */ |
||
| 293 | public PreAuthorization setEmail(String email) { |
||
| 294 | this.email = email; |
||
| 295 | return this; |
||
| 296 | } |
||
| 297 | |||
| 298 | /** |
||
| 299 | * @return the phonenumber |
||
| 300 | */ |
||
| 301 | public String getPhonenumber() { |
||
| 302 | return phonenumber; |
||
| 303 | } |
||
| 304 | |||
| 305 | /** |
||
| 306 | * @param phonenumber the phonenumber to set |
||
| 307 | * @return PreAuthorization |
||
| 308 | */ |
||
| 309 | public PreAuthorization setPhonenumber(String phonenumber) { |
||
| 310 | this.phonenumber = phonenumber; |
||
| 311 | return this; |
||
| 312 | } |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @return the firstname |
||
| 316 | */ |
||
| 317 | public String getFirstname() { |
||
| 318 | return firstname; |
||
| 319 | } |
||
| 320 | |||
| 321 | /** |
||
| 322 | * @param firstname the firstname to set |
||
| 323 | * @return PreAuthorization |
||
| 324 | */ |
||
| 325 | public PreAuthorization setFirstname(String firstname) { |
||
| 326 | this.firstname = firstname; |
||
| 327 | return this; |
||
| 328 | } |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @return the lastname |
||
| 332 | */ |
||
| 333 | public String getLastname() { |
||
| 334 | return lastname; |
||
| 335 | } |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @param lastname the lastname to set |
||
| 339 | * @return PreAuthorization |
||
| 340 | */ |
||
| 341 | public PreAuthorization setLastname(String lastname) { |
||
| 342 | this.lastname = lastname; |
||
| 343 | return this; |
||
| 344 | } |
||
| 345 | |||
| 346 | /** |
||
| 347 | * @return the IP |
||
| 348 | */ |
||
| 349 | public String getIP() { |
||
| 350 | return IP; |
||
| 351 | } |
||
| 352 | |||
| 353 | /** |
||
| 354 | * @param IP the IP to set |
||
| 355 | * @return PreAuthorization |
||
| 356 | */ |
||
| 357 | public PreAuthorization setIP(String IP) { |
||
| 358 | this.IP = IP; |
||
| 359 | return this; |
||
| 360 | } |
||
| 361 | |||
| 362 | /** |
||
| 363 | * @return the txRef |
||
| 364 | */ |
||
| 365 | public String getTxRef() { |
||
| 366 | return txRef; |
||
| 367 | } |
||
| 368 | |||
| 369 | /** |
||
| 370 | * @param txRef the txRef to set |
||
| 371 | * @return PreAuthorization |
||
| 372 | */ |
||
| 373 | public PreAuthorization setTxRef(String txRef) { |
||
| 374 | this.txRef = txRef; |
||
| 375 | return this; |
||
| 376 | } |
||
| 377 | |||
| 378 | /** |
||
| 379 | * @return the redirect_url |
||
| 380 | */ |
||
| 381 | public String getRedirect_url() { |
||
| 382 | return redirect_url; |
||
| 383 | } |
||
| 384 | |||
| 385 | /** |
||
| 386 | * @param redirect_url the redirect_url to set |
||
| 387 | * @return PreAuthorization |
||
| 388 | */ |
||
| 389 | public PreAuthorization setRedirect_url(String redirect_url) { |
||
| 390 | this.redirect_url = redirect_url; |
||
| 391 | return this; |
||
| 392 | } |
||
| 393 | |||
| 394 | /** |
||
| 395 | * @return the device_fingerprint |
||
| 396 | */ |
||
| 397 | public String getDevice_fingerprint() { |
||
| 398 | return device_fingerprint; |
||
| 399 | } |
||
| 400 | |||
| 401 | /** |
||
| 402 | * @param device_fingerprint the device_fingerprint to set |
||
| 403 | * @return PreAuthorization |
||
| 404 | */ |
||
| 405 | public PreAuthorization setDevice_fingerprint(String device_fingerprint) { |
||
| 406 | this.device_fingerprint = device_fingerprint; |
||
| 407 | return this; |
||
| 408 | } |
||
| 409 | |||
| 410 | /** |
||
| 411 | * @return the charge_type |
||
| 412 | */ |
||
| 413 | public String getCharge_type() { |
||
| 414 | return charge_type; |
||
| 415 | } |
||
| 416 | |||
| 417 | /** |
||
| 418 | * @param charge_type the charge_type to set |
||
| 419 | * @return PreAuthorization |
||
| 420 | */ |
||
| 421 | public PreAuthorization setCharge_type(String charge_type) { |
||
| 422 | this.charge_type = charge_type; |
||
| 423 | return this; |
||
| 424 | } |
||
| 425 | } |
||
| 426 |