summaryrefslogtreecommitdiff
path: root/lib/solidus_subscriptions/churn_buster/subscription_customer_serializer.rb
blob: cd17af3c07bed1ea1275dcf45e7f0a95d6ed4fcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

module SolidusSubscriptions
  module ChurnBuster
    class SubscriptionCustomerSerializer < Serializer
      def to_h
        {
          source: 'in_house',
          source_id: object.id,
          email: object.user.email,
          properties: {
            name: name
          },
        }
      end

      private

      def name
        if ::Spree.solidus_gem_version < Gem::Version.new('2.11.0')
          "#{object.shipping_address_to_use.first_name} #{object.shipping_address_to_use.last_name}"
        else
          object.shipping_address_to_use.name
        end
      end
    end
  end
end