naps_flutter 0.0.7
naps_flutter: ^0.0.7 copied to clipboard
A Flutter package for integrating NAPS SUNMI P2 payment terminals using the M2M TLV protocol via TCP/IP and Serial.
NAPS Flutter SDK #
A Flutter package for integrating NAPS SUNMI P2 payment terminals using the M2M TLV protocol over TCP/IP and Serial connections.
Features #
- Multiple Connectivity Options: Connect to your SUNMI P2 terminal via Wi-Fi (TCP/IP socket on port 4444) or USB (Serial COM port).
- Payment Processing: Initiate payments and handle terminal responses seamlessly.
- Confirmation & Cancellation: Confirm approved payments and initiate manual cancellations directly from your POS application.
- Duplicate Receipts: Retrieve duplicate payment receipts using the transaction STAN.
- Payment Totals: Request the daily payment totals statement from the terminal.
Getting Started #
To use this package, ensure that your POS device and the SUNMI P2 terminal are on the same local network (for Wi-Fi) or correctly connected via USB Type-C.
Wi-Fi Configuration #
- Open the SUNMI P2 terminal settings.
- Navigate to About device to find the terminal's IP address.
- The terminal listens on port
4444by default.
Usage #
Here is a basic example of how to use the NAPS SDK to process a payment:
import 'package:naps_flutter/naps_flutter.dart';
void main() async {
// 1. Initialize the Naps connection and SDK (example via Wi-Fi)
final connection = NapsTcpConnection(host: '192.168.1.26', port: 4444);
final napsSdk = NapsSdk(
connection: connection,
posId: '0030007', // 7 chars limit
);
// 2. Initiate a Payment (e.g., 35.00 MAD)
final response = await napsSdk.pay(
amountInCents: 3500, // 35.00 MAD
currencyCode: '504', // 504 for MAD
);
if (response.isSuccess) {
print('Payment Approved! STAN: ${response.stan}');
// 3. Confirm the payment within 40 seconds
final confirmationResponse = await napsSdk.confirmPayment(
originalStan: response.stan!,
amountInCents: 3500,
currencyCode: '504',
sequenceNumber: 1, // original sequence number
cardMasked: response.cardNumber!,
expirationDate: response.cardExpirationDate!,
);
if (confirmationResponse.isSuccess) {
print('Payment confirmed successfully.');
// Print customer receipt using confirmationResponse.customerReceipt
}
} else {
print('Payment Failed or Declined.');
}
}
Supported M2M TLV Commands #
This SDK implements the full M2M TLV API specifications for SUNMI P2:
001 / 101- Payment Request / Response002 / 102- Payment Confirmation003 / 103- Cancellation Request004 / 104- Cancellation Confirmation008 / 108- Duplicate Request010 / 110- Totals Request