createPaymentMethodUpi method

Future<SuccessResponse> createPaymentMethodUpi(
  1. PaymentMethodUpi paymentMethodUpi
)

Implementation

Future<SuccessResponse> createPaymentMethodUpi(
    PaymentMethodUpi paymentMethodUpi) async {
  var successResponse = SuccessResponse();
  var url = Constant.baseURL + Constant.createPaymentMethod;
  print('===paymentMethod==url $url');
  final response = await http.post(Uri.parse(url),
      body: jsonEncode(paymentMethodUpi.toMap()),
      headers: {
        "Content-Type": "application/json",
        "accept": "application/json",
        "x-api-key": SwirepaySdk.secretKey
      });
  final result = jsonDecode(response.body);

  successResponse.responseCode = "${response.statusCode}";
  successResponse.responseBody = response.statusCode == 200
      ? result["entity"]
      : result["message"];
  if (response.statusCode == 200 &&
      result != null &&
      result.toString().isNotEmpty) {
    var paymentMethod = PaymentMethodUpi.fromJson(result["entity"]);
    successResponse.content = paymentMethod;
  } else {
    successResponse.content = null;
  }
  return successResponse;
}