Unicode C Stripe: Update a charge

Back to Index

Updates the specified charge by setting the values of the parameters passed. Any parameters not provided will be left unchanged.

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

CURL Command

curl -X POST  https://api.stripe.com/v1/charges/ch_1BnETJGswQrCoh0XTs0EERBj \
   -u STRIPE_SECRET_KEY: \
   -d description="Charge for aiden.jones@example.com"

Unicode C Example

#include <C_CkRestW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    const wchar_t *strResponseBody;
    HCkJsonObjectW jsonResponse;
    const wchar_t *id;
    const wchar_t *object;
    int amount;
    int amount_refunded;
    BOOL application;
    BOOL application_fee;
    const wchar_t *balance_transaction;
    BOOL captured;
    int created;
    const wchar_t *currency;
    BOOL customer;
    const wchar_t *description;
    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;
    BOOL refundsHas_more;
    int refundsTotal_count;
    const wchar_t *refundsUrl;
    BOOL review;
    BOOL shipping;
    const wchar_t *sourceId;
    const wchar_t *sourceObject;
    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;
    const wchar_t *sourceCountry;
    BOOL sourceCustomer;
    BOOL sourceCvc_check;
    BOOL sourceDynamic_last4;
    int sourceExp_month;
    int sourceExp_year;
    const wchar_t *sourceFingerprint;
    const wchar_t *sourceFunding;
    const wchar_t *sourceLast4;
    BOOL sourceName;
    BOOL sourceTokenization_method;
    BOOL source_transfer;
    BOOL statement_descriptor;
    const wchar_t *status;
    BOOL transfer_group;
    int i;
    int count_i;

    rest = CkRestW_Create();

    //  URL: https://api.stripe.com/v1/charges/ch_1BnETJGswQrCoh0XTs0EERBj
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"api.stripe.com",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    CkRestW_SetAuthBasic(rest,L"STRIPE_SECRET_KEY",L"");

    CkRestW_AddQueryParam(rest,L"description",L"Charge for aiden.jones@example.com");

    strResponseBody = CkRestW_fullRequestFormUrlEncoded(rest,L"POST",L"/v1/charges/ch_1BnETJGswQrCoh0XTs0EERBj");
    if (CkRestW_getLastMethodSuccess(rest) != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    jsonResponse = CkJsonObjectW_Create();
    CkJsonObjectW_Load(jsonResponse,strResponseBody);

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



    CkRestW_Dispose(rest);
    CkJsonObjectW_Dispose(jsonResponse);

    }

Sample JSON Response Body

{
  "id": "ch_1BnETJGswQrCoh0XTs0EERBj",
  "object": "charge",
  "amount": 100,
  "amount_refunded": 0,
  "application": null,
  "application_fee": null,
  "balance_transaction": "txn_1BnETJGswQrCoh0XxO2tGYr7",
  "captured": false,
  "created": 1516662781,
  "currency": "usd",
  "customer": null,
  "description": "Charge for aiden.jones@example.com",
  "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
}