2016-08-21 88 views
0

現在,這是我對我的指控控制器創建行動:條紋充電或計劃?

def create 
    # Amount in cents 
    @amount = 100 

    # Get the credit card details submitted by the form 
    customer = Stripe::Customer.create(
     :email => params[:email], 
     :source => params[:stripeToken] 
    ) 

    # Create the charge on Stripe's servers - this will charge the user's card 
    begin 
     Stripe::Charge.create(
      :amount => @amount, 
      :currency => 'usd', 
      :customer => customer.id, 
      :description => 'Example charge custom form' 
    ) 
     redirect_to root_path 

     rescue Stripe::CardError => e 
     flash[:error] = e.message 
     redirect_to root_path 
    end 

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


    flash[:success] = "Thank you for subscribing. Your account has been unlocked." 
end 

我想這樣做current_user.end_date = (a month from now)。實際上並不確定如何做到這一點。

然後,我會檢查是否將來每次登錄時都會有current_user.end_date。如果不是,我會提供current_user.subscribed = false

這是可能的,如果是這樣,你是否能夠引導我完成這個任務,因爲我不瞭解如何在軌道中使用時間。或者我應該考慮將此作爲一項計劃?我不確定,因爲我不希望重複開單。

回答

相關問題