startFreeTrial method
Implementation
Future<Map<String, dynamic>> startFreeTrial({
required BuildContext context,
required String product,
required String success_url,
required String cancel_url,
String callback = "createFreeTrialSubscription",
String? token,
String? redirect_url,
}) async {
var body = {
'product': product,
'success_url': success_url,
'cancel_url': cancel_url,
'callback': callback,
};
var auth_headers = {};
if (callback != "createFreeTrialSubscription") {
auth_headers = {"Authorization": 'Bearer ' + token!};
}
String formData = body.keys
.map((key) =>
"${Uri.encodeComponent(key)}=${Uri.encodeComponent(body[key].toString())}")
.join("&");
final response = await http.post(
Uri.parse('$webbaseUrl/api/ibl/v1/stripe/post/'),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
...auth_headers
},
// Encoding email as form data
body: formData,
);
var data = json.decode(response.body);
var data_ = await UIView.showModelSheet(
context, data, success_url, cancel_url, redirect_url);
return {'success': data_}; // Returns the API response
}