DataFlex Stripe: Update a Card

Back to Index

Updates only some card details, like the billing address or expiration date, you can do so without having to re-enter the full card details.

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

CURL Command

curl https://api.stripe.com/v1/customers/cus_CBbg3iRMzWBjoe/sources/card_1BnETKGswQrCoh0Xhu1A6BfL \
   -u STRIPE_SECRET_KEY: \
   -d name="Liam Thomas" \
   -X POST

DataFlex Example

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iSuccess
    Boolean iBTls
    Integer iPort
    Boolean iBAutoReconnect
    String sStrResponseBody
    Handle hoJsonResponse
    String sId
    String sObject
    Boolean iAddress_city
    Boolean iAddress_country
    Boolean iAddress_line1
    Boolean iAddress_line1_check
    Boolean iAddress_line2
    Boolean iAddress_state
    Boolean iAddress_zip
    Boolean iAddress_zip_check
    String sBrand
    String sCountry
    String sCustomer
    Boolean iCvc_check
    Boolean iDynamic_last4
    Integer iExp_month
    Integer iExp_year
    String sFingerprint
    String sFunding
    String sLast4
    String sName
    Boolean iTokenization_method
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

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

    //  URL: https://api.stripe.com/v1/customers/cus_CBbg3iRMzWBjoe/sources/card_1BnETKGswQrCoh0Xhu1A6BfL
    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 ComAddQueryParam Of hoRest "name" "Liam Thomas" To iSuccess

    Get ComFullRequestFormUrlEncoded Of hoRest "POST" "/v1/customers/cus_CBbg3iRMzWBjoe/sources/card_1BnETKGswQrCoh0Xhu1A6BfL" To sStrResponseBody
    Get ComLastMethodSuccess Of hoRest To bTemp1
    If (bTemp1 <> 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 ComLoad Of hoJsonResponse sStrResponseBody To iSuccess

    Get ComStringOf Of hoJsonResponse "id" To sId
    Get ComStringOf Of hoJsonResponse "object" To sObject
    Get ComIsNullOf Of hoJsonResponse "address_city" To iAddress_city
    Get ComIsNullOf Of hoJsonResponse "address_country" To iAddress_country
    Get ComIsNullOf Of hoJsonResponse "address_line1" To iAddress_line1
    Get ComIsNullOf Of hoJsonResponse "address_line1_check" To iAddress_line1_check
    Get ComIsNullOf Of hoJsonResponse "address_line2" To iAddress_line2
    Get ComIsNullOf Of hoJsonResponse "address_state" To iAddress_state
    Get ComIsNullOf Of hoJsonResponse "address_zip" To iAddress_zip
    Get ComIsNullOf Of hoJsonResponse "address_zip_check" To iAddress_zip_check
    Get ComStringOf Of hoJsonResponse "brand" To sBrand
    Get ComStringOf Of hoJsonResponse "country" To sCountry
    Get ComStringOf Of hoJsonResponse "customer" To sCustomer
    Get ComIsNullOf Of hoJsonResponse "cvc_check" To iCvc_check
    Get ComIsNullOf Of hoJsonResponse "dynamic_last4" To iDynamic_last4
    Get ComIntOf Of hoJsonResponse "exp_month" To iExp_month
    Get ComIntOf Of hoJsonResponse "exp_year" To iExp_year
    Get ComStringOf Of hoJsonResponse "fingerprint" To sFingerprint
    Get ComStringOf Of hoJsonResponse "funding" To sFunding
    Get ComStringOf Of hoJsonResponse "last4" To sLast4
    Get ComStringOf Of hoJsonResponse "name" To sName
    Get ComIsNullOf Of hoJsonResponse "tokenization_method" To iTokenization_method


End_Procedure

Sample JSON Response Body

{
  "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": "Liam Thomas",
  "tokenization_method": null
}