PowerBuilder Stripe: List all Cards

Back to Index

List the cards belonging to a customer or recipient.

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

CURL Command

curl "https://api.stripe.com/v1/customers/cus_CBbg3iRMzWBjoe/sources?object=card&limit=3" \
   -u STRIPE_SECRET_KEY: \
   -G

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_Object
string ls_Url
integer li_Has_more
integer i
integer li_Count_i
string ls_Id
integer li_Address_city
integer li_Address_country
integer li_Address_line1
integer li_Address_line1_check
integer li_Address_line2
integer li_Address_state
integer li_Address_zip
integer li_Address_zip_check
string ls_Brand
string ls_Country
string ls_Customer
integer li_Cvc_check
integer li_Dynamic_last4
integer li_Exp_month
integer li_Exp_year
string ls_Fingerprint
string ls_Funding
string ls_Last4
integer li_Name
integer li_Tokenization_method

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_CBbg3iRMzWBjoe/sources?object=card&limit=3
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("GET","/v1/customers/cus_CBbg3iRMzWBjoe/sources?object=card&limit=3",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_Object = loo_JsonResponse.StringOf("object")
ls_Url = loo_JsonResponse.StringOf("url")
li_Has_more = loo_JsonResponse.BoolOf("has_more")
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("data")
do while i < li_Count_i
    loo_JsonResponse.I = i
    ls_Id = loo_JsonResponse.StringOf("data[i].id")
    ls_Object = loo_JsonResponse.StringOf("data[i].object")
    li_Address_city = loo_JsonResponse.IsNullOf("data[i].address_city")
    li_Address_country = loo_JsonResponse.IsNullOf("data[i].address_country")
    li_Address_line1 = loo_JsonResponse.IsNullOf("data[i].address_line1")
    li_Address_line1_check = loo_JsonResponse.IsNullOf("data[i].address_line1_check")
    li_Address_line2 = loo_JsonResponse.IsNullOf("data[i].address_line2")
    li_Address_state = loo_JsonResponse.IsNullOf("data[i].address_state")
    li_Address_zip = loo_JsonResponse.IsNullOf("data[i].address_zip")
    li_Address_zip_check = loo_JsonResponse.IsNullOf("data[i].address_zip_check")
    ls_Brand = loo_JsonResponse.StringOf("data[i].brand")
    ls_Country = loo_JsonResponse.StringOf("data[i].country")
    ls_Customer = loo_JsonResponse.StringOf("data[i].customer")
    li_Cvc_check = loo_JsonResponse.IsNullOf("data[i].cvc_check")
    li_Dynamic_last4 = loo_JsonResponse.IsNullOf("data[i].dynamic_last4")
    li_Exp_month = loo_JsonResponse.IntOf("data[i].exp_month")
    li_Exp_year = loo_JsonResponse.IntOf("data[i].exp_year")
    ls_Fingerprint = loo_JsonResponse.StringOf("data[i].fingerprint")
    ls_Funding = loo_JsonResponse.StringOf("data[i].funding")
    ls_Last4 = loo_JsonResponse.StringOf("data[i].last4")
    li_Name = loo_JsonResponse.IsNullOf("data[i].name")
    li_Tokenization_method = loo_JsonResponse.IsNullOf("data[i].tokenization_method")
    i = i + 1
loop


destroy loo_Rest
destroy loo_SbResponseBody
destroy loo_JsonResponse

Sample JSON Response Body

{
  "object": "list",
  "url": "/v1/customers/cus_CBbg3iRMzWBjoe/sources",
  "has_more": false,
  "data": [
    {
      "id": "card_1BnETKGswQrCoh0Xhu1A6BfL",
      "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": "cus_CBbg3iRMzWBjoe",
      "cvc_check": null,
      "dynamic_last4": null,
      "exp_month": 8,
      "exp_year": 2019,
      "fingerprint": "F9mANtIt1TaukpRJ",
      "funding": "credit",
      "last4": "4242",
      "metadata": {},
      "name": null,
      "tokenization_method": null
    }
  ]
}