sendVerificationCode static method
Implementation
static Future<Result<OtpSentResponseData?>> sendVerificationCode(
String phoneNumber,
bool notifications,
) async {
final result = await checkKwikpassHealth();
if(result.isSuccess) {
final healthData = result.getDataOrThrow();
if(healthData?.isKwikpassHealthy == false){
throw Exception('Kwikpass is unhealthy');
}
}
try {
await getBrowserToken();
final gokwik = DioClient().getClient();
// await trackAnalyticsEvent(AnalyticsEvents.appLoginPhone, {
// 'phone': phoneNumber.toString(),
// });
await Future.wait([
cacheInstance.setValue(
cdnConfigInstance.getKeys(StorageKeyKeys.gkNotificationEnabled)!,
notifications.toString(),
),
cacheInstance.setValue(
cdnConfigInstance.getKeys(StorageKeyKeys.gkUserPhone)!,
phoneNumber,
),
]);
await Future.wait([
SnowplowTrackerService.sendCustomEventToSnowPlow({
'category': 'login_modal',
'label': 'phone_number_filled',
'action': 'click',
'property': 'phone_number',
'value': int.tryParse(phoneNumber) ?? 0,
}),
SnowplowTrackerService.sendCustomEventToSnowPlow({
'category': 'login_modal',
'label': 'phone_number_entered',
'action': 'click',
'property': 'phone_number',
'value': int.tryParse(phoneNumber) ?? 0,
}),
]);
final response = (await gokwik.post(
cdnConfigInstance.getEndpoint(APIEndpointKeys.sendVerificationCode)!,
data: {'phone': phoneNumber},
))
.toBaseResponse(
fromJson: (json) => OtpSentResponseData.fromJson(json),
);
// if(response.statusCode == 200){
// var res = OtpSentResponseData.fromJson(response.data);
// }else{
// //manage error
// }
if (response.isSuccess == false) {
return Failure(response.errorMessage ?? 'Failed to send OTP');
}
await SnowplowTrackerService.sendCustomEventToSnowPlow({
'category': 'login_modal',
'label': 'otp_sent_successfully',
'action': 'automated',
'property': 'phone_number',
'value': int.tryParse(phoneNumber) ?? 0,
});
return Success(response.data);
} catch (error) {
// var test = handleApiError(error);
// return test;
throw handleApiError(error);
}
}