createBill method
Create a new bill at WeBirr Servers. Check if(ApiResponse.error == null) to see if there are errors. ApiResponse.res will have the value of the returned PaymentCode on success.
Implementation
Future<ApiResponse<String>> createBill(Bill bill) async {
var client = RetryClient(http.Client());
try {
var resp = await client.post(
Uri.parse('${_baseAddress}/einvoice/api/postbill?api_key=${_apiKey}'),
headers: {"Content-Type": "application/json"},
body: jsonEncode(bill.toJson()));
if (resp.statusCode == 200) {
var map = jsonDecode(resp.body) as Map<String, dynamic>;
return ApiResponse<String>(
error: map['error'], errorCode: map['errorCode'], res: map['res']);
} else {
return new ApiResponse<String>(
error: 'http error ${resp.statusCode} ${resp.reasonPhrase}');
}
} finally {
client.close();
}
}