Saving Cards

    Learn how to save and update card details in your Stripe account so you can charge customers later.

    When you collect a customer’s payment information, a Stripe token is created. This token can only be used once, but that doesn’t mean you have to request your customer’s card details for every payment.

    Stripe provides a Customer object that makes it easy to save this—and other—information for later use. You can use Customer objects for creating subscriptions or future one-off charges.

    Saving credit card details for later

    To make a card available for later charging, including subscriptions, create a new Customer instead of a Charge. Be certain to store the customer ID on your side for later use. You can subsequently charge that customer by passing the customer ID—instead of a card representation—in the charge request.

    # Create a Customer:
    curl https://api.stripe.com/v1/customers \
       -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
       -d source=tok_mastercard \
       -d email="paying.user@example.com"
    
    # Charge the Customer instead of the card:
    curl https://api.stripe.com/v1/charges \
       -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
       -d amount=1000 \
       -d currency=usd \
       -d customer=cus_7sqFSKcBzzYEAf
    
    # YOUR CODE: Save the customer ID and other info in a database for later.
    
    # When it's time to charge the customer again, retrieve the customer ID.
    curl https://api.stripe.com/v1/charges \
       -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
       -d amount=1500 \
       -d currency=usd \
       -d customer=cus_7sqFSKcBzzYEAf
    
    # Set your secret key: remember to change this to your live secret key in production
    # See your keys here: https://dashboard.stripe.com/account/apikeys
    Stripe.api_key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
    
    # Create a Customer:
    customer = Stripe::Customer.create({
        source: 'tok_mastercard',
        email: 'paying.user@example.com',
    })
    
    # Charge the Customer instead of the card:
    charge = Stripe::Charge.create({
        amount: 1000,
        currency: 'usd',
        customer: customer.id,
    })
    
    # YOUR CODE: Save the customer ID and other info in a database for later.
    
    # When it's time to charge the customer again, retrieve the customer ID.
    charge = Stripe::Charge.create({
        amount: 1500, # $15.00 this time
        currency: 'usd',
        customer: customer_id, # Previously stored, then retrieved
    })
    
    # Set your secret key: remember to change this to your live secret key in production
    # See your keys here: https://dashboard.stripe.com/account/apikeys
    stripe.api_key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
    
    # Create a Customer:
    customer = stripe.Customer.create(
      source='tok_mastercard',
      email='paying.user@example.com',
    )
    
    # Charge the Customer instead of the card:
    charge = stripe.Charge.create(
      amount=1000,
      currency='usd',
      customer=customer.id,
    )
    
    # YOUR CODE: Save the customer ID and other info in a database for later.
    
    # When it's time to charge the customer again, retrieve the customer ID.
    charge = stripe.Charge.create(
      amount=1500, # $15.00 this time
      currency='usd',
      customer=customer_id, # Previously stored, then retrieved
    )
    
    // Set your secret key: remember to change this to your live secret key in production
    // See your keys here: https://dashboard.stripe.com/account/apikeys
    \Stripe\Stripe::setApiKey("sk_test_4eC39HqLyjWDarjtT1zdp7dc");
    
    // Create a Customer:
    $customer = \Stripe\Customer::create([
        'source' => 'tok_mastercard',
        'email' => 'paying.user@example.com',
    ]);
    
    // Charge the Customer instead of the card:
    $charge = \Stripe\Charge::create([
        'amount' => 1000,
        'currency' => 'usd',
        'customer' => $customer->id,
    ]);
    
    // YOUR CODE: Save the customer ID and other info in a database for later.
    
    // When it's time to charge the customer again, retrieve the customer ID.
    $charge = \Stripe\Charge::create([
        'amount' => 1500, // $15.00 this time
        'currency' => 'usd',
        'customer' => $customer_id, // Previously stored, then retrieved
    ]);
    
    // Set your secret key: remember to change this to your live secret key in production
    // See your keys here: https://dashboard.stripe.com/account/apikeys
    Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc";
    
    // Create a Customer:
    Map<String, Object> chargeParams = new HashMap<>();
    chargeParams.put("source", "tok_mastercard");
    chargeParams.put("email", "paying.user@example.com");
    Customer customer = Customer.create(chargeParams);
    
    // Charge the Customer instead of the card:
    Map<String, Object> customerParams = new HashMap<>();
    customerParams.put("amount", 1000);
    customerParams.put("currency", "usd");
    customerParams.put("customer", customer.getId());
    Charge charge = Charge.create(customerParams);
    
    // YOUR CODE: Save the customer ID and other info in a database for later.
    
    // When it's time to charge the customer again, retrieve the customer ID.
    Map<String, Object> params = new HashMap<>();
    params.put("amount", 1500); // $15.00 this time
    params.put("currency", "usd");
    params.put("customer", customerId); // Previously stored, then retrieved
    Charge charge = Charge.create(params);
    
    // Set your secret key: remember to change this to your live secret key in production
    // See your keys here: https://dashboard.stripe.com/account/apikeys
    var stripe = require("stripe")("sk_test_4eC39HqLyjWDarjtT1zdp7dc");
    
    (async function() {
      // Create a Customer:
      const customer = await stripe.customers.create({
        source: 'tok_mastercard',
        email: 'paying.user@example.com',
      });
    
      // Charge the Customer instead of the card:
      const charge = await stripe.charges.create({
        amount: 1000,
        currency: 'usd',
        customer: customer.id,
      });
    
      // YOUR CODE: Save the customer ID and other info in a database for later.
    
    })();
    
    (async function() {
      // When it's time to charge the customer again, retrieve the customer ID.
      const charge = stripe.charges.create({
        amount: 1500, // $15.00 this time
        currency: 'usd',
        customer: customer.id, // Previously stored, then retrieved
      });
    })();
    
    // Set your secret key: remember to change this to your live secret key in production
    // See your keys here: https://dashboard.stripe.com/account/apikeys
    stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
    
    // Create a Customer:
    customerParams := &stripe.CustomerParams{
        Email: stripe.String("paying.user@example.com"),
    }
    customerParams.SetSource("tok_mastercard")
    cus, _ := customer.New(customerParams)
    
    // Charge the Customer instead of the card:
    chargeParams := &stripe.ChargeParams{
        Amount: 1000,
        Currency: "usd",
        Customer: customer.id,
    }
    ch, _ := charge.New(chargeParams)
    
    // YOUR CODE: Save the customer ID and other info in a database for later.
    
    // When it's time to charge the customer again, retrieve the customer ID.
    params := &stripe.ChargeParams{
        Amount: 1500, // $15.00 this time
        Currency: "usd",
        Customer: customerId, // Previously stored, then retrieved
    }
    ch, _ := charge.New(params)
    
    // Set your secret key: remember to change this to your live secret key in production
    // See your keys here: https://dashboard.stripe.com/account/apikeys
    StripeConfiguration.SetApiKey("sk_test_4eC39HqLyjWDarjtT1zdp7dc");
    
    // Create a Customer:
    var customerOptions = new StripeCustomerCreateOptions {
        SourceTokenOrExistingSourceId = "tok_mastercard",
        Email = "paying.user@example.com",
    };
    var customerService = new StripeCustomerService();
    StripeCustomer customer = customerService.Create(customerOptions);
    
    // Charge the Customer instead of the card:
    var chargeOptions = new StripeChargeCreateOptions {
        Amount = 1000,
        Currency = "usd",
        Customer = customer.Id,
    };
    var chargeService = new StripeChargeService();
    StripeCharge charge = chargeService.Create(chargeOptions);
    
    // YOUR CODE: Save the customer ID and other info in a database for later.
    
    // When it's time to charge the customer again, retrieve the customer ID.
    var options = new StripeChargeCreateOptions {
        Amount = 1500, // $15.00 this time
        Currency = "usd",
        Customer = customerId, // Previously stored, then retrieved
    };
    var service = new StripeChargeService();
    StripeCharge charge = service.Create(options);
    

    Charges using saved card details can be customized in the same ways as one-time charges.

    Automatic card updates

    Saved payment method details can continue to work even if the physical card has been replaced by the issuing bank. Stripe works with card networks and automatically attempts to update saved card details whenever a customer receives a new card (e.g., replacing an expired card or one that was reported lost or stolen). This allows your customers to continue using your service without interruption and reduces the need for you to collect new card details whenever a card is replaced.

    Automatic card updates requires card issuers to participate with the network and provide this information. It is widely supported in the United States, allowing Stripe to automatically update most American Express, Visa, Mastercard, and Discover cards issued there. International support varies from country to country. It is not possible to identify which cards can be automatically updated.

    You can use webhooks to be notified before or after a card is automatically updated. Listening for customer.source.expiring notifies you when a card is scheduled to expire at the end of the current month. customer.source.updated notifies you when a card is updated. This event includes the new card’s expiration date and last four digits, should you need to update your own records.

    Changing the default payment method

    Although many of the cards you save can be automatically updated, you should still adopt a process that allows customers to update or replace the cards on file (e.g., a customer wants to change the card being billed or their card cannot be automatically updated). The end of the process requires an update customer call, providing a new token for the source parameter.

    curl https://api.stripe.com/v1/customers/cus_V9T7vofUbZMqpv \
       -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
       -d source=tok_visa
    
    # Set your secret key: remember to change this to your live secret key in production
    # See your keys here: https://dashboard.stripe.com/account/apikeys
    Stripe.api_key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
    
    Stripe::Customer.update('cus_V9T7vofUbZMqpv', {
        source: 'tok_visa',
    })
    
    # Set your secret key: remember to change this to your live secret key in production
    # See your keys here: https://dashboard.stripe.com/account/apikeys
    stripe.api_key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
    
    stripe.Customer.modify('cus_V9T7vofUbZMqpv',
     source='tok_visa',
    )
    
    // Set your secret key: remember to change this to your live secret key in production
    // See your keys here: https://dashboard.stripe.com/account/apikeys
    \Stripe\Stripe::setApiKey("sk_test_4eC39HqLyjWDarjtT1zdp7dc");
    
    \Stripe\Customer::update('cus_V9T7vofUbZMqpv', [
        'source' => 'tok_visa',
    ]);
    
    // Set your secret key: remember to change this to your live secret key in production
    // See your keys here: https://dashboard.stripe.com/account/apikeys
    Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc";
    
    Customer customer = Customer.retrieve("cus_V9T7vofUbZMqpv");
    Map<String, Object> params = new HashMap<>();
    params.put("source", "tok_visa");
    customer.update(params);
    
    // Set your secret key: remember to change this to your live secret key in production
    // See your keys here: https://dashboard.stripe.com/account/apikeys
    var stripe = require("stripe")("sk_test_4eC39HqLyjWDarjtT1zdp7dc");
    
    stripe.customers.update('cus_V9T7vofUbZMqpv', {
      source: 'tok_visa',
    });
    
    // Set your secret key: remember to change this to your live secret key in production
    // See your keys here: https://dashboard.stripe.com/account/apikeys
    stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
    
    params := &stripe.CustomerParams{}
    params.SetSource("tok_visa")
    cus, _ := customer.Update("cus_V9T7vofUbZMqpv", params)
    
    // Set your secret key: remember to change this to your live secret key in production
    // See your keys here: https://dashboard.stripe.com/account/apikeys
    StripeConfiguration.SetApiKey("sk_test_4eC39HqLyjWDarjtT1zdp7dc");
    
    var options = new StripeCustomerUpdateOptions {
        SourceTokenOrExistingSourceId = "tok_visa",
    };
    var service = new StripeCustomerService();
    StripeCustomer customer = service.Update("cus_V9T7vofUbZMqpv", options);
    

    This sets the new card as the default payment source for future payments. It also deletes the previously saved card.

    We explain the entire process in more detail in our recipe for handling card updates.

    Multiple payment methods

    Customers can also store multiple payment methods. The first one saved to a customer is set as the default_source. This is used for subscription payments and whenever a charge request is made with just a customer ID.

    You can manage the payment methods saved to a customer (e.g., create or remove cards) and you can update the customer to change default_source to another stored payment method at any time.

    Next steps

    Congrats! Now that you can save and update card details, you might find these topics useful:

    Questions?

    We're always happy to help with code or other questions you might have! Search our documentation, contact support, or connect with our sales team. You can also chat live with other developers in #stripe on freenode.

    Was this page helpful? Yes No

    Send

    Thank you for helping improve Stripe's documentation. If you need help or have any questions, please consider contacting support.