Skip to content

Commit 0c452f7

Browse files
authored
Merge pull request #175 from jeremiahVaris/catch-authModel-switching
Catch Rave Auth Model switching
2 parents af02ee2 + 05e507c commit 0c452f7

File tree

5 files changed

+64
-207
lines changed

5 files changed

+64
-207
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: 44 additions & 168 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
@@ -230,42 +246,7 @@ public void onError(String message, String responseAsJSONString) {
230246
public void chargeSavedCard(Payload payload, String encryptionKey) {
231247
if (payload.getOtp() == null || payload.getOtp() == "") {
232248
sendRaveOTP(payload);
233-
} else {
234-
// Charge saved card
235-
String cardRequestBodyAsString = Utils.convertChargeRequestPayloadToJson(payload);
236-
String encryptedCardRequestBody = Utils.getEncryptedData(cardRequestBodyAsString, encryptionKey);
237-
238-
final ChargeRequestBody body = new ChargeRequestBody();
239-
body.setAlg("3DES-24");
240-
body.setPBFPubKey(payload.getPBFPubKey());
241-
body.setClient(encryptedCardRequestBody);
242-
243-
mView.showProgressIndicator(true);
244-
245-
networkRequest.charge(body, new Callbacks.OnChargeRequestComplete() {
246-
@Override
247-
public void onSuccess(ChargeResponse response, String responseAsJSONString) {
248-
249-
mView.showProgressIndicator(false);
250-
251-
if (response.getData() != null) {
252-
Log.d("Saved card charge", responseAsJSONString);
253-
mView.onChargeCardSuccessful(response);
254-
255-
} else {
256-
mView.onPaymentError("No response data was returned");
257-
}
258-
259-
}
260-
261-
@Override
262-
public void onError(String message, String responseAsJSONString) {
263-
264-
mView.showProgressIndicator(false);
265-
mView.onPaymentError(message);
266-
}
267-
});
268-
}
249+
} else chargeCard(payload, encryptionKey);
269250
}
270251

271252
@Override
@@ -305,61 +286,9 @@ public void chargeCardWithAVSModel(Payload payload, String address, String city,
305286
payload.setBillingcountry(country);
306287
payload.setBillingstate(state);
307288

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-
319289
logEvent(new ChargeAttemptEvent("AVS Card").getEvent(), payload.getPBFPubKey());
320290

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-
});
291+
chargeCard(payload, encryptionKey);
363292

364293
}
365294

@@ -549,7 +478,7 @@ public void processSavedCardTransaction(SavedCard savedCard, RavePayInitializer
549478

550479

551480
@Override
552-
public void chargeCardWithSuggestedAuthModel(Payload payload, String zipOrPin, String authModel, String encryptionKey) {
481+
public void chargeCardWithSuggestedAuthModel(final Payload payload, String zipOrPin, String authModel, String encryptionKey) {
553482

554483
if (authModel.equalsIgnoreCase(AVS_VBVSECURECODE)) {
555484
payload.setBillingzip(zipOrPin);
@@ -559,60 +488,7 @@ public void chargeCardWithSuggestedAuthModel(Payload payload, String zipOrPin, S
559488

560489
payload.setSuggestedAuth(authModel);
561490

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 {
599-
mView.onPaymentError(unknownAuthmsg);
600-
}
601-
} else {
602-
mView.onPaymentError(unknownResCodemsg);
603-
}
604-
} else {
605-
mView.onPaymentError(invalidChargeCode);
606-
}
607-
608-
}
609-
610-
@Override
611-
public void onError(String message, String responseAsJSONString) {
612-
mView.showProgressIndicator(false);
613-
mView.onPaymentError(message);
614-
}
615-
});
491+
chargeCard(payload, encryptionKey);
616492

617493
}
618494

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)