title: Show user subscription as cancelled after billing period
body: <p>I am using Stripe for my subscriptions and I have it set so when a user cancels their subscription (to turn off automatic renewal)  it will keep the subscription active until the end of the billing period on Stripe.</p>
  
  <p>The action works via Stripe, but how can I setup so that the <code>cancelled</code> column in my database takes the same affect? Currently if the user clicks on the cancel subscription link it will mark their <code>cancelled</code> column to <code>1</code>. I would like for it to not mark as cancelled until the end of their billing period so the user can continue have access to the website until their final billing day (I have autorenwal turned on)</p>
  
  <p>I have read txdavidtx suggestion. What he suggests would mark all Users as cancelled at the end of their billing period. That method would not fit with what I am looking to accomplish.</p>
  
  <p>I have subscriptions set to autorenew. I would need a <code>cancel</code> action created that would only mark the <code>current_user</code> as cancelled at the end of their billing period.</p>
  
  <p>For example: </p>
  
  <p>User A signs up for the monthly subscription on September 27. User A decides on December 15 they want to cancel their subscription. User A still has 12 days left in their subscription. User A clicks on the <code>cancel</code> link. User A has autorenew and subscription cancelled in their PayPal or Stripe account. Inside my database their <code>cancelled</code> attribute value will not change until those 12 days have finished (December 27).</p>
  
  <p>If someone can assist that would be great.</p>
  
  <p>Subscriptions controller:</p>
  
  <pre><code>  def new
      plan = Plan.find(params[:plan_id])
      @subscription = plan.subscriptions.build
      render layout: 'new_application'
      if params[:PayerID]
        @subscription.paypal_customer_token = params[:PayerID]
        @subscription.paypal_payment_token = params[:token]
        @subscription.email = @subscription.paypal.checkout_details.email
      end
    end
  
    def create
      @subscription = Subscription.new(params[:subscription])
      if @subscription.save_with_payment
        redirect_to @subscription, :notice =&gt; "Thank you for subscribing!"
      else
        render :new
      end
    end
  
    def show
      @subscription = Subscription.find(params[:id])
      render layout: 'new_application'
    end
  
    def paypal_checkout
      plan = Plan.find(params[:plan_id])
      subscription = plan.subscriptions.build
      redirect_to subscription.paypal.checkout_url(
        return_url: new_subscription_url(:plan_id =&gt; plan.id),
        cancel_url: root_url
      )
    end
  
      def updatesubscription
        @user = current_user
        @customer = Stripe::Customer.retrieve(@user.subscription.stripe_customer_token)
        if @user.subscription.plan_id == 12
        @customer.update_subscription(:plan =&gt; "1", :prorate =&gt; true)
        current_user.subscription.update_attributes(:plan_id =&gt; 1)
        flash.alert = 'Your subscription has been changed to monthly!'
        redirect_to root_url
      elsif @user.subscription.plan_id == 1
        @customer.update_subscription(:plan =&gt; "12", :prorate =&gt; true)
        current_user.subscription.update_attributes(:plan_id =&gt; 12)
       current_user.save!
        flash.alert = 'Your subscription has been changed to annually!'
        redirect_to root_url
      end
       end
  
       def cancelsubscription
         @user = current_user
           @customer = Stripe::Customer.retrieve(@user.subscription.stripe_customer_token)
           @customer.cancel_subscription(:at_period_end =&gt; true) 
           current_user.subscription.update_attributes(:cancelled =&gt; 1)
           current_user.save!
           flash.alert = 'Your subscription has been cancelled successfully!'
           redirect_to root_url
         end
  
         def showcard
           @user = current_user
           Stripe::Customer.retrieve(@user.subscription.stripe_customer_token).cards.all()
         end
  
             def suspend
               @user = current_user
               @user.subscription.suspend_paypal
               current_user.subscription.update_attributes(:cancelled =&gt; 1)
                 flash.alert = 'Billing has been suspended!'
                  redirect_to root_url
             end
  
             def reactivate
               @user = current_user
               @user.subscription.reactivate_paypal
               current_user.subscription.update_attributes(:cancelled =&gt; nil)
                 flash.alert = 'Billing has been activated!'
                  redirect_to root_url
             end
  
  
                 def edit_card
                   @user = current_user
                 end
  
                 def update_card
                   @user = current_user
                   card_info = {
                     name:    params[:name],
                     number:    params[:number],
                     exp_month: params[:date][:month],
                     exp_year:  params[:date][:year],
                     cvc:       params[:cvc]
                   }
                   if @user.subscription.update_card(@subscriber, card_info)
                     flash.alert = 'Saved. Your card information has been updated.'
                     redirect_to root_url
                   else
                     flash.alert = 'Stripe reported an error while updating your card. Please try again.'
                     redirect_to root_url
                   end
                 end
  end
  </code></pre>