uno
uno

Reputation: 1481

Stripe::InvalidRequestError (Must provide source or customer.): Stripe

http://jsfiddle.net/e8wjyb35/

My controller:

class ChargesController < ApplicationController
  skip_before_action :verify_authenticity_token
  protect_from_forgery prepend: true

  def new
  end


  def create

    # Amount in cents
    @amount = 500
    token = params[:stripeToken]
    payment_form = params[:payment_form]


    charge = Stripe::Charge.create({
      :source  => params[:stripeToken],
      :amount      => @amount,
      :description => 'Rails Stripe customer',
      :currency    => 'usd'
    })

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



end

My API requests are going through, all with errors.

Stripe error:

{
  "error": {
    "code": "parameter_missing",
    "doc_url": "https://stripe.com/docs/error-codes/parameter-missing",
    "message": "Must provide source or customer.",
    "type": "invalid_request_error"
  }
}

When I use a customer, the API requests are successful, but with errors. It's essentially the same thing, just wanted to mention that in case it's relevant. The same problem persists either way with the tokens not going through. All my JavaScript seems right, do you see any issues with that, my controller, or anything else?

Just in case, here's the error when i am using the Customer in the controller:

{
"error": {
"code": "missing",
"doc_url": "https://stripe.com/docs/error-codes/missing",
"message": "Cannot charge a customer that has no active card",
"param": "card",
"type": "card_error"
}
}

Whats wrong? Any suggestions or recommendations?

Upvotes: 2

Views: 6463

Answers (1)

uno
uno

Reputation: 1481

For anyone coming across this with similar issues..

This post solved it already: Stripe API Invalid Request: Must provide source or customer

It's due to being in development and not in production.

I changed

:source  => params[:stripeToken],

to

:source  => 'tok_visa',

As long as I'm using a Visa (the Visa test numbers by stripe 4242...) credit card, it works in development.

Once in production, then switch it back, i believe. Not there yet but that's the gist.

Upvotes: 3

Related Questions