Question

I am setting up to cancel subscriptions from the Subscription controller, however on the action I am getting a No Method Error undefined method `stripe_customer_token'

The error points to the line @customer = Stripe::Customer.retrieve(@user.stripe_customer_token)

Subscriptions controller:

     def cancelsubscription
         @customer = Stripe::Customer.retrieve(current_user.stripe_customer_token)
         @customer.cancel_subscription()
         @current_user.subscriptionstatus = false
         current_user.save!
         UserMailer.stripe_cancellation(current_user).deliver
         flash.alert = 'Your subscription has been cancelled successfully!'
         redirect_to edit_user_registration_path
       end
end
Was it helpful?

Solution

stripe_customer_token is a field in Subscription Model. User is associated to Subscription with has_one association.

Make sure to set the value of @user.

And change

@customer = Stripe::Customer.retrieve(@user.stripe_customer_token)

to

@user = ...     ## Set the value of @user
@customer = Stripe::Customer.retrieve(@user.subscription.stripe_customer_token)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top