PureBasic 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

PureBasic Example

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkRest.pb"

Procedure ChilkatExample()

    rest.i = CkRest::ckCreate()
    If rest.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ;  URL: https://api.stripe.com/v1/charges?limit=3
    bTls.i = 1
    port.i = 443
    bAutoReconnect.i = 1
    success = CkRest::ckConnect(rest,"api.stripe.com",port,bTls,bAutoReconnect)
    If success <> 1
        Debug "ConnectFailReason: " + Str(CkRest::ckConnectFailReason(rest))
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    CkRest::ckSetAuthBasic(rest,"STRIPE_SECRET_KEY","")

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkRest::ckFullRequestNoBodySb(rest,"GET","/v1/charges?limit=3",sbResponseBody)
    If success <> 1
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    jsonResponse.i = CkJsonObject::ckCreate()
    If jsonResponse.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jsonResponse,sbResponseBody)

    object.s
    url.s
    has_more.i
    i.i
    count_i.i
    id.s
    amount.i
    amount_refunded.i
    application.i
    application_fee.i
    balance_transaction.s
    captured.i
    created.i
    currency.s
    customer.i
    description.s
    destination.i
    dispute.i
    failure_code.i
    failure_message.i
    invoice.i
    livemode.i
    on_behalf_of.i
    order.i
    outcome.i
    paid.i
    receipt_email.i
    receipt_number.i
    refunded.i
    refundsObject.s
    refundsHas_more.i
    refundsTotal_count.i
    refundsUrl.s
    review.i
    shipping.i
    sourceId.s
    sourceObject.s
    sourceAddress_city.i
    sourceAddress_country.i
    sourceAddress_line1.i
    sourceAddress_line1_check.i
    sourceAddress_line2.i
    sourceAddress_state.i
    sourceAddress_zip.i
    sourceAddress_zip_check.i
    sourceBrand.s
    sourceCountry.s
    sourceCustomer.i
    sourceCvc_check.i
    sourceDynamic_last4.i
    sourceExp_month.i
    sourceExp_year.i
    sourceFingerprint.s
    sourceFunding.s
    sourceLast4.s
    sourceName.i
    sourceTokenization_method.i
    source_transfer.i
    statement_descriptor.i
    status.s
    transfer_group.i
    j.i
    count_j.i

    object = CkJsonObject::ckStringOf(jsonResponse,"object")
    url = CkJsonObject::ckStringOf(jsonResponse,"url")
    has_more = CkJsonObject::ckBoolOf(jsonResponse,"has_more")
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jsonResponse,"data")
    While i < count_i
        CkJsonObject::setCkI(jsonResponse, i)
        id = CkJsonObject::ckStringOf(jsonResponse,"data[i].id")
        object = CkJsonObject::ckStringOf(jsonResponse,"data[i].object")
        amount = CkJsonObject::ckIntOf(jsonResponse,"data[i].amount")
        amount_refunded = CkJsonObject::ckIntOf(jsonResponse,"data[i].amount_refunded")
        application = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].application")
        application_fee = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].application_fee")
        balance_transaction = CkJsonObject::ckStringOf(jsonResponse,"data[i].balance_transaction")
        captured = CkJsonObject::ckBoolOf(jsonResponse,"data[i].captured")
        created = CkJsonObject::ckIntOf(jsonResponse,"data[i].created")
        currency = CkJsonObject::ckStringOf(jsonResponse,"data[i].currency")
        customer = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].customer")
        description = CkJsonObject::ckStringOf(jsonResponse,"data[i].description")
        destination = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].destination")
        dispute = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].dispute")
        failure_code = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].failure_code")
        failure_message = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].failure_message")
        invoice = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].invoice")
        livemode = CkJsonObject::ckBoolOf(jsonResponse,"data[i].livemode")
        on_behalf_of = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].on_behalf_of")
        order = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].order")
        outcome = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].outcome")
        paid = CkJsonObject::ckBoolOf(jsonResponse,"data[i].paid")
        receipt_email = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].receipt_email")
        receipt_number = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].receipt_number")
        refunded = CkJsonObject::ckBoolOf(jsonResponse,"data[i].refunded")
        refundsObject = CkJsonObject::ckStringOf(jsonResponse,"data[i].refunds.object")
        refundsHas_more = CkJsonObject::ckBoolOf(jsonResponse,"data[i].refunds.has_more")
        refundsTotal_count = CkJsonObject::ckIntOf(jsonResponse,"data[i].refunds.total_count")
        refundsUrl = CkJsonObject::ckStringOf(jsonResponse,"data[i].refunds.url")
        review = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].review")
        shipping = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].shipping")
        sourceId = CkJsonObject::ckStringOf(jsonResponse,"data[i].source.id")
        sourceObject = CkJsonObject::ckStringOf(jsonResponse,"data[i].source.object")
        sourceAddress_city = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].source.address_city")
        sourceAddress_country = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].source.address_country")
        sourceAddress_line1 = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].source.address_line1")
        sourceAddress_line1_check = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].source.address_line1_check")
        sourceAddress_line2 = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].source.address_line2")
        sourceAddress_state = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].source.address_state")
        sourceAddress_zip = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].source.address_zip")
        sourceAddress_zip_check = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].source.address_zip_check")
        sourceBrand = CkJsonObject::ckStringOf(jsonResponse,"data[i].source.brand")
        sourceCountry = CkJsonObject::ckStringOf(jsonResponse,"data[i].source.country")
        sourceCustomer = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].source.customer")
        sourceCvc_check = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].source.cvc_check")
        sourceDynamic_last4 = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].source.dynamic_last4")
        sourceExp_month = CkJsonObject::ckIntOf(jsonResponse,"data[i].source.exp_month")
        sourceExp_year = CkJsonObject::ckIntOf(jsonResponse,"data[i].source.exp_year")
        sourceFingerprint = CkJsonObject::ckStringOf(jsonResponse,"data[i].source.fingerprint")
        sourceFunding = CkJsonObject::ckStringOf(jsonResponse,"data[i].source.funding")
        sourceLast4 = CkJsonObject::ckStringOf(jsonResponse,"data[i].source.last4")
        sourceName = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].source.name")
        sourceTokenization_method = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].source.tokenization_method")
        source_transfer = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].source_transfer")
        statement_descriptor = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].statement_descriptor")
        status = CkJsonObject::ckStringOf(jsonResponse,"data[i].status")
        transfer_group = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].transfer_group")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jsonResponse,"data[i].refunds.data")
        While j < count_j
            CkJsonObject::setCkJ(jsonResponse, j)
            j = j + 1
        Wend
        i = i + 1
    Wend


    CkRest::ckDispose(rest)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jsonResponse)


    ProcedureReturn
EndProcedure

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
    }
  ]
}