Create a card

When you create a new credit card, you must specify a customer or recipient on which to create it.

If the card’s owner has no default card, then the new card will become the default. However, if the owner already has a default, then it will not change. To change the default, you should update the customer to have a new default_source.

Parameters

  • sourceobject | stringRequired

    A token, like the ones returned by Stripe.js or a dictionary containing a user’s card details (with the options shown below). Stripe will automatically validate the card.

  • metadatamap

    Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to metadata.

Returns

Returns the Card object.

POST /v1/customers/:id/sources
stripe.Key = "sk_test_4eC39Hq...arjtT1zdp7dcsk_test_4eC39HqLyjWDarjtT1zdp7dc"
params := &stripe.PaymentSourceParams{
Source: stripe.String("tok_visa"),
Customer: stripe.String("cus_9s6XGDTHzA66Po"),
};
result, err := paymentsource.New(params);
Response
{
"id": "card_1NGTaT2eZvKYlo2CZWSctn5n",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"customer": "cus_9s6XGDTHzA66Po",
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 8,
"exp_year": 2024,
"fingerprint": "Xt5EWLLDS7FJjR1c",
"funding": "credit",
"last4": "4242",
"metadata": {},
"name": null,
"redaction": null,
"tokenization_method": null,
"wallet": null
}

Update a card

Updates a specified card for a given customer.

Parameters

  • address_citystring

    City/District/Suburb/Town/Village.

  • address_countrystring

    Billing address country, if provided when creating card.

  • address_line1string

    Address line 1 (Street address/PO Box/Company name).

  • address_line2string

    Address line 2 (Apartment/Suite/Unit/Building).

  • address_statestring

    State/County/Province/Region.

  • address_zipstring

    ZIP or postal code.

  • exp_monthstring

    Two digit number representing the card’s expiration month.

  • exp_yearstring

    Four digit number representing the card’s expiration year.

  • metadatamap

    Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to metadata.

  • namestring

    Cardholder name.

Returns

POST /v1/customers/:id/sources/:id
stripe.Key = "sk_test_4eC39Hq...arjtT1zdp7dcsk_test_4eC39HqLyjWDarjtT1zdp7dc"
params := &stripe.CardParams{
Name: stripe.String("Jenny Rosen"),
Customer: stripe.String("acct_1032D82eZvKYlo2C"),
};
result, err := card.Update("card_1NBLeN2eZvKYlo2CIq1o7Pzs", params);
Response
{
"id": "card_1NBLeN2eZvKYlo2CIq1o7Pzs",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 8,
"exp_year": 2024,
"fingerprint": "Xt5EWLLDS7FJjR1c",
"funding": "credit",
"last4": "4242",
"metadata": {},
"name": "Jenny Rosen",
"redaction": null,
"tokenization_method": null,
"wallet": null,
"account": "acct_1032D82eZvKYlo2C"
}

Retrieve a card

You can always see the 10 most recent cards directly on a customer; this method lets you retrieve details about a specific card stored on the customer.

Parameters

No parameters.

Returns

Returns the Card object.

GET /v1/customers/:id/cards/:id
cURL
curl https://api.stripe.com/v1/customers/cus_NhD8HD2bY8dP3V/cards/card_1MvoiELkdIwHu7ixOeFGbN9D \
-u "sk_test_4eC39Hq...arjtT1zdp7dcsk_test_4eC39HqLyjWDarjtT1zdp7dc:"
We show the cURL request because this method is currently unsupported in the Go client. To see it in the library, let us know about your use case.
Response
{
"id": "card_1MvoiELkdIwHu7ixOeFGbN9D",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"customer": "cus_NhD8HD2bY8dP3V",
"cvc_check": null,
"dynamic_last4": null,
"exp_month": 4,
"exp_year": 2024,
"fingerprint": "mToisGZ01V71BCos",
"funding": "credit",
"last4": "4242",
"metadata": {},
"name": null,
"tokenization_method": null,
"wallet": null
}

List all cards

You can see a list of the cards belonging to a customer. Note that the 10 most recent sources are always available on the Customer object. If you need more than those 10, you can use this API method and the limit and starting_after parameters to page through additional cards.

Parameters

No parameters.

More parameters

  • ending_beforestring

  • limitinteger

  • starting_afterstring

Returns

Returns a list of the cards stored on the customer.

GET /v1/customers/:id/cards
cURL
curl -G https://api.stripe.com/v1/customers/cus_NhD8HD2bY8dP3V/cards \
-u "sk_test_4eC39Hq...arjtT1zdp7dcsk_test_4eC39HqLyjWDarjtT1zdp7dc:" \
-d limit=3
We show the cURL request because this method is currently unsupported in the Go client. To see it in the library, let us know about your use case.
Response
{
"object": "list",
"url": "/v1/customers/cus_NhD8HD2bY8dP3V/cards",
"has_more": false,
"data": [
{
"id": "card_1MvoiELkdIwHu7ixOeFGbN9D",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"customer": "cus_NhD8HD2bY8dP3V",
"cvc_check": null,
"dynamic_last4": null,
"exp_month": 4,
"exp_year": 2024,
"fingerprint": "mToisGZ01V71BCos",
"funding": "credit",
"last4": "4242",
"metadata": {},
"name": null,
"tokenization_method": null,
"wallet": null
}
{...}
{...}
],
}

Delete a card

You can delete cards from a customer. If you delete a card that is currently the default source, then the most recently added source will become the new default. If you delete a card that is the last remaining source on the customer, then the default_source attribute will become null.

For recipients: if you delete the default card, then the most recently added card will become the new default. If you delete the last remaining card on a recipient, then the default_card attribute will become null.

Note that for cards belonging to customers, you might want to prevent customers on paid subscriptions from deleting all cards on file, so that there is at least one default card for the next invoice payment attempt.

Parameters

No parameters.

Returns

DELETE /v1/customers/:id/sources/:id
stripe.Key = "sk_test_4eC39Hq...arjtT1zdp7dcsk_test_4eC39HqLyjWDarjtT1zdp7dc"
params := &stripe.CardParams{Customer: stripe.String("acct_1032D82eZvKYlo2C")};
result, err := card.Del("card_1NGTaT2eZvKYlo2CZWSctn5n", params);
Response
{
"id": "card_1NGTaT2eZvKYlo2CZWSctn5n",
"object": "card",
"deleted": true
}
Stripe Shell
Test mode
Welcome to the Stripe Shell! Stripe Shell is a browser-based shell with the Stripe CLI pre-installed. Log in to your Stripe account and press Control + Backtick (`) on your keyboard to start managing your Stripe resources in test mode. - View supported Stripe commands: - Find webhook events: - Listen for webhook events: - Call Stripe APIs: stripe [api resource] [operation] (e.g., )
The Stripe Shell is best experienced on desktop.
$