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_BQokikJOvBiI2HlWgH4olfQ2: \
       -d email="paying.user@example.com" \
       -d source=tok_gIke7yEqxADSl6DnQUIWOR3p
    # Charge the Customer instead of the card:
    curl https://api.stripe.com/v1/charges \
       -u sk_test_BQokikJOvBiI2HlWgH4olfQ2: \
       -d amount=1000 \
       -d currency=usd \
       -d customer=cus_F3d5D66UMujyeZ
    # 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_BQokikJOvBiI2HlWgH4olfQ2: \
       -d amount=1500 \
       -d currency=usd \
       -d customer=cus_F3d5D66UMujyeZ
    
    # 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_BQokikJOvBiI2HlWgH4olfQ2"
    
    # Token is created using Checkout or Elements!
    # Get the payment token ID submitted by the form:
    token = params[:stripeToken]
    
    # Create a Customer:
    customer = Stripe::Customer.create(
      :email => "paying.user@example.com",
      :source => token,
    )
    
    # 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.
    
    # YOUR CODE (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_BQokikJOvBiI2HlWgH4olfQ2"
    
    # Token is created using Checkout or Elements!
    # Get the payment token ID submitted by the form:
    token = request.form['stripeToken']
    
    # Create a Customer:
    customer = stripe.Customer.create(
      email="paying.user@example.com",
      source=token,
    )
    
    # 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.
    
    # YOUR CODE (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_BQokikJOvBiI2HlWgH4olfQ2");
    
    // Token is created using Checkout or Elements!
    // Get the payment token ID submitted by the form:
    $token = $_POST['stripeToken'];
    
    // Create a Customer:
    $customer = \Stripe\Customer::create(array(
      "email" => "paying.user@example.com",
      "source" => $token,
    ));
    
    // Charge the Customer instead of the card:
    $charge = \Stripe\Charge::create(array(
      "amount" => 1000,
      "currency" => "usd",
      "customer" => $customer->id
    ));
    
    // YOUR CODE: Save the customer ID and other info in a database for later.
    
    // YOUR CODE (LATER): When it's time to charge the customer again, retrieve the customer ID.
    $charge = \Stripe\Charge::create(array(
      "amount" => 1500, // $15.00 this time
      "currency" => "usd",
      "customer" => $customer_id
    ));
    
    // 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_BQokikJOvBiI2HlWgH4olfQ2";
    
    // Token is created using Checkout or Elements!
    // Get the payment token ID submitted by the form:
    String token = request.getParameter("stripeToken");
    
    // Create a Customer:
    Map<String, Object> customerParams = new HashMap<String, Object>();
    customerParams.put("email", "paying.user@example.com");
    customerParams.put("source", token);
    Customer customer = Customer.create(customerParams);
    
    // Charge the Customer instead of the card:
    Map<String, Object> chargeParams = new HashMap<String, Object>();
    chargeParams.put("amount", 1000);
    chargeParams.put("currency", "usd");
    chargeParams.put("customer", customer.getId());
    Charge charge = Charge.create(chargeParams);
    
    // YOUR CODE: Save the customer ID and other info in a database for later.
    
    // YOUR CODE (LATER): When it's time to charge the customer again, retrieve the customer ID.
    Map<String, Object> chargeParams = new HashMap<String, Object>();
    chargeParams.put("amount", 1500); // $15.00 this time
    chargeParams.put("currency", "usd");
    chargeParams.put("customer", customerId);
    Charge charge = Charge.create(chargeParams);
    
    // 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_BQokikJOvBiI2HlWgH4olfQ2");
    
    // Token is created using Checkout or Elements!
    // Get the payment token ID submitted by the form:
    var token = request.body.stripeToken; // Using Express
    
    // Create a Customer:
    stripe.customers.create({
      email: "paying.user@example.com",
      source: token,
    }).then(function(customer) {
      // YOUR CODE: Save the customer ID and other info in a database for later.
      return stripe.charges.create({
        amount: 1000,
        currency: "usd",
        customer: customer.id,
      });
    }).then(function(charge) {
      // Use and save the charge info.
    });
    
    // YOUR CODE (LATER): When it's time to charge the customer again, retrieve the customer ID.
    stripe.charges.create({
      amount: 1500, // $15.00 this time
      currency: "usd",
      customer: customerId,
    });
    
    // 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_BQokikJOvBiI2HlWgH4olfQ2"
    
    // Token is created using Checkout or Elements!
    // Get the payment token ID submitted by the form:
    token := r.FormValue("stripeToken")
    
    // Create a Customer:
    customerParams := &stripe.CustomerParams{
      Email: "paying.user@example.com",
    }
    customerParams.SetSource(token)
    customer, err := customer.New(customerParams)
    
    // Charge the Customer instead of the card:
    chargeParams := &stripe.ChargeParams{
      Amount: 1000,
      Currency: "usd",
      Customer: customer.id,
    }
    charge, err := charge.New(chargeParams)
    
    // YOUR CODE: Save the customer ID and other info in a database for later.
    
    // YOUR CODE (LATER): When it's time to charge the customer again, retrieve the customer ID.
    chargeParams := &stripe.ChargeParams{
      Amount: 1500, // $15.00 this time
      Currency: "usd",
      Customer: customerId,
    }
    charge, err := charge.New(chargeParams)
    
    // 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_BQokikJOvBiI2HlWgH4olfQ2");
    
    // Token is created using Checkout or Elements!
    // Get the payment token submitted by the form:
    var token = model.Token; // Using ASP.NET MVC
    
    var customers = new StripeCustomerService();
    var charges = new StripeChargeService();
    
    var customer = customers.Create(new StripeCustomerCreateOptions {
      Email = "paying.user@example.com",
      SourceToken = token
    });
    
    // YOUR CODE: Save the customer ID and other info in a database for later.
    
    // YOUR CODE (LATER): When it's time to charge the customer again, retrieve the customer ID.
    var charge = charges.Create(new StripeChargeCreateOptions {
      Amount = 1500, // $15.00 this time
      Currency = "usd",
      CustomerId = customer.Id
    });
    

    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 be notified whenever a card is automatically updated by listening for the customer.source.updated webhook notification. 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_edo8QYdkg7Fw2J \
       -u sk_test_BQokikJOvBiI2HlWgH4olfQ2: \
       -d source=tok_6JpfaimWyerG2xx8ScFMVFq4
    
    # 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_BQokikJOvBiI2HlWgH4olfQ2"
    
    cu = Stripe::Customer.retrieve("cus_r93zOgYh66oltP")
    cu.source = "tok_70r1iMshsxaXO2Y7UkWeJlj4"
    cu.save
    
    # 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_BQokikJOvBiI2HlWgH4olfQ2"
    
    cu = stripe.Customer.retrieve("cus_Fea6bakXsAsTNs")
    cu.source = "tok_TP3LaBDKWyOhEeZZ9rpIpRL6"
    cu.save()
    
    // 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_BQokikJOvBiI2HlWgH4olfQ2");
    
    $cu = \Stripe\Customer::retrieve("cus_yFhIC88NYtiihX");
    $cu->source = "tok_taoa2sa2LSIM4BKq5Uwupneq";
    $cu->save();
    
    // 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_BQokikJOvBiI2HlWgH4olfQ2";
    
    Customer cu = Customer.retrieve("cus_d2HqqkO00IkYPm");
    Map<String, Object> updateParams = new HashMap<String, Object>();
    updateParams.put("source", "tok_VLwTq6EyW9UzJUDc8HVg4EJc");
    
    cu.update(updateParams);
    
    // 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_BQokikJOvBiI2HlWgH4olfQ2");
    
    stripe.customers.update("cus_FYejEHIotKCbVm", {
      source: "tok_KFFwJd44nM6kIAfNlJ3Era8e"
    }, function(err, customer) {
      // asynchronously called
    });
    
    // 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_BQokikJOvBiI2HlWgH4olfQ2"
    
    c, err := customer.Update(
          "cus_QFXig514OCdSsv",
          &stripe.CustomerParams{Source: "tok_ZodtyoNIrJGx3Yy9gijsxWYJ"},
        )
    

    This creates an additional saved card and sets it as the default payment source for future payments. If necessary, you can then delete 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: