Creating Charges

    Use Stripe's API and your server-side code to process charges. If you need help after reading this, check out our answers to common questions or chat live with other developers in #stripe on freenode.

    Once you've securely collected and tokenized your customer's credit card using Checkout or Elements, you can charge the card. Unlike collection, which occurs in the browser, charge attempts are made from your server, normally using one of our client libraries. If you haven't already, install the library for your favorite language now. This tutorial shows code for Ruby, PHP, Python, and Node, but we also have libraries for Java and Go.

    On your server, grab the Stripe token in the POST parameters submitted by your form. From there, it's one simple API call to charge the card:

    curl https://api.stripe.com/v1/charges \
       -u sk_test_BQokikJOvBiI2HlWgH4olfQ2: \
       -d amount=1000 \
       -d currency=usd \
       -d description="Example charge" \
       -d source=tok_J6cfHyD09oY2UDaDlrhrxLTe
    
    # 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 Stripe.js or Checkout!
    # Get the payment token submitted by the form:
    token = params[:stripeToken]
    
    # Charge the user's card:
    charge = Stripe::Charge.create(
      :amount => 1000,
      :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_BQokikJOvBiI2HlWgH4olfQ2"
    
    # Token is created using Stripe.js or Checkout!
    # Get the payment token submitted by the form:
    token = request.POST['stripeToken']
    
    # Charge the user's card:
    charge = stripe.Charge.create(
      amount=1000,
      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_BQokikJOvBiI2HlWgH4olfQ2");
    
    // Token is created using Stripe.js or Checkout!
    // Get the payment token submitted by the form:
    $token = $_POST['stripeToken'];
    
    // Charge the user's card:
    $charge = \Stripe\Charge::create(array(
      "amount" => 1000,
      "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_BQokikJOvBiI2HlWgH4olfQ2";
    
    // Token is created using Stripe.js or Checkout!
    // Get the payment token submitted by the form:
    String token = request.getParameter("stripeToken");
    
    // Charge the user's card:
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("amount", 1000);
    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_BQokikJOvBiI2HlWgH4olfQ2");
    
    // Token is created using Stripe.js or Checkout!
    // Get the payment token submitted by the form:
    var token = request.body.stripeToken; // Using Express
    
    // Charge the user's card:
    var charge = stripe.charges.create({
      amount: 1000,
      currency: "usd",
      description: "Example charge",
      source: token,
    }, function(err, charge) {
      // 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"
    
    // Token is created using Stripe.js or Checkout!
    // Get the payment token submitted by the form:
    token := r.FormValue("stripeToken")
    
    // Charge the user's card:
    params := &stripe.ChargeParams{
      Amount: 1000,
      Currency: "usd",
      Description: "Example charge",
    }
    params.SetSource(token)
    
    charge, err := charge.New(params)
    

    As a convenience, if you're logged in while reading this page, we've pre-filled the example with your test secret API key. Only you can see this value. This will authenticate you to Stripe, so keep it secret and keep it safe. Remember to replace the test key with your live key in production. You can get all your keys from the Dashboard.

    That's it! If the charge creation request succeeds, the card has been successfully charged. You will automatically receive your money in two days. If the charge attempt fails, we'll return an error instead.

    Saving credit card details for later

    Stripe tokens 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 type that makes it easy to save this—and other—information for later use.

    Instead of charging the card immediately, create a new Customer, saving the token on the Customer in the process. This will let you charge the customer at any point in the future:

    # Create a Customer:
    curl https://api.stripe.com/v1/customers \
       -u sk_test_BQokikJOvBiI2HlWgH4olfQ2: \
       -d email="paying.user@example.com" \
       -d source=tok_zLrro0x78RxD25GhfvtUGF7Q
    # 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_Wf9MP00W0Xl7jz
    # 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_Wf9MP00W0Xl7jz
    
    # 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 Stripe.js or Checkout!
    # Get the payment token 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 Stripe.js or Checkout!
    # Get the payment token submitted by the form:
    token = request.POST['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 Stripe.js or Checkout!
    // Get the payment token 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 Stripe.js or Checkout!
    // Get the payment token 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 Stripe.js or Checkout!
    // Get the payment token 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 Stripe.js or Checkout!
    // Get the payment token 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)
    

    After creating a customer in Stripe with a stored payment method, you can charge that customer at any point in time by passing the customer ID—instead of a card representation—in the charge request. Be certain to store the customer ID on your side for later use.

    Storing information in metadata

    Stripe supports adding metadata to the most common requests you'll make, such as processing charges. Metadata is for your use only: it isn't shown to customers or factored into whether or not a charge is declined or blocked by our fraud prevention system.

    Through metadata, you can associate other information—meaningful to you—with Stripe activity. Any metadata you include will be viewable in the Dashboard (e.g., when looking at the page for an individual charge), and will also be available in common reports and exports. As an example, your store's order ID can be attached to the charge used to pay for that order. Doing so allows you, your accountant, or your finance team to easily reconcile charges in Stripe to orders in your system.

    If you're using Radar to flag payments for review, consider passing any additional order information as metadata. By doing so, more information about the payment is available within the Dashboard which can expedite your review process.

    curl https://api.stripe.com/v1/charges \
       -u sk_test_BQokikJOvBiI2HlWgH4olfQ2: \
       -d amount=1000 \
       -d currency=usd \
       -d description="Example charge" \
       -d metadata[order_id]=6735 \
       -d source=tok_1J9wFsyPMhcwJ3O6aXqPQknf
    
    # 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 Stripe.js or Checkout!
    # Get the payment token submitted by the form:
    token = params[:stripeToken]
    
    # Charge the user's card:
    charge = Stripe::Charge.create(
      :amount => 1000,
      :currency => "usd",
      :description => "Example charge",
      :metadata => {"order_id" => 6735},
      :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_BQokikJOvBiI2HlWgH4olfQ2"
    
    # Token is created using Stripe.js or Checkout!
    # Get the payment token submitted by the form:
    token = request.POST['stripeToken']
    
    # Charge the user's card:
    charge = stripe.Charge.create(
      amount=1000,
      currency="usd",
      description="Example charge",
      metadata={"order_id": 6735},
      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_BQokikJOvBiI2HlWgH4olfQ2");
    
    // Token is created using Stripe.js or Checkout!
    // Get the payment token submitted by the form:
    $token = $_POST['stripeToken'];
    
    // Charge the user's card:
    $charge = \Stripe\Charge::create(array(
      "amount" => 1000,
      "currency" => "usd",
      "description" => "Example charge",
      "metadata" => array("order_id" => 6735),
      "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_BQokikJOvBiI2HlWgH4olfQ2";
    
    // Token is created using Stripe.js or Checkout!
    // Get the payment token submitted by the form:
    String token = request.getParameter("stripeToken");
    
    // Charge the user's card:
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("amount", 1000);
    params.put("currency", "usd");
    params.put("description", "Example charge");
    Map<String, String> initialMetadata = new HashMap<String, String>();
    initialMetadata.put("order_id", 6735);
    params.put("metadata", initialMetadata);
    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_BQokikJOvBiI2HlWgH4olfQ2");
    
    // Token is created using Stripe.js or Checkout!
    // Get the payment token submitted by the form:
    var token = request.body.stripeToken; // Using Express
    
    // Charge the user's card:
    var charge = stripe.charges.create({
      amount: 1000,
      currency: "usd",
      description: "Example charge",
      metadata: {order_id: 6735},
      source: token,
    }, function(err, charge) {
      // 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"
    
    // Token is created using Stripe.js or Checkout!
    // Get the payment token submitted by the form:
    token := r.FormValue("stripeToken")
    
    // Charge the user's card:
    params := &stripe.ChargeParams{
      Amount: 1000,
      Currency: "usd",
      Description: "Example charge",
    }
    params.AddMeta("order_id", 6735)
    params.SetSource(token)
    
    charge, err := charge.New(params)
    

    Next steps

    Congrats! You've processed your first charge using Stripe. Some things you might want to see next: