Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions ChargeVerificationUtils.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Charge Verification Utils
This module helps you handle charge verification when not using the default drop-in UI provided by Flutterwave's android SDK.

**Step 1.** Add this in your root build.gradle at the end of repositories:

allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}

**Step 2.** Add the dependency for the utils library

dependencies {
implementation 'com.github.Flutterwave.rave-android:rave_utils:2.0.3'
}

**Step 2.** In your payment activity or fragment, create and instance of the `RaveVerificationUtils` class

RaveVerificationUtils verificationUtils = new RaveVerificationUtils(contextProvider, isStaging, publicKey, theme);

##### Parameter definitions
| Parameter Name | Description | Type | Required |
| ------------- |:-------------:| -----:| -----:|
| contextProvider | This is the application or fragment class where you're handling the charge verification. | `Activity` or `Fragment` | Required
| isStaging | Specifies whether it's the staging or live environment. | `Boolean` | Required
| publicKey | Your Flutterwave account's public key. | `String` | Required
| theme | Reference to your custom style. | `int` | Not required

**Step 3** You can call the verification class for these scenarios:

```
// For PIN collection:
verificationUtils.showPinScreen();

// For OTP collection
verificationUtils.showOtpScreen(instructionToBeDisplayed); // instruction parameter is optional

// For Address collection
verificationUtils.showAddressScreen();

// For Authentication webpage display
verificationUtils.showWebpageVerificationScreen(authUrl);
```

**Step 4** Handle the result in `onActivityResult`:

```
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (resultCode == RaveConstants.RESULT_SUCCESS) {
switch (requestCode) {
case RaveConstants.PIN_REQUEST_CODE:
String pin = data.getStringExtra(PinFragment.EXTRA_PIN);
// Use the collected PIN
cardPayManager.submitPin(pin);
break;
case RaveConstants.ADDRESS_DETAILS_REQUEST_CODE:
String streetAddress = data.getStringExtra(AVSVBVFragment.EXTRA_ADDRESS);
String state = data.getStringExtra(AVSVBVFragment.EXTRA_STATE);
String city = data.getStringExtra(AVSVBVFragment.EXTRA_CITY);
String zipCode = data.getStringExtra(AVSVBVFragment.EXTRA_ZIPCODE);
String country = data.getStringExtra(AVSVBVFragment.EXTRA_COUNTRY);
AddressDetails address = new AddressDetails(streetAddress, city, state, zipCode, country);

// Use the address details
cardPayManager.submitAddress(address);
break;
case RaveConstants.WEB_VERIFICATION_REQUEST_CODE:
// Web authentication complete, proceed
cardPayManager.onWebpageAuthenticationComplete();
break;
case RaveConstants.OTP_REQUEST_CODE:
String otp = data.getStringExtra(OTPFragment.EXTRA_OTP);
// Use OTP
cardPayManager.submitOtp(otp);
break;
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
```
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ For example to charge cards, use the `CardPaymentManager`

cardPayManager.chargeCard(card);

> We worked on a module to simplify charge verification when using the No-UI approach. You can read about using it [here](ChargeVerificationUtils.md)

> 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)
## Functions definition
| function | parameter | type | required |
Expand Down
54 changes: 40 additions & 14 deletions app/src/main/java/com/flutterwave/rave_android/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import com.flutterwave.raveandroid.rave_presentation.card.SavedCardsListener;
import com.flutterwave.raveandroid.rave_presentation.data.AddressDetails;
import com.flutterwave.raveandroid.rave_remote.responses.SaveCardResponse;
import com.flutterwave.raveutils.verification.AVSVBVFragment;
import com.flutterwave.raveutils.verification.OTPFragment;
import com.flutterwave.raveutils.verification.PinFragment;
import com.flutterwave.raveutils.verification.RaveVerificationUtils;

import java.util.ArrayList;
Expand Down Expand Up @@ -373,8 +376,8 @@ private void validateEntries() {

cardPayManager = new CardPaymentManager(((RaveNonUIManager) raveManager), this, this);
card = new Card(
// "5531886652142950", // Test MasterCard PIN authentication
"4242424242424242", // Test VisaCard 3D-Secure Authentication
"5531886652142950", // Test MasterCard PIN authentication
// "4242424242424242", // Test VisaCard 3D-Secure Authentication
// "4556052704172643", // Test VisaCard (Address Verification)
"12",
"30",
Expand All @@ -390,6 +393,35 @@ private void validateEntries() {

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RaveConstants.RESULT_SUCCESS) {
switch (requestCode) {
case RaveConstants.PIN_REQUEST_CODE:
String pin = data.getStringExtra(PinFragment.EXTRA_PIN);
// Use the collected PIN
cardPayManager.submitPin(pin);
break;
case RaveConstants.ADDRESS_DETAILS_REQUEST_CODE:
String streetAddress = data.getStringExtra(AVSVBVFragment.EXTRA_ADDRESS);
String state = data.getStringExtra(AVSVBVFragment.EXTRA_STATE);
String city = data.getStringExtra(AVSVBVFragment.EXTRA_CITY);
String zipCode = data.getStringExtra(AVSVBVFragment.EXTRA_ZIPCODE);
String country = data.getStringExtra(AVSVBVFragment.EXTRA_COUNTRY);
AddressDetails address = new AddressDetails(streetAddress, city, state, zipCode, country);

// Use the address details
cardPayManager.submitAddress(address);
break;
case RaveConstants.WEB_VERIFICATION_REQUEST_CODE:
// Web authentication complete, proceed
cardPayManager.onWebpageAuthenticationComplete();
break;
case RaveConstants.OTP_REQUEST_CODE:
String otp = data.getStringExtra(OTPFragment.EXTRA_OTP);
// Use OTP
cardPayManager.submitOtp(otp);
break;
}
}

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

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

@Override
public void collectCardPin() {
Toast.makeText(this, "Submitting PIN", Toast.LENGTH_SHORT).show();
cardPayManager.submitPin("3310");
new RaveVerificationUtils(this, isLiveSwitch.isChecked(), publicKeyEt.getText().toString())
.showPinScreen();
}

@Override
public void collectOtp(String message) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Submitting OTP", Toast.LENGTH_SHORT).show();
cardPayManager.submitOtp("12345");
new RaveVerificationUtils(this, isLiveSwitch.isChecked(), publicKeyEt.getText().toString())
.showOtpScreen(message);
}

@Override
public void collectAddress() {
Toast.makeText(this, "Submitting address details", Toast.LENGTH_SHORT).show();
cardPayManager.submitAddress(new AddressDetails(
"8, Providence Street",
"Lekki Phase 1",
"Lagos",
"102102",
"NG")
);
new RaveVerificationUtils(this, isLiveSwitch.isChecked(), publicKeyEt.getText().toString())
.showAddressScreen();
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions rave_utils/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group = 'com.github.flutterwave'

android {
compileSdkVersion 29
Expand Down