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

Stripe: Preview a plan or seat change

See more Stripe Examples

Preview a seat or plan change and display its proration lines, total, and the timestamp to retain with the quote.

Stripe documentation and cURL example

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL lcApiKey
LOCAL loCurl
LOCAL loCmd
LOCAL loJson
LOCAL lnReplaced
LOCAL lcSubscriptionId
LOCAL lcItemId
LOCAL lcPriceId
LOCAL loNow
LOCAL lcProrationDate
LOCAL i

lnSuccess = 0

*  Requires an unlocked Chilkat bundle. See Global Unlock Sample.
*  Supply a restricted sandbox key from merchant-controlled configuration.
lcApiKey = "YOUR_STRIPE_TEST_KEY"

loCurl = CreateObject('Chilkat.HttpCurl')
loCmd = CreateObject('Chilkat.StringBuilder')
loJson = CreateObject('Chilkat.JsonObject')

lcSubscriptionId = "sub_FROM_ACCOUNT"

lcItemId = "si_SELECTED_ITEM"

lcPriceId = "price_FROM_CATALOG"

loNow = CreateObject('Chilkat.CkDateTime')
loNow.SetFromCurrentSystemTime()
lcProrationDate = loNow.GetAsUnixTimeStr(0)

*  curl -X POST "https://api.stripe.com/v1/invoices/create_preview" \
*    -u "$STRIPE_API_KEY:" \
*    -H "Stripe-Version: 2026-10-28.endive" \
*    -d "subscription={subscriptionId}" \
*    -d "subscription_details[items][0][id]={itemId}" \
*    -d "subscription_details[items][0][price]={priceId}" \
*    -d "subscription_details[items][0][quantity]=5" \
*    -d "subscription_details[proration_behavior]=create_prorations" \
*    -d "subscription_details[proration_date]={prorationDate}"
loCmd.SetString('curl -X POST "https://api.stripe.com/v1/invoices/create_preview"')
loCmd.Append(' -u "@KEY@:"')
loCmd.Append(' -H "Stripe-Version: 2026-10-28.endive"')
loCmd.Append(' -d "subscription=@SUB@"')
loCmd.Append(' -d "subscription_details[items][0][id]=@ITEM@"')
loCmd.Append(' -d "subscription_details[items][0][price]=@PRICE@"')
loCmd.Append(' -d "subscription_details[items][0][quantity]=5"')
loCmd.Append(' -d "subscription_details[proration_behavior]=create_prorations"')
loCmd.Append(' -d "subscription_details[proration_date]=@DATE@"')
lnReplaced = loCmd.Replace("@SUB@",lcSubscriptionId)
lnReplaced = loCmd.Replace("@ITEM@",lcItemId)
lnReplaced = loCmd.Replace("@PRICE@",lcPriceId)
lnReplaced = loCmd.Replace("@DATE@",lcProrationDate)
lnReplaced = loCmd.Replace("@KEY@",lcApiKey)
lnSuccess = loCurl.DoYourThing(loCmd.GetAsString())
IF (lnSuccess <> 1) THEN
    ? "No HTTP response. Chilkat failure code: " + STR(loCurl.FailReason)
    RELEASE loCurl
    RELEASE loCmd
    RELEASE loJson
    RELEASE loNow
    CANCEL
ENDIF

lnSuccess = loCurl.GetResponseJson(loJson)
IF ((loCurl.StatusCode <> 200) OR (lnSuccess <> 1)) THEN
    ? "Stripe HTTP " + STR(loCurl.StatusCode) + "  Request-Id: " + loCurl.GetResponseHeaderField("Request-Id")
    IF (lnSuccess = 1) THEN
        ? loJson.StringOf("error.message")
    ENDIF

    RELEASE loCurl
    RELEASE loCmd
    RELEASE loJson
    RELEASE loNow
    CANCEL
ENDIF

? "total = " + loJson.StringOf("total")
? "currency = " + loJson.StringOf("currency")

? "Save this preview time with the selected changes: " + lcProrationDate
i = 0
DO WHILE (i < loJson.SizeOfArray("lines.data"))
    loJson.I = i
    IF (loJson.BoolOf("lines.data[i].parent.subscription_item_details.proration") = 1) THEN
        ? loJson.StringOf("lines.data[i].description") + "  " + loJson.StringOf("lines.data[i].amount")
    ENDIF

    i = i + 1
ENDDO
IF (loJson.BoolOf("lines.has_more") = 1) THEN
    ? "Only the first page of preview lines is shown. The total covers all lines."
ENDIF

RELEASE loCurl
RELEASE loCmd
RELEASE loJson
RELEASE loNow