Delphi DLL 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

Delphi DLL Example

var
rest: HCkRest;
success: Boolean;
bTls: Boolean;
port: Integer;
bAutoReconnect: Boolean;
strResponseBody: PWideChar;
jsonResponse: HCkJsonObject;
id: PWideChar;
object: PWideChar;
address_city: Boolean;
address_country: Boolean;
address_line1: Boolean;
address_line1_check: Boolean;
address_line2: Boolean;
address_state: Boolean;
address_zip: Boolean;
address_zip_check: Boolean;
brand: PWideChar;
country: PWideChar;
customer: PWideChar;
cvc_check: Boolean;
dynamic_last4: Boolean;
exp_month: Integer;
exp_year: Integer;
fingerprint: PWideChar;
funding: PWideChar;
last4: PWideChar;
name: PWideChar;
tokenization_method: Boolean;

begin
rest := CkRest_Create();

//  URL: https://api.stripe.com/v1/customers/cus_CBbg3iRMzWBjoe/sources/card_1BnETKGswQrCoh0Xhu1A6BfL
bTls := True;
port := 443;
bAutoReconnect := True;
success := CkRest_Connect(rest,'api.stripe.com',port,bTls,bAutoReconnect);
if (success <> True) then
  begin
    Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(CkRest_getConnectFailReason(rest)));
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

CkRest_SetAuthBasic(rest,'STRIPE_SECRET_KEY','');

CkRest_AddQueryParam(rest,'name','Liam Thomas');

strResponseBody := CkRest__fullRequestFormUrlEncoded(rest,'POST','/v1/customers/cus_CBbg3iRMzWBjoe/sources/card_1BnETKGswQrCoh0Xhu1A6BfL');
if (CkRest_getLastMethodSuccess(rest) <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

jsonResponse := CkJsonObject_Create();
CkJsonObject_Load(jsonResponse,strResponseBody);

id := CkJsonObject__stringOf(jsonResponse,'id');
object := CkJsonObject__stringOf(jsonResponse,'object');
address_city := CkJsonObject_IsNullOf(jsonResponse,'address_city');
address_country := CkJsonObject_IsNullOf(jsonResponse,'address_country');
address_line1 := CkJsonObject_IsNullOf(jsonResponse,'address_line1');
address_line1_check := CkJsonObject_IsNullOf(jsonResponse,'address_line1_check');
address_line2 := CkJsonObject_IsNullOf(jsonResponse,'address_line2');
address_state := CkJsonObject_IsNullOf(jsonResponse,'address_state');
address_zip := CkJsonObject_IsNullOf(jsonResponse,'address_zip');
address_zip_check := CkJsonObject_IsNullOf(jsonResponse,'address_zip_check');
brand := CkJsonObject__stringOf(jsonResponse,'brand');
country := CkJsonObject__stringOf(jsonResponse,'country');
customer := CkJsonObject__stringOf(jsonResponse,'customer');
cvc_check := CkJsonObject_IsNullOf(jsonResponse,'cvc_check');
dynamic_last4 := CkJsonObject_IsNullOf(jsonResponse,'dynamic_last4');
exp_month := CkJsonObject_IntOf(jsonResponse,'exp_month');
exp_year := CkJsonObject_IntOf(jsonResponse,'exp_year');
fingerprint := CkJsonObject__stringOf(jsonResponse,'fingerprint');
funding := CkJsonObject__stringOf(jsonResponse,'funding');
last4 := CkJsonObject__stringOf(jsonResponse,'last4');
name := CkJsonObject__stringOf(jsonResponse,'name');
tokenization_method := CkJsonObject_IsNullOf(jsonResponse,'tokenization_method');

CkRest_Dispose(rest);
CkJsonObject_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
}