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

Delphi DLL Example

var
rest: HCkRest;
success: Boolean;
bTls: Boolean;
port: Integer;
bAutoReconnect: Boolean;
strResponseBody: PWideChar;
jsonResponse: HCkJsonObject;
id: PWideChar;
object: PWideChar;
amount: Integer;
amount_refunded: Integer;
application: Boolean;
application_fee: Boolean;
balance_transaction: PWideChar;
captured: Boolean;
created: Integer;
currency: PWideChar;
customer: Boolean;
description: PWideChar;
destination: Boolean;
dispute: Boolean;
failure_code: Boolean;
failure_message: Boolean;
invoice: Boolean;
livemode: Boolean;
on_behalf_of: Boolean;
order: Boolean;
outcome: Boolean;
paid: Boolean;
receipt_email: Boolean;
receipt_number: Boolean;
refunded: Boolean;
refundsObject: PWideChar;
refundsHas_more: Boolean;
refundsTotal_count: Integer;
refundsUrl: PWideChar;
review: Boolean;
shipping: Boolean;
sourceId: PWideChar;
sourceObject: PWideChar;
sourceAddress_city: Boolean;
sourceAddress_country: Boolean;
sourceAddress_line1: Boolean;
sourceAddress_line1_check: Boolean;
sourceAddress_line2: Boolean;
sourceAddress_state: Boolean;
sourceAddress_zip: Boolean;
sourceAddress_zip_check: Boolean;
sourceBrand: PWideChar;
sourceCountry: PWideChar;
sourceCustomer: Boolean;
sourceCvc_check: Boolean;
sourceDynamic_last4: Boolean;
sourceExp_month: Integer;
sourceExp_year: Integer;
sourceFingerprint: PWideChar;
sourceFunding: PWideChar;
sourceLast4: PWideChar;
sourceName: Boolean;
sourceTokenization_method: Boolean;
source_transfer: Boolean;
statement_descriptor: Boolean;
status: PWideChar;
transfer_group: Boolean;
i: Integer;
count_i: Integer;

begin
rest := CkRest_Create();

//  URL: https://api.stripe.com/v1/charges/ch_1BnETJGswQrCoh0XTs0EERBj
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,'description','Charge for aiden.jones@example.com');

strResponseBody := CkRest__fullRequestFormUrlEncoded(rest,'POST','/v1/charges/ch_1BnETJGswQrCoh0XTs0EERBj');
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');
amount := CkJsonObject_IntOf(jsonResponse,'amount');
amount_refunded := CkJsonObject_IntOf(jsonResponse,'amount_refunded');
application := CkJsonObject_IsNullOf(jsonResponse,'application');
application_fee := CkJsonObject_IsNullOf(jsonResponse,'application_fee');
balance_transaction := CkJsonObject__stringOf(jsonResponse,'balance_transaction');
captured := CkJsonObject_BoolOf(jsonResponse,'captured');
created := CkJsonObject_IntOf(jsonResponse,'created');
currency := CkJsonObject__stringOf(jsonResponse,'currency');
customer := CkJsonObject_IsNullOf(jsonResponse,'customer');
description := CkJsonObject__stringOf(jsonResponse,'description');
destination := CkJsonObject_IsNullOf(jsonResponse,'destination');
dispute := CkJsonObject_IsNullOf(jsonResponse,'dispute');
failure_code := CkJsonObject_IsNullOf(jsonResponse,'failure_code');
failure_message := CkJsonObject_IsNullOf(jsonResponse,'failure_message');
invoice := CkJsonObject_IsNullOf(jsonResponse,'invoice');
livemode := CkJsonObject_BoolOf(jsonResponse,'livemode');
on_behalf_of := CkJsonObject_IsNullOf(jsonResponse,'on_behalf_of');
order := CkJsonObject_IsNullOf(jsonResponse,'order');
outcome := CkJsonObject_IsNullOf(jsonResponse,'outcome');
paid := CkJsonObject_BoolOf(jsonResponse,'paid');
receipt_email := CkJsonObject_IsNullOf(jsonResponse,'receipt_email');
receipt_number := CkJsonObject_IsNullOf(jsonResponse,'receipt_number');
refunded := CkJsonObject_BoolOf(jsonResponse,'refunded');
refundsObject := CkJsonObject__stringOf(jsonResponse,'refunds.object');
refundsHas_more := CkJsonObject_BoolOf(jsonResponse,'refunds.has_more');
refundsTotal_count := CkJsonObject_IntOf(jsonResponse,'refunds.total_count');
refundsUrl := CkJsonObject__stringOf(jsonResponse,'refunds.url');
review := CkJsonObject_IsNullOf(jsonResponse,'review');
shipping := CkJsonObject_IsNullOf(jsonResponse,'shipping');
sourceId := CkJsonObject__stringOf(jsonResponse,'source.id');
sourceObject := CkJsonObject__stringOf(jsonResponse,'source.object');
sourceAddress_city := CkJsonObject_IsNullOf(jsonResponse,'source.address_city');
sourceAddress_country := CkJsonObject_IsNullOf(jsonResponse,'source.address_country');
sourceAddress_line1 := CkJsonObject_IsNullOf(jsonResponse,'source.address_line1');
sourceAddress_line1_check := CkJsonObject_IsNullOf(jsonResponse,'source.address_line1_check');
sourceAddress_line2 := CkJsonObject_IsNullOf(jsonResponse,'source.address_line2');
sourceAddress_state := CkJsonObject_IsNullOf(jsonResponse,'source.address_state');
sourceAddress_zip := CkJsonObject_IsNullOf(jsonResponse,'source.address_zip');
sourceAddress_zip_check := CkJsonObject_IsNullOf(jsonResponse,'source.address_zip_check');
sourceBrand := CkJsonObject__stringOf(jsonResponse,'source.brand');
sourceCountry := CkJsonObject__stringOf(jsonResponse,'source.country');
sourceCustomer := CkJsonObject_IsNullOf(jsonResponse,'source.customer');
sourceCvc_check := CkJsonObject_IsNullOf(jsonResponse,'source.cvc_check');
sourceDynamic_last4 := CkJsonObject_IsNullOf(jsonResponse,'source.dynamic_last4');
sourceExp_month := CkJsonObject_IntOf(jsonResponse,'source.exp_month');
sourceExp_year := CkJsonObject_IntOf(jsonResponse,'source.exp_year');
sourceFingerprint := CkJsonObject__stringOf(jsonResponse,'source.fingerprint');
sourceFunding := CkJsonObject__stringOf(jsonResponse,'source.funding');
sourceLast4 := CkJsonObject__stringOf(jsonResponse,'source.last4');
sourceName := CkJsonObject_IsNullOf(jsonResponse,'source.name');
sourceTokenization_method := CkJsonObject_IsNullOf(jsonResponse,'source.tokenization_method');
source_transfer := CkJsonObject_IsNullOf(jsonResponse,'source_transfer');
statement_descriptor := CkJsonObject_IsNullOf(jsonResponse,'statement_descriptor');
status := CkJsonObject__stringOf(jsonResponse,'status');
transfer_group := CkJsonObject_IsNullOf(jsonResponse,'transfer_group');
i := 0;
count_i := CkJsonObject_SizeOfArray(jsonResponse,'refunds.data');
while i < count_i do
  begin
CkJsonObject_putI(jsonResponse,i);
    i := i + 1;
  end;

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