Search
⌃K
Links

SDK

Initialize

  1. 1.
    Add gradle dependency by adding the following code to the your Android App build.gradle
Kotlin and Java
Flutter
React Native
dependencies {
implementation "io.nearpay:nearpay-sdk:2.1.37"
}
flutter pub add nearpay_flutter_sdk --git-url=https://github.com/nearpayio/nearpay-flutter-sdk.git
// after installing the plugin , please import the package
import 'package:nearpay_flutter_sdk/nearpay.dart';
npm install "https://github.com/nearpayio/nearpay-react-native-sdk.git#main" --save
// after installing the plugin , please import the package
import { EmbededNearpay } from 'react-native-nearpay-sdk';
2.Create single instance of NearPay object with context wherever you need.
Kotlin
Java
Flutter
React Native
val nearpay = NearPay(this, AuthenticationData.UserEnter, Locale.getDefault(), Environments.SANDBOX)
nearPay = new NearPay(this, AuthenticationData.UserEnter.INSTANCE, Locale.getDefault(), Environments.SANDBOX);
//Initialize SDK
var reqData = {
"authtype" : AuthenticationType.email.values, //Same as above reference
"authvalue" : "[email protected]", // Give auth type value
"locale" : Locale.localeDefault.value, // [optional] locale reference
"environment" : Environments.sandbox.value // [Required] environment reference
};
var jsonResponse = await Nearpay.initialize(reqData);
var jsonData = json.decode(jsonResponse);
var status = jsonData['status'];
if(status == 200){
// Initialize Success with 200
}else if(status == 204){
// Initialize Failed with 204, Plugin iniyialize failed with null
}else if(status == 400){
// Missing parameter Failed with 400, Authentication paramer missing Auth Type and Auth Value
// Auth type and Auth value missing
}
const nearpay = new new EmbededNearpay({
authtype: AuthenticationType.email, //[Required] the user auth type
authvalue: '[email protected]', //[Required] the auth value
environment: Environments.sandbox, // [Required] the payment enviroment
locale: Locale.default, // [Optional]
});

While creating instance for Nearpay , you need to pass the following:

Context

You need to pass the current context

AuthenticationData .

We have 4 method for login
1- Login with JWT
AuthenticationData.Jwt("jwt here")
2-Login with existing mobile number
AuthenticationData.Mobile("+966500000000")
3-Login with existing email
AuthenticationData.Email("[email protected]")
4-Let the user enter the mobile number or email to Login
AuthenticationData.UserEnter
Here is an explanation on how to use client dashboard , you need to add users to terminals so they can use the SDK
User Manual - Client Dashboard.pdf
1MB
PDF
Client Dashboard : https://sandbox.nearpay.io

Locale

Locale allows you to select the language to be used.

Environment

This will allow you to choose the environments so you need to choose sandbox and we will tell you when it needs to be changed.
NearPay service is working inside Saudi Arabia only , if you are outside Saudi Arabia , please share your Static ip with Nearpay Team
if the package name of your android project is not registered in NearPay system , you won't be able to communicate with our system .

SDK Flow

  1. 1.
    Once you call any function for the first time , it will ask you to install payment plugin.
2. After the installation is done , we will check your device meets the requirements.
3.If you pass the health check then we will check the JWT and let you accept payment.

Setup (optional)

