refund method

  1. @override
Future<Transaction?> refund({
  1. required double amount,
  2. DateTime? transactionDate,
  3. String? cvNumber,
  4. String? originTerminal,
  5. bool? allowPrintCurrentTransaction,
})
override

Processes a refund request via the native platform.

amount is the refund amount and must be greater than zero. transactionDate (optional) specifies the date of the original transaction, formatted as dd/MM/yy. cvNumber (optional) is the control number of the transaction (CV). originTerminal (optional) identifies the origin terminal. allowPrintCurrentTransaction (optional) specifies whether to allow printing the current transaction.

Returns a Transaction object containing the refund details, or null if a transaction is already in progress or if the result is null.

Throws an exception if an error occurs during platform communication.

Implementation

@override
Future<Transaction?> refund({
  required double amount,
  DateTime? transactionDate,
  String? cvNumber,
  String? originTerminal,
  bool? allowPrintCurrentTransaction,
}) async {
  try {
    if (_transactionInProgress) {
      return null;
    }

    _transactionInProgress = true;

    final result = await methodChannel.invokeMethod<String>(
      'refundDeeplink',
      <String, dynamic>{
        'amount': amount,
        'transactionDate': transactionDate != null
            ? DateFormat('dd/MM/yy').format(transactionDate)
            : null,
        'cvNumber': cvNumber,
        'originTerminal': originTerminal,
        'allowPrintCurrentTransaction': allowPrintCurrentTransaction,
      },
    );

    if (result == null) {
      return null;
    }

    _transactionInProgress = false;

    return Transaction.fromJson(result);
  } catch (e) {
    _transactionInProgress = false;
    rethrow;
  }
}