doTransactionOperation method
Future<TransactionStatus>
doTransactionOperation({
- String? clientId,
- String? clientSecret,
- String? merchantTransactionId,
- String? designation,
- String? currencyCode,
- String? buyerName,
- String? buyerReference,
- String? notificationUrl,
- String? paymentMethodReference,
- int? amount,
- String? otp,
override
Implementation
@override
Future<TransactionStatus> doTransactionOperation({
String? clientId,
String? clientSecret,
String? merchantTransactionId,
String? designation,
String? currencyCode,
String? buyerName,
String? buyerReference,
String? notificationUrl,
String? paymentMethodReference,
int? amount,
String? otp}) async{
AccessTokenResult accessTokenResult = await this.getAccessToken(clientId!, clientSecret!);
if(accessTokenResult == null){
final message = 'The requested service needs credentials, but the ones provided were invalid.';
throw new AdjeminPayAuthException(message,401);
}
final String url = "$API_URL/transactions";
final http.Response response = await http.post(
Uri.parse(url),
body: <String, String>{
"merchant_transaction_id": merchantTransactionId!,
"designation": designation!,
"buyer_name":buyerName ==null?"":buyerName,
"buyer_reference":buyerReference!,
"notification_url":notificationUrl!,
"payment_method_reference":paymentMethodReference!,
"amount":"$amount",
"currency_code":currencyCode!,
"otp":otp ==null?"":"$otp"
},
headers: {
'Authorization' : 'Bearer ${accessTokenResult.accessToken}',
'Accept':'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
}
);
print("waiting for httpResponse !");
print('============ Response Initiate Payment ==========');
print("STATUS CODE: ${response.statusCode}");
print('============ Response Initiate Payment status ==========');
print("BODY: ${response.body}");
if(response.statusCode == 200){
final Map<String, dynamic> json = jsonDecode(response.body);
final TransactionStatus result = TransactionStatus.fromJson(json);
return result;
}else{
var message = StatusCode.messages[StatusCode.OPERATION_ERROR];
var code = StatusCode.codes[StatusCode.OPERATION_ERROR];
var status = StatusCode.OPERATION_ERROR;
if(response.headers['content-type'] == 'application/json'){
final Map<String, dynamic> json = jsonDecode(response.body);
if(json.containsKey('message')){
message = json['message'] as String;
}
if(json.containsKey('code')){
code = json['code'] as int;
}
if(json.containsKey('status')){
status = json['status'] as String;
}
}else{
message = "Payment has failed";
}
throw new AdjeminPayException(message, response.statusCode, code,status);
}
}