Skip to content

Commit 9868a0f

Browse files
committed
correct avs billing flow and implement flow for noauth_international
1 parent 78d3de2 commit 9868a0f

File tree

8 files changed

+396
-23
lines changed

8 files changed

+396
-23
lines changed

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,75 @@ public Payload(List<Meta> meta, String narration,
4747
}
4848

4949

50+
public String getBillingcity() {
51+
return billingcity;
52+
}
53+
54+
public void setBillingcity(String billingcity) {
55+
this.billingcity = billingcity;
56+
}
57+
58+
public String getBillingaddress() {
59+
return billingaddress;
60+
}
61+
62+
public void setBillingaddress(String billingaddress) {
63+
this.billingaddress = billingaddress;
64+
}
65+
66+
public String getBillingstate() {
67+
return billingstate;
68+
}
69+
70+
public void setBillingstate(String billingstate) {
71+
this.billingstate = billingstate;
72+
}
73+
74+
public String getBillingcountry() {
75+
return billingcountry;
76+
}
77+
78+
public void setBillingcountry(String billingcountry) {
79+
this.billingcountry = billingcountry;
80+
}
81+
82+
private String billingcity;
83+
private String billingaddress;
84+
private String billingstate;
85+
private String billingcountry;
86+
87+
public Payload(List<Meta> meta, String narration, String IP, String accountnumber, String accountbank,
88+
String lastname, String firstname, String currency, String country, String amount,
89+
String email, String device_fingerprint, String txRef, String PBFPubKey,
90+
String billingaddress, String billingcity, String billingstate, String billingzip, String billingcountry) {
91+
this.meta = meta;
92+
this.narration = narration;
93+
this.IP = IP;
94+
this.accountnumber = accountnumber;
95+
this.accountbank = accountbank;
96+
this.lastname = lastname;
97+
this.firstname = firstname;
98+
this.currency = currency;
99+
this.country = country;
100+
this.amount = amount;
101+
this.email = email;
102+
this.device_fingerprint = device_fingerprint;
103+
this.txRef = txRef;
104+
this.PBFPubKey = PBFPubKey;
105+
this.billingaddress = billingaddress;
106+
this.billingstate = billingstate;
107+
this.billingcity = billingcity;
108+
this.billingcountry = billingcountry;
109+
this.billingzip = billingzip;
110+
111+
if (meta == null) {
112+
meta = new ArrayList<>();
113+
}
114+
115+
meta.add(new Meta("sdk", "android"));
116+
}
117+
118+
50119
public Payload(List<Meta> meta, String narration, String IP, String accountnumber, String accountbank,
51120
String lastname, String firstname, String currency, String country, String amount,
52121
String email, String device_fingerprint, String txRef, String PBFPubKey) {
@@ -116,6 +185,8 @@ public void setPin(String pin) {
116185

117186
private String pin;
118187

188+
private String redirect_url = "https://rave-webhook.herokuapp.com/receivepayment";
189+
119190
public String getPBFSecKey() {
120191
return PBFSecKey;
121192
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class RaveConstants {
1717
public static String GTB_OTP = "GTB_OTP";
1818
public static String PIN = "PIN";
1919
public static String AVS_VBVSECURECODE = "AVS_VBVSECURECODE";
20+
public static String NOAUTH_INTERNATIONAL = "NOAUTH_INTERNATIONAL";
2021
public static String RAVEPAY = "ravepay";
2122
public static String RAVE_PARAMS = "raveparams";
2223
public static int RAVE_REQUEST_CODE = 4199;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ interface View {
6060
void onValidateCardChargeFailed(String flwRef, String responseAsJSON);
6161

6262
void onRequerySuccessful(RequeryResponse response, String responseAsJSONString, String flwRef);
63+
64+
void onNoAuthInternationalSuggested(Payload payload);
6365
}
6466

6567
interface UserActionsListener {
@@ -90,6 +92,9 @@ interface UserActionsListener {
9092
void onDetachView();
9193

9294
void verifyRequeryResponse(RequeryResponse response, String responseAsJSONString, RavePayInitializer ravePayInitializer, String flwRef);
95+
96+
void chargeCardWithAVSModel(Payload payload, String address, String city, String zipCode,
97+
String country, String state, String avsVbvsecurecode, String secretKey);
9398
}
9499

95100
}

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

Lines changed: 130 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,84 @@ public void onClick(View v) {
226226

227227
}
228228

229+
@Override
230+
public void onNoAuthInternationalSuggested(final Payload payload) {
231+
232+
final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(getActivity());
233+
LayoutInflater inflater = LayoutInflater.from(getActivity());
234+
235+
View v = inflater.inflate( R.layout.avsvbv_layout, null, false);
236+
237+
final TextInputEditText addressEt = (TextInputEditText) v.findViewById(R.id.rave_billAddressEt);
238+
final TextInputEditText stateEt = (TextInputEditText) v.findViewById(R.id.rave_billStateEt);
239+
final TextInputEditText cityEt = (TextInputEditText) v.findViewById(R.id.rave_billCityEt);
240+
final TextInputEditText zipCodeEt = (TextInputEditText) v.findViewById(R.id.rave_zipEt);
241+
final TextInputEditText countryEt = (TextInputEditText) v.findViewById(R.id.rave_countryEt);
242+
final TextInputLayout addressTil = (TextInputLayout) v.findViewById(R.id.rave_billAddressTil);
243+
final TextInputLayout stateTil = (TextInputLayout) v.findViewById(R.id.rave_billStateTil);
244+
final TextInputLayout cityTil = (TextInputLayout) v.findViewById(R.id.rave_billCityTil);
245+
final TextInputLayout zipCodeTil = (TextInputLayout) v.findViewById(R.id.rave_zipTil);
246+
final TextInputLayout countryTil = (TextInputLayout) v.findViewById(R.id.rave_countryTil);
247+
248+
Button zipBtn = (Button) v.findViewById(R.id.rave_zipButton);
249+
250+
zipBtn.setOnClickListener(new View.OnClickListener() {
251+
@Override
252+
public void onClick(View v) {
253+
boolean valid = true;
254+
255+
String address = addressEt.getText().toString();
256+
String state = stateEt.getText().toString();
257+
String city = cityEt.getText().toString();
258+
String zipCode = zipCodeEt.getText().toString();
259+
String country = countryEt.getText().toString();
260+
261+
addressTil.setError(null);
262+
stateTil.setError(null);
263+
cityTil.setError(null);
264+
zipCodeTil.setError(null);
265+
countryTil.setError(null);
266+
267+
if (address.length() == 0) {
268+
valid = false;
269+
addressTil.setError("Enter a valid address");
270+
}
271+
272+
if (state.length() == 0) {
273+
valid = false;
274+
stateTil.setError("Enter a valid state");
275+
}
276+
277+
if (city.length() == 0) {
278+
valid = false;
279+
cityTil.setError("Enter a valid city");
280+
}
281+
282+
if (zipCode.length() == 0) {
283+
valid = false;
284+
zipCodeTil.setError("Enter a valid zip code");
285+
}
286+
287+
if (country.length() == 0) {
288+
valid = false;
289+
countryTil.setError("Enter a valid country");
290+
}
291+
292+
if (valid) {
293+
bottomSheetDialog.dismiss();
294+
presenter.chargeCardWithAVSModel(payload, address, city, zipCode, country, state,
295+
RaveConstants.NOAUTH_INTERNATIONAL, ravePayInitializer.getSecretKey());
296+
}
297+
298+
}
299+
});
300+
301+
302+
bottomSheetDialog.setContentView(v);
303+
bottomSheetDialog.show();
304+
305+
}
306+
229307
@Override
230308
public void onResume() {
231309
super.onResume();
@@ -745,25 +823,68 @@ public void onAVS_VBVSECURECODEModelSuggested(final Payload payload) {
745823
LayoutInflater inflater = LayoutInflater.from(getActivity());
746824
View v = inflater.inflate(R.layout.avsvbv_layout, null, false);
747825

826+
827+
final TextInputEditText addressEt = (TextInputEditText) v.findViewById(R.id.rave_billAddressEt);
828+
final TextInputEditText stateEt = (TextInputEditText) v.findViewById(R.id.rave_billStateEt);
829+
final TextInputEditText cityEt = (TextInputEditText) v.findViewById(R.id.rave_billCityEt);
830+
final TextInputEditText zipCodeEt = (TextInputEditText) v.findViewById(R.id.rave_zipEt);
831+
final TextInputEditText countryEt = (TextInputEditText) v.findViewById(R.id.rave_countryEt);
832+
final TextInputEditText addressTil = (TextInputEditText) v.findViewById(R.id.rave_billAddressTil);
833+
final TextInputEditText stateTil = (TextInputEditText) v.findViewById(R.id.rave_billStateTil);
834+
final TextInputEditText cityTil = (TextInputEditText) v.findViewById(R.id.rave_billCityTil);
835+
final TextInputEditText zipCodeTil = (TextInputEditText) v.findViewById(R.id.rave_zipTil);
836+
final TextInputEditText countryTil = (TextInputEditText) v.findViewById(R.id.rave_countryTil);
837+
748838
Button zipBtn = (Button) v.findViewById(R.id.rave_zipButton);
749-
final TextInputEditText zipEt = (TextInputEditText) v.findViewById(R.id.rave_zipEt);
750-
final TextInputLayout zipTil = (TextInputLayout) v.findViewById(R.id.rave_zipTil);
751839

752840
zipBtn.setOnClickListener(new View.OnClickListener() {
753841
@Override
754842
public void onClick(View v) {
755-
String zip = zipEt.getText().toString();
843+
boolean valid = true;
844+
845+
String address = addressEt.getText().toString();
846+
String state = stateEt.getText().toString();
847+
String city = cityEt.getText().toString();
848+
String zipCode = zipCodeEt.getText().toString();
849+
String country = countryEt.getText().toString();
850+
851+
addressTil.setError(null);
852+
stateTil.setError(null);
853+
cityTil.setError(null);
854+
zipCodeTil.setError(null);
855+
countryTil.setError(null);
856+
857+
if (address.length() == 0) {
858+
valid = false;
859+
addressTil.setError("Enter a valid address");
860+
}
756861

757-
zipTil.setError(null);
758-
zipTil.setErrorEnabled(false);
862+
if (state.length() == 0) {
863+
valid = false;
864+
stateTil.setError("Enter a valid state");
865+
}
759866

760-
if (zip.length() == 0) {
761-
zipTil.setError("Enter a valid pin");
867+
if (city.length() == 0) {
868+
valid = false;
869+
cityTil.setError("Enter a valid city");
762870
}
763-
else {
871+
872+
if (zipCode.length() == 0) {
873+
valid = false;
874+
zipCodeTil.setError("Enter a valid zip code");
875+
}
876+
877+
if (country.length() == 0) {
878+
valid = false;
879+
countryTil.setError("Enter a valid country");
880+
}
881+
882+
if (valid) {
764883
dialog.dismiss();
765-
presenter.chargeCardWithSuggestedAuthModel(payload, zip, AVS_VBVSECURECODE, ravePayInitializer.getSecretKey());
884+
presenter.chargeCardWithAVSModel(payload, address, city, zipCode, country, state,
885+
AVS_VBVSECURECODE, ravePayInitializer.getSecretKey());
766886
}
887+
767888
}
768889
});
769890

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

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,12 @@ public void onSuccess(ChargeResponse response, String responseAsJSONString) {
6868
if (suggested_auth.equals(RaveConstants.PIN)) {
6969
mView.onPinAuthModelSuggested(payload);
7070
}
71-
else if (suggested_auth.equals(AVS_VBVSECURECODE)) {
71+
else if (suggested_auth.equals(AVS_VBVSECURECODE)) { //address verification then verification by visa
7272
mView.onAVS_VBVSECURECODEModelSuggested(payload);
7373
}
74+
else if (suggested_auth.equalsIgnoreCase(RaveConstants.NOAUTH_INTERNATIONAL)) {
75+
mView.onNoAuthInternationalSuggested(payload);
76+
}
7477
else {
7578
mView.onPaymentError("Unknown auth model");
7679
}
@@ -109,6 +112,75 @@ public void onError(String message, String responseAsJSONString) {
109112
});
110113
}
111114

115+
@Override
116+
public void chargeCardWithAVSModel(Payload payload, String address, String city, String zipCode, String country, String state, String authModel, String secretKey) {
117+
118+
payload.setSuggestedAuth(authModel);
119+
payload.setBillingaddress(address);
120+
payload.setBillingcity(city);
121+
payload.setBillingzip(zipCode);
122+
payload.setBillingcountry(country);
123+
payload.setBillingstate(state);
124+
125+
String cardRequestBodyAsString = Utils.convertChargeRequestPayloadToJson(payload);
126+
String encryptedCardRequestBody = Utils.getEncryptedData(cardRequestBodyAsString, secretKey).trim().replaceAll("\\n", "");
127+
128+
// Log.d("encrypted", encryptedCardRequestBody);
129+
130+
ChargeRequestBody body = new ChargeRequestBody();
131+
body.setAlg("3DES-24");
132+
body.setPBFPubKey(payload.getPBFPubKey());
133+
body.setClient(encryptedCardRequestBody);
134+
135+
mView.showProgressIndicator(true);
136+
137+
new NetworkRequestImpl().chargeCard(body, new Callbacks.OnChargeRequestComplete() {
138+
@Override
139+
public void onSuccess(ChargeResponse response, String responseAsJSONString) {
140+
141+
mView.showProgressIndicator(false);
142+
143+
if (response.getData() != null && response.getData().getChargeResponseCode() != null) {
144+
String chargeResponseCode = response.getData().getChargeResponseCode();
145+
146+
if (chargeResponseCode.equalsIgnoreCase("00")) {
147+
// mView.showToast("Payment successful");
148+
mView.onChargeCardSuccessful(response);
149+
}
150+
else if (chargeResponseCode.equalsIgnoreCase("02")) {
151+
String authModelUsed = response.getData().getAuthModelUsed();
152+
if (authModelUsed.equalsIgnoreCase(RaveConstants.PIN)) {
153+
String flwRef = response.getData().getFlwRef();
154+
String chargeResponseMessage = response.getData().getChargeResponseMessage();
155+
chargeResponseMessage = (chargeResponseMessage == null || chargeResponseMessage.length() == 0) ? "Enter your one time password (OTP)" : chargeResponseMessage;
156+
mView.showOTPLayout(flwRef, chargeResponseMessage);
157+
}
158+
else if (authModelUsed.equalsIgnoreCase(RaveConstants.VBV)){
159+
String flwRef = response.getData().getFlwRef();
160+
mView.onAVSVBVSecureCodeModelUsed(response.getData().getAuthurl(), flwRef);
161+
}
162+
else {
163+
mView.onPaymentError("Unknown Auth Model");
164+
}
165+
}
166+
else {
167+
mView.onPaymentError("Unknown charge response code");
168+
}
169+
}
170+
else {
171+
mView.onPaymentError("Invalid charge response code");
172+
}
173+
174+
}
175+
176+
@Override
177+
public void onError(String message, String responseAsJSONString) {
178+
mView.showProgressIndicator(false);
179+
mView.onPaymentError(message);
180+
}
181+
});
182+
183+
}
112184

113185
@Override
114186
public void chargeCardWithSuggestedAuthModel(Payload payload, String zipOrPin, String authModel, String secretKey) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public void showProgressIndicator(boolean active) {
2626

2727
}
2828

29+
@Override
30+
public void onNoAuthInternationalSuggested(Payload payload) {
31+
32+
}
33+
2934
@Override
3035
public void onPaymentError(String message) {
3136

0 commit comments

Comments
 (0)