|
| 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 | +``` |
0 commit comments