PowerBuilder 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

PowerBuilder Example

integer li_rc
oleobject loo_Rest
integer li_Success
integer li_BTls
integer li_Port
integer li_BAutoReconnect
oleobject loo_SbResponseBody
oleobject loo_JsonResponse
string ls_Id
string ls_Object
integer li_Amount
string ls_Client_secret
integer li_Created
string ls_Currency
string ls_Flow
integer li_Livemode
integer li_OwnerAddress
string ls_OwnerEmail
integer li_OwnerName
integer li_OwnerPhone
integer li_OwnerVerified_address
integer li_OwnerVerified_email
integer li_OwnerVerified_name
integer li_OwnerVerified_phone
string ls_ReceiverAddress
integer li_ReceiverAmount_charged
integer li_ReceiverAmount_received
integer li_ReceiverAmount_returned
string ls_ReceiverRefund_attributes_method
string ls_ReceiverRefund_attributes_status
integer li_Statement_descriptor
string ls_Status
string ls_Type
string ls_Usage
string ls_BitcoinAddress
integer li_BitcoinAmount
integer li_BitcoinAmount_charged
integer li_BitcoinAmount_received
integer li_BitcoinAmount_returned
string ls_BitcoinUri

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat_9_5_0.Rest")
if li_rc < 0 then
    destroy loo_Rest
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  URL: https://api.stripe.com/v1/customers/cus_CBbg9PmQ9sLbmo/sources/src_1BnETLGswQrCoh0X5KOorXEP
li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("api.stripe.com",li_Port,li_BTls,li_BAutoReconnect)
if li_Success <> 1 then
    Write-Debug "ConnectFailReason: " + string(loo_Rest.ConnectFailReason)
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    return
end if

loo_Rest.SetAuthBasic("STRIPE_SECRET_KEY","")

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

li_Success = loo_Rest.FullRequestNoBodySb("DELETE","/v1/customers/cus_CBbg9PmQ9sLbmo/sources/src_1BnETLGswQrCoh0X5KOorXEP",loo_SbResponseBody)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_SbResponseBody
    return
end if

loo_JsonResponse = create oleobject
li_rc = loo_JsonResponse.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JsonResponse.LoadSb(loo_SbResponseBody)

ls_Id = loo_JsonResponse.StringOf("id")
ls_Object = loo_JsonResponse.StringOf("object")
li_Amount = loo_JsonResponse.IntOf("amount")
ls_Client_secret = loo_JsonResponse.StringOf("client_secret")
li_Created = loo_JsonResponse.IntOf("created")
ls_Currency = loo_JsonResponse.StringOf("currency")
ls_Flow = loo_JsonResponse.StringOf("flow")
li_Livemode = loo_JsonResponse.BoolOf("livemode")
li_OwnerAddress = loo_JsonResponse.IsNullOf("owner.address")
ls_OwnerEmail = loo_JsonResponse.StringOf("owner.email")
li_OwnerName = loo_JsonResponse.IsNullOf("owner.name")
li_OwnerPhone = loo_JsonResponse.IsNullOf("owner.phone")
li_OwnerVerified_address = loo_JsonResponse.IsNullOf("owner.verified_address")
li_OwnerVerified_email = loo_JsonResponse.IsNullOf("owner.verified_email")
li_OwnerVerified_name = loo_JsonResponse.IsNullOf("owner.verified_name")
li_OwnerVerified_phone = loo_JsonResponse.IsNullOf("owner.verified_phone")
ls_ReceiverAddress = loo_JsonResponse.StringOf("receiver.address")
li_ReceiverAmount_charged = loo_JsonResponse.IntOf("receiver.amount_charged")
li_ReceiverAmount_received = loo_JsonResponse.IntOf("receiver.amount_received")
li_ReceiverAmount_returned = loo_JsonResponse.IntOf("receiver.amount_returned")
ls_ReceiverRefund_attributes_method = loo_JsonResponse.StringOf("receiver.refund_attributes_method")
ls_ReceiverRefund_attributes_status = loo_JsonResponse.StringOf("receiver.refund_attributes_status")
li_Statement_descriptor = loo_JsonResponse.IsNullOf("statement_descriptor")
ls_Status = loo_JsonResponse.StringOf("status")
ls_Type = loo_JsonResponse.StringOf("type")
ls_Usage = loo_JsonResponse.StringOf("usage")
ls_BitcoinAddress = loo_JsonResponse.StringOf("bitcoin.address")
li_BitcoinAmount = loo_JsonResponse.IntOf("bitcoin.amount")
li_BitcoinAmount_charged = loo_JsonResponse.IntOf("bitcoin.amount_charged")
li_BitcoinAmount_received = loo_JsonResponse.IntOf("bitcoin.amount_received")
li_BitcoinAmount_returned = loo_JsonResponse.IntOf("bitcoin.amount_returned")
ls_BitcoinUri = loo_JsonResponse.StringOf("bitcoin.uri")


destroy loo_Rest
destroy loo_SbResponseBody
destroy loo_JsonResponse

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