5
votes

I am creating some API for stripe payment. I try to create API to getting card token for payment. below is my code

Postman Data

Request Method: POST,
Request URL: https://api.stripe.com/v1/tokens

Headers Data

Content-Type:application/x-www-form-urlencoded
Authorization:Bearer SECRET_KEY

Body x-www-form-urlencoded

card:{"exp_month":12,"exp_year":2020,"number":'4242424242424242',"cvc":'123'}

Response (Output)

{
    "error": {
        "message": "You must pass full card details to create a token.",
        "type": "invalid_request_error"
    }
}

Postman screenshots:

Headers

enter image description here

Body

enter image description here

1
That JSON looks a little malformed. strings must all be in double quotes and the whole thing should be wrapped in curly brackets. Try this: {"card":{"exp_month":12,"exp_year":2020,"number":"4242424242424242","cvc":"123"}} - tshimkus
@tshimkus :- Yes, I check this but I get the same error. - Praveen Kumar
Can you try with content-type as "application/json"? - tshimkus
Can you add an image of how you have this added in Postman please? - Danny Dainton
As a general point you should almost never do this, as passing card numbers in this way increases your PCI scope. If you want to have a token for testing and creating charges, you can just use tok_visa and friends from Stripe's testing page - karllekko

1 Answers

17
votes

I imported the cURL request from the Stripe documentation into Postman. This request should look like this one below.

Postman

Once, you add the Auth Token into the header - It should then allow you to create the card token (If everything else is ok)

Just for reference, the syntax for the key/value view, should look like this and not like you have it in your request.

Syntax