Skip to content

Commit e822d93

Browse files
committed
Francophone momo flow update
1 parent 8f8608a commit e822d93

File tree

9 files changed

+118
-16
lines changed

9 files changed

+118
-16
lines changed

rave_android/src/main/java/com/flutterwave/raveandroid/francMobileMoney/FrancMobileMoneyFragment.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,33 @@
1919
import com.flutterwave.raveandroid.RavePayActivity;
2020
import com.flutterwave.raveandroid.RavePayInitializer;
2121
import com.flutterwave.raveandroid.ViewObject;
22+
import com.flutterwave.raveandroid.card.savedcards.SavedCardsFragment;
2223
import com.flutterwave.raveandroid.data.Utils;
2324
import com.flutterwave.raveandroid.data.events.FeeDisplayResponseEvent;
2425
import com.flutterwave.raveandroid.data.events.RequeryCancelledEvent;
2526
import com.flutterwave.raveandroid.di.modules.FrancModule;
27+
import com.flutterwave.raveandroid.rave_core.models.SavedCard;
2628
import com.flutterwave.raveandroid.rave_java_commons.Payload;
2729
import com.flutterwave.raveandroid.rave_logger.events.StartTypingEvent;
30+
import com.flutterwave.raveandroid.rave_presentation.data.AddressDetails;
2831
import com.flutterwave.raveandroid.rave_presentation.data.events.ErrorEvent;
32+
import com.flutterwave.raveutils.verification.AVSVBVFragment;
33+
import com.flutterwave.raveutils.verification.OTPFragment;
34+
import com.flutterwave.raveutils.verification.PinFragment;
35+
import com.flutterwave.raveutils.verification.RaveVerificationUtils;
2936
import com.google.android.material.textfield.TextInputEditText;
3037
import com.google.android.material.textfield.TextInputLayout;
38+
import com.google.gson.Gson;
3139

3240
import java.util.HashMap;
3341

3442
import javax.inject.Inject;
3543

3644
import static android.view.View.GONE;
45+
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.ADDRESS_DETAILS_REQUEST_CODE;
46+
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.OTP_REQUEST_CODE;
47+
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.PIN_REQUEST_CODE;
48+
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.WEB_VERIFICATION_REQUEST_CODE;
3749
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.fieldAmount;
3850
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.fieldPhone;
3951
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.response;
@@ -59,6 +71,7 @@ public class FrancMobileMoneyFragment extends Fragment implements FrancMobileMon
5971

6072
private int rave_phoneEtInt;
6173
private RavePayInitializer ravePayInitializer;
74+
private String flwRef;
6275

6376

6477
@Override
@@ -188,6 +201,34 @@ public void showProgressIndicator(boolean active) {
188201
}
189202
}
190203

