6
votes

I'm working on the Stripe API and building a custom checkout function - My error is specifically telling me I must provide a source or customer. This is my controller for creating charges:

I thought I was successfully creating a source and/or customer with the following code (I also included the post logs on my stripe dashboard)

 Stripe::Charge.create(
    :amount => @amount,
    :currency => 'usd',
    :source => params[:stripeToken],
)
Stripe::Customer.create(
    :email => params[:stripeEmail],
    :source => params[:stripeToken]
  )
  "error": {
    "code": "parameter_missing",
    "doc_url": "https://stripe.com/docs/error-codes/parameter-missing",
    "message": "Must provide source or customer.",
    "type": "invalid_request_error"
  }
}

I did go through the docs but I guess I'm still a little lost

Thanks for any assistance!

Update: here is the return of my API POST requests. my api requests Update2: I see that a customer is being created when I send a charge. My events tab

Update 3: Source property is set to the stripeToken parameter, representing the payment method provided. The token is automatically created by Checkout. - this seems possibly connected to my issue - maybe it's not correctly posting?

1
Welcome to SO. Please have a look here to learn how to improve your questions (formatting, proofreading, providing code etc.): stackoverflow.com/help/how-to-askpetezurich
Thank you for making those edits, you taught me a fair bit about asking better questions just by going through the revised markdown. Have a good day!Jason Harder
have u made sure params[:stripeToken] is not empty?Imre Raudsepp
I get a 200 OK for Post /v1/tokens - as I understand it I believe that confirms I am passing the token correctly to that point.Jason Harder
but I'm not sure if I have to do more with it or something ...Jason Harder

1 Answers

3
votes

So it did turn out to be a token request - since I was using a test card for test purposes I imagine I had to pass a test token to ensure that the test card would work.

I believe the Rails Params I was using (: source => params[:stripeToken] ) are fine for production but not when checking against given cards. In case someone comes across this as I did (and of course this probably isn't the first time it was asked on SO)

When using the Stripe API you see there is a token tab beside the test card numbers - I assumed those were optional or "for something else" for some reason. THEY ARE NOT.

You'll want to make sure the token matches whatever test card you plan on using (I think)

My Stripe controller now looks like this

Stripe::Charge.create({
    :amount => @amount,
    :currency => 'usd',
    :source => 'tok_visa',  #params[:stripeToken] might be for in production I think this is for testing.,
    :description => 'Your Donation to Victoria University',
    :statement_descriptor => 'Victoria University'

    # it seems test tokens must be set as string.
  })

Decided to leave my comments in there - because why not?

P.S You'll need different token types for different card payment types. If you switch cards - switch tokens as well !!!! - the tokens are tabbed beside the test card numbers.