getInvoiceStatusEvent method

Future<void> getInvoiceStatusEvent(
  1. _GetInvoiceStatus event,
  2. Emitter<PgState> emit
)

Implementation

Future<void> getInvoiceStatusEvent(
  _GetInvoiceStatus event,
  Emitter<PgState> emit,
) async {
  try {
    emit(state.copyWith(status: PgStatus.loading));

    String req = AesConvert.encryptUsingAes(
      key: kKey,
      plainText: jsonEncode(event.request.toJson()),
      ivKey: kIvKey,
    );

    Map<String, dynamic> res = await state.repo.getInvoiceStatus(
      request: {
        'mid': event.request.mid,
        'req': req,
        'terminalId': event.request.terminalId,
      },
    );

    if (res['status'] == 'SUCCESS' || res['status'] == 'FAILED') {
      final decodedRes = AesConvert.decryptAes(
        key: kKey,
        encoded: res['response'],
        ivKey: kIvKey,
      );

      PgInvoiceResponse response = PgInvoiceResponse.fromJson(
        json.decode(decodedRes),
      );

      log("RESPONSE11111 DEC   >>>>>>   ${json.decode(decodedRes)}");
      log("RESPONSE DEC   >>>>>>   $response");

      if (response.paymentStatus == 'SUCCESS') {
        emit(
          state.copyWith(
            pgInvoiceResponse: response,
            status: PgStatus.success,
          ),
        );
      } else {
        emit(
          state.copyWith(pgInvoiceResponse: response, status: PgStatus.error),
        );
      }
    } else {
      emit(
        state.copyWith(
          status: PgStatus.error,
          error: 'Something went wrong.',
        ),
      );
    }
  } on NetworkException catch (e) {
    emit(state.copyWith(status: PgStatus.error, error: e.message));
  } catch (e) {
    emit(
      state.copyWith(status: PgStatus.error, error: 'Something went wrong.'),
    );
  }
}