payment method

Future<Transaction?> payment({
  1. required double amount,
  2. required PaymentTypeEnum paymentType,
  3. required String callerId,
  4. int installments = 1,
  5. String? creditType,
  6. bool? allowPrintCurrentTransaction,
})

Processes a payment with the provided parameters.

amount is the payment amount and must be greater than zero. paymentType specifies the type of payment (credit or debit). callerId is the transaction identifier and cannot be empty. installments specifies the number of installments (between 1 and 12). creditType (optional) specifies the credit type for credit payments (creditMerchant or creditIssuer). allowPrintCurrentTransaction (optional) specifies whether to allow printing the current transaction. For debit payments, this value must always be 1.

Returns a Transaction object containing transaction details, or null if the transaction fails.

Throws an exception if:

  • amount is less than or equal to 0.
  • installments is less than 1 or greater than 12.
  • callerId is empty.
  • The number of installments is not 1 for debit payment types.

Implementation

Future<Transaction?> payment({
  required double amount,
  required PaymentTypeEnum paymentType,
  required String callerId,
  int installments = 1,
  String? creditType,
  bool? allowPrintCurrentTransaction,
}) async {
  assert(amount > 0, 'The payment amount must be greater than zero');
  assert(installments > 0 && installments <= 12,
      'The number of installments must be between 1 and 12');
  assert(callerId.isNotEmpty, 'The client identifier cannot be empty');
  if (paymentType == PaymentTypeEnum.debit) {
    assert(installments == 1, 'Installments must equal 1 for debit payments');
  }

  try {
    // Delegate the payment process to the platform
    return GetnetDeeplinkPaymentsPlatform.instance.payment(
      amount: amount,
      paymentType: paymentType,
      callerId: callerId,
      installments: installments,
      creditType: creditType,
      allowPrintCurrentTransaction: allowPrintCurrentTransaction,
    );
  } catch (e) {
    // Emit the error through the stream
    rethrow;
  }
}