pay method
Future<ServerResponse>
pay({
- required PaymentTransaction paymentTransaction,
- required BuildContext context,
Implementation
Future<ServerResponse> pay({required PaymentTransaction paymentTransaction, required BuildContext context})async{
String jsonString = json.encode(paymentTransaction.toJson());
String encryptedData = await _encryptData(jsonString);
ServerResponse result = ServerResponse(message: "Transaction Error", status: "ERROR");
if(_companyId.isEmpty || _publicKeyString.isEmpty){
const snackBar = SnackBar(
backgroundColor: Colors.white,
content: Text(
'Getit Payments Not Initialized.',
style: TextStyle(color: Colors.black),
));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
return result;
}
Map auth = {
'testMode': _testMode ? "1": "0",
'companyId': _companyId,
'encryptedTxt': encryptedData,
// 'otherData': ecryOtherData
};
Uri url = Uri.parse('https://us-central1-getitpayments.cloudfunctions.net/makPayment');
try {
await http.post(url, body: auth).then((response) async {
var data = json.decode(response.body);
// debugPrint("data : "+data.toString());
if (data != null) {
if (data["msg"] is String) {
result.message = data["msg"];
} else {
if (data["msg"]["ResultCode"] != null) {
result.status = data["msg"]["ResultCode"][0];
}
if (data["msg"]["FinancialResultCode"] != null) {
result.message = data["msg"]["FinancialResultCode"][0]
.toString(); // if it says Approved then you good.
}
if (data["msg"]["ErrorMessage"] != null) {
result.error = data["msg"]["ErrorMessage"][0].toString();
}
if (data["msg"]["TranId"] != null) {
result.transactionNumber = data["msg"]["TranId"][0].toString();
}
if(data["msg"]["Invoice"] != null){
result.invoiceNumber = data["msg"]["Invoice"][0].toString();
}
}
}
});
} catch (e) {
String error = "`pay_function.dart` ${e.toString()}";
// FirebaseCrashlytics.instance.log(error);
log(error);
}
return result;
}