Unicode C Stripe: Update a Card

Back to Index

Updates only some card details, like the billing address or expiration date, you can do so without having to re-enter the full card details.

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

CURL Command

curl https://api.stripe.com/v1/customers/cus_CBbg3iRMzWBjoe/sources/card_1BnETKGswQrCoh0Xhu1A6BfL \
   -u STRIPE_SECRET_KEY: \
   -d name="Liam Thomas" \
   -X POST

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;
    BOOL address_city;
    BOOL address_country;
    BOOL address_line1;
    BOOL address_line1_check;
    BOOL address_line2;
    BOOL address_state;
    BOOL address_zip;
    BOOL address_zip_check;
    const wchar_t *brand;
    const wchar_t *country;
    const wchar_t *customer;
    BOOL cvc_check;
    BOOL dynamic_last4;
    int exp_month;
    int exp_year;
    const wchar_t *fingerprint;
    const wchar_t *funding;
    const wchar_t *last4;
    const wchar_t *name;
    BOOL tokenization_method;

    rest = CkRestW_Create();

    //  URL: https://api.stripe.com/v1/customers/cus_CBbg3iRMzWBjoe/sources/card_1BnETKGswQrCoh0Xhu1A6BfL
    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"name",L"Liam Thomas");

    strResponseBody = CkRestW_fullRequestFormUrlEncoded(rest,L"POST",L"/v1/customers/cus_CBbg3iRMzWBjoe/sources/card_1BnETKGswQrCoh0Xhu1A6BfL");
    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");
    address_city = CkJsonObjectW_IsNullOf(jsonResponse,L"address_city");
    address_country = CkJsonObjectW_IsNullOf(jsonResponse,L"address_country");
    address_line1 = CkJsonObjectW_IsNullOf(jsonResponse,L"address_line1");
    address_line1_check = CkJsonObjectW_IsNullOf(jsonResponse,L"address_line1_check");
    address_line2 = CkJsonObjectW_IsNullOf(jsonResponse,L"address_line2");
    address_state = CkJsonObjectW_IsNullOf(jsonResponse,L"address_state");
    address_zip = CkJsonObjectW_IsNullOf(jsonResponse,L"address_zip");
    address_zip_check = CkJsonObjectW_IsNullOf(jsonResponse,L"address_zip_check");
    brand = CkJsonObjectW_stringOf(jsonResponse,L"brand");
    country = CkJsonObjectW_stringOf(jsonResponse,L"country");
    customer = CkJsonObjectW_stringOf(jsonResponse,L"customer");
    cvc_check = CkJsonObjectW_IsNullOf(jsonResponse,L"cvc_check");
    dynamic_last4 = CkJsonObjectW_IsNullOf(jsonResponse,L"dynamic_last4");
    exp_month = CkJsonObjectW_IntOf(jsonResponse,L"exp_month");
    exp_year = CkJsonObjectW_IntOf(jsonResponse,L"exp_year");
    fingerprint = CkJsonObjectW_stringOf(jsonResponse,L"fingerprint");
    funding = CkJsonObjectW_stringOf(jsonResponse,L"funding");
    last4 = CkJsonObjectW_stringOf(jsonResponse,L"last4");
    name = CkJsonObjectW_stringOf(jsonResponse,L"name");
    tokenization_method = CkJsonObjectW_IsNullOf(jsonResponse,L"tokenization_method");


    CkRestW_Dispose(rest);
    CkJsonObjectW_Dispose(jsonResponse);

    }

Sample JSON Response Body

{
  "id": "card_1BnETKGswQrCoh0Xhu1A6BfL",
  "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": "cus_CBbg3iRMzWBjoe",
  "cvc_check": null,
  "dynamic_last4": null,
  "exp_month": 8,
  "exp_year": 2019,
  "fingerprint": "F9mANtIt1TaukpRJ",
  "funding": "credit",
  "last4": "4242",
  "metadata": {},
  "name": "Liam Thomas",
  "tokenization_method": null
}