sadadPayTransactionV6 static method

Future<Map?> sadadPayTransactionV6({
  1. required String ipAddress,
  2. required List productDetails,
  3. required String token,
  4. required String otp,
  5. required int userId,
  6. required String orderId,
  7. required String issandboxmode,
  8. required double amount,
  9. required String sadadId,
})

Implementation

static Future<Map?> sadadPayTransactionV6(
    {required String ipAddress,
      required List productDetails,
      required String token,
      required String otp,
      required int userId,
      required String orderId,
      required String issandboxmode,
      required double amount, required String sadadId}) async {
  final url = Uri.parse(
    ApiEndPoint.sadadPayTransationV6,
  );
  Map<String, String> header = {'Content-Type': 'application/json'};
  final body = json.encode({
    "amount": amount,
    "sadadId":sadadId,
    "token": token,
    "orderId": orderId,
    "ipAddress": ipAddress,
    "productDetails": productDetails,
    "userId": userId,
    "otp": otp,
    "issandboxmode" : issandboxmode,
  });

  var result = await http.post(
    url,
    headers: header,
    body: body
  );

  if (result.statusCode == 200) {
    var response = jsonDecode(result.body);
    return response;
  } else {
    final Map<String, dynamic> jsonData = json.decode(result.body);
    ErrorResponse errorResponse = ErrorResponse.fromJson(jsonData);

    // Extract the error message
    final errorMessage = errorResponse.error.message;
    print('Error Message: $errorMessage');

    // Return the error details as a map
    return {
      'statusCode': errorResponse.error.statusCode,
      'name': errorResponse.error.name,
      'message': errorMessage,
    };
  }
  return null;
}