44import android .os .Bundle ;
55import android .util .Log ;
66
7+ import com .flutterwave .raveandroid .DeviceIdGetter ;
78import com .flutterwave .raveandroid .FeeCheckRequestBody ;
9+ import com .flutterwave .raveandroid .GetEncryptedData ;
810import com .flutterwave .raveandroid .Payload ;
911import com .flutterwave .raveandroid .PayloadBuilder ;
12+ import com .flutterwave .raveandroid .PayloadToJson ;
1013import com .flutterwave .raveandroid .RaveConstants ;
1114import com .flutterwave .raveandroid .RavePayInitializer ;
12- import com .flutterwave .raveandroid .Utils ;
1315import com .flutterwave .raveandroid .ViewObject ;
1416import com .flutterwave .raveandroid .card .ChargeRequestBody ;
1517import com .flutterwave .raveandroid .data .Callbacks ;
2830 * Created by hfetuga on 27/06/2018.
2931 */
3032
33+
3134public class BankTransferPresenter implements BankTransferContract .UserActionsListener {
3235 private static final String ACCOUNT_NUMBER = "account_number" ;
3336 private static final String BANK_NAME = "bank_name" ;
@@ -41,18 +44,21 @@ public class BankTransferPresenter implements BankTransferContract.UserActionsLi
4144 AmountValidator amountValidator ;
4245 @ Inject
4346 NetworkRequestImpl networkRequest ;
44-
45- private Context context ;
46- private BankTransferContract .View mView ;
47+ public boolean pollingCancelled = false ;
48+ public boolean hasTransferDetails = false ;
49+ @ Inject
50+ DeviceIdGetter deviceIdGetter ;
51+ BankTransferContract .View mView ;
4752 private String txRef = null , flwRef = null , publicKey = null ;
4853 private long requeryCountdownTime = 0 ;
49- private boolean pollingCancelled = false ;
54+ @ Inject
55+ PayloadToJson payloadToJson ;
5056 private String beneficiaryName , accountNumber , amount , bankName ;
51- private boolean hasTransferDetails = false ;
57+ @ Inject
58+ GetEncryptedData getEncryptedData ;
5259
5360 @ Inject
5461 BankTransferPresenter (Context context , BankTransferContract .View mView ) {
55- this .context = context ;
5662 this .mView = mView ;
5763 }
5864
@@ -74,7 +80,6 @@ public void onSuccess(FeeCheckResponse response) {
7480 try {
7581 mView .displayFee (response .getData ().getCharge_amount (), payload );
7682 } catch (Exception e ) {
77- e .printStackTrace ();
7883 mView .showFetchFeeFailed ("An error occurred while retrieving transaction fee" );
7984 }
8085 }
@@ -90,8 +95,8 @@ public void onError(String message) {
9095
9196 @ Override
9297 public void payWithBankTransfer (final Payload payload , final String encryptionKey ) {
93- String cardRequestBodyAsString = Utils .convertChargeRequestPayloadToJson (payload );
94- String encryptedCardRequestBody = Utils .getEncryptedData (cardRequestBodyAsString , encryptionKey );
98+ String cardRequestBodyAsString = payloadToJson .convertChargeRequestPayloadToJson (payload );
99+ String encryptedCardRequestBody = getEncryptedData .getEncryptedData (cardRequestBodyAsString , encryptionKey );
95100 encryptedCardRequestBody = encryptedCardRequestBody .trim ().replaceAll ("\\ n" , "" );
96101
97102 ChargeRequestBody body = new ChargeRequestBody ();
@@ -143,7 +148,7 @@ public void onError(String message, String responseAsJSONString) {
143148 public void startPaymentVerification () {
144149 requeryCountdownTime = System .currentTimeMillis ();
145150 mView .showPollingIndicator (true );
146- requeryTx ();
151+ requeryTx (flwRef , txRef , publicKey , pollingCancelled , requeryCountdownTime );
147152 }
148153
149154 @ Override
@@ -184,15 +189,17 @@ public void restoreState(Bundle savedInstanceState) {
184189 }
185190
186191 @ Override
187- public void requeryTx () {
192+ public void requeryTx (final String flwRef , final String txRef , final String publicKey , final boolean pollingCancelled , final long requeryCountdownTime ) {
188193
189194 RequeryRequestBody body = new RequeryRequestBody ();
190195 body .setFlw_ref (flwRef );
191196 body .setPBFPubKey (publicKey );
192197
193198 networkRequest .requeryPayWithBankTx (body , new Callbacks .OnRequeryRequestComplete () {
199+
194200 @ Override
195201 public void onSuccess (RequeryResponse response , String responseAsJSONString ) {
202+
196203 if (response .getData () == null ) {
197204 mView .onPaymentFailed (response .getStatus (), responseAsJSONString );
198205 } else if (response .getData ().getChargeResponseCode ().equals ("01" )) {
@@ -201,7 +208,7 @@ public void onSuccess(RequeryResponse response, String responseAsJSONString) {
201208 mView .onPollingCanceled (flwRef , txRef , responseAsJSONString );
202209 } else {
203210 if ((System .currentTimeMillis () - requeryCountdownTime ) < 300000 ) {
204- requeryTx ();
211+ requeryTx (flwRef , txRef , publicKey , pollingCancelled , requeryCountdownTime );
205212 } else {
206213 mView .showPollingIndicator (false );
207214 mView .onPollingTimeout (flwRef , txRef , responseAsJSONString );
@@ -273,13 +280,13 @@ public void processTransaction(HashMap<String, ViewObject> dataHashMap, RavePayI
273280 .setEmail (ravePayInitializer .getEmail ())
274281 .setFirstname (ravePayInitializer .getfName ())
275282 .setLastname (ravePayInitializer .getlName ())
276- .setIP (Utils . getDeviceImei ( context ))
283+ .setIP (deviceIdGetter . getDeviceId ( ))
277284 .setTxRef (ravePayInitializer .getTxRef ())
278285 .setMeta (ravePayInitializer .getMeta ())
279286 .setSubAccount (ravePayInitializer .getSubAccount ())
280287 .setPBFPubKey (ravePayInitializer .getPublicKey ())
281288 .setIsPreAuth (ravePayInitializer .getIsPreAuth ())
282- .setDevice_fingerprint (Utils . getDeviceImei ( context ))
289+ .setDevice_fingerprint (deviceIdGetter . getDeviceId ( ))
283290 .setNarration (ravePayInitializer .getNarration ());
284291
285292 Payload body = builder .createBankTransferPayload ();
0 commit comments