pushSubscriptionEvent function

Future pushSubscriptionEvent(
  1. String? fireBasePermissionToken,
  2. String userId
)

Implementation

Future<dynamic> pushSubscriptionEvent(
    String? fireBasePermissionToken, String userId) async {
  if (fireBasePermissionToken == null) {
    print('Firebase permission token is null');
    return;
  }
  var dio = ApiService().createDio();

  final apiKey = await getApiKey();
  final dataCenterPushUrl = await getDataCenterPushUrl();
  final deviceInformation = await getDeviceInformation();
  final deviceType = deviceInformation['deviceType'];
  final configuration = await getConfiguration();
  final isApnsEnabled = configuration['isApnsEnabled'];

  Map<String, dynamic> dataToShip = {
    'providerType': 'FIREBASE',
    'deviceToken': fireBasePermissionToken,
    'userId': userId,
    'os': deviceType,
  };

  if (deviceType == 'ios' && isApnsEnabled) {
    dataToShip['providerType'] = 'APNS';
  }
  final jsonDataToShip = convert.jsonEncode(dataToShip);

  final response = await dio.post(
      '$dataCenterPushUrl$pushNotificationUrl?apiKey=$apiKey',
      data: jsonDataToShip);

  return response.data;
}