Sha256: 7ce98ed1b1305ed3cb2bf4498e71a7b3a5ea4ebd83fb9ad0348c40eeff414088

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

module SolidusSubscriptions
  module ChurnBusterSubscriber
    include ::Spree::Event::Subscriber

    event_action :report_subscription_cancellation, event_name: 'solidus_subscriptions.subscription_canceled'
    event_action :report_subscription_ending, event_name: 'solidus_subscriptions.subscription_ended'
    event_action :report_payment_success, event_name: 'solidus_subscriptions.installment_succeeded'
    event_action :report_payment_failure, event_name: 'solidus_subscriptions.installment_failed_payment'
    event_action :report_payment_method_change, event_name: 'solidus_subscriptions.subscription_payment_method_changed'

    def report_subscription_cancellation(event)
      churn_buster&.report_subscription_cancellation(event.payload.fetch(:subscription))
    end

    def report_subscription_ending(event)
      churn_buster&.report_subscription_cancellation(event.payload.fetch(:subscription))
    end

    def report_payment_success(event)
      churn_buster&.report_successful_payment(event.payload.fetch(:order))
    end

    def report_payment_failure(event)
      churn_buster&.report_failed_payment(event.payload.fetch(:order))
    end

    def report_payment_method_change(event)
      churn_buster&.report_payment_method_change(event.payload.fetch(:subscription))
    end

    private

    def churn_buster
      SolidusSubscriptions.churn_buster
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
solidus_subscriptions-1.0.0 app/subscribers/solidus_subscriptions/churn_buster_subscriber.rb
solidus_subscriptions-1.0.0.rc1 app/subscribers/solidus_subscriptions/churn_buster_subscriber.rb