postToMerchant method
Future<MerchantResponseModel?>
postToMerchant(
- RequestModel requestModel,
- String tokenId,
- dynamic context
Implementation
Future<MerchantResponseModel?> postToMerchant(
RequestModel requestModel, String tokenId, context) async {
try {
String authToken =
"Basic ${base64.encode(utf8.encode("${requestModel.user.toString()}:${requestModel.password.toString()}"))}";
//Setup post data
Map<String, String> data = new Map();
data["TokenId"] = tokenId.toString();
data["Amount"] = requestModel.amount.toString();
data["ReferenceId"] = requestModel.refId.toString();
data["MerchantCode"] = requestModel.merchantCode.toString();
//Setup headers data
Map<String, String> headers = new Map();
headers["Authorization"] = authToken;
headers["Module"] = requestModel.module.toString();
headers["Content-Type"] = "application/json;charset=UTF-8";
var response = await http.post(Uri.parse(requestModel.merchantUrl ?? ""),
body: jsonEncode(data), headers: headers);
if (response.statusCode == 401) {
Utils.showSnackbar(context, "Unauthorized");
return null;
} else if (response.body == null) {
Utils.showSnackbar(context, "Something Went Wrong");
return null;
} else {
MerchantResponseModel model =
MerchantResponseModel.fromJson(json.decode(response.body));
return model;
}
} catch (ex) {
Utils.showSnackbar(context, "Something Went Wrong");
}
}