Skip to content

Commit 7ffbf6a

Browse files
authored
Merge pull request #188 from jeremiahVaris/verification_utils
Document verification utils usage
2 parents 08e7ec1 + 60c652b commit 7ffbf6a

File tree

4 files changed

+129
-14
lines changed

4 files changed

+129
-14
lines changed

ChargeVerificationUtils.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Charge Verification Utils
2+
This module helps you handle charge verification when not using the default drop-in UI provided by Flutterwave's android SDK.
3+
4+
**Step 1.** Add this in your root build.gradle at the end of repositories:
5+
6+
allprojects {
7+
repositories {
8+
...
9+
maven { url 'https://jitpack.io' }
10+
}
11+
}
12+
13+
**Step 2.** Add the dependency for the utils library
14+
15+
dependencies {
16+
implementation 'com.github.Flutterwave.rave-android:rave_utils:2.0.3'
17+
}
18+
19+
**Step 2.** In your payment activity or fragment, create and instance of the `RaveVerificationUtils` class
20+
21+
RaveVerificationUtils verificationUtils = new RaveVerificationUtils(contextProvider, isStaging, publicKey, theme);
22+
23+
##### Parameter definitions
24+
| Parameter Name | Description | Type | Required |
25+
| ------------- |:-------------:| -----:| -----:|
26+
| contextProvider | This is the application or fragment class where you're handling the charge verification. | `Activity` or `Fragment` | Required
27+
| isStaging | Specifies whether it's the staging or live environment. | `Boolean` | Required
28+
| publicKey | Your Flutterwave account's public key. | `String` | Required
29+
| theme | Reference to your custom style. | `int` | Not required
30+
31+
**Step 3** You can call the verification class for these scenarios:
32+
33+
```
34+
// For PIN collection:
35+
verificationUtils.showPinScreen();
36+
37+
// For OTP collection
38+
verificationUtils.showOtpScreen(instructionToBeDisplayed); // instruction parameter is optional
39+
40+
// For Address collection
41+
verificationUtils.showAddressScreen();
42+
43+
// For Authentication webpage display
44+
verificationUtils.showWebpageVerificationScreen(authUrl);
45+
```
46+
47+
**Step 4** Handle the result in `onActivityResult`:
48+
49+
```
50+
@Override
51+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
52+
53+
if (resultCode == RaveConstants.RESULT_SUCCESS) {
54+
switch (requestCode) {
55+
case RaveConstants.PIN_REQUEST_CODE:
56+
String pin = data.getStringExtra(PinFragment.EXTRA_PIN);
57+
// Use the collected PIN
58+
cardPayManager.submitPin(pin);
59+
break;
60+
case RaveConstants.ADDRESS_DETAILS_REQUEST_CODE:
61+
String streetAddress = data.getStringExtra(AVSVBVFragment.EXTRA_ADDRESS);
62+
String state = data.getStringExtra(AVSVBVFragment.EXTRA_STATE);
63+
String city = data.getStringExtra(AVSVBVFragment.EXTRA_CITY);
64+
String zipCode = data.getStringExtra(AVSVBVFragment.EXTRA_ZIPCODE);
65+
String country = data.getStringExtra(AVSVBVFragment.EXTRA_COUNTRY);
66+
AddressDetails address = new AddressDetails(streetAddress, city, state, zipCode, country);
67+
68+
// Use the address details
69+
cardPayManager.submitAddress(address);
70+
break;
71+
case RaveConstants.WEB_VERIFICATION_REQUEST_CODE:
72+
// Web authentication complete, proceed
73+
cardPayManager.onWebpageAuthenticationComplete();
74+
break;
75+
case RaveConstants.OTP_REQUEST_CODE:
76+
String otp = data.getStringExtra(OTPFragment.EXTRA_OTP);
77+
// Use OTP
78+
cardPayManager.submitOtp(otp);
79+
break;
80+
}
81+
} else {
82+
super.onActivityResult(requestCode, resultCode, data);
83+
}
84+
}
85+
```

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ For example to charge cards, use the `CardPaymentManager`
186186

187187
cardPayManager.chargeCard(card);
188188

