Search
K
Links

Quick Start

This section shows you the minimum steps to develop and start experiencing your first transaction. In other words, it gives you the flow of creating your first purchase transaction.

Before you begin

NearPay team needs to create sandbox account for you using your email and phone number and your android package name to be able to start this integration. In addition, you need to have an android physical device that supports NFC to be able to test the integration and run the app on it.

Start your first transaction

1. Add this dependency in your project build.gradle to download the plugin from Google:
Kotlin and Java
Flutter
React Native
dependencies {
implementation "io.nearpay:nearpay-sdk-store:2.1.64"
}
flutter pub add nearpay_flutter_sdk --git-url=https://github.com/nearpayio/nearpay-flutter-sdk.git --git-ref=google
// 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#google" --save
// after installing the plugin , please import the package
import { EmbededNearpay } from '@nearpaydev/react-native-nearpay-sdk';
2. Create single instance of NearPay object with context wherever you need:
Kotlin
Java
Flutter
React Native
Ionic
nearPay = NearPay.Builder()
.context(context)
.authenticationData(AuthenticationData.Email("yourEmail"))
.environment(environment)
.networkConfiguration(NetworkConfiguration.SIM_PREFERRED)
.loadingUi(true)
.build()
nearPay = new NearPay.Builder()
.context(this)
.authenticationData(new AuthenticationData.Email("yourEmail"))
.environment(Environments.SANDBOX)
.locale(Locale.getDefault())
.networkConfiguration(NetworkConfiguration.SIM_PREFERRED)
.uiPosition(UIPosition.CENTER_BOTTOM)
.paymentText(new PaymentText("يرجى تمرير الطاقة", "please tap your card"))
.loadingUi(true)
.build();
//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]
});
import {
AuthenticationType,
EmbededNearpay,
Environments,
Locale,
} from '@nearpaydev/nearpay-ionic-sdk';
const embededNearpay = new EmbededNearpay({
authtype: AuthenticationType.email, // the Authentication type (Email, mobile, etc)
authvalue: '<Enter Your Email Here>', // the Authentication value
environment: Environments.sandbox, // Transation enviroment
locale: Locale.default, // [Optional] language options
});
// the line bellow is optional, initialization will be done automatically
// only used if you want to add listeners to success and fail
embededNearpay.initialize({
onSuccess: () => {},
onFail: () => {},
});
// (EmbededNearpay) obeject should be created once and served to the wholl application
3. Purchase transaction
Kotlin
Java
Flutter
React Native
Ionic
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(transactionData: TransactionData) {
TODO("Your Code Here")
}
override fun onPurchaseFailed(purchaseFailure: PurchaseFailure) {
//your code here
}
})
Long amount = 100L; // [Required] ammount you want to set .
String customerReferenceNumber = ""; // [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(@NonNull TransactionData transactionData) {
// 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) {
}
});
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
"transactionId": "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
transactionId: uuidv4(), //[Optional] speacify the transaction uuid for later retreval
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)
});
embededNearpay.purchase({
amount: 1000, // Required, maens 10.00
transactionUUID: uuidv4(), //[Optional] speacify the transaction uuid
customerReferenceNumber: '', // [Optional] referance number for customer use only
enableReceiptUi: true, // [Optional] show the reciept in ui
enableReversalUi: true, //[Optional] enable reversal of transaction from ui
enableUiDismiss: true, //[Optional] the ui is dimissible
finishTimeout: 60, //[Optional] finish timeout in seconds
onPurchaseSuccess: receipts => console.log(receipts), //[Optional] callback on suceess
onPurchaseFailed: err => console.log(err), //[Optional] callback on error
});