2929import java .util .HashMap ;
3030import java .util .List ;
3131
32+ import static com .flutterwave .raveandroid .RaveConstants .*;
33+
3234/**
3335 * Created by hamzafetuga on 20/07/2017.
3436 */
@@ -136,15 +138,15 @@ public void onSuccess(ChargeResponse response, String responseAsJSONString) {
136138 String status = response .getStatus ();
137139 String message = response .getMessage ();
138140
139- if (status .equalsIgnoreCase (RaveConstants . success )) {
141+ if (status .equalsIgnoreCase (success )) {
140142 mView .onValidateSuccessful (flwRef , responseAsJSONString );
141143 }
142144 else {
143145 mView .onValidateError (status , responseAsJSONString );
144146 }
145147 }
146148 else {
147- mView .onPaymentError (RaveConstants . invalidCharge );
149+ mView .onPaymentError (invalidCharge );
148150 }
149151 }
150152
@@ -179,15 +181,15 @@ public void onSuccess(FeeCheckResponse response) {
179181 }
180182 catch (Exception e ) {
181183 e .printStackTrace ();
182- mView .showFetchFeeFailed ("An error occurred while retrieving transaction fee" );
184+ mView .showFetchFeeFailed (transactionError );
183185 }
184186 }
185187
186188 @ Override
187189 public void onError (String message ) {
188190 mView .showProgressIndicator (false );
189- Log .e (RaveConstants . RAVEPAY , message );
190- mView .showFetchFeeFailed ("An error occurred while retrieving transaction fee" );
191+ Log .e (RAVEPAY , message );
192+ mView .showFetchFeeFailed (transactionError );
191193 }
192194 });
193195 }
@@ -234,56 +236,59 @@ public void onDataCollected(HashMap<String, ViewObject> dataHashMap) {
234236
235237 boolean valid = true ;
236238
237- int amountID = dataHashMap .get (RaveConstants . fieldAmount ).getViewId ();
238- String amount = dataHashMap .get (RaveConstants . fieldAmount ).getData ();
239- Class amountViewType = dataHashMap .get (RaveConstants . fieldAmount ).getViewType ();
239+ int amountID = dataHashMap .get (fieldAmount ).getViewId ();
240+ String amount = dataHashMap .get (fieldAmount ).getData ();
241+ Class amountViewType = dataHashMap .get (fieldAmount ).getViewType ();
240242
241- int emailID = dataHashMap .get (RaveConstants . fieldEmail ).getViewId ();
242- String email = dataHashMap .get (RaveConstants . fieldEmail ).getData ();
243- Class emailViewType = dataHashMap .get (RaveConstants . fieldEmail ).getViewType ();
243+ int emailID = dataHashMap .get (fieldEmail ).getViewId ();
244+ String email = dataHashMap .get (fieldEmail ).getData ();
245+ Class emailViewType = dataHashMap .get (fieldEmail ).getViewType ();
244246
245- int accountID = dataHashMap .get (RaveConstants . fieldAccount ).getViewId ();
246- String account = dataHashMap .get (RaveConstants . fieldAccount ).getData ();
247- Class accountViewType = dataHashMap .get (RaveConstants . fieldAccount ).getViewType ();
247+ int accountID = dataHashMap .get (fieldAccount ).getViewId ();
248+ String account = dataHashMap .get (fieldAccount ).getData ();
249+ Class accountViewType = dataHashMap .get (fieldAccount ).getViewType ();
248250
249- int phoneID = dataHashMap .get (RaveConstants . fieldPhone ).getViewId ();
250- String phone = dataHashMap .get (RaveConstants . fieldPhone ).getData ();
251- Class phoneViewType = dataHashMap .get (RaveConstants . fieldPhone ).getViewType ();
251+ int phoneID = dataHashMap .get (fieldPhone ).getViewId ();
252+ String phone = dataHashMap .get (fieldPhone ).getData ();
253+ Class phoneViewType = dataHashMap .get (fieldPhone ).getViewType ();
252254
255+ boolean isAmountValid = amountValidator .isAmountValid (Double .valueOf (amount ));
256+ boolean isPhoneValid = phoneValidator .isPhoneValid (phone );
257+ boolean isEmailValid = emailValidator .isEmailValid (email );
253258
254- if (!amountValidator . isAmountValid ( Double . valueOf ( amount )) ) {
259+ if (!isAmountValid ) {
255260 valid = false ;
256- mView .showFieldError (amountID , RaveConstants . validAmountPrompt , amountViewType );
261+ mView .showFieldError (amountID , validAmountPrompt , amountViewType );
257262 }
258263
259- if (!phoneValidator . isPhoneValid ( phone ) ) {
264+ if (!isPhoneValid ) {
260265 valid = false ;
261- mView .showFieldError (phoneID , RaveConstants . validPhonePrompt , phoneViewType );
266+ mView .showFieldError (phoneID , validPhonePrompt , phoneViewType );
262267 }
263268
264- if (!emailValidator . isEmailValid ( email ) ) {
269+ if (!isEmailValid ) {
265270 valid = false ;
266- mView .showFieldError (emailID , RaveConstants . validEmailPrompt , emailViewType );
271+ mView .showFieldError (emailID , validEmailPrompt , emailViewType );
267272 }
268273
269274 if (account .isEmpty ()) {
270275 valid = false ;
271- mView .showFieldError (accountID , "Enter a valid account number" , phoneViewType );
276+ mView .showFieldError (accountID , accounNumberPrompt , phoneViewType );
272277 } else {
273- account = "0000000000" ;
278+ account = defaultAccounNumber ;
274279 }
275280
276281 try {
277282 double amnt = Double .parseDouble (amount );
278283
279284 if (amnt <= 0 ) {
280285 valid = false ;
281- mView .showToast (RaveConstants . validAmountPrompt );
286+ mView .showToast (validAmountPrompt );
282287 }
283288 } catch (Exception e ) {
284289 e .printStackTrace ();
285290 valid = false ;
286- mView .showToast (RaveConstants . validAmountPrompt );
291+ mView .showToast (validAmountPrompt );
287292 }
288293
289294 if (valid ){
@@ -299,32 +304,32 @@ public void processTransaction(HashMap<String, ViewObject> dataHashMap, RavePayI
299304
300305 if (ravePayInitializer !=null ) {
301306 PayloadBuilder builder = new PayloadBuilder ();
302- builder .setAmount (ravePayInitializer .getAmount () + "" )
303- .setEmail (dataHashMap .get (RaveConstants . fieldEmail ).getData ())
304- .setCountry ("NG" ).setCurrency (" NGN" )
307+ builder .setAmount (String . valueOf ( ravePayInitializer .getAmount ()) )
308+ .setEmail (dataHashMap .get (fieldEmail ).getData ())
309+ .setCountry (NG ).setCurrency (NGN )
305310 .setPBFPubKey (ravePayInitializer .getPublicKey ())
306311 .setDevice_fingerprint (Utils .getDeviceImei (context ))
307312 .setIP (Utils .getDeviceImei (context )).setTxRef (ravePayInitializer .getTxRef ())
308- .setAccountbank (dataHashMap .get (RaveConstants . fieldBankCode ).getData ())
313+ .setAccountbank (dataHashMap .get (fieldBankCode ).getData ())
309314 .setMeta (ravePayInitializer .getMeta ())
310315 .setSubAccount (ravePayInitializer .getSubAccount ())
311- .setAccountnumber (dataHashMap .get (RaveConstants . fieldAccount ).getData ())
312- .setBVN (RaveConstants . fieldBVN )
316+ .setAccountnumber (dataHashMap .get (fieldAccount ).getData ())
317+ .setBVN (fieldBVN )
313318 .setIsPreAuth (ravePayInitializer .getIsPreAuth ());
314319
315320 Payload body = builder .createBankPayload ();
316- body .setPasscode (RaveConstants . date_of_birth );
317- body .setPhonenumber (RaveConstants . fieldPhone );
321+ body .setPasscode (date_of_birth );
322+ body .setPhonenumber (fieldPhone );
318323
319- if ((dataHashMap .get (RaveConstants . fieldBankCode ).getData ().equalsIgnoreCase ("058" ) ||
320- dataHashMap .get (RaveConstants . fieldBankCode ).getData ().equalsIgnoreCase ("011" ))
321- && (Double .parseDouble (dataHashMap .get (RaveConstants . fieldAmount ).getData ()) <= 100 )) {
324+ if ((dataHashMap .get (fieldBankCode ).getData ().equalsIgnoreCase ("058" ) ||
325+ dataHashMap .get (fieldBankCode ).getData ().equalsIgnoreCase ("011" ))
326+ && (Double .parseDouble (dataHashMap .get (fieldAmount ).getData ()) <= 100 )) {
322327 mView .showGTBankAmountIssue ();
323328 } else {
324329 if (ravePayInitializer .getIsDisplayFee ()) {
325- fetchFee (body , Boolean .valueOf (dataHashMap .get (RaveConstants . isInternetBanking ).getData ()));
330+ fetchFee (body , Boolean .valueOf (dataHashMap .get (isInternetBanking ).getData ()));
326331 } else {
327- chargeAccount (body , ravePayInitializer .getEncryptionKey (), Boolean .valueOf (dataHashMap .get (RaveConstants . isInternetBanking ).getData ()));
332+ chargeAccount (body , ravePayInitializer .getEncryptionKey (), Boolean .valueOf (dataHashMap .get (isInternetBanking ).getData ()));
328333 }
329334 }
330335 }
@@ -345,8 +350,10 @@ public void onDetachView() {
345350 public void init (RavePayInitializer ravePayInitializer ) {
346351
347352 if (ravePayInitializer !=null ) {
353+
348354 boolean isEmailValid = emailValidator .isEmailValid (ravePayInitializer .getEmail ());
349355 boolean isAmountValid = amountValidator .isAmountValid (ravePayInitializer .getAmount ());
356+
350357 if (isEmailValid ) {
351358 mView .onEmailValidated (ravePayInitializer .getEmail (), View .GONE );
352359 } else {
0 commit comments