DataFlex 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

DataFlex Example

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iSuccess
    Boolean iBTls
    Integer iPort
    Boolean iBAutoReconnect
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJsonResponse
    String sId
    String sObject
    Integer iAmount
    Integer iAmount_refunded
    Boolean iApplication
    Boolean iApplication_fee
    String sBalance_transaction
    Boolean iCaptured
    Integer iCreated
    String sCurrency
    Boolean iCustomer
    String sDescription
    Boolean iDestination
    Boolean iDispute
    Boolean iFailure_code
    Boolean iFailure_message
    Boolean iInvoice
    Boolean iLivemode
    Boolean iOn_behalf_of
    Boolean iOrder
    Boolean iOutcome
    Boolean iPaid
    Boolean iReceipt_email
    Boolean iReceipt_number
    Boolean iRefunded
    String sRefundsObject
    Boolean iRefundsHas_more
    Integer iRefundsTotal_count
    String sRefundsUrl
    Boolean iReview
    Boolean iShipping
    String sSourceId
    String sSourceObject
    Boolean iSourceAddress_city
    Boolean iSourceAddress_country
    Boolean iSourceAddress_line1
    Boolean iSourceAddress_line1_check
    Boolean iSourceAddress_line2
    Boolean iSourceAddress_state
    Boolean iSourceAddress_zip
    Boolean iSourceAddress_zip_check
    String sSourceBrand
    String sSourceCountry
    Boolean iSourceCustomer
    Boolean iSourceCvc_check
    Boolean iSourceDynamic_last4
    Integer iSourceExp_month
    Integer iSourceExp_year
    String sSourceFingerprint
    String sSourceFunding
    String sSourceLast4
    Boolean iSourceName
    Boolean iSourceTokenization_method
    Boolean iSource_transfer
    Boolean iStatement_descriptor
    String sStatus
    Boolean iTransfer_group
    Integer i
    Integer iCount_i
    String sTemp1
    Integer iTemp1

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    //  URL: https://api.stripe.com/v1/charges/ch_1BnETJGswQrCoh0XTs0EERBj/capture
    Move True To iBTls
    Move 443 To iPort
    Move True To iBAutoReconnect
    Get ComConnect Of hoRest "api.stripe.com" iPort iBTls iBAutoReconnect To iSuccess
    If (iSuccess <> True) Begin
        Get ComConnectFailReason Of hoRest To iTemp1
        Showln "ConnectFailReason: " iTemp1
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComSetAuthBasic Of hoRest "STRIPE_SECRET_KEY" "" To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComFullRequestNoBodySb Of hoRest "POST" "/v1/charges/ch_1BnETJGswQrCoh0XTs0EERBj/capture" vSbResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonResponse
    If (Not(IsComObjectCreated(hoJsonResponse))) Begin
        Send CreateComObject of hoJsonResponse
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJsonResponse vSbResponseBody To iSuccess

    Get ComStringOf Of hoJsonResponse "id" To sId
    Get ComStringOf Of hoJsonResponse "object" To sObject
    Get ComIntOf Of hoJsonResponse "amount" To iAmount
    Get ComIntOf Of hoJsonResponse "amount_refunded" To iAmount_refunded
    Get ComIsNullOf Of hoJsonResponse "application" To iApplication
    Get ComIsNullOf Of hoJsonResponse "application_fee" To iApplication_fee
    Get ComStringOf Of hoJsonResponse "balance_transaction" To sBalance_transaction
    Get ComBoolOf Of hoJsonResponse "captured" To iCaptured
    Get ComIntOf Of hoJsonResponse "created" To iCreated
    Get ComStringOf Of hoJsonResponse "currency" To sCurrency
    Get ComIsNullOf Of hoJsonResponse "customer" To iCustomer
    Get ComStringOf Of hoJsonResponse "description" To sDescription
    Get ComIsNullOf Of hoJsonResponse "destination" To iDestination
    Get ComIsNullOf Of hoJsonResponse "dispute" To iDispute
    Get ComIsNullOf Of hoJsonResponse "failure_code" To iFailure_code
    Get ComIsNullOf Of hoJsonResponse "failure_message" To iFailure_message
    Get ComIsNullOf Of hoJsonResponse "invoice" To iInvoice
    Get ComBoolOf Of hoJsonResponse "livemode" To iLivemode
    Get ComIsNullOf Of hoJsonResponse "on_behalf_of" To iOn_behalf_of
    Get ComIsNullOf Of hoJsonResponse "order" To iOrder
    Get ComIsNullOf Of hoJsonResponse "outcome" To iOutcome
    Get ComBoolOf Of hoJsonResponse "paid" To iPaid
    Get ComIsNullOf Of hoJsonResponse "receipt_email" To iReceipt_email
    Get ComIsNullOf Of hoJsonResponse "receipt_number" To iReceipt_number
    Get ComBoolOf Of hoJsonResponse "refunded" To iRefunded
    Get ComStringOf Of hoJsonResponse "refunds.object" To sRefundsObject
    Get ComBoolOf Of hoJsonResponse "refunds.has_more" To iRefundsHas_more
    Get ComIntOf Of hoJsonResponse "refunds.total_count" To iRefundsTotal_count
    Get ComStringOf Of hoJsonResponse "refunds.url" To sRefundsUrl
    Get ComIsNullOf Of hoJsonResponse "review" To iReview
    Get ComIsNullOf Of hoJsonResponse "shipping" To iShipping
    Get ComStringOf Of hoJsonResponse "source.id" To sSourceId
    Get ComStringOf Of hoJsonResponse "source.object" To sSourceObject
    Get ComIsNullOf Of hoJsonResponse "source.address_city" To iSourceAddress_city
    Get ComIsNullOf Of hoJsonResponse "source.address_country" To iSourceAddress_country
    Get ComIsNullOf Of hoJsonResponse "source.address_line1" To iSourceAddress_line1
    Get ComIsNullOf Of hoJsonResponse "source.address_line1_check" To iSourceAddress_line1_check
    Get ComIsNullOf Of hoJsonResponse "source.address_line2" To iSourceAddress_line2
    Get ComIsNullOf Of hoJsonResponse "source.address_state" To iSourceAddress_state
    Get ComIsNullOf Of hoJsonResponse "source.address_zip" To iSourceAddress_zip
    Get ComIsNullOf Of hoJsonResponse "source.address_zip_check" To iSourceAddress_zip_check
    Get ComStringOf Of hoJsonResponse "source.brand" To sSourceBrand
    Get ComStringOf Of hoJsonResponse "source.country" To sSourceCountry
    Get ComIsNullOf Of hoJsonResponse "source.customer" To iSourceCustomer
    Get ComIsNullOf Of hoJsonResponse "source.cvc_check" To iSourceCvc_check
    Get ComIsNullOf Of hoJsonResponse "source.dynamic_last4" To iSourceDynamic_last4
    Get ComIntOf Of hoJsonResponse "source.exp_month" To iSourceExp_month
    Get ComIntOf Of hoJsonResponse "source.exp_year" To iSourceExp_year
    Get ComStringOf Of hoJsonResponse "source.fingerprint" To sSourceFingerprint
    Get ComStringOf Of hoJsonResponse "source.funding" To sSourceFunding
    Get ComStringOf Of hoJsonResponse "source.last4" To sSourceLast4
    Get ComIsNullOf Of hoJsonResponse "source.name" To iSourceName
    Get ComIsNullOf Of hoJsonResponse "source.tokenization_method" To iSourceTokenization_method
    Get ComIsNullOf Of hoJsonResponse "source_transfer" To iSource_transfer
    Get ComIsNullOf Of hoJsonResponse "statement_descriptor" To iStatement_descriptor
    Get ComStringOf Of hoJsonResponse "status" To sStatus
    Get ComIsNullOf Of hoJsonResponse "transfer_group" To iTransfer_group
    Move 0 To i
    Get ComSizeOfArray Of hoJsonResponse "refunds.data" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJsonResponse To i
        Move i + 1 To i
    Loop



End_Procedure

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
}