Skip to content

Commit b357ba3

Browse files
committed
Ach Presenter Test Update
chargeAccount code moved into 1 singular processTransaction() to follow the single responsibility principle which makes the code more testable Ach Fragment and Contract modified to allow for the parameter change in processTransaction() new implementation Test adjust in view of this code change onAmountValidated() included.
1 parent 6e26d49 commit b357ba3

File tree

6 files changed

+131
-135
lines changed

6 files changed

+131
-135
lines changed

raveandroid/src/main/java/com/flutterwave/raveandroid/RavePayInitializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ public void setPreAuth(boolean isPreAuth) {
253253
public boolean getIsDisplayFee() {
254254
return displayFee;
255255
}
256-
public void setIsDisplayFee() {
256+
257+
public void setIsDisplayFee(boolean displayFee) {
257258
this.displayFee = displayFee;
258259
}
259260
}

raveandroid/src/main/java/com/flutterwave/raveandroid/ach/AchContract.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.flutterwave.raveandroid.ach;
22

3-
import com.flutterwave.raveandroid.Payload;
43
import com.flutterwave.raveandroid.RavePayInitializer;
54
import com.flutterwave.raveandroid.responses.RequeryResponse;
65

@@ -28,20 +27,20 @@ interface View {
2827
void showFee(String authUrl, String flwRef, String chargedAmount, String currency);
2928

3029
void onValidationSuccessful(String amount);
30+
31+
void onAmountValidated(String amountToSet, int visibility);
3132
}
3233

3334
interface UserActionsListener {
3435
void init(RavePayInitializer ravePayInitializer);
3536

3637
void onPayButtonClicked(RavePayInitializer ravePayInitializer, String amount);
3738

38-
void chargeAccount(Payload payload, String encryptionKey, boolean isDisplayFee);
39-
4039
void verifyRequeryResponse(RequeryResponse response, String responseAsJSONString, RavePayInitializer ravePayInitializer, String flwRef);
4140

4241
void onFeeConfirmed(String authUrl, String flwRef);
4342

44-
void processTransaction(String amount, RavePayInitializer ravePayInitializer);
43+
void processTransaction(String amount, RavePayInitializer ravePayInitializer, boolean isDisplayFee);
4544

4645
void onAttachView(View view);
4746

raveandroid/src/main/java/com/flutterwave/raveandroid/ach/AchFragment.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,14 @@ public void onClick(DialogInterface dialog, int which) {
127127

128128
@Override
129129
public void onValidationSuccessful(String amount) {
130-
presenter.processTransaction(amount, ravePayInitializer);
130+
presenter.processTransaction(amount, ravePayInitializer, ravePayInitializer.getIsDisplayFee());
131+
}
132+
133+
@Override
134+
public void onAmountValidated(String amountToSet, int visibility) {
135+
amountTil.setVisibility(visibility);
136+
amountEt.setText(amountToSet);
137+
131138
}
132139

133140
@Override

raveandroid/src/main/java/com/flutterwave/raveandroid/ach/AchPresenter.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.flutterwave.raveandroid.ach;
22

33
import android.content.Context;
4+
import android.view.View;
45

56
import com.flutterwave.raveandroid.DeviceIdGetter;
67
import com.flutterwave.raveandroid.GetEncryptedData;
@@ -55,11 +56,12 @@ public void init(RavePayInitializer ravePayInitializer) {
5556
if (ravePayInitializer != null) {
5657

5758
boolean isAmountValid = amountValidator.isAmountValid(ravePayInitializer.getAmount());
59+
5860
if (isAmountValid) {
59-
mView.showAmountField(false);
61+
mView.onAmountValidated(String.valueOf(ravePayInitializer.getAmount()), View.GONE);
6062
mView.showRedirectMessage(true);
6163
} else {
62-
mView.showAmountField(true);
64+
mView.onAmountValidated("", View.VISIBLE);
6365
mView.showRedirectMessage(false);
6466
}
6567
}
@@ -82,7 +84,7 @@ public void onPayButtonClicked(RavePayInitializer ravePayInitializer, String amo
8284
}
8385

8486
@Override
85-
public void processTransaction(String amount, RavePayInitializer ravePayInitializer) {
87+
public void processTransaction(String amount, final RavePayInitializer ravePayInitializer, final boolean isDisplayFee) {
8688

8789
ravePayInitializer.setAmount(Double.parseDouble(amount));
8890
PayloadBuilder builder = new PayloadBuilder();
@@ -103,21 +105,14 @@ public void processTransaction(String amount, RavePayInitializer ravePayInitiali
103105
builder.setPaymentPlan(ravePayInitializer.getPayment_plan());
104106
}
105107

106-
Payload body = builder.createBankPayload();
107-
108-
chargeAccount(body, ravePayInitializer.getEncryptionKey(), ravePayInitializer.getIsDisplayFee());
109-
}
108+
Payload bankPayload = builder.createBankPayload();
110109

111-
112-
@Override
113-
public void chargeAccount(Payload payload, String encryptionKey, final boolean isDisplayFee) {
114-
115-
String requestBodyAsString = payloadToJson.convertChargeRequestPayloadToJson(payload);
116-
String accountRequestBody = getEncryptedData.getEncryptedData(requestBodyAsString, encryptionKey);
110+
String requestBodyAsString = payloadToJson.convertChargeRequestPayloadToJson(bankPayload);
111+
String accountRequestBody = getEncryptedData.getEncryptedData(requestBodyAsString, ravePayInitializer.getEncryptionKey());
117112

118113
final ChargeRequestBody body = new ChargeRequestBody();
119114
body.setAlg("3DES-24");
120-
body.setPBFPubKey(payload.getPBFPubKey());
115+
body.setPBFPubKey(bankPayload.getPBFPubKey());
121116
body.setClient(accountRequestBody);
122117

123118
mView.showProgressIndicator(true);
@@ -140,17 +135,14 @@ public void onSuccess(ChargeResponse response, String responseAsJSONString) {
140135

141136
if (isDisplayFee) {
142137
mView.showFee(authUrl, flwRef, chargedAmount, currency);
143-
}
144-
else {
138+
} else {
145139
mView.showWebView(authUrl, flwRef);
146140
}
147-
}
148-
else {
141+
} else {
149142
mView.onPaymentError(RaveConstants.no_authurl_was_returnedmsg);
150143
}
151144

152-
}
153-
else {
145+
} else {
154146
mView.onPaymentError(RaveConstants.noResponse);
155147
}
156148

raveandroid/src/main/java/com/flutterwave/raveandroid/ach/NullAchView.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,9 @@ public void showFee(String authUrl, String flwRef, String chargedAmount, String
5757
public void onValidationSuccessful(String amount) {
5858

5959
}
60+
61+
@Override
62+
public void onAmountValidated(String amountToSet, int visibility) {
63+
64+
}
6065
}

0 commit comments

Comments
 (0)