Visual FoxPro Stripe: List all Charges

Back to Index

Returns a list of charges you’ve previously created. The charges are returned in sorted order, with the most recent charges appearing first.

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

CURL Command

curl https://api.stripe.com/v1/charges?limit=3 \
   -u STRIPE_SECRET_KEY: \
   -G

Visual FoxPro Example

LOCAL loRest
LOCAL lnSuccess
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loSbResponseBody
LOCAL loJsonResponse
LOCAL lcObject
LOCAL lcUrl
LOCAL lnHas_more
LOCAL i
LOCAL lnCount_i
LOCAL lcId
LOCAL lnAmount
LOCAL lnAmount_refunded
LOCAL lnApplication
LOCAL lnApplication_fee
LOCAL lcBalance_transaction
LOCAL lnCaptured
LOCAL lnCreated
LOCAL lcCurrency
LOCAL lnCustomer
LOCAL lcDescription
LOCAL lnDestination
LOCAL lnDispute
LOCAL lnFailure_code
LOCAL lnFailure_message
LOCAL lnInvoice
LOCAL lnLivemode
LOCAL lnOn_behalf_of
LOCAL lnOrder
LOCAL lnOutcome
LOCAL lnPaid
LOCAL lnReceipt_email
LOCAL lnReceipt_number
LOCAL lnRefunded
LOCAL lcRefundsObject
LOCAL lnRefundsHas_more
LOCAL lnRefundsTotal_count
LOCAL lcRefundsUrl
LOCAL lnReview
LOCAL lnShipping
LOCAL lcSourceId
LOCAL lcSourceObject
LOCAL lnSourceAddress_city
LOCAL lnSourceAddress_country
LOCAL lnSourceAddress_line1
LOCAL lnSourceAddress_line1_check
LOCAL lnSourceAddress_line2
LOCAL lnSourceAddress_state
LOCAL lnSourceAddress_zip
LOCAL lnSourceAddress_zip_check
LOCAL lcSourceBrand
LOCAL lcSourceCountry
LOCAL lnSourceCustomer
LOCAL lnSourceCvc_check
LOCAL lnSourceDynamic_last4
LOCAL lnSourceExp_month
LOCAL lnSourceExp_year
LOCAL lcSourceFingerprint
LOCAL lcSourceFunding
LOCAL lcSourceLast4
LOCAL lnSourceName
LOCAL lnSourceTokenization_method
LOCAL lnSource_transfer
LOCAL lnStatement_descriptor
LOCAL lcStatus
LOCAL lnTransfer_group
LOCAL j
LOCAL lnCount_j

loRest = CreateObject('Chilkat_9_5_0.Rest')

*  URL: https://api.stripe.com/v1/charges?limit=3
lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("api.stripe.com",lnPort,lnBTls,lnBAutoReconnect)
IF (lnSuccess <> 1) THEN
    ? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
ENDIF

loRest.SetAuthBasic("STRIPE_SECRET_KEY","")

loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestNoBodySb("GET","/v1/charges?limit=3",loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJsonResponse = CreateObject('Chilkat_9_5_0.JsonObject')
loJsonResponse.LoadSb(loSbResponseBody)

lcObject = loJsonResponse.StringOf("object")
lcUrl = loJsonResponse.StringOf("url")
lnHas_more = loJsonResponse.BoolOf("has_more")
i = 0
lnCount_i = loJsonResponse.SizeOfArray("data")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lcId = loJsonResponse.StringOf("data[i].id")
    lcObject = loJsonResponse.StringOf("data[i].object")
    lnAmount = loJsonResponse.IntOf("data[i].amount")
    lnAmount_refunded = loJsonResponse.IntOf("data[i].amount_refunded")
    lnApplication = loJsonResponse.IsNullOf("data[i].application")
    lnApplication_fee = loJsonResponse.IsNullOf("data[i].application_fee")
    lcBalance_transaction = loJsonResponse.StringOf("data[i].balance_transaction")
    lnCaptured = loJsonResponse.BoolOf("data[i].captured")
    lnCreated = loJsonResponse.IntOf("data[i].created")
    lcCurrency = loJsonResponse.StringOf("data[i].currency")
    lnCustomer = loJsonResponse.IsNullOf("data[i].customer")
    lcDescription = loJsonResponse.StringOf("data[i].description")
    lnDestination = loJsonResponse.IsNullOf("data[i].destination")
    lnDispute = loJsonResponse.IsNullOf("data[i].dispute")
    lnFailure_code = loJsonResponse.IsNullOf("data[i].failure_code")
    lnFailure_message = loJsonResponse.IsNullOf("data[i].failure_message")
    lnInvoice = loJsonResponse.IsNullOf("data[i].invoice")
    lnLivemode = loJsonResponse.BoolOf("data[i].livemode")
    lnOn_behalf_of = loJsonResponse.IsNullOf("data[i].on_behalf_of")
    lnOrder = loJsonResponse.IsNullOf("data[i].order")
    lnOutcome = loJsonResponse.IsNullOf("data[i].outcome")
    lnPaid = loJsonResponse.BoolOf("data[i].paid")
    lnReceipt_email = loJsonResponse.IsNullOf("data[i].receipt_email")
    lnReceipt_number = loJsonResponse.IsNullOf("data[i].receipt_number")
    lnRefunded = loJsonResponse.BoolOf("data[i].refunded")
    lcRefundsObject = loJsonResponse.StringOf("data[i].refunds.object")
    lnRefundsHas_more = loJsonResponse.BoolOf("data[i].refunds.has_more")
    lnRefundsTotal_count = loJsonResponse.IntOf("data[i].refunds.total_count")
    lcRefundsUrl = loJsonResponse.StringOf("data[i].refunds.url")
    lnReview = loJsonResponse.IsNullOf("data[i].review")
    lnShipping = loJsonResponse.IsNullOf("data[i].shipping")
    lcSourceId = loJsonResponse.StringOf("data[i].source.id")
    lcSourceObject = loJsonResponse.StringOf("data[i].source.object")
    lnSourceAddress_city = loJsonResponse.IsNullOf("data[i].source.address_city")
    lnSourceAddress_country = loJsonResponse.IsNullOf("data[i].source.address_country")
    lnSourceAddress_line1 = loJsonResponse.IsNullOf("data[i].source.address_line1")
    lnSourceAddress_line1_check = loJsonResponse.IsNullOf("data[i].source.address_line1_check")
    lnSourceAddress_line2 = loJsonResponse.IsNullOf("data[i].source.address_line2")
    lnSourceAddress_state = loJsonResponse.IsNullOf("data[i].source.address_state")
    lnSourceAddress_zip = loJsonResponse.IsNullOf("data[i].source.address_zip")
    lnSourceAddress_zip_check = loJsonResponse.IsNullOf("data[i].source.address_zip_check")
    lcSourceBrand = loJsonResponse.StringOf("data[i].source.brand")
    lcSourceCountry = loJsonResponse.StringOf("data[i].source.country")
    lnSourceCustomer = loJsonResponse.IsNullOf("data[i].source.customer")
    lnSourceCvc_check = loJsonResponse.IsNullOf("data[i].source.cvc_check")
    lnSourceDynamic_last4 = loJsonResponse.IsNullOf("data[i].source.dynamic_last4")
    lnSourceExp_month = loJsonResponse.IntOf("data[i].source.exp_month")
    lnSourceExp_year = loJsonResponse.IntOf("data[i].source.exp_year")
    lcSourceFingerprint = loJsonResponse.StringOf("data[i].source.fingerprint")
    lcSourceFunding = loJsonResponse.StringOf("data[i].source.funding")
    lcSourceLast4 = loJsonResponse.StringOf("data[i].source.last4")
    lnSourceName = loJsonResponse.IsNullOf("data[i].source.name")
    lnSourceTokenization_method = loJsonResponse.IsNullOf("data[i].source.tokenization_method")
    lnSource_transfer = loJsonResponse.IsNullOf("data[i].source_transfer")
    lnStatement_descriptor = loJsonResponse.IsNullOf("data[i].statement_descriptor")
    lcStatus = loJsonResponse.StringOf("data[i].status")
    lnTransfer_group = loJsonResponse.IsNullOf("data[i].transfer_group")
    j = 0
    lnCount_j = loJsonResponse.SizeOfArray("data[i].refunds.data")
    DO WHILE j < lnCount_j
        loJsonResponse.J = j
        j = j + 1
    ENDDO
    i = i + 1
ENDDO

RELEASE loRest
RELEASE loSbResponseBody
RELEASE loJsonResponse

Sample JSON Response Body

{
  "object": "list",
  "url": "/v1/charges",
  "has_more": false,
  "data": [
    {
      "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": "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
    }
  ]
}