Skip to content

Commit

Permalink
fix "cancellation feedback received" event definition
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinSchneider committed May 14, 2024
1 parent 566c849 commit ab58c9e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ class CancellationFeedbackReceived < Base

def properties
mrr = nil
display_mrr = nil
begin
mrr = StripeHelpers::MrrCalculator.calculate_for_stripe_subscription(stripe_record, include_canceled: true)
display_mrr = "$#{sprintf('%.2f', (mrr / 100.0))}" if mrr.is_a?(Numeric)
rescue => e
Sentry.capture_message("Failed to calculate MRR for subscription #{stripe_record.id} (#{e.message})")
end
{
stripe_subscription_id: stripe_record.id,
mrr: mrr,
display_mrr: display_mrr,
cancellation_comment: stripe_record.cancellation_details&.comment,
cancellation_feedback: stripe_record.cancellation_details&.feedback,
cancellation_reason: stripe_record.cancellation_details&.reason,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def is_churned_subscription_event?
end

def just_received_cancellation_feedback?
@stripe_event.type == 'customer.subscription.updated' && attribute_changed?('cancellation_details')
cancellation_details = previous_attributes['cancellation_details'] || {}
cancellation_details.keys.include?(:feedback) || cancellation_details.keys.include?(:comment)
end

def is_new_free_trial_event?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ def occurred_at

def properties
mrr = nil
display_mrr = nil
begin
mrr = StripeHelpers::MrrCalculator.calculate_for_stripe_subscription(stripe_record, include_canceled: true, include_trialing: true)
display_mrr = "$#{sprintf('%.2f', (mrr / 100.0))}" if mrr.is_a?(Numeric)
rescue => e
Sentry.capture_message("Failed to calculate MRR for subscription #{stripe_record.id} (#{e.message})")
end
{
stripe_subscription_id: stripe_record.id,
mrr: StripeHelpers::MrrCalculator.calculate_for_stripe_subscription(stripe_record, include_canceled: true, include_trialing: true),
mrr: mrr,
display_mrr: display_mrr,
}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ def occurred_at

def properties
mrr = nil
display_mrr = nil
begin
mrr = StripeHelpers::MrrCalculator.calculate_for_stripe_subscription(stripe_record, include_trialing: true, include_canceled: true)
display_mrr = "$#{sprintf('%.2f', (mrr / 100.0))}" if mrr.is_a?(Numeric)
rescue => e
Sentry.capture_message("Failed to calculate MRR for subscription #{stripe_record.id} (#{e.message})")
end
{
stripe_subscription_id: stripe_record.id,
potential_mrr: mrr,
potential_display_mrr: display_mrr,
free_trial_length_in_days: (stripe_record.trial_end.to_f - stripe_record.trial_start) / 1.day
}
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ def occurred_at

def properties
mrr = nil
display_mrr = nil
begin
mrr = StripeHelpers::MrrCalculator.calculate_for_stripe_subscription(stripe_record, include_canceled: true)
display_mrr = "$#{sprintf('%.2f', (mrr / 100.0))}" if mrr.is_a?(Numeric)
rescue => e
Sentry.capture_message("Failed to calculate MRR for subscription #{stripe_record.id} (#{e.message})")
end
{
stripe_subscription_id: stripe_record.id,
mrr: mrr,
display_mrr: display_mrr,
cancellation_comment: stripe_record.cancellation_details&.comment,
cancellation_feedback: stripe_record.cancellation_details&.feedback,
cancellation_reason: stripe_record.cancellation_details&.reason,
Expand Down

0 comments on commit ab58c9e

Please sign in to comment.