Sample code for 30+ languages & platforms
DataFlex Requires Chilkat v11.7.0+

Stripe: Start a subscription billed by invoice

See more Stripe Examples

Start an invoice-billed subscription for an existing customer, using a recurring price and 30-day payment terms.

Stripe documentation and cURL example

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    String sApiKey
    String sOperationId
    Handle hoCurl
    Handle hoCmd
    Variant vJson
    Handle hoJson
    Integer iReplaced
    String sCustomerId
    String sPriceId
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

    //  Requires an unlocked Chilkat bundle. See Global Unlock Sample.
    //  Supply a restricted sandbox key from merchant-controlled configuration.
    Move "YOUR_STRIPE_TEST_KEY" To sApiKey
    //  Load the saved UUID for this operation. Reuse it only for a retry with identical inputs.
    Move "YOUR_SAVED_OPERATION_UUID" To sOperationId

    Get Create (RefClass(cComChilkatHttpCurl)) To hoCurl
    If (Not(IsComObjectCreated(hoCurl))) Begin
        Send CreateComObject of hoCurl
    End
    Get Create (RefClass(cComChilkatStringBuilder)) To hoCmd
    If (Not(IsComObjectCreated(hoCmd))) Begin
        Send CreateComObject of hoCmd
    End
    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End

    Move "cus_FROM_BILLING_ACCOUNT" To sCustomerId

    Move "price_FROM_CATALOG" To sPriceId

    //  Choose a recurring price. The customer pays the invoice under the agreed terms.

    //  curl -X POST "https://api.stripe.com/v1/subscriptions" \
    //    -u "$STRIPE_API_KEY:" \
    //    -H "Stripe-Version: 2026-10-28.endive" \
    //    -H "Idempotency-Key: {operationId}-subscription" \
    //    -d "customer={customerId}" \
    //    -d "items[0][price]={priceId}" \
    //    -d "items[0][quantity]=3" \
    //    -d "collection_method=send_invoice" \
    //    -d "days_until_due=30"
    Get ComSetString Of hoCmd 'curl -X POST "https://api.stripe.com/v1/subscriptions"' To iSuccess
    Get ComAppend Of hoCmd ' -u "@KEY@:"' To iSuccess
    Get ComAppend Of hoCmd ' -H "Stripe-Version: 2026-10-28.endive"' To iSuccess
    Get ComAppend Of hoCmd ' -H "Idempotency-Key: @OP@-subscription"' To iSuccess
    Get ComAppend Of hoCmd ' -d "customer=@CUSTOMER@"' To iSuccess
    Get ComAppend Of hoCmd ' -d "items[0][price]=@PRICE@"' To iSuccess
    Get ComAppend Of hoCmd ' -d "items[0][quantity]=3"' To iSuccess
    Get ComAppend Of hoCmd ' -d "collection_method=send_invoice"' To iSuccess
    Get ComAppend Of hoCmd ' -d "days_until_due=30"' To iSuccess
    Get ComReplace Of hoCmd "@CUSTOMER@" sCustomerId To iReplaced
    Get ComReplace Of hoCmd "@PRICE@" sPriceId To iReplaced
    Get ComReplace Of hoCmd "@OP@" sOperationId To iReplaced
    Get ComReplace Of hoCmd "@KEY@" sApiKey To iReplaced
    Get ComGetAsString Of hoCmd To sTemp1
    Get ComDoYourThing Of hoCurl sTemp1 To iSuccess
    If (iSuccess <> True) Begin
        Get ComFailReason Of hoCurl To iTemp1
        Showln "No HTTP response. Chilkat failure code: " iTemp1
        Procedure_Return
    End

    Get pvComObject of hoJson to vJson
    Get ComGetResponseJson Of hoCurl vJson To iSuccess
    Get ComStatusCode Of hoCurl To iTemp1
    If ((iTemp1 <> 200) Or (iSuccess <> True)) Begin
        Get ComStatusCode Of hoCurl To iTemp1
        Get ComGetResponseHeaderField Of hoCurl "Request-Id" To sTemp1
        Showln "Stripe HTTP " iTemp1 "  Request-Id: " sTemp1
        If (iSuccess = True) Begin
            Get ComStringOf Of hoJson "error.message" To sTemp1
            Showln sTemp1
        End

        Procedure_Return
    End

    Get ComStringOf Of hoJson "id" To sTemp1
    Showln "id = " sTemp1
    Get ComStringOf Of hoJson "status" To sTemp1
    Showln "status = " sTemp1
    Get ComStringOf Of hoJson "latest_invoice" To sTemp1
    Showln "latest_invoice = " sTemp1

    //  Save the subscription and invoice IDs. Read payment status from the invoice.


End_Procedure