generatePaymentLink method
Implementation
Future<Map> generatePaymentLink({
required double amount,
required String successUrl,
required String cancelUrl,
required String errorUrl,
required String notifyUrl,
}) async {
if (_apiKey.isEmpty || _siteCode.isEmpty || _privateKey.isEmpty) {
return {
'errorMessage':
"Please call init and pass in the correct API, Private key and Site Code"
};
} else {
var ref = _generateRandomString(6);
var value = await generateRequestHash(
amountP: amount,
cancelUrlP: cancelUrl,
successUrlP: successUrl,
errorUrlP: errorUrl,
notifyUrlP: notifyUrl,
ref: ref,
);
var response =
await http.post(Uri.parse("https://api.ozow.com/postpaymentrequest"),
headers: {
'Content-Type': 'application/json',
'ApiKey': _apiKey,
'Accept': "application/json",
},
body: jsonEncode({
'countryCode': 'ZA',
'amount': amount,
'transactionReference': ref,
'bankReference': ref,
'cancelUrl': cancelUrl,
'currencyCode': 'ZAR',
'errorUrl': errorUrl,
'isTest': _isTest,
'notifyUrl': notifyUrl,
'siteCode': _siteCode,
'successUrl': successUrl,
'hashCheck': value
}));
if (response.statusCode == 200) {
Map map = await jsonDecode(response.body) as Map;
return map;
} else {
return {
"code": response.statusCode,
"message": response.body,
};
}
}
}