66
77import com .flutterwave .raveandroid .DeviceIdGetter ;
88import com .flutterwave .raveandroid .FeeCheckRequestBody ;
9+ import com .flutterwave .raveandroid .GetEncryptedData ;
910import com .flutterwave .raveandroid .Payload ;
1011import com .flutterwave .raveandroid .PayloadBuilder ;
12+ import com .flutterwave .raveandroid .PayloadToJson ;
1113import com .flutterwave .raveandroid .RaveConstants ;
1214import com .flutterwave .raveandroid .RavePayInitializer ;
13- import com .flutterwave .raveandroid .Utils ;
1415import com .flutterwave .raveandroid .ViewObject ;
1516import com .flutterwave .raveandroid .card .ChargeRequestBody ;
1617import com .flutterwave .raveandroid .data .Callbacks ;
2930 * Created by hfetuga on 27/06/2018.
3031 */
3132
33+
3234public class BankTransferPresenter implements BankTransferContract .UserActionsListener {
3335 private static final String ACCOUNT_NUMBER = "account_number" ;
3436 private static final String BANK_NAME = "bank_name" ;
@@ -44,14 +46,18 @@ public class BankTransferPresenter implements BankTransferContract.UserActionsLi
4446 NetworkRequestImpl networkRequest ;
4547 @ Inject
4648 DeviceIdGetter deviceIdGetter ;
49+ public boolean pollingCancelled = false ;
50+ public boolean hasTransferDetails = false ;
4751
4852 private Context context ;
4953 private BankTransferContract .View mView ;
5054 private String txRef = null , flwRef = null , publicKey = null ;
5155 private long requeryCountdownTime = 0 ;
52- private boolean pollingCancelled = false ;
56+ @ Inject
57+ PayloadToJson payloadToJson ;
5358 private String beneficiaryName , accountNumber , amount , bankName ;
54- private boolean hasTransferDetails = false ;
59+ @ Inject
60+ GetEncryptedData getEncryptedData ;
5561
5662 @ Inject
5763 BankTransferPresenter (Context context , BankTransferContract .View mView ) {
@@ -77,7 +83,6 @@ public void onSuccess(FeeCheckResponse response) {
7783 try {
7884 mView .displayFee (response .getData ().getCharge_amount (), payload );
7985 } catch (Exception e ) {
80- e .printStackTrace ();
8186 mView .showFetchFeeFailed ("An error occurred while retrieving transaction fee" );
8287 }
8388 }
@@ -93,8 +98,8 @@ public void onError(String message) {
9398
9499 @ Override
95100 public void payWithBankTransfer (final Payload payload , final String encryptionKey ) {
96- String cardRequestBodyAsString = Utils .convertChargeRequestPayloadToJson (payload );
97- String encryptedCardRequestBody = Utils .getEncryptedData (cardRequestBodyAsString , encryptionKey );
101+ String cardRequestBodyAsString = payloadToJson .convertChargeRequestPayloadToJson (payload );
102+ String encryptedCardRequestBody = getEncryptedData .getEncryptedData (cardRequestBodyAsString , encryptionKey );
98103 encryptedCardRequestBody = encryptedCardRequestBody .trim ().replaceAll ("\\ n" , "" );
99104
100105 ChargeRequestBody body = new ChargeRequestBody ();
@@ -146,7 +151,7 @@ public void onError(String message, String responseAsJSONString) {
146151 public void startPaymentVerification () {
147152 requeryCountdownTime = System .currentTimeMillis ();
148153 mView .showPollingIndicator (true );
149- requeryTx ();
154+ requeryTx (flwRef , txRef , publicKey , pollingCancelled , requeryCountdownTime );
150155 }
151156
152157 @ Override
@@ -187,15 +192,17 @@ public void restoreState(Bundle savedInstanceState) {
187192 }
188193
189194 @ Override
190- public void requeryTx () {
195+ public void requeryTx (final String flwRef , final String txRef , final String publicKey , final boolean pollingCancelled , final long requeryCountdownTime ) {
191196
192197 RequeryRequestBody body = new RequeryRequestBody ();
193198 body .setFlw_ref (flwRef );
194199 body .setPBFPubKey (publicKey );
195200
196201 networkRequest .requeryPayWithBankTx (body , new Callbacks .OnRequeryRequestComplete () {
202+
197203 @ Override
198204 public void onSuccess (RequeryResponse response , String responseAsJSONString ) {
205+
199206 if (response .getData () == null ) {
200207 mView .onPaymentFailed (response .getStatus (), responseAsJSONString );
201208 } else if (response .getData ().getChargeResponseCode ().equals ("01" )) {
@@ -204,7 +211,7 @@ public void onSuccess(RequeryResponse response, String responseAsJSONString) {
204211 mView .onPollingCanceled (flwRef , txRef , responseAsJSONString );
205212 } else {
206213 if ((System .currentTimeMillis () - requeryCountdownTime ) < 300000 ) {
207- requeryTx ();
214+ requeryTx (flwRef , txRef , publicKey , pollingCancelled , requeryCountdownTime );
208215 } else {
209216 mView .showPollingIndicator (false );
210217 mView .onPollingTimeout (flwRef , txRef , responseAsJSONString );
0 commit comments