Setup allows you to install the payment plugin and log in to our app .
if this function is not used , it will be called automatically when you use any other function.
Please don't use SetUp before any other method like purchase,refund,reconcile and reverse.
Kotlin
Java
Flutter
React Native
nearpay.setup(object : SetupListener{
override fun onSetupCompleted() {
// if you wish to get the receipt in Json format use nearPay.toJson()
TODO("Your Code Here")
}
override fun onSetupFailed(setupFailure: SetupFailure) {
when (setupFailure) {
is SetupFailure.AlreadyInstalled -> {
// when the payment plugin is already installed .
TODO("Your Code Here")
}
is SetupFailure.NotInstalled -> {
// when the installtion failed .
TODO("Your Code Here")
}
is SetupFailure.AuthenticationFailed -> {
// when the authentication failed .
// You can use the following method to update your JWT
nearpay.updateAuthentication(AuthenticationData.Jwt("JWT HERE")
TODO("Your Code Here")
}
is SetupFailure.InvalidStatus -> {
// Please note that you can get the status using setupFailure.status
TODO("Your Code Here")
}
}
}
})
nearPay.setup(new SetupListener() {
@Override
public void onSetupCompleted() {
// when the setup is done successfully
}
@Override
public void onSetupFailed(@NonNull SetupFailure setupFailure) {
if (setupFailure instanceof SetupFailure.AlreadyInstalled) {
// when the payment plugin is already installed .
}
else if (setupFailure instanceof SetupFailure.NotInstalled){
// when the installtion failed .
}
else if (setupFailure instanceof SetupFailure.AuthenticationFailed){
// when the Authentication Failed.
nearPay.updateAuthentication(new AuthenticationData.Jwt("JWT is here"));
}
else if (setupFailure instanceof SetupFailure.InvalidStatus){
// you can get the status using the following code
List<StatusCheckError> status = ((SetupFailure.InvalidStatus) setupFailure).getStatus();
}
}
});
var jsonResponse = await Nearpay.setup();
var jsonData = json.decode(jsonResponse);
var status = jsonData['status'];
if(status == 200){
// Initialize Success with 200
}else if(status == 204){
// Initialize Failed with 204, Plugin iniyialize failed with null
}else if(status == 400){
// Missing parameter Failed with 400, Authentication paramer missing Auth Type and Auth Value
// Auth type and Auth value missing
}
await nearpay.setup()
Find Setup Errors here.

Purchase

Please note the amount should be entered like this 100 which means 1.00 SAR so 1455 will be 14.55 SAR & max length is 12 digits include exponent ( 123456789012 ) which will result in 1,234,567,890.12
You may pass Reference ID in customerReferenceNumber field to be attached to this transaction. or null otherwise.
enableReceiptUi is Boolean so you can set it true or false.
Kotlin
Java
Flutter
React Native
val amount : Long = 100 // [Required] ammount you want to set .
val customerReferenceNumber = "9ace70b7-977d-4094-b7f4-4ecb17de6753" //[optional] any number you want to add as a refrence
val enableReceiptUi = true// [optional] true will enable the ui and false will disable
val enableReversal = true // it will allow you to enable or disable the reverse button
val finishTimeOut : Long = 10 // Add the number of seconds
val transactionId = UUID.randomUUID(); // [optional] You can add your UUID here which allows you to ask about the transaction again using the same UUID
val enableUiDismiss = true // [optional] it will allow you to control dismissing the UI
nearpay.purchase(amount, customerReferenceNumber, enableReceiptUi, enableReversal, finishTimeOut, transactionId, enableUiDismiss, object : PurchaseListener{
override fun onPurchaseApproved(receipts: List<TransactionReceipt>?) {
// you can use the object "TransactionReceipt" to get the TransactionReceipt data .
// if you wish to get the receipt in Json format use nearPay.toJson()
TODO("Your Code Here")
}
override fun onPurchaseFailed(purchaseFailure: PurchaseFailure) {
when (purchaseFailure) {
is PurchaseFailure.PurchaseDeclined -> {
// when the payment declined.
TODO("Your Code Here")
}
is PurchaseFailure.PurchaseRejected -> {
// when the payment is rejected .
TODO("Your Code Here")
}
is PurchaseFailure.AuthenticationFailed -> {
// when the authentication failed .
// You can use the following method to update your JWT
nearpay.updateAuthentication(AuthenticationData.Jwt("JWT HERE")
TODO("Your Code Here")
}
is PurchaseFailure.InvalidStatus -> {
// Please note that you can get the status using purchaseFailure.status
TODO("Your Code Here")
}
is PurchaseFailure.GeneralFailure -> {
// when there is General error .
}
}
}
})
Long amount = 100L; // [Required] ammount you want to set .
String customerReferenceNumber = "9ace70b7-977d-4094-b7f4-4ecb17de6753"; // [optional] any number you want to add as a refrence
Boolean enableReceiptUi = true; // [optional] true will enable the ui and false will disable
Boolean enableReversal = true; // it will allow you to enable or disable the reverse button
Long finishTimeOut = 10L; // Add the number of seconds
UUID transactionId = java.util.UUID.randomUUID(); // You can add your UUID here which allows you to ask about the transaction again using the same UUID
Boolean enableUiDismiss = true ;// [optional] it will allow you to control dismissing the UI
nearPay.purchase(amount, customerReferenceNumber, enableReceiptUi, enableReversal, finishTimeOut,transactionId,enableUiDismiss, new PurchaseListener() {
@Override
public void onPurchaseApproved(@Nullable List<TransactionReceipt> list) {
// if you wish to get the receipt in Json format use ReceiptUtilsKt.toJson(list.get(0))
//write your code here.
}
@Override
public void onPurchaseFailed(@NonNull PurchaseFailure purchaseFailure) {
if (purchaseFailure instanceof PurchaseFailure.GeneralFailure) {
// when there is General error .
}
else if (purchaseFailure instanceof PurchaseFailure.PurchaseDeclined){
// when the payment declined.
}
else if (purchaseFailure instanceof PurchaseFailure.PurchaseRejected){
// when the payment rejected.
}
else if (purchaseFailure instanceof PurchaseFailure.AuthenticationFailed){
// when the authentication failed .
// You can use the following method to update your JWT
nearPay.updateAuthentication(new AuthenticationData.Jwt("JWT is here"));
}
else if (purchaseFailure instanceof PurchaseFailure.InvalidStatus){
// you can get the status using the following code
List<StatusCheckError> status = ((PurchaseFailure.InvalidStatus) purchaseFailure).getStatus();
}
}
});
var reqData = {
"amount": 0001, // [Required] ammount you want to set .
"customer_reference_number": "uuid()", // [optional] any number you want to add as a refrence Any string as a reference number
"isEnableUI" : true, // [optional] true will enable the ui and false will disable
"isEnableReversal" : true, // it will allow you to enable or disable the reverse button
"finishTimeout" : 2 , //[optional] Add the number of seconds
"isUiDismissible": true, //[optional] allow the transaction to be dismissed from ui
"transactionUuid": "740dc2a9-125a-4ee4-8739-13670b3cd5cd", // [optional] uuid for referancing transaction
};
var purchaseReceipt = await Nearpay.purchase(reqData);
var jsonData = json.decode(purchaseReceipt);
var status = jsonData['status'];
if(status == 200){
// Initialize Success with 200
}else if(status == 204){
// Initialize Failed with 204, Plugin iniyialize failed with null
}else if(status == 400){
// Missing parameter Failed with 400, Authentication paramer missing Auth Type and Auth Value
// Auth type and Auth value missing
//Amount parameter null
}
await nearpay.purchase({
amount: amount, // Required
transactionUUID: uuidv4(), //[Optional] speacify the transaction uuid
customerReferenceNumber: '', // [Optional] referance nuber for customer use only
enableReceiptUi: true, // [Optional] show the reciept in ui
enableReversalUi: true, //[Optional] enable reversal of transaction from ui
finishTimeout: 60, //[Optional] finish timeout in seconds
enableUiDismiss: true, //[Optional] the ui is dimissible
}).then((response) => {
console.log(response.receipts)
});
Find TransactionReceipt model here.
Find Purchase errors here.

Refund

pass the transactionUuid of the transaction you want to refund
enableReceiptUi is Boolean so you can set it true or false.
Kotlin
Java
Flutter
React Native
val amount : Long = 100 // [Required] ammount you want to set .
val transactionUuid = "9ace70b7-977d-4094-b7f4-4ecb17de6753" // [Required] add Transaction UUID
val customerReferenceNumber = "9ace70b7-977d-4094-b7f4-4ecb17de6751"; // [optional] any number you want to add as a refrence
val enableReceiptUi = true // [optional] true will enable the ui and false will disable
val enableReversal = true // it will allow you to enable or disable the reverse button
val enableEditableRefundAmountUi = true // [optional] true will enable the ui and false will disable
val finishTimeOut : Long = 10 // Add the number of seconds
val transactionId = UUID.randomUUID(); // [optional] You can add your UUID here which allows you to ask about the transaction again using the same UUID
val adminPin = "0000" //[optional] when you add the admin pin here , the UI for admin pin won't be shown.
val enableUiDismiss = true // [optional] it will allow you to control dismissing the UI
nearpay.refund(amount, transactionUuid, customerReferenceNumber, enableReceiptUi, enableReversal, enableEditableRefundAmountUi, finishTimeOut, adminPin, transactionId, enableUiDismiss, object : RefundListener{
override fun onRefundApproved(receipts: List<TransactionReceipt>?) {
// if you wish to get the receipt in Json format use nearPay.toJson()
TODO("Your Code Here")
}
override fun onRefundFailed(refundFailure: RefundFailure) {
when (refundFailure) {
is RefundFailure.RefundDeclined -> {
// when the refund is declined
TODO("Your Code Here")
}
is RefundFailure.RefundRejected -> {
// when the refund is rejected
TODO("Your Code Here")
}
is RefundFailure.AuthenticationFailed -> {
// when the Authentication is failed
// You can use the following method to update your JWT
nearpay.updateAuthentication(AuthenticationData.Jwt("JWT HERE")
}
is RefundFailure.InvalidStatus -> {
// you can get the status using refundFailure.status .
TODO("Your Code Here")
}
is RefundFailure.GeneralFailure -> {
// when there is general error .
TODO("Your Code Here")
}
}
}
})
Long amount = 100L; // [Required] ammount you want to set .
String transactionUuid = "9ace70b7-977d-4094-b7f4-4ecb17de6753"; // [Required] add Transaction UUID
customerReferenceNumber = "9ace70b7-977d-4094-b7f4-4ecb17de6751"; // [optional] any number you want to add as a refrence
Boolean enableReceiptUi = true; // [optional] true will enable the ui and false will disable
Boolean enableReversal = true; // it will allow you to enable or disable the reverse button
Boolean enableEditableRefundAmountUi = true; // [optional] true will enable the ui and false will disable
Long finishTimeOut = 10L; // Add the number of seconds
UUID transactionId = java.util.UUID.randomUUID(); // [optional] You can add your UUID here which allows you to ask about the transaction again using the same UUID
String adminPin = "0000"; //[optional] when you add the admin pin here , the UI for admin pin won't be shown.
Boolean enableUiDismiss = true ;// [optional] it will allow you to control dismissing the UI
nearPay.refund(amount, transactionUuid, customerReferenceNumber, enableReceiptUi, enableReversal, enableEditableRefundAmountUi, finishTimeOut, transactionId, adminPin,enableUiDismiss, new RefundListener() {
@Override
public void onRefundApproved(@Nullable List<TransactionReceipt> list) {
// write your code here
// if you wish to get the receipt in Json format use ReceiptUtilsKt.toJson(list.get(0))
}
@Override
public void onRefundFailed(@NonNull RefundFailure refundFailure) {
if (refundFailure instanceof RefundFailure.RefundDeclined) {
// when the refund is declined
}
else if (refundFailure instanceof RefundFailure.RefundRejected){
// when the refund is rejected
}
else if (refundFailure instanceof RefundFailure.AuthenticationFailed){
// when the Authentication is failed
// You can use the following method to update your JWT
nearPay.updateAuthentication(new AuthenticationData.Jwt("JWT is here"));
}
else if (refundFailure instanceof RefundFailure.GeneralFailure){
// when there is general error .
}
else if (refundFailure instanceof RefundFailure.InvalidStatus){
// you can get the status using the following code
List<StatusCheckError> status = ((RefundFailure.InvalidStatus) refundFailure).getStatus();
}
}
});
var reqData = {
"amount": 0001, // [Required] ammount you want to set .
"transaction_uuid" : purchaseReceipt.uuid,// [Required] add Transaction UUID we need to pass from purchase response list contains uuid dict key "udid", pass that value here.
"customer_reference_number": "uuid()", // [optional] any number you want to add as a refrence Any string as a reference number
"isEnableUI" : true, // [optional] true will enable the ui and false will disable
"isEnableReversal" : true, // it will allow you to enable or disable the reverse button
"isEditableReversalUI" : true, // [optional] true will enable the ui and false will disable
"finishTimeout" : 2,//[optional] Add the number of seconds
"adminPin" : "0000", // Optional
"isUiDismissible": true, //[optional] allow the transaction to be dismissed from ui
"transactionUuid": "740dc2a9-125a-4ee4-8739-13670b3cd5cd", // [optional] uuid for referancing transaction
};
var refundReceipt = await Nearpay.refund(reqData);
var jsonData = json.decode(refundReceipt);
var status = jsonData['status'];
if(status == 200){
// Initialize Success with 200
}else if(status == 204){
// Initialize Failed with 204, Plugin iniyialize failed with null
}else if(status == 400){
// Missing parameter Failed with 400, Authentication paramer missing Auth Type and Auth Value
// Auth type and Auth value missing
// Amount parameter null
// Transaction UUID null
}
await nearpay.refund({
amount: amount, // [Required]
originalTransactionUUID: uuid, // [Required] the orginal trnasaction uuid that you want to reverse
transactionUUID: uuidv4(), //[Optional] speacify the transaction uuid
customerReferenceNumber: 'rerretest123333333', //[Optional]
enableReceiptUi: true, // [Optional] show the reciept in ui
enableReversalUi: true, //[Optional] enable reversal of transaction from ui
editableReversalAmountUI: true, // [Optional] edit the reversal amount from uid
finishTimeout: 60, //[Optional] finish timeout in seconds
enableUiDismiss: true, //[Optional] the ui is dimissible
adminPin: '0000', // [Optional] when you add the admin pin here , the UI for admin pin won't be shown.
}).then((response) => {
console.log(response.receipts)
});
Find TransactionReceipt model here.
Find Refund errors here.

Reconcile

To perform a reconciliation, Payment reconciliation is an accounting process that verifies account balances to ensure all sets of records are true, consistent, and up-to-date. Businesses can reconcile their accounts daily, weekly, or monthly.
enableReceiptUi is Boolean so you can set it true or false.
Kotlin
Java
Flutter
React Native
val enableReceiptUi = true //[optional] true will enable the ui and false will disable.
val finishTimeOut : Long = 10 //[optional] Add the number of seconds.
val adminPin = "0000" //[optional] when you add the admin pin here , the UI for admin pin won't be shown.
val enableUiDismiss = true // [optional] it will allow you to control dismissing the UI
nearpay.reconcile(enableReceiptUi, adminPin, finishTimeOut, enableUiDismiss, object : ReconcileListener {
override fun onReconcileFinished(receipt: ReconciliationReceipt?) {
// you can use the object to get the reconciliationReceipt data .
// if you wish to get the receipt in Json format use nearPay.toJson()
TODO("Your Code Here")
}
override fun onReconcileFailed(reconcileFailure: ReconcileFailure) {
when (reconcileFailure) {
is ReconcileFailure.FailureMessage -> {
// when there is FailureMessage
TODO("Your Code Here")
}
is ReconcileFailure.AuthenticationFailed -> {
// when the Authentication is failed
// You can use the following method to update your JWT
nearpay.updateAuthentication(AuthenticationData.Jwt("JWT HERE")
}
is ReconcileFailure.InvalidStatus -> {
// you can get the status using reconcileFailure.status
TODO("Your Code Here")
}
is ReconcileFailure.GeneralFailure -> {
// when there is unexpected error .
TODO("Your Code Here")
}
}
}
})
Boolean enableReceiptUi = true; //[optional] true will enable the ui and false will disable
Long finishTimeOut = 10L; // Add the number of seconds
String adminPin = "0000"; //[optional] when you add the admin pin here , the UI for admin pin won't be shown.
Boolean enableUiDismiss = true ;// [optional] it will allow you to control dismissing the UI
nearPay.reconcile(enableReceiptUi, adminPin, finishTimeOut,enableUiDismiss, new ReconcileListener() {
@Override
public void onReconcileFinished(@Nullable ReconciliationReceipt reconciliationReceipt) {
// you can use the object to get the reconciliationReceipt data .
// if you wish to get the receipt in Json format use nearPay.toJson()
}
@Override
public void onReconcileFailed(@NonNull ReconcileFailure reconcileFailure) {
if (reconcileFailure instanceof ReconcileFailure.AuthenticationFailed) {
// when the Authentication is failed
// You can use the following method to update your JWT
nearPay.updateAuthentication(new AuthenticationData.Jwt("JWT is here"));
}
else if (reconcileFailure instanceof ReconcileFailure.GeneralFailure){
// when there is general error .
}
else if (reconcileFailure instanceof ReconcileFailure.FailureMessage){
// when there is FailureMessage
}
else if (reconcileFailure instanceof ReconcileFailure.InvalidStatus){
// you can get the status using following code
List<StatusCheckError> status = ((ReconcileFailure.InvalidStatus) reconcileFailure).getStatus();
}
}
});
var reqData = {
"isEnableUI" : true, //[optional] true will enable the ui and false will disable
"finishTimeout" : 2, // [optional] Add the number of seconds
"adminPin" : "0000",// Optional
"isUiDismissible": true //[optional] allow the transaction to be dismissed from ui
};
var reconciliationReceipt = await Nearpay.reconcile(reqData);
var jsonData = json.decode(reconciliationReceipt);
var status = jsonData['status'];
if(status == 200){
// Initialize Success with 200
}else if(status == 204){
// Initialize Failed with 204, Plugin iniyialize failed with null
}
await nearpay.reconcile({
enableReceiptUi: true, // [Optional] show the reciept in ui
finishTimeout: 60, //[Optional] finish timeout in seconds
enableUiDismiss: true, //[Optional] the ui is dimissible
adminPin: '0000', // [optional] when you add the admin pin here , the UI for admin pin won't be shown.
}).then((response) => {
console.log(response.receipts)
});
Find Reconcile Data here.
Find Reconcile Error here.

Reverse

To perform a Reverse Transaction , it should be within one minute
enableReceiptUi is Boolean so you can set it true or false.
Kotlin
Java
Flutter
React Native
val transactionUuid = "2c094354-38ed-11ed-a261-0242ac120002" // [Required] add your transaction uuid
val enableReceiptUi = true // [optional] true will enable the ui and false will disable
val finishTimeOut : Long = 10 // Add the number of seconds
val enableUiDismiss = true // [optional] it will allow you to control dismissing the UI
nearpay.reverse(transaction_uuid, enableReceiptUi, finishTimeOut, enableUiDismiss, object : ReversalListener {
override fun onReversalFinished(receipts: List<TransactionReceipt>?) {
// you can use "transactionReceipt" to get the transactionReceipt data.
// if you wish to get the receipt in Json format use nearPay.toJson()
TODO("Your Code Here")
}
override fun onReversalFailed(reversalFailure: ReversalFailure) {
when(reversalFailure) {
is ReversalFailure.FailureMessage -> {
// when there is FailureMessage
TODO("Your Code Here")
}
is ReversalFailure.AuthenticationFailed -> {
// when the Authentication is failed
// You can use the following method to update your JWT
nearpay.updateAuthentication(AuthenticationData.Jwt("JWT HERE")
}
is ReversalFailure.InvalidStatus -> {
// you can get the status using reversalFailure.status
TODO("Your Code Here")
}
is ReversalFailure.GeneralFailure -> {
// when there is general error .
TODO("Your Code Here")
}
}
}
})
String transactionUuid = "2c094354-38ed-11ed-a261-0242ac120002"; // [Required] add your transaction uuid
Boolean enableReceiptUi = true; // [optional] true will enable the ui and false will disable
Long finishTimeOut = 10L; // Add the number of seconds
Boolean enableUiDismiss = true ;// [optional] it will allow you to control dismissing the UI
nearPay.reverse(transactionUuid, enableReceiptUi, finishTimeOut,enableUiDismiss, new ReversalListener() {
@Override
public void onReversalFinished(@Nullable List<TransactionReceipt> list) {
// you can use "transactionReceipt" to get the transactionReceipt data.
// if you wish to get the receipt in Json format use ReceiptUtilsKt.toJson(list.get(0))
}
@Override
public void onReversalFailed(@NonNull ReversalFailure reversalFailure) {
if (reversalFailure instanceof ReversalFailure.AuthenticationFailed) {
// when the Authentication is failed
// You can use the following method to update your JWT
nearPay.updateAuthentication(new AuthenticationData.Jwt("JWT is here"));
}
else if (reversalFailure instanceof ReversalFailure.GeneralFailure){
// when there is general error .
}
else if (reversalFailure instanceof ReversalFailure.FailureMessage){
// when there is FailureMessage
}
else if (reversalFailure instanceof ReversalFailure.InvalidStatus){
// you can get the status using following code
List<StatusCheckError> status = ((ReversalFailure.InvalidStatus) reversalFailure).getStatus();
}
}
});
var reqData = {
"isEnableUI" : true, //[optional] true will enable the ui and false will disable
"transaction_uuid" :purchaseReceipt.uuid, //[Required] add Transaction Reference Retrieval Number we need to pass from purchase response list contains uuid dict key "udid", pass that value here.
"finishTimeout" : 2, // [optional] Add the number of seconds
"isUiDismissible": true //[optional] allow the transaction to be dismissed from ui
};
var jsonResponse = await Nearpay.reverse(reqData);
var jsonData = json.decode(jsonResponse);
var status = jsonData['status'];
if(status == 200){
// Initialize Success with 200
}else if(status == 204){
// Initialize Failed with 204, Plugin iniyialize failed with null
}else if(status == 400){
// Missing parameter Failed with 400, Authentication paramer missing Auth Type and Auth Value
// Auth type and Auth value missing
// Transaction UUID null
}
await nearpay.reverse({
originalTransactionUUID: uuid, // [Required] the orginal trnasaction uuid that you want to reverse
enableReceiptUi: true, // [Optional] show the reciept in ui
finishTimeout: 60, //[Optional] finish timeout in seconds
enableUiDismiss: true, //[Optional] the ui is dimissible
}).then((response) => {
console.log(response.receipts)
});
Find TransactionReceipt model here.
Find Reversal Error here.

Session

Session is used to allow your users to make one transaction while the session is open, once it is closed they are not allowed to make transaction till you create another session, you need to pass the session id that you are getting when creating a new session using our api Create Session
Kotlin
Java
Flutter
React Native
val sessionID = "9ace70b7-977d-4094-b7f4-4ecb17de6753" // [Required] Session id that's passed from your backend
val enableReceiptUi = true // [optional] true will enable the ui and false will disable
val enableReversal = true // it will allow you to enable or disable the reverse button
val finishTimeOut : Long = 10 // Add the number of seconds
val enableUiDismiss = true // [optional] it will allow you to control dismissing the UI
nearpay.session(sessionID, enableReceiptUi, enableReversal, finishTimeOut, enableUiDismiss, object : SessionListener{
override fun onSessionClosed(session: Session?) {
// you can use the object "TransactionReceipt" to get the TransactionReceipt data .
// if you wish to get the receipt in Json format use nearPay.toJson()
TODO("Your Code Here")
}
override fun onSessionOpen(receipts: List<TransactionReceipt>?) {
// you can use the object "TransactionReceipt" to get the TransactionReceipt data .
TODO("Your Code Here")
}
override fun onSessionFailed(sessionFailure: SessionFailure) {
when (sessionFailure) {
is SessionFailure.AuthenticationFailed -> {
// when the authentication is failed
TODO("Your Code Here")
}
is SessionFailure.GeneralFailure -> {
// when there is general error
TODO("Your Code Here")
}
is SessionFailure.FailureMessage -> {
// when there is FailureMessage
TODO("Your Code Here")
}
is SessionFailure.InvalidStatus -> {
// Please note that you can get the status using sessionFailure.status
TODO("Your Code Here")
}
}
}
})
String sessionID = "9ace70b7-977d-4094-b7f4-4ecb17de6753"; // [Required] Session id that's passed from your backend
Boolean enableReceiptUi = true; // [optional] true will enable the ui and false will disable
Boolean enableReversal = true; // it will allow you to enable or disable the reverse button
Long finishTimeOut = 10L; // Add the number of seconds
Boolean enableUiDismiss = true ;// [optional] it will allow you to control dismissing the UI
nearPay.session(sessionID, enableReceiptUi, enableReversal, finishTimeOut,enableUiDismiss, new SessionListener() {
@Override
public void onSessionClosed(@Nullable Session session) {
// when the session is closed
}
@Override
public void onSessionOpen(@Nullable List<TransactionReceipt> list) {
// when the session is open , you can get the receipt by using TransactionReceipt
}
@Override
public void onSessionFailed(@NonNull SessionFailure sessionFailure) {
if (sessionFailure instanceof SessionFailure.AuthenticationFailed) {
// when the authentication is failed
}
else if (sessionFailure instanceof SessionFailure.GeneralFailure) {
// when there is general error.
}
else if (sessionFailure instanceof SessionFailure.FailureMessage) {
// when there is FailureMessage
}
else if (sessionFailure instanceof SessionFailure.InvalidStatus) {
// you can get the status using reconcileFailure.status
}
}
});
var reqData = {
"sessionID" :"ea5e30d4-54c7-4ad9-8372-f798259ff589", // Required
"isEnableUI" : true, //Optional
"isEnableReversal" : true,