transformToPLYEventProperties static method

PLYEventProperties transformToPLYEventProperties(
  1. Map properties
)

Implementation

static PLYEventProperties transformToPLYEventProperties(
    Map<dynamic, dynamic> properties) {
  PLYEventName eventName = PLYEventName.APP_CONFIGURED;
  try {
    eventName = PLYEventName.values.firstWhere(
        (e) => e.toString() == 'PLYEventName.' + properties['event_name']);
  } catch (e) {
    print(e);
  }

  List<PLYEventPropertyPlan> plans = new List.empty(growable: true);
  properties['purchasable_plans']?.forEach((element) => plans.add(
      PLYEventPropertyPlan(
          element['type'],
          element['purchasely_plan_id'],
          element['store'],
          element['store_country'],
          element['store_product_id'],
          element['price_in_customer_currency'],
          element['customer_currency'],
          element['period'],
          element['duration'],
          element['intro_price_in_customer_currency'],
          element['intro_period'],
          element['intro_duration'],
          element['has_free_trial'],
          element['free_trial_period'],
          element['free_trial_duration'],
          element['discount_referent'],
          element['discount_percentage_comparison_to_referent'],
          element['discount_price_comparison_to_referent'],
          element['is_default'])));

  List<PLYEventPropertyCarousel> carousels = new List.empty(growable: true);
  properties['carousels']?.forEach((element) {
    bool isAutoPlaying = element['is_carousel_auto_playing'] ?? false;
    carousels.add(PLYEventPropertyCarousel(
        element['selected_slide'],
        element['number_of_slides'],
        isAutoPlaying,
        element['default_slide'],
        element['previous_slide']));
  });

  List<PLYEventPropertySubscription> subscriptions =
      new List.empty(growable: true);
  properties['running_subscriptions']?.forEach((element) => subscriptions.add(
      PLYEventPropertySubscription(element['plan'], element['product'])));

  return PLYEventProperties(
      properties['sdk_version'],
      eventName,
      properties['event_created_at'],
      properties['displayed_presentation'],
      properties['user_id'],
      properties['anonymous_user_id'],
      plans,
      properties['deeplink_identifier'],
      properties['source_identifier'],
      properties['selected_plan'],
      properties['previous_selected_plan'],
      properties['selected_presentation'],
      properties['previous_selected_presentation'],
      properties['link_identifier'],
      carousels,
      properties['language'],
      properties['device'],
      properties['os_version'],
      properties['device_type'],
      properties['error_message'],
      properties['cancellation_reason_id'],
      properties['cancellation_reason'],
      properties['plan'],
      properties['selected_product'],
      properties['plan_change_type'],
      subscriptions);
}