Skip to content

Commit 0dd97b8

Browse files
committed
BankTransferTest Update
Refactor requeryTx() in BankTransfer Class, Contract More tests for requerytx, saved instance states
1 parent 2205c17 commit 0dd97b8

File tree

7 files changed

+280
-25
lines changed

7 files changed

+280
-25
lines changed

raveandroid/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ dependencies {
5151
testImplementation 'com.google.dagger:dagger:2.17'
5252
testAnnotationProcessor 'com.google.dagger:dagger-compiler:2.17'
5353
testImplementation 'org.mockito:mockito-core:2.25.0'
54+
testImplementation 'org.mockito:mockito-inline:2.13.0'
5455

5556

5657
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.flutterwave.raveandroid;
2+
3+
import javax.inject.Inject;
4+
import javax.inject.Singleton;
5+
6+
import static com.scottyab.aescrypt.AESCrypt.encrypt;
7+
8+
@Singleton
9+
public class GetEncryptedData {
10+
11+
@Inject
12+
public GetEncryptedData() {
13+
}
14+
15+
public String getEncryptedData(String unEncryptedString, String encryptionKey) {
16+
17+
if (unEncryptedString != null && encryptionKey != null) {
18+
try {
19+
return encrypt(unEncryptedString, encryptionKey);
20+
} catch (Exception e) {
21+
e.printStackTrace();
22+
}
23+
}
24+
return "";
25+
}
26+
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.flutterwave.raveandroid;
2+
3+
import com.google.gson.Gson;
4+
import com.google.gson.reflect.TypeToken;
5+
6+
import java.lang.reflect.Type;
7+
8+
import javax.inject.Inject;
9+
import javax.inject.Singleton;
10+
11+
@Singleton
12+
public class PayloadToJson {
13+
14+
public Gson gson;
15+
16+
@Inject
17+
public PayloadToJson(Gson gson) {
18+
this.gson = gson;
19+
}
20+
21+
public String convertChargeRequestPayloadToJson(Payload body) {
22+
23+
Type type = new TypeToken<Payload>() {
24+
}.getType();
25+
return gson.toJson(body, type);
26+
}
27+
28+
}

raveandroid/src/main/java/com/flutterwave/raveandroid/banktransfer/BankTransferContract.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ interface View {
3232

3333
interface UserActionsListener {
3434
void fetchFee(Payload payload);
35-
void requeryTx();
35+
36+
void requeryTx(String flwRef, String txRef, String publicKey, boolean pollingCancelled, long requeryCountdownTime);
3637
void payWithBankTransfer(Payload body, String encryptionKey);
3738
void init(RavePayInitializer ravePayInitializer);
3839
void processTransaction(HashMap<String, ViewObject> dataHashMap, RavePayInitializer ravePayInitializer);

raveandroid/src/main/java/com/flutterwave/raveandroid/banktransfer/BankTransferPresenter.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
import com.flutterwave.raveandroid.DeviceIdGetter;
88
import com.flutterwave.raveandroid.FeeCheckRequestBody;
9+
import com.flutterwave.raveandroid.GetEncryptedData;
910
import com.flutterwave.raveandroid.Payload;
1011
import com.flutterwave.raveandroid.PayloadBuilder;
12+
import com.flutterwave.raveandroid.PayloadToJson;
1113
import com.flutterwave.raveandroid.RaveConstants;
1214
import com.flutterwave.raveandroid.RavePayInitializer;
13-
import com.flutterwave.raveandroid.Utils;
1415
import com.flutterwave.raveandroid.ViewObject;
1516
import com.flutterwave.raveandroid.card.ChargeRequestBody;
1617
import com.flutterwave.raveandroid.data.Callbacks;
@@ -29,6 +30,7 @@
2930
* Created by hfetuga on 27/06/2018.
3031
*/
3132

33+
3234
public 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

Comments
 (0)