hobex_hps 0.1.0 copy "hobex_hps: ^0.1.0" to clipboard
hobex_hps: ^0.1.0 copied to clipboard

Dart & Flutter client for the hobex Payment Service (HPS) local REST API: card payments, refunds, pre-auth and voids on hobex / Sunmi card terminals.

example/hobex_hps_example.dart

import 'dart:convert';

import 'package:hobex_hps/hobex_hps.dart';

/// Minimal end-to-end example for the hobex HPS client.
///
/// Run on the terminal itself with the default base URL, or from a dev machine
/// by pointing [HpsClient.baseUrl] at the terminal's IP.
Future<void> main() async {
  final hps = HpsClient(
    // On the device this can be omitted (defaults to http://127.0.0.1:8080).
    baseUrl: Uri.parse('http://192.168.0.187:8080'),
    tid: '3600335', // no leading zero!
    defaultLanguage: 'DE',
  );

  try {
    // 1) Safe health check — no card required.
    final diag = await hps.diagnosis();
    print(
      'Device : ${diag.deviceStatus} '
      '(HPS ${diag.hps}, test=${diag.isTestEnvironment})',
    );
    if (!diag.isInOperation) {
      print('Terminal not operable — aborting.');
      return;
    }

    // 2) A € 1,00 sale. The terminal will prompt for a card; this awaits the
    //    full card flow.
    final res = await hps.payment(amount: 1.00, reference: 'demo');
    if (res.isApproved) {
      print(
        'APPROVED ${res.brand} ${res.cardNumber} '
        'approval=${res.approvalCode} receipt=${res.receipt}',
      );
      print('Store this to void later: ${res.transactionId}');
    } else {
      print('DECLINED ${res.responseCode} — ${res.responseText}');
    }

    // The full, unmodified JSON the terminal returned:
    print('\nFull response JSON:');
    print(const JsonEncoder.withIndent('  ').convert(res.raw));
  } on HpsHttpException catch (e) {
    print('HPS returned an error: ${e.statusCode} ${e.message}');
  } on HpsException catch (e) {
    print('Could not reach the HPS: ${e.message}');
  } finally {
    hps.close();
  }
}
0
likes
160
points
50
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Dart & Flutter client for the hobex Payment Service (HPS) local REST API: card payments, refunds, pre-auth and voids on hobex / Sunmi card terminals.

Homepage

Topics

#payments #pos #terminal #ecr #flutter

License

MIT (license)

Dependencies

http

More

Packages that depend on hobex_hps