createPaymentsession method
Implementation
Future<PaymentSession> createPaymentsession(OrderInfo orderInfo, {String? bankName}) async {
var successResponse = SuccessResponse();
var paymentSession = PaymentSession();
var url = Constant.baseURL + Constant.createPaymentSession;
print('"=====ps url $url');
print('"=====ps request ${orderInfo.toMap()}');
final response = await http
.post(Uri.parse(url), body: jsonEncode(orderInfo.toMap()), headers: {
"Content-Type": "application/json",
"accept": "application/json",
"x-api-key": SwirepaySdk.secretKey
});
final result = jsonDecode(response.body);
if (result["entity"] == null) {
paymentSession.error = orderInfo.paymentMethodType.toString().contains("NET_BANKING") ? "Netbanking from bank $bankName is not enabled by this merchand" : result["message"];
successResponse.responseCode = "${response.statusCode}";
successResponse.responseBody = response.statusCode == 200
? result["entity"]
: result;
} else {
paymentSession = PaymentSession.fromJson(result["entity"]);
successResponse.responseCode = "${response.statusCode}";
successResponse.responseBody = response.statusCode == 200
? result["entity"]
: result;
}
return paymentSession;
}