authorizePayment method

Future<LokotroPayOnResponse> authorizePayment({
  1. required MastercardPaymentRequest paymentRequest,
})

Authorize payment

Implementation

Future<LokotroPayOnResponse> authorizePayment({
  required MastercardPaymentRequest paymentRequest,
}) async {
  try {
    final paymentResponse = await _paymentService.authorizePayment(
      orderId: paymentRequest.orderId,
      cardDetails: paymentRequest.cardDetails,
      amount: paymentRequest.amount,
      currency: paymentRequest.currency,
      billingAddress: paymentRequest.billingAddress?.toJson(),
      customerInfo: paymentRequest.customer?.toJson(),
    );

    return _convertToLokotroResponse(paymentResponse);

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