Matt R. Wilson
Matt R. Wilson

Reputation: 7575

Stripe API: create customer and charge in one request

Lets say I have a new customer who is checking out and wants to store their card for future use. If I'm reading the docs right, I need to make separate calls out to Stripe, one to create the customer with the card and another to charge the card.

Considering the endpoint for creating a charge accepts either a token or a dictionary for the card, I'm suprised the same isn't true for the customer parameter.

I have tried sending a dictionary for the customer in a create charge request to no avail.

Am I forced to make two calls? And if so does Stripe accept feature requests?

Upvotes: 4

Views: 4728

Answers (1)

anisha vasandani
anisha vasandani

Reputation: 76

Q: Am I forced to make two calls?

A: Yes, you're forced to make two calls to the Stripe API upon creation of a Stripe customer.

If a customer already exists in your database, you only need to make one call to the Stripe API, as shown below. Here, we're creating a charge and passing the retrieved customer ID:

Stripe::Charge.create(
  :amount   => 1500,
  :currency => "usd",
  :customer => customer_id
)

Making a charge is outlined here in Stripe's documentation: https://stripe.com/docs/tutorials/charges

Q: And if so does Stripe accept feature requests?

A: I'm not 100% sure if Stripe accepts feature requests across all languages, but it is available for Go: https://github.com/stripe/stripe-go/blob/master/README.md#development

I'd double check the Development section of each README or contact a developer at Stripe directly (freenode #stripe)

Upvotes: 6

Related Questions