Skip to content

Commit 77264ba

Browse files
committed
implement uniform payment flow for all payment methods
2 parents 8fa0454 + 0d6e92e commit 77264ba

39 files changed

+1634
-1039
lines changed

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

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,75 @@
1515
/**
1616
* A simple {@link Fragment} subclass.
1717
*/
18-
public class OTPFragment extends Fragment {
18+
public class OTPFragment extends Fragment implements View.OnClickListener {
19+
1920
public static final String EXTRA_OTP = "extraOTP";
20-
public static final String EXTRA_CHARGE_MESSAGE = "extraChargeMessage";
21-
String otp;
21+
TextInputEditText otpEt;
22+
TextInputLayout otpTil;
23+
TextView chargeMessage;
2224
Button otpButton;
2325

26+
public static final String EXTRA_CHARGE_MESSAGE = "extraChargeMessage";
27+
View v;
28+
String otp;
2429

2530
public OTPFragment() {
2631
// Required empty public constructor
2732
}
2833

29-
3034
@Override
3135
public View onCreateView(LayoutInflater inflater, ViewGroup container,
3236
Bundle savedInstanceState) {
33-
// Inflate the layout for this fragment
34-
final View v = inflater.inflate(R.layout.fragment_ot, container, false);
35-
final TextInputLayout otpTil = (TextInputLayout) v.findViewById(R.id.otpTil);
36-
final TextInputEditText otpEt = (TextInputEditText) v.findViewById(R.id.otpEv);
37-
otpButton = (Button) v.findViewById(R.id.otpButton);
38-
TextView chargeMessage = (TextView) v.findViewById(R.id.otpChargeMessage);
39-
if(getArguments().containsKey(EXTRA_CHARGE_MESSAGE)){
40-
chargeMessage.setText(getArguments().getString(EXTRA_CHARGE_MESSAGE));
41-
}
42-
otpButton.setOnClickListener(new View.OnClickListener() {
43-
@Override
44-
public void onClick(View view) {
45-
otp = otpEt.getText().toString();
46-
47-
otpTil.setError(null);
48-
otpTil.setErrorEnabled(false);
49-
50-
if (otp.length() < 1) {
51-
otpTil.setError("Enter a valid one time password");
52-
} else {
53-
goBack();
54-
}
55-
}
56-
});
37+
38+
v = inflater.inflate(R.layout.fragment_ot, container, false);
39+
40+
initializeViews();
41+
42+
setChargeMessage();
43+
44+
setListeners();
5745

5846
return v;
5947
}
6048

49+
private void setListeners() {
50+
otpButton.setOnClickListener(this);
51+
}
52+
53+
private void initializeViews() {
54+
otpTil = v.findViewById(R.id.otpTil);
55+
otpEt = v.findViewById(R.id.otpEv);
56+
otpButton = v.findViewById(R.id.otpButton);
57+
chargeMessage = v.findViewById(R.id.otpChargeMessage);
58+
}
59+
60+
@Override
61+
public void onClick(View view) {
62+
int i = view.getId();
63+
if (i == R.id.otpButton) {
64+
clearErrors();
65+
otp = otpEt.getText().toString();
66+
if (otp.length() < 1) {
67+
otpTil.setError("Enter a valid one time password");
68+
} else {
69+
goBack();
70+
}
71+
}
72+
}
73+
74+
private void clearErrors() {
75+
otpTil.setErrorEnabled(false);
76+
otpTil.setError(null);
77+
}
78+
79+
private void setChargeMessage() {
80+
if (getArguments() != null) {
81+
if (getArguments().containsKey(EXTRA_CHARGE_MESSAGE)) {
82+
chargeMessage.setText(getArguments().getString(EXTRA_CHARGE_MESSAGE));
83+
}
84+
}
85+
}
86+
6187
public void goBack(){
6288
Intent intent = new Intent();
6389
intent.putExtra(EXTRA_OTP, otp);
@@ -68,5 +94,4 @@ public void goBack(){
6894
}
6995

7096

71-
7297
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ public class RaveConstants {
2020
public static String VBV = "VBVSECURECODE";
2121
public static String GTB_OTP = "GTB_OTP";
2222
public static String ACCESS_OTP = "ACCESS_OTP";
23+
public static String NG = "NG";
24+
public static String NGN = "NGN";
25+
public static String UGX = "UGX";
2326
public static String NOAUTH = "NOAUTH";
2427
public static String PIN = "PIN";
2528
public static String AVS_VBVSECURECODE = "AVS_VBVSECURECODE";
29+
public static String enterOTP = "Enter your one time password (OTP)";
2630
public static String NOAUTH_INTERNATIONAL = "NOAUTH_INTERNATIONAL";
2731
public static String RAVEPAY = "ravepay";
2832
public static String RAVE_PARAMS = "raveparams";
@@ -47,6 +51,11 @@ public class RaveConstants {
4751

4852
public static String success = "success";
4953
public static String noResponse = "No response data was returned";
54+
public static String invalidAccountNoMessage = "Enter a valid account number";
55+
public static String invalidDateOfBirthMessage = "Enter a valid date of birth";
56+
public static String invalidBvnMessage = "Enter a valid BVN";
57+
public static String invalidBankCodeMessage = "You need to select bank";
58+
public static String defaultAccounNumber = "0000000000";
5059

5160
public static String response = "response";
5261
public static String mtn = "mtn";
@@ -77,7 +86,6 @@ public class RaveConstants {
7786
public static String unknownAuthmsg = "Unknown Auth Model";
7887
public static String unknownResCodemsg = "Unknown charge response code";
7988
public static String no_authurl_was_returnedmsg = "No authUrl was returned";
80-
public static String no_response_data_was_returnedmsg = "No response data was returned";
8189
public static String wait = "Please wait...";
8290
public static String cancelPayment = "CANCEL PAYMENT";
8391
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,13 @@ public static PublicKey getKey(String key) {
193193
}
194194

195195
public static String getEncryptedData(String unEncryptedString, String encryptionKey) {
196-
try {
197-
return encrypt(unEncryptedString, encryptionKey);
198-
} catch (Exception e) {
199-
e.printStackTrace();
196+
197+
if (unEncryptedString != null && encryptionKey != null) {
198+
try {
199+
return encrypt(unEncryptedString, encryptionKey);
200+
} catch (Exception e) {
201+
e.printStackTrace();
202+
}
200203
}
201204
return null;
202205
}

raveandroid/src/main/java/com/flutterwave/raveandroid/account/AccountContract.java

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

33

4-
import android.app.Activity;
5-
64
import com.flutterwave.raveandroid.Payload;
75
import com.flutterwave.raveandroid.RavePayInitializer;
86
import com.flutterwave.raveandroid.ViewObject;
@@ -35,7 +33,7 @@ interface View {
3533

3634
void onPaymentFailed(String status, String responseAsJSONString);
3735

38-
void onValidateSuccessful(String flwRef, String responseAsJSONString);
36+
void onValidationSuccessful(String flwRef, String responseAsJSONString);
3937

4038
void onValidateError(String message, String responseAsJSONString);
4139

@@ -57,11 +55,11 @@ interface View {
5755

5856
void onAmountValidated(String amountToSet, int visibility);
5957

60-
void showDateOfBirth(int whatToShow);
58+
void showDateOfBirth(int isVisible);
6159

62-
void showBVN(int whatToShow);
60+
void showBVN(int isVisible);
6361

64-
void showInternetBankingSelected(int whatToShow);
62+
void showAccountNumberField(int isVisible);
6563
}
6664

6765
interface UserActionsListener {
@@ -85,7 +83,7 @@ interface UserActionsListener {
8583

8684
void init(RavePayInitializer ravePayInitializer);
8785

88-
void onInternetBankingValidated(Bank bank);
86+
void onBankSelected(Bank bank);
8987
}
9088

9189
}

0 commit comments

Comments
 (0)