Skip to content

Commit a9fe6f9

Browse files
committed
Merge branch 'checkCardAllowed'
2 parents 1d422ab + 10c9580 commit a9fe6f9

File tree

11 files changed

+279
-19
lines changed

11 files changed

+279
-19
lines changed

rave_android/src/main/java/com/flutterwave/raveandroid/RavePayInitializer.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class RavePayInitializer {
2525
String narration;
2626
String currency;
2727
String country;
28+
String barterCountry;
2829
String fName;
2930
String lName;
3031
String meta;
@@ -41,7 +42,7 @@ public class RavePayInitializer {
4142

4243
public RavePayInitializer(String email, double amount, String publicKey,
4344
String encryptionKey, String txRef, String narration,
44-
String currency, String country, String fName,
45+
String currency, String country, String barterCountry, String fName,
4546
String lName, int theme, String phoneNumber,
4647
boolean isPhoneEditable, boolean saveCardFeatureAllowed, boolean usePhoneAndEmailSuppliedToSaveCards,
4748
boolean isPermanent, int duration, int frequency,
@@ -55,6 +56,7 @@ public RavePayInitializer(String email, double amount, String publicKey,
5556
this.narration = narration;
5657
this.currency = currency;
5758
this.country = country;
59+
this.barterCountry = barterCountry;
5860
this.fName = fName;
5961
this.lName = lName;
6062
this.isPermanent = isPermanent;
@@ -184,6 +186,14 @@ public void setCountry(String country) {
184186
this.country = country;
185187
}
186188

189+
public String getBarterCountry() {
190+
return barterCountry;
191+
}
192+
193+
public void setBarterCountry(String barterCountry) {
194+
this.barterCountry = barterCountry;
195+
}
196+
187197
public String getfName() {
188198
return fName;
189199
}

rave_android/src/main/java/com/flutterwave/raveandroid/RaveUiManager.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,16 @@ public RaveUiManager setCurrency(String currency) {
128128
return this;
129129
}
130130

131-
@Deprecated
132131
public RaveUiManager setCountry(String country) {
133132
this.country = country;
134133
return this;
135134
}
136135

136+
public RaveUiManager setBarterCountry(String barterCountry) {
137+
this.barterCountry = barterCountry;
138+
return this;
139+
}
140+
137141
public RaveUiManager setfName(String fName) {
138142
this.fName = fName;
139143
return this;
@@ -348,6 +352,7 @@ private RavePayInitializer createRavePayInitializer() {
348352
getNarration(),
349353
getCurrency(),
350354
getCountry(),
355+
getBarterCountry(),
351356
getfName(),
352357
getlName(),
353358
theme,

rave_android/src/main/java/com/flutterwave/raveandroid/card/CardUiPresenter.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ public void processTransaction(HashMap<String, ViewObject> dataHashMap, RavePayI
209209

210210
String deviceID = deviceIdGetter.getDeviceId();
211211

212+
String cardFirstSix = "";
213+
if (dataHashMap.get(fieldcardNoStripped).getData().length() > 6) {
214+
cardFirstSix = dataHashMap.get(fieldcardNoStripped).getData().substring(0, 6);
215+
}
212216

213217
PayloadBuilder builder = new PayloadBuilder();
214218
builder.setAmount(String.valueOf(ravePayInitializer.getAmount()))
@@ -234,11 +238,16 @@ public void processTransaction(HashMap<String, ViewObject> dataHashMap, RavePayI
234238

235239
Payload body = builder.createPayload();
236240

237-
if (ravePayInitializer.getIsDisplayFee()) {
238-
fetchFee(body);
239-
} else {
240-
chargeCard(body, ravePayInitializer.getEncryptionKey());
241+
if (ravePayInitializer.getNarration().equalsIgnoreCase("barterRavePay")){
242+
checkCard(cardFirstSix, body, ravePayInitializer.getIsDisplayFee(), ravePayInitializer.getEncryptionKey(), ravePayInitializer.getBarterCountry());
243+
}else{
244+
if (ravePayInitializer.getIsDisplayFee()) {
245+
fetchFee(body);
246+
} else {
247+
chargeCard(body, ravePayInitializer.getEncryptionKey());
248+
}
241249
}
250+
242251
}
243252
}
244253

@@ -273,10 +282,19 @@ public void processSavedCardTransaction(SavedCard savedCard, RavePayInitializer
273282

274283
Payload body = builder.createSavedCardChargePayload();
275284

276-
if (ravePayInitializer.getIsDisplayFee()) {
277-
fetchFee(body);
278-
} else {
279-
chargeSavedCard(body, ravePayInitializer.getEncryptionKey());
285+
String cardFirstSix = "";
286+
if (savedCard.getMasked_pan().length() >= 6) {
287+
cardFirstSix = savedCard.getMasked_pan().substring(0, 6);
288+
}
289+
290+
if (ravePayInitializer.getBarterCountry()!= null){
291+
checkCard(cardFirstSix, body, ravePayInitializer.getIsDisplayFee(), ravePayInitializer.getEncryptionKey(), ravePayInitializer.getBarterCountry());
292+
}else{
293+
if (ravePayInitializer.getIsDisplayFee()) {
294+
fetchFee(body);
295+
} else {
296+
chargeCard(body, ravePayInitializer.getEncryptionKey());
297+
}
280298
}
281299
}
282300
}
@@ -298,7 +316,7 @@ public void checkForSavedCardsInMemory(RavePayInitializer ravePayInitializer) {
298316
savedCards = new ArrayList<>();
299317
}
300318

301-
if(ravePayInitializer.getPhoneNumber().equals(sharedManager.fetchPhoneNumber())){
319+
if (ravePayInitializer.getPhoneNumber().equals(sharedManager.fetchPhoneNumber())) {
302320
retrieveSavedCardsFromMemory(ravePayInitializer.getPhoneNumber(), ravePayInitializer.getPublicKey());
303321
}
304322

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class RaveConstants {
3232
// public static String LIVE_URL = "https://raveapi.azurewebsites.net";
3333
public static String STAGING_URL = "https://ravesandboxapi.flutterwave.com";
3434
public static String LIVE_URL = "https://api.ravepay.co";
35+
public static String CARD_CHECK_URL = "https://lookup.binlist.net";
3536
public static String EVENT_LOGGING_URL = "https://kgelfdz7mf.execute-api.us-east-1.amazonaws.com/";
3637
public static String FLUTTERWAVE_UK_ACCOUNT = "43271228";
3738
public static String FLUTTERWAVE_UK_SORT_CODE = "04-00-53";
@@ -78,6 +79,7 @@ public class RaveConstants {
7879

7980
public static String success = "success";
8081
public static String noResponse = "No response data was returned";
82+
public static String cardNotAllowed = "You can’t fund with cards from other countries yet. Please add a card issued in your country to proceed.";
8183
public static String invalidAccountNoMessage = "Enter a valid account number";
8284
public static String invalidDateOfBirthMessage = "Enter a valid date of birth";
8385
public static String invalidBvnMessage = "Enter a valid BVN";

rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/RavePayManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ abstract public class RavePayManager {
99
protected String narration = "";
1010
protected String currency = "NGN";
1111
protected String country = "NG";
12+
protected String barterCountry = "NG";
1213
protected String fName = "";
1314
protected String lName = "";
1415
protected String meta = "";
@@ -57,6 +58,10 @@ public String getCountry() {
5758
return country;
5859
}
5960

61+
public String getBarterCountry() {
62+
return barterCountry;
63+
}
64+
6065
public String getfName() {
6166
return fName;
6267
}

rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardContract.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ interface CardPaymentHandler {
161161

162162
void chargeCard(Payload payload, String encryptionKey);
163163

164+
void checkCard(String cardFirstSix, Payload body, Boolean isDisplayFee, String encryptionKey, String barterCountry);
165+
164166
void validateCardCharge(String flwRef, String otp, String publicKey);
165167

166168
void requeryTx(String flwRef, String publicKey);

rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardPaymentHandler.java

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.flutterwave.raveandroid.rave_remote.requests.SendOtpRequestBody;
2828
import com.flutterwave.raveandroid.rave_remote.requests.ValidateChargeBody;
2929
import com.flutterwave.raveandroid.rave_remote.responses.ChargeResponse;
30+
import com.flutterwave.raveandroid.rave_remote.responses.CheckCardResponse;
3031
import com.flutterwave.raveandroid.rave_remote.responses.FeeCheckResponse;
3132
import com.flutterwave.raveandroid.rave_remote.responses.LookupSavedCardsResponse;
3233
import com.flutterwave.raveandroid.rave_remote.responses.RequeryResponse;
@@ -48,6 +49,7 @@
4849
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.PIN;
4950
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.RAVEPAY;
5051
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.VBV;
52+
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.cardNotAllowed;
5153
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.enterOTP;
5254
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.noResponse;
5355
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.success;
@@ -186,6 +188,46 @@ public void onError(String message) {
186188
});
187189
}
188190

191+
@Override
192+
public void checkCard(String cardFirstSix, final Payload body, final Boolean isDisplayFee, final String encryptionKey, final String barterCountry) {
193+
194+
mCardInteractor.showProgressIndicator(true);
195+
196+
networkRequest.checkCard(cardFirstSix, new ResultCallback<CheckCardResponse>() {
197+
@Override
198+
public void onSuccess(CheckCardResponse response) {
199+
mCardInteractor.showProgressIndicator(false);
200+
201+
if (response != null && response.getCountry() != null && response.getCountry().getAlpha2() != null) {
202+
if (response.getCountry().getAlpha2().equalsIgnoreCase(barterCountry)) {
203+
continueCharge( isDisplayFee, body, encryptionKey);
204+
} else {
205+
mCardInteractor.onPaymentError(cardNotAllowed);
206+
}
207+
208+
} else {
209+
continueCharge(isDisplayFee, body, encryptionKey);
210+
}
211+
212+
}
213+
214+
@Override
215+
public void onError(String message) {
216+
mCardInteractor.showProgressIndicator(false);
217+
mCardInteractor.onPaymentError(message);
218+
}
219+
});
220+
221+
}
222+
223+
private void continueCharge(boolean isDisplayFee, Payload body, String encryptionKey) {
224+
if (isDisplayFee) {
225+
fetchFee(body);
226+
} else {
227+
chargeCard(body, encryptionKey);
228+
}
229+
}
230+
189231
@Override
190232
public void chargeSavedCard(Payload payload, String encryptionKey) {
191233
if (payload.getOtp() == null || payload.getOtp() == "") {
@@ -344,7 +386,7 @@ public void onError(String message) {
344386
}
345387

346388
@Override
347-
public void deleteASavedCard(String cardHash, String phoneNumber, String publicKey){
389+
public void deleteASavedCard(String cardHash, String phoneNumber, String publicKey) {
348390
mCardInteractor.showProgressIndicator(true);
349391
RemoveSavedCardRequestBody body = new RemoveSavedCardRequestBody(cardHash, phoneNumber, publicKey);
350392
networkRequest.deleteASavedCard(body, new ResultCallback<SaveCardResponse>() {
@@ -371,7 +413,7 @@ public void lookupSavedCards(String publicKey,
371413
body.setDevice_key(phoneNumber);
372414
body.setPublic_key(publicKey);
373415

374-
if(showLoader)
416+
if (showLoader)
375417
mCardInteractor.showProgressIndicator(true);
376418

377419

rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/ApiService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
import com.flutterwave.raveandroid.rave_remote.requests.SaveCardRequestBody;
1111
import com.flutterwave.raveandroid.rave_remote.requests.SendOtpRequestBody;
1212
import com.flutterwave.raveandroid.rave_remote.requests.ValidateChargeBody;
13+
import com.flutterwave.raveandroid.rave_remote.responses.CheckCardResponse;
1314

1415
import retrofit2.Call;
1516
import retrofit2.http.Body;
1617
import retrofit2.http.GET;
18+
import retrofit2.http.Header;
1719
import retrofit2.http.POST;
20+
import retrofit2.http.Path;
1821
import retrofit2.http.Url;
1922

2023
/**
@@ -27,6 +30,9 @@ public interface ApiService {
2730
// Call<ChargeResponse> charge(@Body ChargeRequestBody body);
2831
Call<String> charge(@Body ChargeRequestBody body);
2932

33+
@GET("/{card-first-six}")
34+
Call<String> checkCard(@Path("card-first-six") String cardFirstSix);
35+
3036
@POST("/flwv3-pug/getpaidx/api/charge?use_polling=1")
3137
// Call<ChargeResponse> charge(@Body ChargeRequestBody body);
3238
Call<String> chargeWithPolling(@Body ChargeRequestBody body);

rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/RemoteRepository.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.flutterwave.raveandroid.rave_java_commons.ExecutorCallback;
77
import com.flutterwave.raveandroid.rave_java_commons.NetworkRequestExecutor;
88
import com.flutterwave.raveandroid.rave_java_commons.Payload;
9+
import com.flutterwave.raveandroid.rave_java_commons.RaveConstants;
910
import com.flutterwave.raveandroid.rave_remote.requests.ChargeRequestBody;
1011
import com.flutterwave.raveandroid.rave_remote.requests.LookupSavedCardsRequestBody;
1112
import com.flutterwave.raveandroid.rave_remote.requests.RemoveSavedCardRequestBody;
@@ -14,6 +15,7 @@
1415
import com.flutterwave.raveandroid.rave_remote.requests.SendOtpRequestBody;
1516
import com.flutterwave.raveandroid.rave_remote.requests.ValidateChargeBody;
1617
import com.flutterwave.raveandroid.rave_remote.responses.ChargeResponse;
18+
import com.flutterwave.raveandroid.rave_remote.responses.CheckCardResponse;
1719
import com.flutterwave.raveandroid.rave_remote.responses.FeeCheckResponse;
1820
import com.flutterwave.raveandroid.rave_remote.responses.LookupSavedCardsResponse;
1921
import com.flutterwave.raveandroid.rave_remote.responses.MobileMoneyChargeResponse;
@@ -42,25 +44,28 @@
4244
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.tokenExpired;
4345
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.tokenNotFound;
4446

45-
/**
46-
* Created by hamzafetuga on 18/07/2017.
47-
*/
4847
@Singleton
4948
public class RemoteRepository {
5049

5150
private Retrofit mainRetrofit;
51+
private Retrofit barterRetrofit;
5252
private ApiService service;
53+
private ApiService barterService;
5354
private Gson gson;
5455
private NetworkRequestExecutor executor;
5556
private String errorParsingError = "An error occurred parsing the error response";
5657

5758
@Inject
5859
public RemoteRepository(@Named("mainRetrofit") Retrofit mainRetrofit,
59-
ApiService service,
60+
@Named("barterRetrofit") Retrofit barterRetrofit,
61+
@Named("mainApiService") ApiService service,
62+
@Named("barterApiService") ApiService barterService,
6063
Gson gson,
6164
NetworkRequestExecutor executor) {
6265
this.mainRetrofit = mainRetrofit;
66+
this.barterRetrofit = barterRetrofit;
6367
this.service = service;
68+
this.barterService = barterService;
6469
this.gson = gson;
6570
this.executor = executor;
6671
}
@@ -74,6 +79,16 @@ public void charge(ChargeRequestBody body, final ResultCallback callback) {
7479
);
7580
}
7681

82+
public void checkCard(String cardFirstSix, final ResultCallback callback) {
83+
84+
85+
executor.execute(barterService.checkCard(cardFirstSix),
86+
new TypeToken<CheckCardResponse>() {
87+
}.getType(),
88+
new GenericNetworkCallback<CheckCardResponse>(callback)
89+
);
90+
}
91+
7792
public void chargeWithPolling(ChargeRequestBody body, final ResultCallback callback) {
7893

7994
Call<String> call = service.chargeWithPolling(body);

0 commit comments

Comments
 (0)