Skip to content

Commit 08eeb6a

Browse files
committed
add mpesa and ghana mobile money payment options
1 parent 653729a commit 08eeb6a

File tree

7 files changed

+105
-25
lines changed

7 files changed

+105
-25
lines changed

app/src/main/java/com/flutterwave/rave_android/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private void validateEntries() {
144144
.acceptCardPayments(cardSwitch.isChecked())
145145
.acceptGHMobileMoneyPayments(ghMobileMoneySwitch.isChecked())
146146
.onStagingEnv(!isLiveSwitch.isChecked())
147-
.setMeta(meta)
147+
// .setMeta(meta)
148148
// .withTheme(R.style.TestNewTheme)
149149
.initialize();
150150

raveandroid/src/main/java/com/flutterwave/raveandroid/ghmobilemoney/GhMobileMoneyContract.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public interface GhMobileMoneyContract {
1010

1111
interface View {
1212
void showProgressIndicator(boolean active);
13+
void showPollingIndicator(boolean active);
14+
void onPollingRoundComplete(String flwRef, String txRef, String secretKey);
1315
void onPaymentError(String message);
1416
void showToast(String message);
1517
void onPaymentSuccessful(String status, String flwRef, String responseAsString);
@@ -21,5 +23,6 @@ interface View {
2123
interface UserActionsListener {
2224
void fetchFee(Payload payload);
2325
void chargeGhMobileMoney(Payload payload, String secretKey);
26+
void requeryTxv2(String flwRef, String txRef, String secretKey);
2427
}
2528
}

raveandroid/src/main/java/com/flutterwave/raveandroid/ghmobilemoney/GhMobileMoneyFragment.java

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public class GhMobileMoneyFragment extends Fragment implements GhMobileMoneyCont
3838
TextInputEditText phoneEt;
3939
TextInputLayout phoneTil;
4040
RavePayInitializer ravePayInitializer;
41-
private ProgressDialog progessDialog ;
41+
private ProgressDialog progressDialog;
42+
private ProgressDialog pollingProgressDialog ;
4243
GhMobileMoneyPresenter presenter;
4344
Spinner networkSpinner;
4445

@@ -164,16 +165,50 @@ private void validate() {
164165
public void showProgressIndicator(boolean active) {
165166

166167
if (getActivity().isFinishing()) { return; }
167-
if(progessDialog == null) {
168-
progessDialog = new ProgressDialog(getActivity());
169-
progessDialog.setMessage("Please wait...");
168+
if(progressDialog == null) {
169+
progressDialog = new ProgressDialog(getActivity());
170+
progressDialog.setMessage("Please wait...");
170171
}
171172

172-
if (active && !progessDialog.isShowing()) {
173-
progessDialog.show();
173+
if (active && !progressDialog.isShowing()) {
174+
progressDialog.show();
174175
}
175176
else {
176-
progessDialog.dismiss();
177+
progressDialog.dismiss();
178+
}
179+
}
180+
181+
@Override
182+
public void showPollingIndicator(boolean active) {
183+
if (getActivity().isFinishing()) { return; }
184+
185+
if(pollingProgressDialog == null) {
186+
pollingProgressDialog = new ProgressDialog(getActivity());
187+
pollingProgressDialog.setMessage("Checking transaction status. \nPlease wait");
188+
}
189+
190+
if (active && !pollingProgressDialog.isShowing()) {
191+
pollingProgressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
192+
@Override
193+
public void onClick(DialogInterface dialog, int which) {
194+
pollingProgressDialog.dismiss();
195+
}
196+
});
197+
198+
pollingProgressDialog.show();
199+
}
200+
else if (active && pollingProgressDialog.isShowing()) {
201+
//pass
202+
}
203+
else {
204+
pollingProgressDialog.dismiss();
205+
}
206+
}
207+
208+
@Override
209+
public void onPollingRoundComplete(String flwRef, String txRef, String secretKey) {
210+
if (pollingProgressDialog != null && pollingProgressDialog.isShowing()) {
211+
presenter.requeryTxv2(flwRef, txRef, secretKey);
177212
}
178213
}
179214

raveandroid/src/main/java/com/flutterwave/raveandroid/ghmobilemoney/GhMobileMoneyPresenter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ public void onError(String message, String responseAsJSONString) {
105105
});
106106
}
107107

108-
private void requeryTxv2(final String flwRef, final String txRef, final String secretKey) {
109-
108+
@Override
109+
public void requeryTxv2(final String flwRef, final String txRef, final String secretKey) {
110110

111111
RequeryRequestBodyv2 body = new RequeryRequestBodyv2();
112112
body.setTxref(txRef);
113113
body.setSECKEY(secretKey);
114114

115-
mView.showProgressIndicator(true);
115+
mView.showPollingIndicator(true);
116116

117117
new NetworkRequestImpl().requeryTxv2(body, new Callbacks.OnRequeryRequestv2Complete() {
118118
@Override
@@ -121,7 +121,7 @@ public void onSuccess(RequeryResponsev2 response, String responseAsJSONString) {
121121
mView.onPaymentFailed(response.getStatus(), responseAsJSONString);
122122
}
123123
else if (response.getData().getChargecode().equals("02")){
124-
requeryTxv2(flwRef, txRef, secretKey);
124+
mView.onPollingRoundComplete(flwRef, txRef, secretKey);
125125
}
126126
else if (response.getData().getChargecode().equals("00")) {
127127
requeryTx(flwRef, secretKey);
@@ -146,6 +146,7 @@ private void requeryTx(final String flwRef, final String SECKEY) {
146146
body.setFlw_ref(flwRef);
147147
body.setSECKEY(SECKEY);
148148

149+
mView.showPollingIndicator(false);
149150
mView.showProgressIndicator(true);
150151

151152
new NetworkRequestImpl().requeryTx(body, new Callbacks.OnRequeryRequestComplete() {

raveandroid/src/main/java/com/flutterwave/raveandroid/mpesa/MpesaContract.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public interface MpesaContract {
1010

1111
interface View {
1212
void showProgressIndicator(boolean active);
13+
void showPollingIndicator(boolean active);
14+
void onPollingRoundComplete(String flwRef, String txRef, String secretKey);
1315
void onPaymentError(String message);
1416
void showToast(String message);
1517
void onPaymentSuccessful(String status, String flwRef, String responseAsString);
@@ -21,5 +23,6 @@ interface View {
2123
interface UserActionsListener {
2224
void fetchFee(Payload payload);
2325
void chargeMpesa(Payload payload, String secretKey);
26+
void requeryTxv2(String flwRef, String txRef, String secretKey);
2427
}
2528
}

raveandroid/src/main/java/com/flutterwave/raveandroid/mpesa/MpesaFragment.java

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.flutterwave.raveandroid.Payload;
2020
import com.flutterwave.raveandroid.PayloadBuilder;
2121
import com.flutterwave.raveandroid.R;
22-
import com.flutterwave.raveandroid.RaveConstants;
2322
import com.flutterwave.raveandroid.RavePayActivity;
2423
import com.flutterwave.raveandroid.RavePayInitializer;
2524
import com.flutterwave.raveandroid.Utils;
@@ -37,7 +36,8 @@ public class MpesaFragment extends Fragment implements MpesaContract.View {
3736
TextInputEditText phoneEt;
3837
TextInputLayout phoneTil;
3938
RavePayInitializer ravePayInitializer;
40-
private ProgressDialog progessDialog ;
39+
private ProgressDialog progressDialog;
40+
private ProgressDialog pollingProgressDialog ;
4141
MpesaPresenter presenter;
4242

4343
public MpesaFragment() {
@@ -79,6 +79,42 @@ public void onClick(View v) {
7979
return v;
8080
}
8181

82+
@Override
83+
public void onPollingRoundComplete(String flwRef, String txRef, String secretKey) {
84+
85+
if (pollingProgressDialog != null && pollingProgressDialog.isShowing()) {
86+
presenter.requeryTxv2(flwRef, txRef, secretKey);
87+
}
88+
89+
}
90+
91+
@Override
92+
public void showPollingIndicator(boolean active) {
93+
if (getActivity().isFinishing()) { return; }
94+
95+
if(pollingProgressDialog == null) {
96+
pollingProgressDialog = new ProgressDialog(getActivity());
97+
pollingProgressDialog.setMessage("Checking transaction status. \nPlease wait");
98+
}
99+
100+
if (active && !pollingProgressDialog.isShowing()) {
101+
pollingProgressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
102+
@Override
103+
public void onClick(DialogInterface dialog, int which) {
104+
pollingProgressDialog.dismiss();
105+
}
106+
});
107+
108+
pollingProgressDialog.show();
109+
}
110+
else if (active && pollingProgressDialog.isShowing()) {
111+
//pass
112+
}
113+
else {
114+
pollingProgressDialog.dismiss();
115+
}
116+
}
117+
82118
private void clearErrors() {
83119
amountTil.setError(null);
84120
phoneTil.setError(null);
@@ -154,19 +190,19 @@ public void showProgressIndicator(boolean active) {
154190

155191
if (getActivity().isFinishing()) { return; }
156192

157-
if(progessDialog == null) {
158-
progessDialog = new ProgressDialog(getActivity());
159-
progessDialog.setMessage("Please wait...");
193+
if(progressDialog == null) {
194+
progressDialog = new ProgressDialog(getActivity());
195+
progressDialog.setMessage("Please wait...");
160196
}
161197

162-
if (active && !progessDialog.isShowing()) {
163-
progessDialog.show();
198+
if (active && !progressDialog.isShowing()) {
199+
progressDialog.show();
164200
}
165-
else if (active && progessDialog.isShowing()) {
201+
else if (active && progressDialog.isShowing()) {
166202
//pass
167203
}
168204
else {
169-
progessDialog.dismiss();
205+
progressDialog.dismiss();
170206
}
171207
}
172208

raveandroid/src/main/java/com/flutterwave/raveandroid/mpesa/MpesaPresenter.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,14 @@ public void onError(String message, String responseAsJSONString) {
106106
});
107107
}
108108

109-
private void requeryTxv2(final String flwRef, final String txRef, final String secretKey) {
109+
@Override
110+
public void requeryTxv2(final String flwRef, final String txRef, final String secretKey) {
110111

111112
RequeryRequestBodyv2 body = new RequeryRequestBodyv2();
112113
body.setTxref(txRef);
113114
body.setSECKEY(secretKey);
114115

115-
mView.showProgressIndicator(true);
116+
mView.showPollingIndicator(true);
116117

117118
new NetworkRequestImpl().requeryTxv2(body, new Callbacks.OnRequeryRequestv2Complete() {
118119
@Override
@@ -121,13 +122,13 @@ public void onSuccess(RequeryResponsev2 response, String responseAsJSONString) {
121122
mView.onPaymentFailed(response.getStatus(), responseAsJSONString);
122123
}
123124
else if (response.getData().getChargecode().equals("02")){
124-
requeryTxv2(flwRef, txRef, secretKey);
125+
mView.onPollingRoundComplete(flwRef, txRef, secretKey);
125126
}
126127
else if (response.getData().getChargecode().equals("00")) {
127128
requeryTx(flwRef, secretKey);
128129
}
129130
else {
130-
mView.showProgressIndicator(false);
131+
mView.showPollingIndicator(false);
131132
mView.onPaymentFailed(response.getData().getStatus(), responseAsJSONString);
132133
}
133134
}
@@ -146,6 +147,7 @@ private void requeryTx(final String flwRef, final String SECKEY) {
146147
body.setFlw_ref(flwRef);
147148
body.setSECKEY(SECKEY);
148149

150+
mView.showPollingIndicator(false);
149151
mView.showProgressIndicator(true);
150152

151153
new NetworkRequestImpl().requeryTx(body, new Callbacks.OnRequeryRequestComplete() {

0 commit comments

Comments
 (0)