Body format for Stripe POST operations

stripe charge api
stripe post v1 charges
stripe api
stripe 502
stripe webhooks
expandable stripe
how to authenticate stripe
stripe payment methods

I'm accessing the stripe API directly with the REST API (not using a library) but, surprisingly, I can't find documentation on the appropriate body format post data.

Does Stripe expect JSON or form-encoded pairs?


You need to post raw data like key-value pair. (No Json)

e.g. key1=value1&key2=value2

Make sure you include following in header Content-Type = application/x-www-form-urlencoded

Stripe API Reference, as long as you're doing under $1 million in volume per year. This rate varies country to country, but it's always flat. 1. Now let us add a Request Body to our POST request. Every Endpoint will be document with what kind of Method type and the format of body that it expects. Let us see what body this request expects and how to add it. For that click on Body tab. 2. Click on raw and select format type as JSON, since we have to send in correct format which the server expects.


Here is the sample of the curl code to Nodejs I am working on a similar problem

as you know we can't send JSON for the "post" method it must be URL encoded

here is the sample provided by stripe https://stripe.com/docs/api/checkout/sessions/create

curl https://api.stripe.com/v1/checkout/sessions \
>   -u stripe_key_here: \
>   -d success_url="https://example.com/success" \
>   -d cancel_url="https://example.com/cancel" \
>   -d "payment_method_types[]=card" \
>   -d "line_items[][name]=T-shirt" \
>   -d "line_items[][description]=Comfortable cotton t-shirt" \
>   -d "line_items[][amount]=1500" \
>   -d "line_items[][currency]=usd" \
>   -d "line_items[][quantity]=2"

-u means authorization which we provide in the headers -d means body of the url

sample code in node js

const fetch = require("node-fetch");
const stripeKey = process.env.STRIPE_KEY;

async function getCheckoutID() {
  try {
    const endpoint = "https://api.stripe.com/v1/checkout/sessions";

    const query = objToQuery({
      success_url: "https://example.com/success",
      cancel_url: "https://example.com/cancel",
      "payment_method_types[]": "card",
      "line_items[][name]": "T-shirt",
      "line_items[][description]": "Comfortable cotton t-shirt",
      "line_items[][amount]": 1500,
      "line_items[][quantity]": 1,
      "line_items[][currency]": "usd"
    });

    // enpoint => "https://www.domin.com/api"
    // query => "?key=value&key1=value1"
    const URL = `${endpoint}${query}`;

    const fetchOpts = {
      method: "post",
      headers: {
        "Authorization": `Bearer ${stripeKey}`,
        "Content-Type": "application/x-www-form-urlencoded"
      }
    }
    const checkout = await getJSON(URL, fetchOpts);

    console.log("CHECKOUT OBJECT : " , checkout);

    return checkout;
  }
  catch(e) {
      console.error(e);
   }
}


// hepler functions

// instead of using fetch
// getJSON will make it readable code
async function getJSON(url, options) {
  const http = await fetch(url, options);
  if (!http.ok) {
    console.log(http);
    throw new Error("ERROR STATUS IS NOT OK :");
  }
  return http.json();
}

// convert JS object to url query
// {key:"value" , key1: "value1"} to "key=value&key1=value1"
function objToQuery(obj) {
  const query = Object.keys(obj).map( k => `${k}=${obj[k]}`).join("&");
  return query.length > 0 ? `?${query}` : "";
}

Stripe vs PayPal: Who should you choose?, occurrence, Stripe POSTs the webhook data to your endpoint in JSON format. 'json' # Using Sinatra post '/webhook' do payload = request.body.read event  The webhook endpoint uses the event details to take any required actions, such as indicating that an order should be fulfilled. When to use webhooks Many events that occur within a Stripe account have synchronous results–immediate and direct–to an executed request.


Here is an example cURL charge using a test card:

curl https://api.stripe.com/v1/charges -u your_test_key: -d card[number]=4000056655665556 -d card[exp_month]=11 -d card[exp_year]=2020 -d amount=100 -d currency=eur -d description="Stripe cUrl charge test"

Exchange your_test_key with your stripe test key. Remember to keep the : after your key to not get asked for a password.

How to delay payments and hold funds with Stripe, events by checking the type field of the event object sent in the request body. 4242 post '/webhook' do payload = request.body.read event = nil begin event  Stripe API Reference. We challenge you to find a discussion about the best API reference docs that doesn’t include Stripe. Spoiler alert: there isn’t one. The Stripe API documentation, or the Stripe API Reference, is a work of art. It features a sleek and cool two-panel design, with explanations written in plain English on the left and


Form encoded pairs

The docs for cURL provide good examples. They're just feeding form encoded key/value pairs via the -d switch via cURL on the command line. Just make sure you use your test secret key so you don't screw up any live data. Then you can play around all you want.

The returned data is JSON.

How Does Stripe Work?, curl https://api.stripe.com/v1/charges \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \ -d amount=999 \ -d currency=usd \ -d description="Example charge" \ -d  Found the following information on another post. AR 670-1, Ch 28-28 (12) One overseas service bar is authorized for each 6-month period of Federal service as a member of a U.S. Service participating in Operation Enduring Freedom, the CENTCOM area of operations, or under the control of the Combatant Commander, CENTCOM, from 19 September 2001


Build a webhook endpoint, For example, the API servers might return a 401 if an invalid API key was provided, For a POST operation using an idempotency key, as long as an API method if it should retry based solely on a status code or content in the response body. The type of the body of the request is indicated by the Content-Type header. The difference between PUT and POST is that PUT is idempotent: calling it once or several times successively has the same effect (that is no side effect), where successive identical POST may have additional effects, like passing an order several times.


Handle payment events, The webhook endpoint has an associated URL (e.g., https://example.com/​webhooks). The Stripe notifications are Event objects. This Event object contains all  Accept a payment Charges API. Accept online payments from your U.S. and Canadian customers. The Charges API is an older payments API that does not handle bank requests for card authentication. Try our new payments APIs and integrations instead.


The Charges API, The following example shows how to handle both events: require 'sinatra' require 'stripe' post '/webhook' do payload = request.body.read sig_header  Email receipts. Send payment or refund receipts automatically. Receipts in test mode. Receipts for payments created using your test API keys are not sent automatically. Instead, you can view or manually send a receipt using the Dashboard. Stripe can automatically send email receipts after a successful payment, or when you refund one.