Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Charge card with stripe token returning nil  RSS feed

 
Jeremiah Parrack
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am setting up my app with stripe and i am having a horrible time ha. I have spent close to 10 hours on it.
I finally realized that my token is returning nil.
The error on my logs is


On the second to last line, I am printing out the token but it is not returning anything. This is giving me




My create method is
``` [code=ruby]def create
      @order = Order.new(order_params)
      @listing = Listing.find(params[:listing_id])
      @seller = @listing.user

      @order.listing_id = @listing.id
      @order.buyer_id = current_user.id
      @order.seller_id = @seller.id

      Stripe.api_key ="sk_test_wCVovzzFUCYefEcIDpnCzcNq"
      token = params[:stripeToken]
  logger.debug "TOKEN IS: #{token}"

      begin
>>ERROR      charge = Stripe::Charge.create(
          :amount => (@listing.price * 100).floor,
          :currency => "usd",
          :source => token,
        )
        flash[:notice] = "Thanks for ordering!"
      rescue Stripe::CardError => e
        flash[:danger] = e.message
      end
      respond_to do |format|
        if @order.save
          format.html { redirect_to root_url, notice: "Thanks for ordering!" }
          format.json { render action: 'show', status: :created, location: @order }
        else
          format.html { render action: 'new' }
          format.json { render json: @order.errors, status: :unprocessable_entity }
        end
      end
    end
[code=ruby]

https://github.com/jeremiahlukus/Abound


I have been reading the docs and countless stackoverflow posts but everything I try does not seem to work.
Any help on this would be great. I know my API keys should be kept private however if I do not do it this way I get errors saying missing API key.
 
Jeremiah Parrack
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not know how to edit the post, sorry about the unformatted method create.
 
Jeremiah Parrack
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
https://abound.herokuapp.com/
 
Jeremiah Parrack
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!