Sha256: 9f4eab8e5d7afc87436b44113b0ba97380a5316310161e277168fcefa894655f

Contents?: true

Size: 965 Bytes

Versions: 7

Compression:

Stored size: 965 Bytes

Contents

# frozen_string_literal: true

module SolidusSubscriptions
  module ChurnBuster
    class SubscriptionPaymentMethodSerializer < Serializer
      def to_h
        {
          payment_method: {
            source: 'in_house',
            source_id: [
              object.payment_method_to_use&.id,
              object.payment_source_to_use&.id
            ].compact.join('-'),
            type: 'card',
            properties: payment_source_properties,
          },
          customer: SubscriptionCustomerSerializer.serialize(object),
        }
      end

      private

      def payment_source_properties
        if object.payment_source.is_a?(::Spree::CreditCard)
          {
            brand: object.payment_source.cc_type,
            last4: object.payment_source.last_digits,
            exp_month: object.payment_source.month,
            exp_year: object.payment_source.year,
          }
        else
          {}
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
solidus_subscriptions-2.0.2 lib/solidus_subscriptions/churn_buster/subscription_payment_method_serializer.rb
solidus_subscriptions-2.0.1 lib/solidus_subscriptions/churn_buster/subscription_payment_method_serializer.rb
solidus_subscriptions-2.0.0 lib/solidus_subscriptions/churn_buster/subscription_payment_method_serializer.rb
solidus_subscriptions-1.1.0 lib/solidus_subscriptions/churn_buster/subscription_payment_method_serializer.rb
solidus_subscriptions-1.0.1 lib/solidus_subscriptions/churn_buster/subscription_payment_method_serializer.rb
solidus_subscriptions-1.0.0 lib/solidus_subscriptions/churn_buster/subscription_payment_method_serializer.rb
solidus_subscriptions-1.0.0.rc1 lib/solidus_subscriptions/churn_buster/subscription_payment_method_serializer.rb