Skip to content

Commit 23f332c

Browse files
committed
1. change ui component ids by appending rave to avoid conflicts
2. Create function to check tx validity across account and card transactions
1 parent f9adc21 commit 23f332c

File tree

11 files changed

+169
-113
lines changed

11 files changed

+169
-113
lines changed

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import com.google.gson.reflect.TypeToken;
1212
import com.scottyab.aescrypt.AESCrypt;
1313

14+
import org.json.JSONException;
15+
import org.json.JSONObject;
16+
1417
import java.lang.reflect.Type;
1518
import java.security.GeneralSecurityException;
1619
import java.security.MessageDigest;
@@ -37,6 +40,50 @@ public static String getDeviceImei(Context c) {
3740
return mTelephonyManager.getDeviceId();
3841
}
3942

43+
public static boolean wasTxSuccessful(RavePayInitializer ravePayInitializer, String responseAsJSONString){
44+
45+
String amount = ravePayInitializer.getAmount() + "";
46+
String currency = ravePayInitializer.getCurrency();
47+
48+
try {
49+
JSONObject jsonObject = new JSONObject(responseAsJSONString);
50+
JSONObject jsonData = jsonObject.getJSONObject("data");
51+
String status = jsonData.getString("status");
52+
String txAmount = jsonData.getString("amount");
53+
String txCurrency = jsonData.getString("transaction_currency");
54+
JSONObject flwMetaJsonObject = jsonData.getJSONObject("flwMeta");
55+
String chargeResponse = flwMetaJsonObject.getString("chargeResponse");
56+
57+
if (chargeResponse.equalsIgnoreCase("00") &&
58+
status.contains("success") &&
59+
amount.equalsIgnoreCase(txAmount) &&
60+
currency.equalsIgnoreCase(txCurrency)) {
61+
return true;
62+
}
63+
}
64+
catch (JSONException e) {
65+
e.printStackTrace();
66+
return false;
67+
}
68+
69+
70+
// if (unNullify(status).equalsIgnoreCase("success") &&
71+
// )
72+
73+
74+
return true;
75+
}
76+
77+
public static String unNullify(String text) {
78+
79+
if (text == null) {
80+
return "";
81+
}
82+
83+
return text;
84+
85+
}
86+
4087
public static void hide_keyboard(Activity activity) {
4188
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
4289
//Find the currently focused view, so we can grab the correct window token from it.

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,21 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
9292
// Inflate the layout for this fragment
9393
View v = inflater.inflate(R.layout.fragment_account, container, false);
9494

95-
otpTil = (TextInputLayout) v.findViewById(R.id.otpTil);
96-
otpEt = (TextInputEditText) v.findViewById(R.id.otpEv);
97-
otpButton = (Button) v.findViewById(R.id.otpButton);
98-
bankEt = (EditText) v.findViewById(R.id.bankEditText);
99-
amountEt = (TextInputEditText) v.findViewById(R.id.amountTV);
100-
amountTil = (TextInputLayout) v.findViewById(R.id.amountTil);
101-
phoneEt = (TextInputEditText) v.findViewById(R.id.phoneEt);
102-
phoneTil = (TextInputLayout) v.findViewById(R.id.phoneTil);
103-
emailEt = (TextInputEditText) v.findViewById(R.id.emailEt);
104-
emailTil = (TextInputLayout) v.findViewById(R.id.emailTil);
105-
accountNumberEt = (TextInputEditText) v.findViewById(R.id.accountNumberEt);
106-
accountNumberTil = (TextInputLayout) v.findViewById(R.id.accountNumberTil);
107-
payButton = (Button) v.findViewById(R.id.payButton);
108-
webView = (WebView) v.findViewById(R.id.webview);
109-
pcidss_tv = (TextView) v.findViewById(R.id.pcidss_compliant_tv);
95+
otpTil = (TextInputLayout) v.findViewById(R.id.rave_otpTil);
96+
otpEt = (TextInputEditText) v.findViewById(R.id.rave_otpEv);
97+
otpButton = (Button) v.findViewById(R.id.rave_otpButton);
98+
bankEt = (EditText) v.findViewById(R.id.rave_bankEditText);
99+
amountEt = (TextInputEditText) v.findViewById(R.id.rave_amountTV);
100+
amountTil = (TextInputLayout) v.findViewById(R.id.rave_amountTil);
101+
phoneEt = (TextInputEditText) v.findViewById(R.id.rave_phoneEt);
102+
phoneTil = (TextInputLayout) v.findViewById(R.id.rave_phoneTil);
103+
emailEt = (TextInputEditText) v.findViewById(R.id.rave_emailEt);
104+
emailTil = (TextInputLayout) v.findViewById(R.id.rave_emailTil);
105+
accountNumberEt = (TextInputEditText) v.findViewById(R.id.rave_accountNumberEt);
106+
accountNumberTil = (TextInputLayout) v.findViewById(R.id.rave_accountNumberTil);
107+
payButton = (Button) v.findViewById(R.id.rave_payButton);
108+
webView = (WebView) v.findViewById(R.id.rave_webview);
109+
pcidss_tv = (TextView) v.findViewById(R.id.rave_pcidss_compliant_tv);
110110

111111
Linkify.TransformFilter filter = new Linkify.TransformFilter() {
112112
public final String transformUrl(final Matcher match, String url) {
@@ -117,10 +117,10 @@ public final String transformUrl(final Matcher match, String url) {
117117
Pattern pattern = Pattern.compile("()PCI-DSS COMPLIANT");
118118
Linkify.addLinks(pcidss_tv, pattern, "https://www.pcisecuritystandards.org/pci_security/", null, filter);
119119

120-
FrameLayout internetBankingLayout = (FrameLayout) v.findViewById(R.id.internetBankingBottomSheet);
120+
FrameLayout internetBankingLayout = (FrameLayout) v.findViewById(R.id.rave_internetBankingBottomSheet);
121121
bottomSheetBehaviorInternetBanking = BottomSheetBehavior.from(internetBankingLayout);
122122

123-
otpLayout = (LinearLayout) v.findViewById(R.id.OTPBottomSheet);
123+
otpLayout = (LinearLayout) v.findViewById(R.id.rave_OTPBottomSheet);
124124
bottomSheetBehaviorOTP = BottomSheetBehavior.from(otpLayout);
125125

126126
ravePayInitializer = ((RavePayActivity) getActivity()).getRavePayInitializer();
@@ -259,7 +259,7 @@ public void showBanks(List<Bank> banks) {
259259
bottomSheetDialog = new BottomSheetDialog(getActivity());
260260
LayoutInflater inflater = LayoutInflater.from(getActivity());
261261
View v = inflater.inflate(R.layout.add_exisiting_bank, null, false);
262-
RecyclerView recyclerView = (RecyclerView) v.findViewById(R.id.recycler);
262+
RecyclerView recyclerView = (RecyclerView) v.findViewById(R.id.rave_recycler);
263263

264264
BanksRecyclerAdapter adapter = new BanksRecyclerAdapter();
265265
adapter.set(banks);

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.flutterwave.raveandroid.FeeCheckRequestBody;
77
import com.flutterwave.raveandroid.Payload;
88
import com.flutterwave.raveandroid.RaveConstants;
9+
import com.flutterwave.raveandroid.RavePayActivity;
10+
import com.flutterwave.raveandroid.RavePayInitializer;
911
import com.flutterwave.raveandroid.Utils;
1012
import com.flutterwave.raveandroid.card.ChargeRequestBody;
1113
import com.flutterwave.raveandroid.data.Bank;
@@ -182,8 +184,13 @@ public void requeryTx(String flwRef, String SECKEY) {
182184
new NetworkRequestImpl().requeryTx(body, new Callbacks.OnRequeryRequestComplete() {
183185
@Override
184186
public void onSuccess(RequeryResponse response, String responseAsJSONString) {
187+
188+
RavePayInitializer ravePayInitializer = ((RavePayActivity) context).getRavePayInitializer();
189+
boolean wasTxSuccessful = Utils.wasTxSuccessful(ravePayInitializer, responseAsJSONString);
190+
185191
mView.showProgressIndicator(false);
186-
if (response.getStatus() != null && response.getStatus().equalsIgnoreCase("status")) {
192+
193+
if (wasTxSuccessful) {
187194
mView.onPaymentSuccessful(response.getStatus(), responseAsJSONString);
188195
}
189196
else {

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

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@
4444
import com.flutterwave.raveandroid.data.SavedCard;
4545
import com.flutterwave.raveandroid.responses.ChargeResponse;
4646

47-
import org.json.JSONException;
48-
import org.json.JSONObject;
49-
5047
import java.util.List;
5148
import java.util.regex.Matcher;
5249
import java.util.regex.Pattern;
@@ -106,25 +103,25 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
106103
presenter = new CardPresenter(getActivity(), this);
107104
// Inflate the layout for this fragment
108105
v = inflater.inflate(R.layout.fragment_card, container, false);
109-
otpTil = (TextInputLayout) v.findViewById(R.id.otpTil);
110-
otpEt = (TextInputEditText) v.findViewById(R.id.otpEv);
111-
otpButton = (Button) v.findViewById(R.id.otpButton);
112-
savedCardBtn = (Button) v.findViewById(R.id.savedCardButton);
113-
amountEt = (TextInputEditText) v.findViewById(R.id.amountTV);
114-
emailEt = (TextInputEditText) v.findViewById(R.id.emailTv);
115-
cardNoTv = (TextInputEditText) v.findViewById(R.id.cardNoTv);
116-
cardExpiryTv = (TextInputEditText) v.findViewById(R.id.cardExpiryTv);
117-
cvvTv = (TextInputEditText) v.findViewById(R.id.cvvTv);
118-
payButton = (Button) v.findViewById(R.id.payButton);
119-
saveCardSwitch = (SwitchCompat) v.findViewById(R.id.saveCardSwitch);
120-
amountTil = (TextInputLayout) v.findViewById(R.id.amountTil);
121-
emailTil = (TextInputLayout) v.findViewById(R.id.emailTil);
122-
cardNoTil = (TextInputLayout) v.findViewById(R.id.cardNoTil);
123-
cardExpiryTil = (TextInputLayout) v.findViewById(R.id.cardExpiryTil);
124-
cvvTil = (TextInputLayout) v.findViewById(R.id.cvvTil);
125-
webView = (WebView) v.findViewById(R.id.webview);
126-
pcidss_tv = (TextView) v.findViewById(R.id.pcidss_compliant_tv);
127-
progressContainer = (FrameLayout) v.findViewById(R.id.progressContainer);
106+
otpTil = (TextInputLayout) v.findViewById(R.id.rave_otpTil);
107+
otpEt = (TextInputEditText) v.findViewById(R.id.rave_otpEv);
108+
otpButton = (Button) v.findViewById(R.id.rave_otpButton);
109+
savedCardBtn = (Button) v.findViewById(R.id.rave_savedCardButton);
110+
amountEt = (TextInputEditText) v.findViewById(R.id.rave_amountTV);
111+
emailEt = (TextInputEditText) v.findViewById(R.id.rave_emailTv);
112+
cardNoTv = (TextInputEditText) v.findViewById(R.id.rave_cardNoTv);
113+
cardExpiryTv = (TextInputEditText) v.findViewById(R.id.rave_cardExpiryTv);
114+
cvvTv = (TextInputEditText) v.findViewById(R.id.rave_cvvTv);
115+
payButton = (Button) v.findViewById(R.id.rave_payButton);
116+
saveCardSwitch = (SwitchCompat) v.findViewById(R.id.rave_saveCardSwitch);
117+
amountTil = (TextInputLayout) v.findViewById(R.id.rave_amountTil);
118+
emailTil = (TextInputLayout) v.findViewById(R.id.rave_emailTil);
119+
cardNoTil = (TextInputLayout) v.findViewById(R.id.rave_cardNoTil);
120+
cardExpiryTil = (TextInputLayout) v.findViewById(R.id.rave_cardExpiryTil);
121+
cvvTil = (TextInputLayout) v.findViewById(R.id.rave_cvvTil);
122+
webView = (WebView) v.findViewById(R.id.rave_webview);
123+
pcidss_tv = (TextView) v.findViewById(R.id.rave_pcidss_compliant_tv);
124+
progressContainer = (FrameLayout) v.findViewById(R.id.rave_progressContainer);
128125

129126
ravePayInitializer = ((RavePayActivity) getActivity()).getRavePayInitializer();
130127

@@ -190,8 +187,8 @@ public void onDialogExpirationSet(int reference, int year, int monthOfYear) {
190187

191188
payButton.setOnClickListener(this);
192189

193-
otpLayout = (LinearLayout) v.findViewById(R.id.OTPButtomSheet);
194-
vbvLayout = (FrameLayout) v.findViewById(R.id.VBVBottomSheet);
190+
otpLayout = (LinearLayout) v.findViewById(R.id.rave_OTPButtomSheet);
191+
vbvLayout = (FrameLayout) v.findViewById(R.id.rave_VBVBottomSheet);
195192
bottomSheetBehaviorOTP = BottomSheetBehavior.from(otpLayout);
196193
bottomSheetBehaviorVBV = BottomSheetBehavior.from(vbvLayout);
197194

@@ -239,7 +236,7 @@ public boolean closeBottomSheetsIfOpen() {
239236
public void onClick(View v) {
240237

241238
int i = v.getId();
242-
if (i == R.id.payButton) {
239+
if (i == R.id.rave_payButton) {
243240
validateDetails();
244241
}
245242

@@ -406,9 +403,9 @@ public void onPinAuthModelSuggested(final Payload payload) {
406403
LayoutInflater inflater = LayoutInflater.from(getActivity());
407404
View v = inflater.inflate(R.layout.pin_layout, null, false);
408405

409-
Button pinBtn = (Button) v.findViewById(R.id.pinButton);
410-
final TextInputEditText pinEv = (TextInputEditText) v.findViewById(R.id.pinEv);
411-
final TextInputLayout pinTil = (TextInputLayout) v.findViewById(R.id.pinTil);
406+
Button pinBtn = (Button) v.findViewById(R.id.rave_pinButton);
407+
final TextInputEditText pinEv = (TextInputEditText) v.findViewById(R.id.rave_pinEv);
408+
final TextInputLayout pinTil = (TextInputLayout) v.findViewById(R.id.rave_pinTil);
412409

413410
pinBtn.setOnClickListener(new View.OnClickListener() {
414411
@Override
@@ -563,7 +560,7 @@ public void onPaymentFailed(String status, String responseAsJSONString) {
563560
public void showFullProgressIndicator(boolean active) {
564561

565562
if (progressContainer == null) {
566-
progressContainer = (FrameLayout) v.findViewById(R.id.progressContainer);
563+
progressContainer = (FrameLayout) v.findViewById(R.id.rave_progressContainer);
567564
}
568565

569566
if (active) {
@@ -591,7 +588,7 @@ public void showSavedCards(List<SavedCard> cards) {
591588
final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(getActivity());
592589
LayoutInflater inflater = LayoutInflater.from(getActivity());
593590
View v = inflater.inflate(R.layout.pick_saved_card_layout, null, false);
594-
RecyclerView recyclerView = (RecyclerView) v.findViewById(R.id.recycler);
591+
RecyclerView recyclerView = (RecyclerView) v.findViewById(R.id.rave_recycler);
595592

596593
SavedCardRecyclerAdapter adapter = new SavedCardRecyclerAdapter();
597594
adapter.set(cards);
@@ -732,9 +729,9 @@ public void onAVS_VBVSECURECODEModelSuggested(final Payload payload) {
732729
LayoutInflater inflater = LayoutInflater.from(getActivity());
733730
View v = inflater.inflate(R.layout.avsvbv_layout, null, false);
734731

735-
Button zipBtn = (Button) v.findViewById(R.id.zipButton);
736-
final TextInputEditText zipEt = (TextInputEditText) v.findViewById(R.id.zipEt);
737-
final TextInputLayout zipTil = (TextInputLayout) v.findViewById(R.id.zipTil);
732+
Button zipBtn = (Button) v.findViewById(R.id.rave_zipButton);
733+
final TextInputEditText zipEt = (TextInputEditText) v.findViewById(R.id.rave_zipEt);
734+
final TextInputLayout zipTil = (TextInputLayout) v.findViewById(R.id.rave_zipTil);
738735

739736
zipBtn.setOnClickListener(new View.OnClickListener() {
740737
@Override

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.flutterwave.raveandroid.FeeCheckRequestBody;
99
import com.flutterwave.raveandroid.Payload;
1010
import com.flutterwave.raveandroid.RavePayActivity;
11+
import com.flutterwave.raveandroid.RavePayInitializer;
1112
import com.flutterwave.raveandroid.Utils;
1213
import com.flutterwave.raveandroid.data.Callbacks;
1314
import com.flutterwave.raveandroid.data.CardDetsToSave;
@@ -223,8 +224,12 @@ public void requeryTx(final String flwRef, final String SECKEY, final boolean sh
223224
new NetworkRequestImpl().requeryTx(body, new Callbacks.OnRequeryRequestComplete() {
224225
@Override
225226
public void onSuccess(RequeryResponse response, String responseAsJSONString) {
227+
228+
RavePayInitializer ravePayInitializer = ((RavePayActivity) context).getRavePayInitializer();
229+
boolean wasTxSuccessful = Utils.wasTxSuccessful(ravePayInitializer, responseAsJSONString);
226230
mView.showFullProgressIndicator(false);
227-
if (response.getStatus() != null && response.getStatus().equalsIgnoreCase("success")) {
231+
232+
if (wasTxSuccessful) {
228233
mView.onPaymentSuccessful(response.getStatus(), flwRef, responseAsJSONString);
229234
}
230235
else {

raveandroid/src/main/res/layout/add_exisiting_bank.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
android:layout_marginBottom="10dp"
1414
android:textColor="#4a4a4a"
1515
android:gravity="center_horizontal|center_vertical"
16-
android:id="@+id/title_textView"
16+
android:id="@+id/rave_title_textView"
1717
/>
1818

1919
<android.support.v7.widget.RecyclerView
2020
android:layout_width="match_parent"
21-
android:id="@+id/recycler"
21+
android:id="@+id/rave_recycler"
2222
android:layout_height="wrap_content"/>
2323

2424

raveandroid/src/main/res/layout/avsvbv_layout.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
<android.support.design.widget.TextInputLayout
2727
android:layout_width="match_parent"
28-
android:id="@+id/zipTil"
28+
android:id="@+id/rave_zipTil"
2929
android:layout_marginBottom="20dp"
3030
android:layout_marginLeft="30dp"
3131
android:layout_marginRight="30dp"
@@ -39,13 +39,13 @@
3939
android:drawableStart="@drawable/ic_lock_outline_black_24dp"
4040
android:drawablePadding="7dp"
4141
android:maxLength="4"
42-
android:id="@+id/zipEt"
42+
android:id="@+id/rave_zipEt"
4343
/>
4444

4545
</android.support.design.widget.TextInputLayout>
4646

4747
<Button
48-
android:id="@+id/zipButton"
48+
android:id="@+id/rave_zipButton"
4949
android:layout_width="match_parent"
5050
android:layout_height="wrap_content"
5151
android:layout_marginRight="30dp"

0 commit comments

Comments
 (0)