dimanche 21 juin 2015

Rails, undefined method `encoding' for nil:NilClass

So I tried canceling subscription but it results in error. There is one thing where I switch to customer.subscriptions.retrieve(customer.subscriptions.first.id).delete and that didn't result in error but it didn't affect stripe because the subscription was still active.

Right now its, customer.subscriptions.retrieve(params[:plan_id]).delete but to my best guess that doesn't work and it results in the error below.

What do I do? Any help would be appreciated

enter image description here

SubscribesController.rb

    class SubscribesController < ApplicationController
        before_action :authenticate_user!


        def new
        end

        def update
            token = params[:stripeToken]
            customer = Stripe::Customer.create(
                :card => token,
                :plan => 2,
                :email => current_user.email               
            )

            current_user.subscribed = true
            current_user.stripeid = customer.id
            current_user.save

            redirect_to user_path, :notice => "Your subscription was setup!"
        end

def cancel_plan
    if 
        customer = Stripe::Customer.retrieve(current_user.stripeid)
        customer.subscriptions.retrieve(params[:plan_id]).delete

    current_user.subscribed = false
    current_user.stripeid = nil
    current_user.save!

      flash[:notice] = "Canceled subscription."
      redirect_to edit_user_registration_path
    else
      flash[:error] = "There was an error canceling your subscription. Please notify us."
      redirect_to edit_user_registration_path
  end
end

Aucun commentaire:

Enregistrer un commentaire