doTransaction method

Future<ResponseModel?> doTransaction({
  1. required TransactionType transactionType,
  2. String? billingRefNo,
  3. required double paymentAmount,
  4. String? mobileNumberForEChargeSlip,
  5. HeaderModel? overrideHeader,
})

do transaction for pinelabs device. calls pinelab device with MethodId 1001.

transactionType is the transaction type from TransactionType enum. billingRefNo is the billing reference number. paymentAmount is the payment amount only two decimal places are allowed. if more than two decimal places are added then it will be rounded off using toStringAsFixed(2). mobileNumberForEChargeSlip is the mobile number for eChargeSlip.

Implementation

Future<ResponseModel?> doTransaction({
  required TransactionType transactionType,
  String? billingRefNo,
  required double paymentAmount,
  String? mobileNumberForEChargeSlip,
  HeaderModel? overrideHeader,
}) async {
  if (overrideHeader == null && this.header == null) {
    throw Exception(
      '''
Header is required, add header during initialization or pass header as parameter
in override header.''',
    );
  }

  // only double with two decimal places is allowed.
  // and remove the dot in decimal.
  final paymentAmountStr =
      paymentAmount.toStringAsFixed(2).replaceAll('.', '');

  final detail = TransactionModel(
    transactionType: transactionType.code,
    billingRefNo: billingRefNo,
    paymentAmount: paymentAmountStr,
    mobileNumberForEChargeSlip: mobileNumberForEChargeSlip,
  );
  final header = overrideHeader?.copyWith(methodId: '1001') ??
      this.header?.copyWith(methodId: '1001');
  final requestBody =
      {'Header': header?.toJson(), 'Detail': detail.toJson()}.toString();

  final response = await FlutterPinelabsPlatform.instance
      .sendRequest(request: requestBody);
  return response != null ? ResponseModel.fromJson(response) : null;
}