DataFlex Stripe: Create a Customer

Back to Index

Creates a new customer object.

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

CURL Command

curl -X POST https://api.stripe.com/v1/customers \
   -u STRIPE_SECRET_KEY: \
   -d description="Customer for isabella.williams@example.com" \
   -d source=tok_amex

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
    Integer iAccount_balance
    Integer iCreated
    String sCurrency
    Boolean iDefault_source
    Boolean iDelinquent
    Boolean iDescription
    Boolean iDiscount
    Boolean iEmail
    Boolean iLivemode
    Boolean iShipping
    String sSourcesObject
    Boolean iSourcesHas_more
    Integer iSourcesTotal_count
    String sSourcesUrl
    String sSubscriptionsObject
    Boolean iSubscriptionsHas_more
    Integer iSubscriptionsTotal_count
    String sSubscriptionsUrl
    Integer i
    Integer iCount_i
    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
    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 "description" "Customer for isabella.williams@example.com" To iSuccess
    Get ComAddQueryParam Of hoRest "source" "tok_amex" To iSuccess

    Get ComFullRequestFormUrlEncoded Of hoRest "POST" "/v1/customers" 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 ComIntOf Of hoJsonResponse "account_balance" To iAccount_balance
    Get ComIntOf Of hoJsonResponse "created" To iCreated
    Get ComStringOf Of hoJsonResponse "currency" To sCurrency
    Get ComIsNullOf Of hoJsonResponse "default_source" To iDefault_source
    Get ComBoolOf Of hoJsonResponse "delinquent" To iDelinquent
    Get ComIsNullOf Of hoJsonResponse "description" To iDescription
    Get ComIsNullOf Of hoJsonResponse "discount" To iDiscount
    Get ComIsNullOf Of hoJsonResponse "email" To iEmail
    Get ComBoolOf Of hoJsonResponse "livemode" To iLivemode
    Get ComIsNullOf Of hoJsonResponse "shipping" To iShipping
    Get ComStringOf Of hoJsonResponse "sources.object" To sSourcesObject
    Get ComBoolOf Of hoJsonResponse "sources.has_more" To iSourcesHas_more
    Get ComIntOf Of hoJsonResponse "sources.total_count" To iSourcesTotal_count
    Get ComStringOf Of hoJsonResponse "sources.url" To sSourcesUrl
    Get ComStringOf Of hoJsonResponse "subscriptions.object" To sSubscriptionsObject
    Get ComBoolOf Of hoJsonResponse "subscriptions.has_more" To iSubscriptionsHas_more
    Get ComIntOf Of hoJsonResponse "subscriptions.total_count" To iSubscriptionsTotal_count
    Get ComStringOf Of hoJsonResponse "subscriptions.url" To sSubscriptionsUrl
    Move 0 To i
    Get ComSizeOfArray Of hoJsonResponse "sources.data" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJsonResponse To i
        Move i + 1 To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJsonResponse "subscriptions.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": "cus_CBbgVLJqv487Oq",
  "object": "customer",
  "account_balance": 0,
  "created": 1516662781,
  "currency": "usd",
  "default_source": null,
  "delinquent": false,
  "description": null,
  "discount": null,
  "email": null,
  "livemode": false,
  "metadata": {},
  "shipping": null,
  "sources": {
    "object": "list",
    "data": [
    ],
    "has_more": false,
    "total_count": 0,
    "url": "/v1/customers/cus_CBbgVLJqv487Oq/sources"
  },
  "subscriptions": {
    "object": "list",
    "data": [
    ],
    "has_more": false,
    "total_count": 0,
    "url": "/v1/customers/cus_CBbgVLJqv487Oq/subscriptions"
  }
}