Reputation:
I have been setting Stripe's events and wanted to setup an event when a user's free trial is close to expiration. There is a relevant event on Stripe's side which is customer.subscription.trial_will_end
.
So I am using the stripe_event gem and already setup the following events on stripe.rb
StripeEvent.setup do
subscribe 'charge.failed' do |event|
user = User.where(stripe_customer_token: event.data.object.customer).first
user.subscriptionstatus = "notactive"
user.save!
UserMailer.stripe_cancellation(user).deliver
end
subscribe 'charge.succeeded' do |event|
user = User.where(stripe_customer_token: event.data.object.customer).first
user.subscriptionstatus = "active"
user.save!
UserMailer.invoice_mail.deliver
end
end
I was wondering how this customer.subscription.trial_will_end
will be setup. Is it described as: subscribe 'trial_will_end'
or customer 'subscription.trial_will_end
' or...? How do I figure this out? The two previous one I created them with a clue I had from another developer, here in stackoverflow.
Upvotes: 0
Views: 281
Reputation: 4288
stripe_event
uses the actual event name (or optionally its higher-level namespace, if you want to perform the same action on a whole class of events).
To handle customer.subscription.trial_will_end
events, subscribe to them just as you have with your existing event types:
subscribe 'customer.subscription.trial_will_end' do |event|
# do stuff
end
Upvotes: 1