Unicode C++ Stripe: Capture a Charge

Back to Index

Capture the payment of an existing, uncaptured, charge. This is the second half of the two-step payment flow, where first you created a charge with the capture option set to false.

Documentation: https://stripe.com/docs/api/curl#capture_charge

CURL Command

curl https://api.stripe.com/v1/charges/ch_1BnETJGswQrCoh0XTs0EERBj/capture \
   -u STRIPE_SECRET_KEY: \
   -X POST

Unicode C++ Example

#include <CkRestW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    CkRestW rest;
    bool success;

    //  URL: https://api.stripe.com/v1/charges/ch_1BnETJGswQrCoh0XTs0EERBj/capture
    bool bTls = true;
    int port = 443;
    bool bAutoReconnect = true;
    success = rest.Connect(L"api.stripe.com",port,bTls,bAutoReconnect);
    if (success != true) {
        wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    rest.SetAuthBasic(L"STRIPE_SECRET_KEY",L"");

    CkStringBuilderW sbResponseBody;
    success = rest.FullRequestNoBodySb(L"POST",L"/v1/charges/ch_1BnETJGswQrCoh0XTs0EERBj/capture",sbResponseBody);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    CkJsonObjectW jsonResponse;
    jsonResponse.LoadSb(sbResponseBody);

    const wchar_t *id = 0;
    const wchar_t *object = 0;
    int amount;
    int amount_refunded;
    bool application;
    bool application_fee;
    const wchar_t *balance_transaction = 0;
    bool captured;
    int created;
    const wchar_t *currency = 0;
    bool customer;
    const wchar_t *description = 0;
    bool destination;
    bool dispute;
    bool failure_code;
    bool failure_message;
    bool invoice;
    bool livemode;
    bool on_behalf_of;
    bool order;
    bool outcome;
    bool paid;
    bool receipt_email;
    bool receipt_number;
    bool refunded;
    const wchar_t *refundsObject = 0;
    bool refundsHas_more;
    int refundsTotal_count;
    const wchar_t *refundsUrl = 0;
    bool review;
    bool shipping;
    const wchar_t *sourceId = 0;
    const wchar_t *sourceObject = 0;
    bool sourceAddress_city;
    bool sourceAddress_country;
    bool sourceAddress_line1;
    bool sourceAddress_line1_check;
    bool sourceAddress_line2;
    bool sourceAddress_state;
    bool sourceAddress_zip;
    bool sourceAddress_zip_check;
    const wchar_t *sourceBrand = 0;
    const wchar_t *sourceCountry = 0;
    bool sourceCustomer;
    bool sourceCvc_check;
    bool sourceDynamic_last4;
    int sourceExp_month;
    int sourceExp_year;
    const wchar_t *sourceFingerprint = 0;
    const wchar_t *sourceFunding = 0;
    const wchar_t *sourceLast4 = 0;
    bool sourceName;
    bool sourceTokenization_method;
    bool source_transfer;
    bool statement_descriptor;
    const wchar_t *status = 0;
    bool transfer_group;
    int i;
    int count_i;

    id = jsonResponse.stringOf(L"id");
    object = jsonResponse.stringOf(L"object");
    amount = jsonResponse.IntOf(L"amount");
    amount_refunded = jsonResponse.IntOf(L"amount_refunded");
    application = jsonResponse.IsNullOf(L"application");
    application_fee = jsonResponse.IsNullOf(L"application_fee");
    balance_transaction = jsonResponse.stringOf(L"balance_transaction");
    captured = jsonResponse.BoolOf(L"captured");
    created = jsonResponse.IntOf(L"created");
    currency = jsonResponse.stringOf(L"currency");
    customer = jsonResponse.IsNullOf(L"customer");
    description = jsonResponse.stringOf(L"description");
    destination = jsonResponse.IsNullOf(L"destination");
    dispute = jsonResponse.IsNullOf(L"dispute");
    failure_code = jsonResponse.IsNullOf(L"failure_code");
    failure_message = jsonResponse.IsNullOf(L"failure_message");
    invoice = jsonResponse.IsNullOf(L"invoice");
    livemode = jsonResponse.BoolOf(L"livemode");
    on_behalf_of = jsonResponse.IsNullOf(L"on_behalf_of");
    order = jsonResponse.IsNullOf(L"order");
    outcome = jsonResponse.IsNullOf(L"outcome");
    paid = jsonResponse.BoolOf(L"paid");
    receipt_email = jsonResponse.IsNullOf(L"receipt_email");
    receipt_number = jsonResponse.IsNullOf(L"receipt_number");
    refunded = jsonResponse.BoolOf(L"refunded");
    refundsObject = jsonResponse.stringOf(L"refunds.object");
    refundsHas_more = jsonResponse.BoolOf(L"refunds.has_more");
    refundsTotal_count = jsonResponse.IntOf(L"refunds.total_count");
    refundsUrl = jsonResponse.stringOf(L"refunds.url");
    review = jsonResponse.IsNullOf(L"review");
    shipping = jsonResponse.IsNullOf(L"shipping");
    sourceId = jsonResponse.stringOf(L"source.id");
    sourceObject = jsonResponse.stringOf(L"source.object");
    sourceAddress_city = jsonResponse.IsNullOf(L"source.address_city");
    sourceAddress_country = jsonResponse.IsNullOf(L"source.address_country");
    sourceAddress_line1 = jsonResponse.IsNullOf(L"source.address_line1");
    sourceAddress_line1_check = jsonResponse.IsNullOf(L"source.address_line1_check");
    sourceAddress_line2 = jsonResponse.IsNullOf(L"source.address_line2");
    sourceAddress_state = jsonResponse.IsNullOf(L"source.address_state");
    sourceAddress_zip = jsonResponse.IsNullOf(L"source.address_zip");
    sourceAddress_zip_check = jsonResponse.IsNullOf(L"source.address_zip_check");
    sourceBrand = jsonResponse.stringOf(L"source.brand");
    sourceCountry = jsonResponse.stringOf(L"source.country");
    sourceCustomer = jsonResponse.IsNullOf(L"source.customer");
    sourceCvc_check = jsonResponse.IsNullOf(L"source.cvc_check");
    sourceDynamic_last4 = jsonResponse.IsNullOf(L"source.dynamic_last4");
    sourceExp_month = jsonResponse.IntOf(L"source.exp_month");
    sourceExp_year = jsonResponse.IntOf(L"source.exp_year");
    sourceFingerprint = jsonResponse.stringOf(L"source.fingerprint");
    sourceFunding = jsonResponse.stringOf(L"source.funding");
    sourceLast4 = jsonResponse.stringOf(L"source.last4");
    sourceName = jsonResponse.IsNullOf(L"source.name");
    sourceTokenization_method = jsonResponse.IsNullOf(L"source.tokenization_method");
    source_transfer = jsonResponse.IsNullOf(L"source_transfer");
    statement_descriptor = jsonResponse.IsNullOf(L"statement_descriptor");
    status = jsonResponse.stringOf(L"status");
    transfer_group = jsonResponse.IsNullOf(L"transfer_group");
    i = 0;
    count_i = jsonResponse.SizeOfArray(L"refunds.data");
    while (i < count_i) {
        jsonResponse.put_I(i);
        i = i + 1;
    }
    }

