Visual FoxPro Stripe: Detach a Source

Back to Index

Detaches a Source object from a Customer. The status of a source is changed to consumed when it is detached and it can no longer be used to create a charge.

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

CURL Command

curl https://api.stripe.com/v1/customers/cus_CBbg9PmQ9sLbmo/sources/src_1BnETLGswQrCoh0X5KOorXEP \
   -u STRIPE_SECRET_KEY: \
   -X DELETE

Visual FoxPro Example

LOCAL loRest
LOCAL lnSuccess
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loSbResponseBody
LOCAL loJsonResponse
LOCAL lcId
LOCAL lcObject
LOCAL lnAmount
LOCAL lcClient_secret
LOCAL lnCreated
LOCAL lcCurrency
LOCAL lcFlow
LOCAL lnLivemode
LOCAL lnOwnerAddress
LOCAL lcOwnerEmail
LOCAL lnOwnerName
LOCAL lnOwnerPhone
LOCAL lnOwnerVerified_address
LOCAL lnOwnerVerified_email
LOCAL lnOwnerVerified_name
LOCAL lnOwnerVerified_phone
LOCAL lcReceiverAddress
LOCAL lnReceiverAmount_charged
LOCAL lnReceiverAmount_received
LOCAL lnReceiverAmount_returned
LOCAL lcReceiverRefund_attributes_method
LOCAL lcReceiverRefund_attributes_status
LOCAL lnStatement_descriptor
LOCAL lcStatus
LOCAL lcType
LOCAL lcUsage
LOCAL lcBitcoinAddress
LOCAL lnBitcoinAmount
LOCAL lnBitcoinAmount_charged
LOCAL lnBitcoinAmount_received
LOCAL lnBitcoinAmount_returned
LOCAL lcBitcoinUri

loRest = CreateObject('Chilkat_9_5_0.Rest')

*  URL: https://api.stripe.com/v1/customers/cus_CBbg9PmQ9sLbmo/sources/src_1BnETLGswQrCoh0X5KOorXEP
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("DELETE","/v1/customers/cus_CBbg9PmQ9sLbmo/sources/src_1BnETLGswQrCoh0X5KOorXEP",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")
lcClient_secret = loJsonResponse.StringOf("client_secret")
lnCreated = loJsonResponse.IntOf("created")
lcCurrency = loJsonResponse.StringOf("currency")
lcFlow = loJsonResponse.StringOf("flow")
lnLivemode = loJsonResponse.BoolOf("livemode")
lnOwnerAddress = loJsonResponse.IsNullOf("owner.address")
lcOwnerEmail = loJsonResponse.StringOf("owner.email")
lnOwnerName = loJsonResponse.IsNullOf("owner.name")
lnOwnerPhone = loJsonResponse.IsNullOf("owner.phone")
lnOwnerVerified_address = loJsonResponse.IsNullOf("owner.verified_address")
lnOwnerVerified_email = loJsonResponse.IsNullOf("owner.verified_email")
lnOwnerVerified_name = loJsonResponse.IsNullOf("owner.verified_name")
lnOwnerVerified_phone = loJsonResponse.IsNullOf("owner.verified_phone")
lcReceiverAddress = loJsonResponse.StringOf("receiver.address")
lnReceiverAmount_charged = loJsonResponse.IntOf("receiver.amount_charged")
lnReceiverAmount_received = loJsonResponse.IntOf("receiver.amount_received")
lnReceiverAmount_returned = loJsonResponse.IntOf("receiver.amount_returned")
lcReceiverRefund_attributes_method = loJsonResponse.StringOf("receiver.refund_attributes_method")
lcReceiverRefund_attributes_status = loJsonResponse.StringOf("receiver.refund_attributes_status")
lnStatement_descriptor = loJsonResponse.IsNullOf("statement_descriptor")
lcStatus = loJsonResponse.StringOf("status")
lcType = loJsonResponse.StringOf("type")
lcUsage = loJsonResponse.StringOf("usage")
lcBitcoinAddress = loJsonResponse.StringOf("bitcoin.address")
lnBitcoinAmount = loJsonResponse.IntOf("bitcoin.amount")
lnBitcoinAmount_charged = loJsonResponse.IntOf("bitcoin.amount_charged")
lnBitcoinAmount_received = loJsonResponse.IntOf("bitcoin.amount_received")
lnBitcoinAmount_returned = loJsonResponse.IntOf("bitcoin.amount_returned")
lcBitcoinUri = loJsonResponse.StringOf("bitcoin.uri")

RELEASE loRest
RELEASE loSbResponseBody
RELEASE loJsonResponse

Sample JSON Response Body

{
  "id": "src_1BnETLGswQrCoh0X5KOorXEP",
  "object": "source",
  "amount": 1000,
  "client_secret": "src_client_secret_CBbgdvc1AflN5jN0wQevA2jA",
  "created": 1516662783,
  "currency": "usd",
  "flow": "receiver",
  "livemode": false,
  "metadata": {},
  "owner": {
    "address": null,
    "email": "jenny.rosen@example.com",
    "name": null,
    "phone": null,
    "verified_address": null,
    "verified_email": null,
    "verified_name": null,
    "verified_phone": null
  },
  "receiver": {
    "address": "test_1MBhWS3uv4ynCfQXF3xQjJkzFPukr4K56N",
    "amount_charged": 0,
    "amount_received": 0,
    "amount_returned": 0,
    "refund_attributes_method": "email",
    "refund_attributes_status": "missing"
  },
  "statement_descriptor": null,
  "status": "consumed",
  "type": "bitcoin",
  "usage": "single_use",
  "bitcoin": {
    "address": "test_1MBhWS3uv4ynCfQXF3xQjJkzFPukr4K56N",
    "amount": 2371000,
    "amount_charged": 0,
    "amount_received": 0,
    "amount_returned": 0,
    "uri": "bitcoin:test_1MBhWS3uv4ynCfQXF3xQjJkzFPukr4K56N?amount=0.02371000"
  }
}