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

Stripe: Schedule or undo a period-end cancellation

See more Stripe Examples

Schedule cancellation at the end of the billing period or undo a pending cancellation.

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 sSubscriptionId
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    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 "sub_FROM_ACCOUNT" To sSubscriptionId

    //  Use false to undo a pending cancellation while the subscription is active.

    //  curl -X POST "https://api.stripe.com/v1/subscriptions/{subscriptionId}" \
    //    -u "$STRIPE_API_KEY:" \
    //    -H "Stripe-Version: 2026-10-28.endive" \
    //    -H "Idempotency-Key: {operationId}-period-end" \
    //    -d "cancel_at_period_end=true"
    Get ComSetString Of hoCmd 'curl -X POST "https://api.stripe.com/v1/subscriptions/@SUB@"' 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@-period-end"' To iSuccess
    Get ComAppend Of hoCmd ' -d "cancel_at_period_end=true"' To iSuccess
    Get ComReplace Of hoCmd "@SUB@" sSubscriptionId 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 ComBoolOf Of hoJson "cancel_at_period_end" To bTemp1
    Showln "Cancel at period end: " bTemp1


End_Procedure