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:
// Some codedependencies {
implementation "io.nearpay:nearpay-sdk-store:2.1.72"
}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:
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]
});3. Purchase transaction
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
}
})// Some code// Some code// Some codeLast updated