Sample JSON Response Body

{
  "id": "ch_1BnETJGswQrCoh0XTs0EERBj",
  "object": "charge",
  "amount": 100,
  "amount_refunded": 0,
  "application": null,
  "application_fee": null,
  "balance_transaction": "txn_1BnETJGswQrCoh0XxO2tGYr7",
  "captured": true,
  "created": 1516662781,
  "currency": "usd",
  "customer": null,
  "description": "My First Test Charge (created for API docs)",
  "destination": null,
  "dispute": null,
  "failure_code": null,
  "failure_message": null,
  "fraud_details": {},
  "invoice": null,
  "livemode": false,
  "metadata": {},
  "on_behalf_of": null,
  "order": null,
  "outcome": null,
  "paid": true,
  "receipt_email": null,
  "receipt_number": null,
  "refunded": false,
  "refunds": {
    "object": "list",
    "data": [
    ],
    "has_more": false,
    "total_count": 0,
    "url": "/v1/charges/ch_1BnETJGswQrCoh0XTs0EERBj/refunds"
  },
  "review": null,
  "shipping": null,
  "source": {
    "id": "card_18ropuGswQrCoh0XjCJ5Zvma",
    "object": "card",
    "address_city": null,
    "address_country": null,
    "address_line1": null,
    "address_line1_check": null,
    "address_line2": null,
    "address_state": null,
    "address_zip": null,
    "address_zip_check": null,
    "brand": "Visa",
    "country": "US",
    "customer": null,
    "cvc_check": null,
    "dynamic_last4": null,
    "exp_month": 8,
    "exp_year": 2017,
    "fingerprint": "F9mANtIt1TaukpRJ",
    "funding": "credit",
    "last4": "4242",
    "metadata": {},
    "name": null,
    "tokenization_method": null
  },
  "source_transfer": null,
  "statement_descriptor": null,
  "status": "succeeded",
  "transfer_group": null
}