204+
/**
205+
* Called when the auth model suggested is VBV. It opens a WebView
206+
* that loads the authURL
207+
*
208+
* @param authenticationUrl URL to display in webview
209+
* @param flwRef Reference of the payment transaction
210+
*/
211+
@Override
212+
public void showWebPage(String authenticationUrl, String flwRef) {
213+
214+
this.flwRef = flwRef;
215+
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
216+
.showWebpageVerificationScreen(authenticationUrl);
217+
}
218+
219+
220+
@Override
221+
public void onActivityResult(int requestCode, int resultCode, Intent data) {
222+
if (resultCode == RavePayActivity.RESULT_SUCCESS) {
223+
//just to be sure this v sent the receiving intent
224+
if (requestCode == WEB_VERIFICATION_REQUEST_CODE) {
225+
presenter.requeryTx(flwRef, ravePayInitializer.getPublicKey());
226+
}
227+
} else {
228+
super.onActivityResult(requestCode, resultCode, data);
229+
}
230+
}
231+
191232
@Override
192233
public void onValidationSuccessful(HashMap<String, ViewObject> dataHashMap) {
193234
presenter.processTransaction(dataHashMap, ravePayInitializer);
@@ -230,7 +271,7 @@ public void showToast(String message) {
230271
}
231272

232273
@Override
233-
public void onPaymentSuccessful(String status, String flwRef, String responseAsString) {
274+
public void onPaymentSuccessful(String flwRef, String responseAsString) {
234275
Intent intent = new Intent();
235276
intent.putExtra(response, responseAsString);
236277

rave_android/src/main/java/com/flutterwave/raveandroid/francMobileMoney/FrancMobileMoneyUiContract.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ interface View extends FrancMobileMoneyContract.Interactor {
2121

2222
void showFieldError(int viewID, String message, Class<?> viewType);
2323

24-
void onPaymentSuccessful(String status, String flwRef, String responseAsString);
2524
}
2625

2726
interface UserActionsListener extends FrancMobileMoneyContract.Handler {

rave_android/src/main/java/com/flutterwave/raveandroid/francMobileMoney/NullfrancMobileMoneyView.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public void showFetchFeeFailed(String s) {
1212

1313
}
1414

15+
@Override
16+
public void showWebPage(String authenticationUrl, String flwRef) {
17+
18+
}
19+
1520
@Override
1621
public void onPaymentError(String message) {
1722

@@ -48,17 +53,17 @@ public void onPaymentFailed(String message, String responseAsJSONString) {
4853
}
4954

5055
@Override
51-
public void onValidationSuccessful(HashMap<String, ViewObject> dataHashMap) {
56+
public void onPaymentSuccessful(String flwRef, String responseAsString) {
5257

5358
}
5459

5560
@Override
56-
public void showFieldError(int viewID, String message, Class<?> viewType) {
61+
public void onValidationSuccessful(HashMap<String, ViewObject> dataHashMap) {
5762

5863
}
5964

6065
@Override
61-
public void onPaymentSuccessful(String status, String flwRef, String responseAsString) {
66+
public void showFieldError(int viewID, String message, Class<?> viewType) {
6267

6368
}
6469
}

rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/francmobilemoney/FrancMobileMoneyContract.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.flutterwave.raveandroid.rave_presentation.francmobilemoney;
22

3+
import android.webkit.WebResourceRequest;
4+
import android.webkit.WebView;
5+
36
import com.flutterwave.raveandroid.rave_java_commons.Payload;
47
import com.flutterwave.raveandroid.rave_logger.Event;
8+
import com.flutterwave.raveandroid.rave_presentation.card.CardContract;
59

610
/**
711
* Created by hfetuga on 27/06/2018.
@@ -12,6 +16,22 @@ public interface FrancMobileMoneyContract {
1216
interface Interactor {
1317
void showFetchFeeFailed(String s);
1418

19+
/**
20+
* Called to display a {@link android.webkit.WebView} for charges that require webpage authentication.
21+
* When the payment is completed, the authentication page redirects to a {@link com.flutterwave.raveandroid.rave_java_commons.RaveConstants#RAVE_3DS_CALLBACK predefined url}
22+
* with the payment details appended to the url.
23+
* <p>
24+
* You should override the webview client's {@link android.webkit.WebViewClient#shouldOverrideUrlLoading(WebView, WebResourceRequest) shouldOverrideUrlLoading}
25+
* function to check if the {@link WebResourceRequest#getUrl() url being loaded} contains the
26+
* {@link com.flutterwave.raveandroid.rave_java_commons.RaveConstants#RAVE_3DS_CALLBACK predefined redirect url}.
27+
* <p>
28+
* If it does, it means the transaction has been completed and you can now call {@link CardContract.CardPaymentHandler#requeryTx(String, String)} with the {@code flwRef} to check the transaction status.
29+
*
30+
* @param authenticationUrl The url to the authentication page
31+
* @param flwRef The Flutterwave transaction reference
32+
*/
33+
void showWebPage(String authenticationUrl, String flwRef);
34+
1535
void onPaymentError(String message);
1636

1737
void showPollingIndicator(boolean active);
@@ -22,15 +42,15 @@ interface Interactor {
2242

2343
void onPaymentFailed(String message, String responseAsJSONString);
2444

25-
void onPaymentSuccessful(String status, String flwRef, String responseAsString);
45+
void onPaymentSuccessful( String flwRef, String responseAsString);
2646
}
2747

2848
interface Handler {
2949
void fetchFee(Payload payload);
3050

3151
void chargeFranc(Payload payload, String encryptionKey);
3252

33-
void requeryTx(String flwRef, String txRef, String publicKey);
53+
void requeryTx(String flwRef, String publicKey);
3454

3555
void logEvent(Event event, String publicKey);
3656
}

rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/francmobilemoney/FrancMobileMoneyHandler.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,14 @@ public void onSuccess(ChargeResponse response) {
9898
mInteractor.showProgressIndicator(false);
9999

100100
if (response.getData() != null) {
101+
101102
String flwRef = response.getData().getData().getFlw_reference();
102103
String txRef = response.getData().getData().getTransaction_reference();
103-
requeryTx(flwRef, txRef, payload.getPBFPubKey());
104+
if (response.getRedirectUrl()!=null){
105+
mInteractor.showWebPage(response.getRedirectUrl(), flwRef);
106+
}else {
107+
requeryTx(flwRef, payload.getPBFPubKey());
108+
}
104109
} else {
105110
mInteractor.onPaymentError(noResponse);
106111
}
@@ -117,7 +122,7 @@ public void onError(String message) {
117122

118123

119124
@Override
120-
public void requeryTx(final String flwRef, final String txRef, final String publicKey) {
125+
public void requeryTx(final String flwRef, final String publicKey) {
121126

122127
RequeryRequestBody body = new RequeryRequestBody();
123128
body.setFlw_ref(flwRef);
@@ -138,10 +143,10 @@ public void onSuccess(RequeryResponse response, String responseAsJSONString) {
138143
mInteractor.showProgressIndicator(false);
139144
mInteractor.onPaymentFailed(response.getData().getStatus(), responseAsJSONString);
140145
} else if (response.getData().getChargeResponseCode().equals("02")) {
141-
requeryTx(flwRef, txRef, publicKey);
146+
requeryTx(flwRef, publicKey);
142147
} else if (response.getData().getChargeResponseCode().equals("00")) {
143148
mInteractor.showPollingIndicator(false);
144-
mInteractor.onPaymentSuccessful(flwRef, txRef, responseAsJSONString);
149+
mInteractor.onPaymentSuccessful(flwRef, responseAsJSONString);
145150
} else {
146151
mInteractor.showProgressIndicator(false);
147152
mInteractor.onPaymentFailed(response.getData().getStatus(), responseAsJSONString);

rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/francmobilemoney/FrancMobileMoneyInteractorImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void onPaymentFailed(String message, String responseAsJSONString) {
4141
}
4242

4343
@Override
44-
public void onPaymentSuccessful(String status, String flwRef, String responseAsString) {
44+
public void onPaymentSuccessful(String flwRef, String responseAsString) {
4545
callback.onSuccessful(flwRef);
4646
}
4747

@@ -65,6 +65,11 @@ public void showPollingIndicator(boolean active) {
6565
callback.showProgressIndicator(active);
6666
}
6767

68+
@Override
69+
public void showWebPage(String authenticationUrl, String flwRef) {
70+
this.flwRef = flwRef;
71+
callback.showAuthenticationWebPage(authenticationUrl);
72+
}
6873
public String getFlwRef() {
6974
return flwRef;
7075
}

rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/francmobilemoney/FrancophoneMobileMoneyPaymentCallback.java

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

3+
import android.webkit.WebResourceRequest;
4+
import android.webkit.WebView;
5+
36
import androidx.annotation.Nullable;
47

8+
import com.flutterwave.raveandroid.rave_presentation.card.CardPaymentManager;
9+
510
public interface FrancophoneMobileMoneyPaymentCallback {
611

712
/**
@@ -26,4 +31,19 @@ public interface FrancophoneMobileMoneyPaymentCallback {
2631
* @param flwRef The Flutterwave reference to the transaction.
2732
*/
2833
void onSuccessful(String flwRef);
34+
35+
/**
36+
* Called to display a {@link android.webkit.WebView} for charges that require webpage authentication.
37+
* When the payment is completed, the authentication page redirects to a {@link com.flutterwave.raveandroid.rave_java_commons.RaveConstants#RAVE_3DS_CALLBACK predefined url}
38+
* with the payment details appended to the url.
39+
* <p>
40+
* You should override the webview client's {@link android.webkit.WebViewClient#shouldOverrideUrlLoading(WebView, WebResourceRequest)} shouldOverrideUrlLoading}
41+
* function to check if the {@link WebResourceRequest#getUrl() url being loaded} contains the
42+
* {@link com.flutterwave.raveandroid.rave_java_commons.RaveConstants#RAVE_3DS_CALLBACK predefined redirect url}.
43+
* <p>
44+
* If it does, it means the transaction has been completed and you can now call {@link CardPaymentManager#onWebpageAuthenticationComplete()} to check the transaction status.
45+
*
46+
* @param authenticationUrl The url to the authentication page
47+
*/
48+
void showAuthenticationWebPage(String authenticationUrl);
2949
}

rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/francmobilemoney/NullFrancMobileMoneyPaymentCallback.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ public void onSuccessful(String flwRef) {
1919

2020
}
2121

22+
@Override
23+
public void showAuthenticationWebPage(String authenticationUrl) {
24+
25+
}
26+
2227
}

rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/responses/ChargeResponse.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ public void setInstruction(String instruction) {
9898

9999
}
100100

101+
public String getRedirectUrl() {
102+
return (data == null) ? null : data.getRedirectUrl() != null ? data.getRedirectUrl() : data.getData() != null ? data.getData().getRedirectUrl() : null;
103+
}
104+
101105
public static class Data {
102106

103107
JsonElement meta_data;
@@ -175,9 +179,6 @@ public void setCharged_amount(String charged_amount) {
175179
this.charged_amount = charged_amount;
176180
}
177181

178-
public void setRedirectUrl(String redirectUrl) {
179-
this.redirectUrl = redirectUrl;
180-
}
181182

182183

183184
String note;
@@ -260,8 +261,9 @@ public void setTx_ref(String txRef) {
260261
String currency;
261262
String charged_amount;
262263

264+
263265
public String getRedirectUrl() {
264-
return redirectUrl;
266+
return redirectUrl == null ? redirect_url:redirectUrl;
265267
}
266268

267269
String redirectUrl;

0 commit comments

Comments
 (0)