ruby on rails - Stripe::InvalidRequestError Must provide source or customer -
order controller page
begin stripe.api_key = env["stripe_api_key"] token = params[:stripetoken] charge = stripe::charge.create( :amount => (@listing.price * 100).floor, :currency => "usd", :source => params[:stripetoken], :destination => @seller.recipient ) flash[:notice] = "thanks ordering!" rescue stripe::carderror => e flash[:danger] = e.message end
order.js.coffee
jquery -> stripe.setpublishablekey($('meta[name="stripe-key"]').attr('content')) payment.setupform() payment = setupform: -> $('#new_order').submit -> $('input[type=submit]').attr('disabled', true) stripe.card.createtoken($('#new_order'), payment.handlestriperesponse) false handlestriperesponse: (status, response) -> if status == 200 $('#new_order').append($('<input type="hidden" name="stripetoken" />').val(response.id)) $('#new_order')[0].submit() else $('#stripe_error').text(response.error.message).show() $('input[type=submit]').attr('disabled', false)
i not sure why source => params[:stripetoken] not passing thru when check log in stripe account. token null?
usually when receive error because publishable key not in form when send form stripe doesn´t recognize , doesn´t send token.
the process of charging client goes way.
1.- in site tell user type card information in form (hosted locally or created stripe script).
2.- once user submit form. information submitted stripe server publishable key. receive response server token. token forwarded action in controller , since linked account can create customer, charge or join user plan. 'params[:stripetoken]'. card information never reaches controller, receive token.
you can 2 things charge clients, first create form self , second delegate stripe script.
the first 1 more tricky since stripe updates api time time. requires knowledge of js , api. example stripe v3 different v2. allows more rationalization requires more knowledge of js. information , examples of how configure can found in stripe elements.
the second 1 pretty easy. recommend not advanced users. can implement following instructions in link using checkout , rails.
i use second option since takes 5 minutes , delegate hard work stripe.
Comments
Post a Comment