makeCustomerPayment method

dynamic makeCustomerPayment(
  1. String amount,
  2. String currency,
  3. String customerCardToken,
  4. String appId,
  5. String appToken,
)

Implementation

makeCustomerPayment(
  String amount,
  String currency,
  String customerCardToken,
  String appId,
  String appToken,
) async {
  try {
    final payloadData = CustomerPaymentRequest(
      cardToken: customerCardToken,
      appId: appId,
      amount: amount,
      currency: currency,
    );
    CustomerPaymentResponse customerPaymentResponse =
        await _customerRepository.makeCustomerPayment(payloadData, appToken);
    if (kDebugMode) {
      print("CUSTOMER PAYMENT: $customerPaymentResponse");
    }
    if (customerPaymentResponse.status == 200) {
      customerPaymentResponseSink.add(
        Response.completed(
          customerPaymentResponse.data!,
          message: customerPaymentResponse.message,
        ),
      );
    } else {
      if (kDebugMode) {
        print(
          "CUSTOMER PAYMENT FAILED MESSAGE: ${customerPaymentResponse.message}",
        );
      }
      customerPaymentResponseSink.add(
        Response.error(customerPaymentResponse.message),
      );
    }
  } on UnauthorisedException {
    if (kDebugMode) {
      print("CUSTOMER PAYMENT ERROR: ${IPGErrorMessages.invalidAppToken}");
    }
    customerPaymentResponseSink.add(
      Response.error(IPGErrorMessages.invalidAppToken),
    );
  } catch (e) {
    customerPaymentResponseSink.add(Response.error(e.toString()));
    if (kDebugMode) {
      print("CUSTOMER PAYMENT ERROR: ${e.toString()}");
    }
  }
}