Card Payments Quickstart

    Securely collect card information from your customers and create a card payment.

    Accepting a card payment using Stripe is a two-step process, with a client-side and a server-side action:

    1. From your website running in the customer’s browser, Stripe securely collects your customer’s payment information and returns a representative token. This, along with any other form data, is then submitted by the browser to your server.
    2. Using the token, your server-side code makes an API request to create a charge and complete the payment.

    Tokenization ensures that no sensitive card data ever needs to touch your server, so your integration can operate in a PCI-compliant way. Card details are never fully revealed, although Stripe’s Dashboard and API do provide limited information about the card (such as its last four digits, expiration date, and brand).

    Step 1: Securely collecting payment information

    The simplest way for you to securely collect and tokenize card information is with Checkout. It combines HTML, JavaScript, and CSS to create an embedded payment form. When your customer enters their payment information, the card details are validated and tokenized for your server-side code to use.

    To see Checkout in action, click the button below, filling in the resulting form with:

    • Any random, syntactically valid email address (the more random, the better)
    • One of Stripe’s test card numbers, such as 4242 4242 4242 4242
    • Any three-digit CVC code
    • Any expiration date in the future
    • Any billing ZIP code, such as 12345

    To get started, add the following code to your payment page, making sure that the form submits to your own server-side code:

    <form action="your-server-side-code" method="POST">
      <script
        src="https://checkout.stripe.com/checkout.js" class="stripe-button"
        data-key="pk_test_TYooMQauvdEDq54NiTphI7jx"
        data-amount="999"
        data-name="Stripe.com"
        data-description="Example charge"
        data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
        data-locale="auto"
        data-zip-code="true">
      </script>
    </form>

    We’ve pre-filled the data-key attribute with a random test publishable API key. Replace it with your own to test this code through your Stripe account. When you’re ready to go live with your payment form, you must replace the test key with your live key. Learn more about how the keys play into test and live modes.

    Checkout also accepts the user’s ZIP code, if enabled, and passes this to Stripe. Although optional, using address and ZIP code verifications is highly recommended as they’ll help reduce fraud. You can also set Checkout to collect the user’s full billing and shipping addresses by adding the required attributes to the form.

    An alternative to the blue button demonstrated above is to implement a custom Checkout integration. The custom approach allows you to use any HTML element or JavaScript event to open Checkout, as well as be able to specify dynamic arguments, such as custom amounts.

    Stripe.js and Elements

    If you’d prefer to have complete control over the look and feel of your payment form, you can make use of Stripe.js and Elements, our pre-built UI components. Refer to our Elements quickstart to learn more.

    Mobile SDKs

    Using our native mobile libraries for iOS and Android, Stripe can collect your customer’s payment information from within your mobile app and create a token for your server-side code to use.

    Step 2: Creating a charge to complete the payment

    Once a token is created, your server-side code makes an API request to create a one-time charge. This request contains the token, currency, amount to charge, and any additional information you may want to pass (e.g., metadata).

    curl https://api.stripe.com/v1/charges \
       -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
       -d amount=999 \
       -d currency=usd \
       -d description="Example charge" \
       -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"
    
    # Token is created using Checkout or Elements!
    # Get the payment token ID submitted by the form:
    token = params[:stripeToken]
    
    charge = Stripe::Charge.create({
        amount: 999,
        currency: 'usd',
        description: 'Example charge',
        source: token,
    })
    
    # 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"
    
    # Token is created using Checkout or Elements!
    # Get the payment token ID submitted by the form:
    token = request.form['stripeToken'] # Using Flask
    
    charge = stripe.Charge.create(
        amount=999,
        currency='usd',
        description='Example charge',
        source=token,
    )
    
    // 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");
    
    // Token is created using Checkout or Elements!
    // Get the payment token ID submitted by the form:
    $token = $_POST['stripeToken'];
    
    $charge = \Stripe\Charge::create([
        'amount' => 999,
        'currency' => 'usd',
        'description' => 'Example charge',
        'source' => $token,
    ]);
    
    // 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";
    
    // Token is created using Checkout or Elements!
    // Get the payment token ID submitted by the form:
    String token = request.getParameter("stripeToken");
    
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("amount", 999);
    params.put("currency", "usd");
    params.put("description", "Example charge");
    params.put("source", token);
    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");
    
    // Token is created using Checkout or Elements!
    // Get the payment token ID submitted by the form:
    const token = request.body.stripeToken; // Using Express
    
    const charge = stripe.charges.create({
      amount: 999,
      currency: 'usd',
      description: 'Example charge',
      source: token,
    });
    
    // 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"
    
    // Token is created using Checkout or Elements!
    // Get the payment token ID submitted by the form:
    token := r.FormValue("stripeToken")
    
    params := &stripe.ChargeParams{
        Amount: stripe.Int64(999),
        Currency: stripe.String(string(stripe.CurrencyUSD)),
        Description: stripe.String("Example charge"),
    }
    params.SetSource(token)
    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");
    
    // Token is created using Checkout or Elements!
    // Get the payment token submitted by the form:
    var token = model.Token; // Using ASP.NET MVC
    
    var options = new ChargeCreateOptions {
        Amount = 999,
        Currency = "usd",
        Description = "Example charge",
        SourceId = token,
    };
    var service = new ChargeService();
    Charge charge = service.Create(options);
    

    Tokens can only be used once, and within a few minutes of creation. Using this approach, your customers need to re-enter their payment details each time they make a purchase. You can also save card details with Stripe for later use. Using this method, returning customers can quickly make a payment without providing their card details again.

    Next steps

    Congrats! You can now accept card payments with Stripe using Checkout. You may now want to check out these resources:

    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.