Stripe javascript with Ruby on Rails -


i sure simple, cannot figure out. new stripe , configuring on website first time. using following javascript code stripe's library make charges.

<script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"                 data-key="<%= rails.configuration.stripe[:publishable_key] %>"                 data-description="qsnag 1 time fee"                 data-amount="<%=@amount*100%>"                 data-email="<%=current_user.email%>"> </script> 

as can see here, amount variable based on plan user chooses. question how can access amount in charge controller create charge. charges controller code below

  def create     customer = stripe::customer.create(       :email => params[:stripeemail],       :card  => params[:stripetoken],       :plan  => @plan_id,     )      charge = stripe::charge.create(       :customer    => customer.id,       :amount      => @amount*100,       :description => 'qsnag customer',       :currency    => 'usd'     )      rescue stripe::carderror => e       flash[:error] = e.message   end 

as expect, @amount in charges#create 0. want avoid creating custom form , use javascript api. there way access amount javascript api in charges controller.

i added amount hidden field , put script in form tag.

here updated answer:

        <form action="/charge" method="post">           <script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"                   data-key="<%= rails.configuration.stripe[:publishable_key] %>"                   data-description="qsnag 1 time fee"                   data-amount="<%=@amount*100%>"                   data-email="<%=current_user.email%>">           </script>           <input type="hidden" name="amount" value="<%=@amount*100%>"/>           <input type="hidden" name="plan" value="<%=@plan%>"/>         </form> 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -