Visual FoxPro 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

Visual FoxPro Example

LOCAL loRest
LOCAL lnSuccess
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loSbResponseBody
LOCAL loJsonResponse
LOCAL lcId
LOCAL lcObject
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 i
LOCAL lnCount_i

loRest = CreateObject('Chilkat_9_5_0.Rest')

*  URL: https://api.stripe.com/v1/charges/ch_1BnETJGswQrCoh0XTs0EERBj/capture
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("POST","/v1/charges/ch_1BnETJGswQrCoh0XTs0EERBj/capture",loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loSbResponseBody
    CANCEL
ENDIF

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

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

RELEASE loRest
RELEASE loSbResponseBody
RELEASE loJsonResponse

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
}