Flutter NearPay SDK kann keine Verbindung zum Terminal herstellen, da in der Sandbox der Fehler „Benutzer nicht gefundenAndroid

Forum für diejenigen, die für Android programmieren
Anonymous
 Flutter NearPay SDK kann keine Verbindung zum Terminal herstellen, da in der Sandbox der Fehler „Benutzer nicht gefunden

Post by Anonymous »

Ich integriere NearPay SDK in eine Flutter-Anwendung, um NFC-Zahlungen auf einem iMin-POS-Gerät zu verarbeiten und Belege mit einem iMin-Drucker zu drucken.
Umgebung
Flutter: 3.35.5
Android: minSdkVersion 26
NearPay SDK: neueste Version
Umgebung: Sandbox
Gerät: iMin POS (z. B. S1)
Was funktioniert
NearPay SDK wird erfolgreich initialisiert
NFC-Berechtigungen werden erteilt
Das Gerät und das Terminal sind eingeschaltet
Problem
Beim Versuch, eine Verbindung zum Terminal herzustellen, schlägt der Vorgang mit der folgenden Fehlermeldung fehl: Benutzer nicht gefunden Dies geschieht, obwohl die SDK-Initialisierung ohne Probleme abgeschlossen wird.
import 'package:donations/core/nearpay/terminal_config.dart';
import 'package:flutter/material.dart';
import 'package:flutter_terminal_sdk/flutter_terminal_sdk.dart';
import 'package:flutter_terminal_sdk/models/card_reader_callbacks.dart';
import 'package:flutter_terminal_sdk/models/data/ui_dock_position.dart';
import 'package:flutter_terminal_sdk/models/nearpay_user_response.dart';
import 'package:flutter_terminal_sdk/models/purchase_callbacks.dart';
import 'package:flutter_terminal_sdk/models/terminal_response.dart';
import 'package:uuid/uuid.dart';
final FlutterTerminalSdk _terminalSdk = FlutterTerminalSdk();
Future initialize() async {
// Das Initialisieren des terminalSDK kann eine Ausnahme auslösen, also packen Sie es in einen Try-Catch-Block
try {

Code: Select all

await \_terminalSdk.initialize(

environment: Environment.sandbox,

// Choose sandbox, production, internal

googleCloudProjectNumber: 162056333315,

// Add your google cloud project number

huaweiSafetyDetectApiKey:

"3lA5jiaqe14enqRRgsVPj0O5FRmEL4LUjsoDlqqXwNs7Jy7eO0pUFvAGhy4w",

// Add your huawei safety detect api key

uiDockPosition: UiDockPosition.BOTTOM_CENTER,

// Optional: set the location of the Tap to Pay modal

country: Country.sa, // Choose country: sa, tr, usa

);
} Catch (e) {

Code: Select all

print("Error initializing TerminalSDK: $e");
}
}
Future sendOtp(String mobile) async {
try {

Code: Select all

await \_terminalSdk.sendMobileOtp(mobile);

print("✅ OTP sent to $mobile");
} Catch (e) {

Code: Select all

print("❌ Error sending OTP: $e");
}
}
Future connectToTerminal() async {
versuchen {

Code: Select all

print("🔄 جاري الاتصال بالـ Terminal (TID: ${TerminalConfig.tid})...");

// await initialize();

final result = await \_terminalSdk.connectTerminal(

tid: TerminalConfig.tid,

userUUID: TerminalConfig.userUUID,

terminalUUID: TerminalConfig.terminalUUID,

);

print(result);

return result;
} Catch (e) {

Code: Select all

print("❌ خطأ أثناء الاتصال: $e");

print(e.toString());

if (e.toString().contains("timeout")) {

print("⏰ الجهاز غير متصل بالشبكة أو بعيد");

} else if (e.toString().contains("invalid")) {

print("🔑 تأكدي من TID أو UUID");

}

return null;
}
}
Future Transaction1(BuildContext context, String amount) async {
//await initialize();
final mobile = "+966509738300";
if (TerminalConfig.userUUID.isEmpty) {

Code: Select all

await sendOtp(mobile);

final code = await promptForOtp(context);

if (code == null || code.isEmpty) {

print("❌ User cancelled OTP entry");

return false;

}

final verified = await verifyOtp(mobile, code);

if (!verified) {

print("❌ OTP verification failed, aborting transaction");

return false;

}
} // BenutzerUUID
final connectedTerminal = waiting connectToTerminal();
if (connectedTerminal == null) {

Code: Select all

print("فشل الاتصال بالترمينال، لا يمكن إتمام العملية");

return false;
}
print(connectedTerminal?.tid ?? "");
double? amountDouble = double.tryParse(amount.replaceAll(',', ''));
try {

Code: Select all

final intentUUID = const Uuid().v4();

final customerReferenceNumber = "01142674856";

await connectedTerminal?.purchase(

intentUUID: intentUUID,

amount: amountDouble?.toInt() ?? 0,

callbacks: PurchaseCallbacks(

cardReaderCallbacks: CardReaderCallbacks(

onCardReadSuccess: () {

print("success");

},

onReaderDismissed:  () {

print("Reader dismissed by user");

},

),

),

);
print("connectedTerminal.terminalUUID:${connectedTerminal?.terminalUUID}"); print("connectedTerminal.name:${connectedTerminal?.name}");
print("connectedTerminal.tid:${connectedTerminal?.tid}");

Code: Select all

return true;
} Catch (e) {

Code: Select all

print(e.toString());

return false;
}
}
Future promptForOtp(BuildContext context) async {
String otp = '';
return showDialog(

Code: Select all

context: context,

barrierDismissible: false,

builder: (context) =\> AlertDialog(

title: Text('Enter OTP'),

content: TextField(

keyboardType: TextInputType.number,

onChanged: (value) =\> otp = value,

decoration: InputDecoration(hintText: "OTP code"),

),

actions: \[

TextButton(

onPressed: () =\> Navigator.of(context).pop(otp),

child: Text('Submit'),

),

\],

),
);
}
Future verifyOtp(String mobile, String code) async {
try {

Code: Select all

final user = await \_terminalSdk.verifyMobileOtp(

mobileNumber: mobile,

code: code,

);

TerminalConfig.userUUID = user.userUUID ?? "";

print("✅ OTP verified, userUUID: ${TerminalConfig.userUUID}");

return TerminalConfig.userUUID.isNotEmpty;
} Catch (e) {

Code: Select all

print("❌ Error verifying OTP: $e");

return false;
}
Ich verwende die Funktion „Transaktion1“
Frage
Bedeutet der Fehler „Benutzer nicht gefunden“, dass das Terminal nicht mit demselben Händler-/Benutzerkonto wie die API-Anmeldeinformationen verknüpft ist, obwohl die SDK-Initialisierung erfolgreich war?
Wenn ja, wie kann das Problem richtig validiert oder behoben werden? Terminal-Händler-Konfiguration für Sandbox-Tests?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post