PureBasic Stripe: Capture a Charge

Back to Index

Capture the payment of an existing, uncaptured, charge. This is the second half of the two-step payment flow, where first you created a charge with the capture option set to false.

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

CURL Command

curl https://api.stripe.com/v1/charges/ch_1BnETJGswQrCoh0XTs0EERBj/capture \
   -u STRIPE_SECRET_KEY: \
   -X POST

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/ch_1BnETJGswQrCoh0XTs0EERBj/capture
    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,"POST","/v1/charges/ch_1BnETJGswQrCoh0XTs0EERBj/capture",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)

    id.s
    object.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
    i.i
    count_i.i

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


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


    ProcedureReturn
EndProcedure

Sample JSON Response Body

{
  "id": "ch_1BnETJGswQrCoh0XTs0EERBj",
  "object": "charge",
  "amount": 100,
  "amount_refunded": 0,
  "application": null,
  "application_fee": null,
  "balance_transaction": "txn_1BnETJGswQrCoh0XxO2tGYr7",
  "captured": true,
  "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
}