I just started looking at the payola gem and having an issue. The gem creates a table called payola_subscription
, which is supposed to record subscription creation, cancellation, etc. So far, when I create a new subscription, it is recorded in this table, but when I cancel a subscription, this table does not get updated. My question is: Is payola gem supposed to update records on this table if actions such as cancel subscription
are performed, or I have to implement these manually in my cancel
method? Strange thing (for me) is that Payola::UpdateCard.call
used in the card_update
method updates the database with the new credit card number, but Payola::CancelSubscription.call
does not update the table. Below is the controller code for canceling subscriptions. What am I overlooking or doing wrong?
# subscriptions_controller.rb
class SubscriptionsController < ApplicationController
include Payola::StatusBehavior
def create
owner = current_user # this is just an example for Devise
# set your plan in the params hash
params[:plan] = SubscriptionPlan.find_by(id: params[:plan_id])
# call Payola::CreateSubscription
subscription = Payola::CreateSubscription.call(params, owner)
current_user.subscription_plan_id=params[:plan_id]
current_user.save
flash.notice = "Subscription successfully created"
UserMailer.subscribe_email(current_user).deliver_now
render_payola_status(subscription)
end
def cancel
if params[:guid].present?
@subscription = Payola::Subscription.find_by(:guid => params[:guid])
Payola::CancelSubscription.call(@subscription) if [email protected]?
current_user.subscription_plan_id=nil
current_user.save
UserMailer.unsubscribe_email(current_user).deliver_now
flash.notice = "Subscription successfully cancelled"
redirect_to dashboard_path
end
end
def card_update
@subscription = Payola::Subscription.find_by!(guid: params[:guid])
Payola::UpdateCard.call(@subscription, params[:stripeToken])
flash.notice = "Your credit card successfully updated!"
render_payola_status(@subscription)
end
end
Setup the Stripe webhook to get cancellations and other changes synced from Stripe to your app. Details on webhook setup at https://github.com/peterkeen/payola#installation.
(Original source for this answer https://github.com/peterkeen/payola/issues/237#issuecomment-234737250)