shopifyVerifyEmail static method

Future<Map<String, dynamic>> shopifyVerifyEmail(
  1. String email,
  2. String otp
)

Implementation

static Future<Map<String, dynamic>> shopifyVerifyEmail(
  String email,
  String otp,
) async {
  try {
    final gokwik = DioClient().getClient();

    final notifications = await cacheInstance.getValue(
      KeyConfig.gkNotificationEnabled,
    );

    final response = await gokwik.post(
      APIConfig.verifyEmailCode,
      data: {
        'email': email,
        'otp': otp,
        'redirectUrl': '/',
        'isMarketingEventSubscribed': notifications == 'true',
      },
    );

    final userData =
        await cacheInstance.getValue(KeyConfig.gkVerifiedUserKey);
    final userDataObj = userData != null ? jsonDecode(userData) : {};

    final user = {
      ...response.data?['data'],
      'phone': userDataObj['phone'],
    };

    await cacheInstance.setValue(
      KeyConfig.gkVerifiedUserKey,
      jsonEncode(user),
    );

    await SnowplowTrackerService.sendCustomEventToSnowPlow({
      'category': 'login_modal',
      'label': 'otp_verified',
      'action': 'logged_in',
      'property': 'phone_number',
      'value': int.tryParse(user['phone'] ?? '0') ?? 0,
    });

    return response.data;
  } catch (error) {
    throw await ApiService.handleApiError(error);
  }
}