2

I have following code that allows me to make a Stripe Payment from CLI.

curl -u stripe-secret-key-here: -d amount=100 -d currency=gbp -d 'card[number]=4242424242424242' -d 'card[exp_month]=5' -d 'card[exp_year]=2015' https://api.stripe.com/v1/charges 

However if I try to use the following from the URL/Asterisk Dial Plan then I receive below given error.

https://stripe-secret-key-here:@api.stripe.com/v1/charges?amount=100& currency=gbp&card[number]=4242424242424242&card[exp_month]=5&card[exp_year]=2015 

Error:

{ "error": { "type": "invalid_request_error", "message": "Received unknown parameter: card", "param": "card" } } 

Would appreciate a little help... Thanks.

2

2 Answers 2

2

Even though this is an old question, it still shows up as one of the most relevant when searching for stripe-payments, so I thought I'd offer an answer.

The reason the request fails when using the URL form is because this would be a GET request.

The Stripe API documentation notes clearly that charge creation requests are POST requests.

When using curl with the -d option, the request is sent as POST. From the cURL manual:

POST (HTTP)

It's easy to post data using curl. This is done using the -d <data> option. The post data must be urlencoded.

So the reason you get the "unknown parameter: card" error is because the https://api.stripe.com/v1/charges endpoint expects only two different types of GET requests: charge retrieval and list charges, neither of which expect a card parameter.

More information on GET vs. POST :

Sign up to request clarification or add additional context in comments.

Comments

0

You will need to generate a stripe card token using the card params you trying to pass instead of passing the card params.

Example:

curl https://api.stripe.com/v1/charges \ -u YOUR_SECRET_KEY: \ -d amount=2000 \ -d currency=usd \ -d source=tok_visa \ -d description="Charge for [email protected]" 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.