189+
> We worked on a module to simplify charge verification when using the No-UI approach. You can read about using it [here](ChargeVerificationUtils.md)
190+
189191
> To see a more practical way of using the sdk, head to our sample app in the repository [here](https://github.com/Flutterwave/rave-android/tree/master/app)
190192
## Functions definition
191193
| function | parameter | type | required |

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

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
import com.flutterwave.raveandroid.rave_presentation.card.SavedCardsListener;
3535
import com.flutterwave.raveandroid.rave_presentation.data.AddressDetails;
3636
import com.flutterwave.raveandroid.rave_remote.responses.SaveCardResponse;
37+
import com.flutterwave.raveutils.verification.AVSVBVFragment;
38+
import com.flutterwave.raveutils.verification.OTPFragment;
39+
import com.flutterwave.raveutils.verification.PinFragment;
3740
import com.flutterwave.raveutils.verification.RaveVerificationUtils;
3841

3942
import java.util.ArrayList;
@@ -373,8 +376,8 @@ private void validateEntries() {
373376

374377
cardPayManager = new CardPaymentManager(((RaveNonUIManager) raveManager), this, this);
375378
card = new Card(
376-
// "5531886652142950", // Test MasterCard PIN authentication
377-
"4242424242424242", // Test VisaCard 3D-Secure Authentication
379+
"5531886652142950", // Test MasterCard PIN authentication
380+
// "4242424242424242", // Test VisaCard 3D-Secure Authentication
378381
// "4556052704172643", // Test VisaCard (Address Verification)
379382
"12",
380383
"30",
@@ -390,6 +393,35 @@ private void validateEntries() {
390393

391394
@Override
392395
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
396+
if (resultCode == RaveConstants.RESULT_SUCCESS) {
397+
switch (requestCode) {
398+
case RaveConstants.PIN_REQUEST_CODE:
399+
String pin = data.getStringExtra(PinFragment.EXTRA_PIN);
400+
// Use the collected PIN
401+
cardPayManager.submitPin(pin);
402+
break;
403+
case RaveConstants.ADDRESS_DETAILS_REQUEST_CODE:
404+
String streetAddress = data.getStringExtra(AVSVBVFragment.EXTRA_ADDRESS);
405+
String state = data.getStringExtra(AVSVBVFragment.EXTRA_STATE);
406+
String city = data.getStringExtra(AVSVBVFragment.EXTRA_CITY);
407+
String zipCode = data.getStringExtra(AVSVBVFragment.EXTRA_ZIPCODE);
408+
String country = data.getStringExtra(AVSVBVFragment.EXTRA_COUNTRY);
409+
AddressDetails address = new AddressDetails(streetAddress, city, state, zipCode, country);
410+
411+
// Use the address details
412+
cardPayManager.submitAddress(address);
413+
break;
414+
case RaveConstants.WEB_VERIFICATION_REQUEST_CODE:
415+
// Web authentication complete, proceed
416+
cardPayManager.onWebpageAuthenticationComplete();
417+
break;
418+
case RaveConstants.OTP_REQUEST_CODE:
419+
String otp = data.getStringExtra(OTPFragment.EXTRA_OTP);
420+
// Use OTP
421+
cardPayManager.submitOtp(otp);
422+
break;
423+
}
424+
}
393425

394426
if (requestCode == RaveConstants.RAVE_REQUEST_CODE && data != null) {
395427

@@ -500,27 +532,21 @@ public void showProgressIndicator(boolean active) {
500532

501533
@Override
502534
public void collectCardPin() {
503-
Toast.makeText(this, "Submitting PIN", Toast.LENGTH_SHORT).show();
504-
cardPayManager.submitPin("3310");
535+
new RaveVerificationUtils(this, isLiveSwitch.isChecked(), publicKeyEt.getText().toString())
536+
.showPinScreen();
505537
}
506538

507539
@Override
508540
public void collectOtp(String message) {
509-
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
510-
Toast.makeText(this, "Submitting OTP", Toast.LENGTH_SHORT).show();
511-
cardPayManager.submitOtp("12345");
541+
new RaveVerificationUtils(this, isLiveSwitch.isChecked(), publicKeyEt.getText().toString())
542+
.showOtpScreen(message);
512543
}
513544

514545
@Override
515546
public void collectAddress() {
516547
Toast.makeText(this, "Submitting address details", Toast.LENGTH_SHORT).show();
517-
cardPayManager.submitAddress(new AddressDetails(
518-
"8, Providence Street",
519-
"Lekki Phase 1",
520-
"Lagos",
521-
"102102",
522-
"NG")
523-
);
548+
new RaveVerificationUtils(this, isLiveSwitch.isChecked(), publicKeyEt.getText().toString())
549+
.showAddressScreen();
524550
}
525551

526552
@Override

rave_utils/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
apply plugin: 'com.android.library'
2+
apply plugin: 'com.github.dcendents.android-maven'
3+
group = 'com.github.flutterwave'
24

35
android {
46
compileSdkVersion 29

0 commit comments

Comments
 (0)