ruby on rails - Update charge field after stripe charge is processed -
i'm using stripe gem, , followed basic setup charge card. trying have field in database changed when charge has been processed. below code not updating :charge (boolean type) field of database 1.
after processing has succeeded redirects user create.html.erb, redirect them different path, haven't been able find out how that.
thanks stack!
charges controller:
class chargescontroller < applicationcontroller def index end def new end def create @event = event.find(session[:event_id]) #amount in cents @amount = 199 customer = stripe::customer.create( :email => "user email", :card => params[:stripetoken] ) charge = stripe::charge.create( :customer => customer.id, :amount => @amount, :description => 'description', :currency => 'usd' ) @event[:charge] == 1 rescue stripe::carderror => e flash[:error] = e.message redirect_to charges_path end end
new.html.erb:
<ul class="breadcrumb"> <li><a href="#">event information</a></li> <li><a href="#">image upload</a></li> <li><a href="#">verify details</a></li> <li class="active">pay</li> </ul> <%= form_tag charges_path %> <article> <label class="amount"> <span>amount: $1.99</span> </label> </article> <script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button" data-key="<%= rails.configuration.stripe[:publishable_key] %>" data-description="description" data-amount="199"></script> <% end %>
create.html.erb
<h2>thanks, paid <strong>$1.99</strong>!</h2>
Comments
Post a Comment