refundPayment method

Future<LokotroPayOnResponse> refundPayment({
  1. required String orderId,
  2. required String originalTransactionId,
  3. required double amount,
  4. String? currency,
  5. String? reason,
})

Refund payment

Implementation

Future<LokotroPayOnResponse> refundPayment({
  required String orderId,
  required String originalTransactionId,
  required double amount,
  String? currency,
  String? reason,
}) async {
  try {
    final paymentResponse = await _paymentService.refundPayment(
      orderId: orderId,
      originalTransactionId: originalTransactionId,
      amount: amount,
      currency: currency ?? config.currency,
      reason: reason,
    );

    return _convertToLokotroResponse(paymentResponse);

  } on MastercardException catch (e) {
    return LokotroPayOnResponse(
      title: 'Refund Failed',
      message: e.errorMessage,
      paymentStatus: LokotroPaymentStatus.failed,
      apiResponseCode: LokotroPayApiResponseCode.lok001,
      amount: amount,
      currency: currency ?? config.currency,
      systemRef: _uuid.v4(),
      customRef: orderId,
      timestamp: DateTime.now(),
      transactionId: null,
    );
  }
}