Skip to content

Commit 2d623d1

Browse files
committed
Clean up logic replication
1 parent 9a887e0 commit 2d623d1

File tree

4 files changed

+45
-176
lines changed

4 files changed

+45
-176
lines changed

raveandroid/src/main/java/com/flutterwave/raveandroid/card/CardContract.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ interface View {
5959

6060
void onTokenRetrieved(String flwRef, String cardBIN, String token);
6161

62-
void onAVSVBVSecureCodeModelUsed(String authurl, String flwRef);
63-
6462
void onValidateCardChargeFailed(String flwRef, String responseAsJSON);
6563

6664
void onNoAuthInternationalSuggested(Payload payload);

raveandroid/src/main/java/com/flutterwave/raveandroid/card/CardFragment.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,11 @@ public void onValidateError(String message) {
542542
}
543543

544544
/**
545-
* Called when the auth model suggested is VBV. It opens a webview
545+
* Called when the auth model suggested is VBV. It opens a WebView
546546
* that loads the authURL
547547
*
548-
* @param authUrlCrude = URL to display in webview
549-
* @param flwRef = reference of the payment transaction
548+
* @param authUrlCrude URL to display in webview
549+
* @param flwRef Reference of the payment transaction
550550
*/
551551
@Override
552552
public void onVBVAuthModelUsed(String authUrlCrude, String flwRef) {
@@ -825,25 +825,6 @@ public void onAVS_VBVSECURECODEModelSuggested(final Payload payload) {
825825
startActivityForResult(intent, FOR_AVBVV);
826826
}
827827

828-
/**
829-
* Called when the auth model suggested is AVS_VBVSecureCode. It opens a webview
830-
* that loads the authURL
831-
*
832-
* @param authurl = URL to display in webview
833-
* @param flwRef = reference of the payment transaction
834-
*/
835-
@Override
836-
public void onAVSVBVSecureCodeModelUsed(String authurl, String flwRef) {
837-
this.flwRef = flwRef;
838-
Intent intent = new Intent(getContext(), VerificationActivity.class);
839-
intent.putExtra(EXTRA_IS_STAGING, ravePayInitializer.isStaging());
840-
intent.putExtra(VerificationActivity.PUBLIC_KEY_EXTRA, ravePayInitializer.getPublicKey());
841-
intent.putExtra(WebFragment.EXTRA_AUTH_URL, authurl);
842-
intent.putExtra(VerificationActivity.ACTIVITY_MOTIVE, "web");
843-
intent.putExtra("theme", ravePayInitializer.getTheme());
844-
startActivityForResult(intent, FOR_INTERNET_BANKING);
845-
}
846-
847828
private class ExpiryWatcher implements TextWatcher {
848829

849830
private final Calendar calendar;

raveandroid/src/main/java/com/flutterwave/raveandroid/card/CardPresenter.java

Lines changed: 42 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,12 @@
6666
import static com.flutterwave.raveandroid.RaveConstants.fieldCvv;
6767
import static com.flutterwave.raveandroid.RaveConstants.fieldEmail;
6868
import static com.flutterwave.raveandroid.RaveConstants.fieldcardNoStripped;
69-
import static com.flutterwave.raveandroid.RaveConstants.invalidChargeCode;
7069
import static com.flutterwave.raveandroid.RaveConstants.noResponse;
7170
import static com.flutterwave.raveandroid.RaveConstants.success;
7271
import static com.flutterwave.raveandroid.RaveConstants.tokenExpired;
7372
import static com.flutterwave.raveandroid.RaveConstants.tokenNotFound;
7473
import static com.flutterwave.raveandroid.RaveConstants.transactionError;
7574
import static com.flutterwave.raveandroid.RaveConstants.unknownAuthmsg;
76-
import static com.flutterwave.raveandroid.RaveConstants.unknownResCodemsg;
7775
import static com.flutterwave.raveandroid.RaveConstants.validAmountPrompt;
7876
import static com.flutterwave.raveandroid.RaveConstants.validCreditCardPrompt;
7977
import static com.flutterwave.raveandroid.RaveConstants.validCvvPrompt;
@@ -134,7 +132,7 @@ public CardPresenter(Context context, CardContract.View mView) {
134132
this.context = context;
135133
}
136134

137-
public CardPresenter(Context context, CardContract.View mView, AppComponent appComponent){
135+
public CardPresenter(Context context, CardContract.View mView, AppComponent appComponent) {
138136
this.context = context;
139137
this.mView = mView;
140138
this.eventLogger = appComponent.eventLogger();
@@ -152,6 +150,13 @@ public CardPresenter(Context context, CardContract.View mView, AppComponent appC
152150
this.gson = appComponent.gson();
153151
}
154152

153+
/**
154+
* Makes a generic call to the charge endpoint with the payload provided. Handles both conditions
155+
* for initial charge request and when the suggested auth has been added.
156+
*
157+
* @param payload {@link Payload} object to be sent.
158+
* @param encryptionKey Rave encryption key gotten from dashboard
159+
*/
155160
@Override
156161
public void chargeCard(final Payload payload, final String encryptionKey) {
157162

@@ -189,33 +194,44 @@ public void onSuccess(ChargeResponse response, String responseAsJSONString) {
189194
mView.onPaymentError(unknownAuthmsg);
190195
}
191196
} else {
192-
String authModelUsed = response.getData().getAuthModelUsed();
193-
194-
if (authModelUsed != null) {
195-
196-
if (authModelUsed.equalsIgnoreCase(VBV)) {
197-
String authUrlCrude = response.getData().getAuthurl();
198-
String flwRef = response.getData().getFlwRef();
199-
200-
mView.onVBVAuthModelUsed(authUrlCrude, flwRef);
201-
} else if (authModelUsed.equalsIgnoreCase(GTB_OTP)
202-
|| authModelUsed.equalsIgnoreCase(ACCESS_OTP)
203-
|| authModelUsed.toLowerCase().contains("otp")) {
204-
String flwRef = response.getData().getFlwRef();
205-
String chargeResponseMessage = response.getData().getChargeResponseMessage();
206-
chargeResponseMessage = chargeResponseMessage == null ? enterOTP : chargeResponseMessage;
207-
mView.showOTPLayout(flwRef, chargeResponseMessage);
208-
209-
} else if (authModelUsed.equalsIgnoreCase(NOAUTH)) {
210-
String flwRef = response.getData().getFlwRef();
211-
mView.onNoAuthUsed(flwRef, payload.getPBFPubKey());
197+
// Check if transaction is already successful
198+
if (response.getData().getChargeResponseCode() != null && response.getData().getChargeResponseCode().equalsIgnoreCase("00")) {
199+
mView.onChargeCardSuccessful(response);
200+
201+
} else {
202+
203+
String authModelUsed = response.getData().getAuthModelUsed();
204+
205+
if (authModelUsed != null) {
206+
207+
if (authModelUsed.equalsIgnoreCase(VBV) || authModelUsed.equalsIgnoreCase(AVS_VBVSECURECODE)) {
208+
String authUrlCrude = response.getData().getAuthurl();
209+
String flwRef = response.getData().getFlwRef();
210+
211+
mView.onVBVAuthModelUsed(authUrlCrude, flwRef);
212+
} else if (authModelUsed.equalsIgnoreCase(GTB_OTP)
213+
|| authModelUsed.equalsIgnoreCase(ACCESS_OTP)
214+
|| authModelUsed.toLowerCase().contains("otp")
215+
|| authModelUsed.equalsIgnoreCase(PIN)) {
216+
String flwRef = response.getData().getFlwRef();
217+
String chargeResponseMessage = response.getData().getChargeResponseMessage();
218+
chargeResponseMessage = (chargeResponseMessage == null || chargeResponseMessage.length() == 0) ? enterOTP : chargeResponseMessage;
219+
mView.showOTPLayout(flwRef, chargeResponseMessage);
220+
221+
} else if (authModelUsed.equalsIgnoreCase(NOAUTH)) {
222+
String flwRef = response.getData().getFlwRef();
223+
mView.onNoAuthUsed(flwRef, payload.getPBFPubKey());
224+
} else {
225+
mView.onPaymentError(unknownAuthmsg);
226+
}
227+
} else {
228+
mView.onPaymentError(unknownAuthmsg);
212229
}
213230
}
214231
}
215232
} else {
216233
mView.onPaymentError(noResponse);
217234
}
218-
219235
}
220236

221237
@Override
@@ -305,61 +321,9 @@ public void chargeCardWithAVSModel(Payload payload, String address, String city,
305321
payload.setBillingcountry(country);
306322
payload.setBillingstate(state);
307323

308-
String cardRequestBodyAsString = Utils.convertChargeRequestPayloadToJson(payload);
309-
String encryptedCardRequestBody = payloadEncryptor.getEncryptedData(cardRequestBodyAsString, encryptionKey).trim().replaceAll("\\n", "");
310-
311-
ChargeRequestBody body = new ChargeRequestBody();
312-
body.setAlg("3DES-24");
313-
body.setPBFPubKey(payload.getPBFPubKey());
314-
body.setClient(encryptedCardRequestBody);
315-
316-
mView.showProgressIndicator(true);
317-
318-
319324
logEvent(new ChargeAttemptEvent("AVS Card").getEvent(), payload.getPBFPubKey());
320325

321-
322-
networkRequest.charge(body, new Callbacks.OnChargeRequestComplete() {
323-
324-
@Override
325-
public void onSuccess(ChargeResponse response, String responseAsJSONString) {
326-
327-
mView.showProgressIndicator(false);
328-
329-
if (response.getData() != null && response.getData().getChargeResponseCode() != null) {
330-
String chargeResponseCode = response.getData().getChargeResponseCode();
331-
332-
if (chargeResponseCode.equalsIgnoreCase("00")) {
333-
mView.onChargeCardSuccessful(response);
334-
} else if (chargeResponseCode.equalsIgnoreCase("02")) {
335-
String authModelUsed = response.getData().getAuthModelUsed();
336-
337-
if (authModelUsed.equalsIgnoreCase(PIN)) {
338-
String flwRef = response.getData().getFlwRef();
339-
String chargeResponseMessage = response.getData().getChargeResponseMessage();
340-
chargeResponseMessage = (chargeResponseMessage == null || chargeResponseMessage.length() == 0) ? enterOTP : chargeResponseMessage;
341-
mView.showOTPLayout(flwRef, chargeResponseMessage);
342-
} else if (authModelUsed.equalsIgnoreCase(VBV)) {
343-
String flwRef = response.getData().getFlwRef();
344-
mView.onAVSVBVSecureCodeModelUsed(response.getData().getAuthurl(), flwRef);
345-
} else {
346-
mView.onPaymentError(unknownAuthmsg);
347-
}
348-
} else {
349-
mView.onPaymentError(unknownResCodemsg);
350-
}
351-
} else {
352-
mView.onPaymentError(invalidChargeCode);
353-
}
354-
355-
}
356-
357-
@Override
358-
public void onError(String message, String responseAsJSONString) {
359-
mView.showProgressIndicator(false);
360-
mView.onPaymentError(message);
361-
}
362-
});
326+
chargeCard(payload, encryptionKey);
363327

364328
}
365329

@@ -559,76 +523,7 @@ public void chargeCardWithSuggestedAuthModel(final Payload payload, String zipOr
559523

560524
payload.setSuggestedAuth(authModel);
561525

562-
String cardRequestBodyAsString = Utils.convertChargeRequestPayloadToJson(payload);
563-
String encryptedCardRequestBody = payloadEncryptor.getEncryptedData(cardRequestBodyAsString, encryptionKey).trim().replaceAll("\\n", "");
564-
565-
ChargeRequestBody body = new ChargeRequestBody();
566-
body.setAlg("3DES-24");
567-
body.setPBFPubKey(payload.getPBFPubKey());
568-
body.setClient(encryptedCardRequestBody);
569-
570-
mView.showProgressIndicator(true);
571-
572-
logEvent(new ChargeAttemptEvent("Card").getEvent(), payload.getPBFPubKey());
573-
574-
575-
networkRequest.charge(body, new Callbacks.OnChargeRequestComplete() {
576-
@Override
577-
public void onSuccess(ChargeResponse response, String responseAsJSONString) {
578-
579-
mView.showProgressIndicator(false);
580-
581-
if (response.getData() != null && response.getData().getChargeResponseCode() != null) {
582-
String chargeResponseCode = response.getData().getChargeResponseCode();
583-
584-
if (chargeResponseCode.equalsIgnoreCase("00")) {
585-
mView.onChargeCardSuccessful(response);
586-
} else if (chargeResponseCode.equalsIgnoreCase("02")) {
587-
588-
String authModelUsed = response.getData().getAuthModelUsed();
589-
590-
if (authModelUsed.equalsIgnoreCase(PIN)) {
591-
String flwRef = response.getData().getFlwRef();
592-
String chargeResponseMessage = response.getData().getChargeResponseMessage();
593-
chargeResponseMessage = (chargeResponseMessage == null || chargeResponseMessage.length() == 0) ? "Enter your one time password (OTP)" : chargeResponseMessage;
594-
mView.showOTPLayout(flwRef, chargeResponseMessage);
595-
} else if (authModelUsed.equalsIgnoreCase(AVS_VBVSECURECODE)) {
596-
String flwRef = response.getData().getFlwRef();
597-
mView.onAVSVBVSecureCodeModelUsed(response.getData().getAuthurl(), flwRef);
598-
} else if (authModelUsed.equalsIgnoreCase(VBV)) {
599-
String authUrlCrude = response.getData().getAuthurl();
600-
String flwRef = response.getData().getFlwRef();
601-
602-
mView.onVBVAuthModelUsed(authUrlCrude, flwRef);
603-
} else if (authModelUsed.equalsIgnoreCase(GTB_OTP)
604-
|| authModelUsed.equalsIgnoreCase(ACCESS_OTP)
605-
|| authModelUsed.toLowerCase().contains("otp")) {
606-
String flwRef = response.getData().getFlwRef();
607-
String chargeResponseMessage = response.getData().getChargeResponseMessage();
608-
chargeResponseMessage = chargeResponseMessage == null ? enterOTP : chargeResponseMessage;
609-
mView.showOTPLayout(flwRef, chargeResponseMessage);
610-
611-
} else if (authModelUsed.equalsIgnoreCase(NOAUTH)) {
612-
String flwRef = response.getData().getFlwRef();
613-
mView.onNoAuthUsed(flwRef, payload.getPBFPubKey());
614-
} else {
615-
mView.onPaymentError(unknownAuthmsg);
616-
}
617-
} else {
618-
mView.onPaymentError(unknownResCodemsg);
619-
}
620-
} else {
621-
mView.onPaymentError(invalidChargeCode);
622-
}
623-
624-
}
625-
626-
@Override
627-
public void onError(String message, String responseAsJSONString) {
628-
mView.showProgressIndicator(false);
629-
mView.onPaymentError(message);
630-
}
631-
});
526+
chargeCard(payload, encryptionKey);
632527

633528
}
634529

raveandroid/src/main/java/com/flutterwave/raveandroid/card/NullCardView.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,6 @@ public void onAVS_VBVSECURECODEModelSuggested(Payload payload) {
187187

188188
}
189189

190-
@Override
191-
public void onAVSVBVSecureCodeModelUsed(String authurl, String flwRef) {
192-
193-
}
194-
195190
@Override
196191
public void onValidateCardChargeFailed(String flwRef, String responseAsJSON) {
197192

0 commit comments

Comments
 (0)