Xbase++ Requires Chilkat v11.7.0+
Xbase++
Stripe: Apply the selected plan or seat change
See more Stripe Examples
Apply an accepted subscription change to the original item and retrieve that item to verify the new price and quantity.
Stripe documentation and cURL example
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL cApiKey
LOCAL cOperationId
LOCAL oCurl
LOCAL oCmd
LOCAL oJson
LOCAL nReplaced
LOCAL cSubscriptionId
LOCAL cItemId
LOCAL cPriceId
LOCAL cProrationDate
nSuccess := 0
// Requires an unlocked Chilkat bundle. See Global Unlock Sample.
// Supply a restricted sandbox key from merchant-controlled configuration.
cApiKey := "YOUR_STRIPE_TEST_KEY"
// Load the saved UUID for this operation. Reuse it only for a retry with identical inputs.
cOperationId := "YOUR_SAVED_OPERATION_UUID"
oCurl := CreateObject("Chilkat.HttpCurl")
oCmd := CreateObject("Chilkat.StringBuilder")
oJson := CreateObject("Chilkat.JsonObject")
cSubscriptionId := "sub_FROM_ACCOUNT"
cItemId := "si_SELECTED_ITEM"
cPriceId := "price_FROM_CATALOG"
cProrationDate := "UNIX_SECONDS_FROM_PREVIEW"
// Use the item, quantity, price, and UTC timestamp accepted by the operator.
// 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}-plan-change" \
// -d "items[0][id]={itemId}" \
// -d "items[0][price]={priceId}" \
// -d "items[0][quantity]=5" \
// -d "proration_behavior=create_prorations" \
// -d "proration_date={prorationDate}"
oCmd:SetString('curl -X POST "https://api.stripe.com/v1/subscriptions/@SUB@"')
oCmd:Append(' -u "@KEY@:"')
oCmd:Append(' -H "Stripe-Version: 2026-10-28.endive"')
oCmd:Append(' -H "Idempotency-Key: @OP@-plan-change"')
oCmd:Append(' -d "items[0][id]=@ITEM@"')
oCmd:Append(' -d "items[0][price]=@PRICE@"')
oCmd:Append(' -d "items[0][quantity]=5"')
oCmd:Append(' -d "proration_behavior=create_prorations"')
oCmd:Append(' -d "proration_date=@DATE@"')
nReplaced := oCmd:Replace("@SUB@", cSubscriptionId)
nReplaced := oCmd:Replace("@ITEM@", cItemId)
nReplaced := oCmd:Replace("@PRICE@", cPriceId)
nReplaced := oCmd:Replace("@DATE@", cProrationDate)
nReplaced := oCmd:Replace("@OP@", cOperationId)
nReplaced := oCmd:Replace("@KEY@", cApiKey)
nSuccess := oCurl:DoYourThing(oCmd:GetAsString())
IF (nSuccess != 1)
? "No HTTP response. Chilkat failure code: " + Str(oCurl:FailReason)
oCurl:destroy()
oCmd:destroy()
oJson:destroy()
RETURN
ENDIF
nSuccess := oCurl:GetResponseJson(oJson)
IF ((oCurl:StatusCode != 200) .OR. (nSuccess != 1))
? "Stripe HTTP " + Str(oCurl:StatusCode) + " Request-Id: " + oCurl:GetResponseHeaderField("Request-Id")
IF (nSuccess == 1)
? oJson:StringOf("error.message")
ENDIF
oCurl:destroy()
oCmd:destroy()
oJson:destroy()
RETURN
ENDIF
? "id = " + oJson:StringOf("id")
? "status = " + oJson:StringOf("status")
// curl -X GET "https://api.stripe.com/v1/subscription_items/{itemId}" \
// -u "$STRIPE_API_KEY:" \
// -H "Stripe-Version: 2026-10-28.endive"
oCmd:SetString('curl -X GET "https://api.stripe.com/v1/subscription_items/@ITEM@"')
oCmd:Append(' -u "@KEY@:"')
oCmd:Append(' -H "Stripe-Version: 2026-10-28.endive"')
nReplaced := oCmd:Replace("@ITEM@", cItemId)
nReplaced := oCmd:Replace("@KEY@", cApiKey)
nSuccess := oCurl:DoYourThing(oCmd:GetAsString())
IF (nSuccess != 1)
? "No HTTP response. Chilkat failure code: " + Str(oCurl:FailReason)
oCurl:destroy()
oCmd:destroy()
oJson:destroy()
RETURN
ENDIF
nSuccess := oCurl:GetResponseJson(oJson)
IF ((oCurl:StatusCode != 200) .OR. (nSuccess != 1))
? "Stripe HTTP " + Str(oCurl:StatusCode) + " Request-Id: " + oCurl:GetResponseHeaderField("Request-Id")
IF (nSuccess == 1)
? oJson:StringOf("error.message")
ENDIF
oCurl:destroy()
oCmd:destroy()
oJson:destroy()
RETURN
ENDIF
? "id = " + oJson:StringOf("id")
? "id = " + oJson:StringOf("price.id")
? "quantity = " + oJson:StringOf("quantity")
oCurl:destroy()
oCmd:destroy()
oJson:destroy()