Never store raw card data on your servers. This endpoint creates a secure token through Stripe that represents the card information.
Creates a token representing a credit card. The token can then be used to attach the card to a customer or make a payment. This approach ensures PCI compliance by never storing sensitive card data on your servers.
Request Body
The card number, as a string without any separators. For testing, use Stripe test card: 4242424242424242
The card’s expiration month (1-12). Example: "12"
The card’s expiration year as a 4-digit number. Example: "2026"
The card’s CVC/CVV security code. Example: "123"
Response
Indicates if the request was successful (true) or failed (false).
Human-readable message describing the result. Example: "Tarjeta tokenizada correctamente"
The tokenized card data. The Stripe token ID that represents the card. Starts with tok_. Example: "tok_1234567890abcdef"
The unique card ID from Stripe. Starts with card_. Example: "card_1234567890abcdef"
The card brand (Visa, MasterCard, American Express, etc.). Example: "Visa"
The last 4 digits of the card number. Example: "4242"
Example Request
curl -X POST https://your-api.com/api/cards/create \
-H "Content-Type: application/json" \
-d '{
"number": "4242424242424242",
"exp_month": "12",
"exp_year": "2026",
"cvc": "123"
}'
Example Response
201 - Success
400 - Bad Request
400 - Invalid Card
500 - Server Error
{
"status" : true ,
"message" : "Tarjeta tokenizada correctamente" ,
"data" : {
"token_id" : "tok_1QRs9eKZ4xUzN2TP9vQqWXYZ" ,
"card_id" : "card_1QRs9eKZ4xUzN2TPabcdefgh" ,
"card_brand" : "Visa" ,
"card_last4" : "4242"
}
}
Error Codes
Code Description incorrect_numberThe card number is incorrect invalid_expiry_monthThe expiration month is invalid invalid_expiry_yearThe expiration year is invalid invalid_cvcThe CVC/CVV code is invalid card_declinedThe card was declined by the issuer
Test Cards : Use Stripe’s test card numbers for development:
Success: 4242424242424242
Declined: 4000000000000002
Insufficient funds: 4000000000009995
See Stripe’s test cards documentation for more.