getTransactionStatus method

Future<EasyPaymobResponse?> getTransactionStatus({
  1. required String transactionId,
})

get transaction status with only calling this function by transactionId.

Implementation

Future<EasyPaymobResponse?> getTransactionStatus({
  required String transactionId,
}) async {
  if (!_isInitialized) {
    throw Exception('PaymobPayment is not initialized call:`PaymobPayment.instance.initialize`');
  }

  String token = await _getAuthToken();

  var headers = {'Authorization': 'Bearer $token', 'Content-Type': 'application/json'};

  final response = await _dio.request(
    'acceptance/transactions/$transactionId',
    options: Options(
      method: 'GET',
      headers: headers,
    ),
  );

  if (response.statusCode == 200) {
    return EasyPaymobResponse(
      success: response.data['success'] == true,
      transactionID: response.data['id'].toString(),
      pending: response.data['pending'] == true,
      responseCode: response.statusCode.toString(),
      message: response.data['data']['message'],
      type: response.data['source_data']['type'],
      billReference: response.data['data']["bill_reference"],
    );
  } else {
    throw Exception(response.statusMessage);
  }
}