Tarjeta Presente
...
Android
API
26 min
referencia completa de la clase principal sdconn y los modelos de datos del sdk paquete com mobbex sdconn clase sdconn fachada principal del sdk punto de entrada único para todas las operaciones constructor sdconn(context context, config sdconnconfig = sdconnconfig()) true 220,220,221left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type propiedades connectionstate stateflow\<connectionstate> estado reactivo de la conexión se puede observar con collect o collectlatest sdconn connectionstate collect { state > } isconnected boolean true si hay un dispositivo conectado credentialsconfigured boolean true si las credenciales de mobbex están guardadas credenciales setcredentials(apikey string, accesstoken string) guarda las credenciales de mobbex de forma cifrada persisten entre sesiones clearcredentials() elimina las credenciales almacenadas conexión serial suspend fun connectserial() busca y conecta un dispositivo pos por usb serial escanea todos los drivers usb serial disponibles envía hello a cada puerto y conecta al primero que responda lanza sdconnexception si no encuentra dispositivo actualiza connectionstate a connected(mode="serial", detail=portname) conexión http suspend fun connecthttp(ip string, port int = 5000) conecta directamente a un dispositivo por http (sin emparejamiento) true 220,220,221left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type lanza sdconnexception si el dispositivo no es alcanzable emparejamiento suspend fun requestpairing(ip string, port int = 5000) boolean solicita emparejamiento con un dispositivo el dispositivo muestra un pin de 6 dígitos en su pantalla retorna true si el dispositivo aceptó la solicitud lanza sdconnexception si el dispositivo no es alcanzable suspend fun confirmpairing(ip string, port int = 5000, pin string) discovereddevice confirma el emparejamiento con el pin mostrado en el dispositivo true 220,220,221left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type retorna discovereddevice con los datos del dispositivo emparejado efectos guarda el dispositivo y token de confianza para reconexión establece la conexión http pone el dispositivo en modo pinpad lanza sdconnexception si el pin es incorrecto o el dispositivo no responde suspend fun reconnect() discovereddevice reconecta al último dispositivo emparejado usando el token de confianza guardado no requiere pin retorna discovereddevice reconectado lanza sdconnexception si no hay dispositivo guardado, no es alcanzable, o el token fue rechazado fun hassaveddevice() boolean indica si hay un dispositivo guardado disponible para reconexión desconexión fun disconnect() desconecta el dispositivo actual no borra el dispositivo guardado ni el token de confianza fun forgetdevice() desconecta y borra el dispositivo guardado y su token de confianza la próxima conexión requerirá emparejamiento completo lectura de tarjeta suspend fun read(request readrequest) readresult operación completa de lectura de tarjeta ejecuta internamente obtiene información del dispositivo (cacheada) obtiene ubicación gps del dispositivo crea una operación en la api de mobbex (/p/pos/operation) envía el token al dispositivo para lectura de tarjeta retorna los datos leídos retorna readresult con el resultado de la operación requiere dispositivo conectado credenciales configuradas total > 0 no lanza excepciones — los errores se devuelven en readresult error suspend fun cancelread() cancela una lectura de tarjeta en progreso el dispositivo deja de esperar y la operación read() retorna con error cancelled pantalla de resultado suspend fun display(request displayrequest) muestra una pantalla de resultado en el dispositivo pos lanza sdconnexception si no hay dispositivo conectado suspend fun dismissdisplay() oculta la pantalla de resultado antes de que expire el timeout el dispositivo vuelve a la pantalla de espera modo del dispositivo suspend fun setmode(mode string) map\<string, any?> cambia el modo de operación del dispositivo true 330,331left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type retorna respuesta del dispositivo como mapa información del dispositivo suspend fun getdeviceinfo() deviceinfo obtiene información del hardware y software del dispositivo se cachea tras la primera consulta; el caché se limpia al cambiar de conexión suspend fun getdevicelocation() devicelocation obtiene la ubicación gps del dispositivo en tiempo real (sin caché) lanza sdconnexception si la ubicación no está disponible modelos de datos sdconnconfig data class sdconnconfig( val serialbaudrate int = 115200, val mobbexapibase string = "https //api mobbex com", val debug boolean = false ) true 165,165,165,166left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type readrequest data class readrequest( val total double, val otheramount double = 0 0, val intent string? = null, val currency string? = null, val hideamount boolean = false, val test boolean = false ) true 165,165,165,166left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type readresult data class readresult( val result boolean, val sourcedata map\<string, any?>? = null, val error string? = null ) true 220,220,221left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type posibles errores true 330,331left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type displayrequest data class displayrequest( val status any, val title string? = null, val total double? = null, val currency string? = null, val text string? = null, val timeout int? = null ) true 165,165,165,166left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type deviceinfo data class deviceinfo( val type string = "", val serialnumber string = "", val deviceextras map\<string, string> = emptymap() ) true 220,220,221left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type ejemplo de deviceextras { "os" "android", "osversion" "11", "manufacturer" "nexgo", "model" "n62", "serialnumber" "sn12345", "bundleid" "com sugaway pos", "buildnumber" "42", "appversion" "1 2 3" } devicelocation data class devicelocation( val latitude double, val longitude double, val accuracy double? = null, val provider string? = null, val timestamp long? = null ) true 220,220,221left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type discovereddevice data class discovereddevice( val ip string, val port int = 5000, val name string = "dispositivo pos" ) representa un dispositivo encontrado o emparejado por red connectionstate sealed class connectionstate { data object disconnected connectionstate() data object searching connectionstate() data class connected(val mode string, val detail string) connectionstate() data class error(val message string) connectionstate() } true 330,331left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type sdconnexception class sdconnexception(message string, cause throwable? = null) exception(message, cause) excepción general del sdk lanzada por operaciones que fallan (conexión, emparejamiento, etc ) flujo completo app android sdconn sdk dispositivo pos │ │ │ │ setcredentials(key, token) │ │ │ ────────────────────────────>│ │ │ │ │ │ requestpairing(ip, port) │ │ │ ────────────────────────────>│ post /device/request pairing │ │ │ ───────────────────────────────>│ │ │ (muestra pin)│ │ true │ │ │<────────────────────────────│ │ │ │ │ │ confirmpairing(ip, port, pin)│ │ │ ────────────────────────────>│ post /device/confirm pairing │ │ │ ───────────────────────────────>│ │ │<─────────── { trusttoken } │ │ │ │ │ │ patch /device/mode │ │ │ { mode "pinpad" } │ │ │ ───────────────────────────────>│ │ discovereddevice │ │ │<────────────────────────────│ │ │ │ │ │ read(readrequest) │ │ │ ────────────────────────────>│ │ │ │ get /device/info │ │ │ ───────────────────────────────>│ │ │<──────────────────────────────│ │ │ │ │ │ get /device/location │ │ │ ───────────────────────────────>│ │ │<──────────────────────────────│ │ │ │ │ │ post api mobbex com │ │ │ /p/pos/operation │ │ │ ──────────> mobbex api │ │ │<────────── { token } │ │ │ │ │ │ read card { token } │ │ │ ───────────────────────────────>│ │ │ (usuario pasa tarjeta) │ │ │<────────── { sourcedata } │ │ │ │ │ readresult(true, sourcedata)│ │ │<────────────────────────────│ │ │ │ │ │ display(displayrequest) │ │ │ ────────────────────────────>│ display result │ │ │ ───────────────────────────────>│ │ │ (pantalla de resultado) │