This Android application demonstrates the integration of the NetAppsPaySheet
library for handling payments. The application includes a button that triggers the payment process using the NetAppsPaySheet
library with predefined payment parameters.
The TestNetAppPay
class is an AppCompatActivity
that implements the NetAppsPaySheet.NetAppsPayActionSheetListener
interface. The class is responsible for initializing the payment process using the NetAppsPaySheet
library, and handling the success and error callbacks.
Go to gradle.properties and add the line below:
android.enableJetifier=true
Add https://jitpack.io
to your repository example below:
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
To get started with the Payment SDK, you will need to:
- Obtain an API key from NetAppsPay. This can be done by signing up for a developer account at NetAppsPay Developer Portal.
- Install the Payment SDK in your Android project. This can be done by adding the following dependency to your build.gradle file:
- Import the necessary packages and classes.
- Extend the
AppCompatActivity
and implement theNetAppsPaySheet.NetAppsPayActionSheetListener
interface. - Override the
onCreate
method to initialize the view and set up the button click listener. - Create a new
JSONObject
with the required payment parameters. - Call
NetAppsPaySheet.start()
with the required parameters. - Override the
onSuccess
andonError
methods to handle the success and error callbacks, respectively.
-
onCreate(@Nullable Bundle savedInstanceState)
: Initializes the view, sets up the button click listener, and triggers the payment process using theNetAppsPaySheet
library. -
onSuccess(String message)
: Handles the success callback, logs the message. -
onError(String message)
: Handles the error callback, logs the message.
In order to use the NetAppsPaySheet
library in your project, ensure that the required dependencies are added to your project's build.gradle
file.
implementation 'com.github.vi31b:netappssdk:0.0.7'
- Add the required dependencies to your project's
build.gradle
file. - Create a new Android Activity class (e.g.,
TestNetAppPay
) that extendsAppCompatActivity
and implements theNetAppsPaySheet.NetAppsPayActionSheetListener
interface. - In the
onCreate
method, initialize the view and set up the button click listener. - In the button click listener, create a new
JSONObject
with the required payment parameters. - Call
NetAppsPaySheet.start()
with the context, payment parameters, and the listener. - Override the
onSuccess
andonError
methods to handle the success and error callbacks, respectively.
Example:
public class TestNetAppPay extends AppCompatActivity implements NetAppsPaySheet.NetAppsPayActionSheetListener {
protected void onCreate(@Nullable Bundle savedInstanceState) {
// ...
}
@Override
public void onSuccess(String message) {
// Handle success
}
@Override
public void onError(String message) {
// Handle error
}
}
Complete Code:
package com.netapps.com;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import org.jetbrains.annotations.Nullable;
import org.json.JSONObject;
import com.netappssdk.NetAppsPaySheet;
public class TestNetAppPay extends AppCompatActivity implements NetAppsPaySheet.NetAppsPayActionSheetListener {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_main);
Button btnGoRNScreen = this.findViewById(R.id.btnGoRNScreen);
btnGoRNScreen.setOnClickListener(it -> {
try {
JSONObject obj = new JSONObject();
obj.put("public_key","b1108bfb3e2542b287162ef27da838f9");
obj.put("currency", "NGN");
obj.put("amount", "1000");
obj.put("phone", "***080");
obj.put("email", "[email protected]");
obj.put("fullname", "Nwoko Ndubueze");
obj.put("narration", "Testing");
obj.put("tx_ref", "12o9876eertyuiolkjkvghjkjhjjhklhgf344sdsd");
obj.put("paymentChannels", "card,ussd,transfer,payatitude");
NetAppsPaySheet.start(this, obj, this);
} catch (Exception e) {
Log.d("Law", e.getMessage());
}
});
}
@Override
public void onSuccess(String message) {
Log.d("Develop", "onSuccess: ");
}
@Override
public void onError(String message) {
Log.d("develop", "onError: ");
}
}