createCustomer method

Future<Customer> createCustomer(
  1. Customer customer
)

Implementation

Future<Customer> createCustomer(Customer customer) async {
  var successResponse = SuccessResponse();
  var url = Constant.baseURL + Constant.getCustomer;
  final response = await http
      .post(Uri.parse(url), body: jsonEncode(customer.toMapCreateCustomer()), headers: {
    "Content-Type": "application/json",
    "accept": "application/json",
    "x-api-key": SwirepaySdk.secretKey
  });
  final result = jsonDecode(response.body);
  var customerVal = Customer();
  if (response.statusCode == 200 && result["entity"]?.toString() != "") {
    customerVal = Customer.fromJson(result["entity"]);
  } else {
    customerVal.error = result["message"].toString();
  }
  return customerVal;
}