Preview a project billing change
Preview a project billing change: previewProjectChange in the TypeScript, Python, Rust and Go clients.
POST /v1/organizations/{organizationId}/billing/projects/{projectId}/preview
Previews a change on the selected project's subscription in the supplied category: a fixed-charge quantity change, or a plan change with the held fixed charges it carries over. Prices the change by the billing engine exactly as making it would bill it now: dueNow is that invoice, with taxes and the payer's credits applied. A purchase bills each unit it adds, even after a release this period. A release bills nothing; releasing a prorated charge credits its unused days to the organization's credit. dueLater is what the change leads to that is billed later instead, upcomingInvoices what the subscription it leaves bills in the following periods, and nextCharge the first of them. This operation does not change billing. An upgrade bills the replaced plan's usage to date and the new plan from now, less the replaced plan's unused time; a downgrade, or choosing the held plan again, bills nothing now; change says when it applies and which held fixed charges the target does not sell: released first for a change that applies now, released with a downgrade when it applies. additions quotes what is added once an upgrade applies, each billed when it is added, in dueLater and outside dueNow. promotionCode previews a code as the purchase redeems it, and needs billing:manage; a refused code answers PROMOTION_CODE_REJECTED with the reason a refused purchase gives. Supply both organizationId and projectId; the organization must pay for the project.
photon.organizations.billing.previewProjectChange(input: PreviewProjectChangeInput, options?: RequestOptions): Promise<PreviewProjectChangeOutput>photon.organizations.billing.preview_project_change(input: PreviewProjectChangeInput, *, options: RequestOptions | None = None) -> models.PreviewProjectChangeResponseclient.preview_project_change(organization_id: String, project_id: String, body: &types::PreviewProjectChangeRequest).await -> Result<ResponseValue<types::PreviewProjectChangeResponse>, Error<PreviewProjectChangeError>>client.Organizations.Billing.PreviewProjectChange(ctx context.Context, params *PreviewProjectChangeParams, opts ...RequestOption) (*PreviewProjectChangeResponse, error)import { Photon } from "@photon-ai/api";
const photon = new Photon({
headers: { Authorization: `Bearer ${process.env.PHOTON_API_TOKEN}` },
});
const result = await photon.organizations.billing.previewProjectChange({
path: {
organizationId: "organizationId",
projectId: "projectId",
},
body: {
category: "category",
fixedCharge: {
fixedChargeCode: "fixedChargeCode",
increment: -10000,
},
},
});import os
from photon_api import Photon
from photon_api.rpc_generated import PreviewProjectChangeInput
photon = Photon(headers={"Authorization": f"Bearer {os.environ['PHOTON_API_TOKEN']}"})
result = photon.organizations.billing.preview_project_change(
PreviewProjectChangeInput.model_validate({
"path": {
"organizationId": "organizationId",
"projectId": "projectId",
},
"body": {
"category": "category",
"fixedCharge": {
"fixedChargeCode": "fixedChargeCode",
"increment": -10000,
},
},
})
)use photon_ai_api::{Credential, PhotonClientBuilder, SecretString};
let token = std::env::var("PHOTON_API_TOKEN")?;
let client = PhotonClientBuilder::new()
.credential("accountServiceKey", Credential::Bearer(SecretString::from(token)))
.build()?;
let result = client
.preview_project_change(
"organizationId".to_owned(),
"projectId".to_owned(),
&serde_json::from_value(serde_json::json!({
"category": "category",
"fixedCharge": {
"fixedChargeCode": "fixedChargeCode",
"increment": -10000,
},
}))?,
)
.await
.map_err(|error| format!("{error:?}"))?
.into_inner();import (
"context"
"encoding/json"
"os"
photonapi "github.com/photon-hq/api/packages/go"
)
ctx := context.Background()
client := photonapi.NewClient(photonapi.WithAPIKey(os.Getenv("PHOTON_API_TOKEN")))
var body photonapi.PreviewProjectChangeRequest
if err := json.Unmarshal([]byte(`{
"category": "category",
"fixedCharge": {
"fixedChargeCode": "fixedChargeCode",
"increment": -10000
}
}`), &body); err != nil {
return err
}
result, err := client.Organizations.Billing.PreviewProjectChange(ctx, &photonapi.PreviewProjectChangeParams{
OrganizationID: "organizationId",
ProjectID: "projectId",
Body: body,
})
if err != nil {
return err
}
_ = result{
"balanceAfterCents": null,
"change": {
"quote": {
"amount": "string",
"currency": "string",
"currentPeriodEnd": "string"
},
"type": "fixed_charge"
},
"dueLater": {
"currency": "string",
"lines": [
{
"amountCents": -9007199254740991,
"code": "string",
"discountCents": -9007199254740991,
"kind": "fixed_charge",
"name": "string",
"periodEnd": null,
"periodStart": null,
"units": "string"
}
],
"totalCents": -9007199254740991
},
"dueNow": {
"creditsCents": -9007199254740991,
"currency": "string",
"discountCents": -9007199254740991,
"feesCents": -9007199254740991,
"lines": [
{
"amountCents": -9007199254740991,
"code": "string",
"discountCents": -9007199254740991,
"kind": "fixed_charge",
"name": "string",
"periodEnd": null,
"periodStart": null,
"units": "string"
}
],
"taxesCents": -9007199254740991,
"totalCents": -9007199254740991
},
"nextCharge": null,
"nextInvoiceAt": null,
"timeZone": "string",
"upcomingInvoices": [
{
"at": "string",
"invoice": {
"creditsCents": -9007199254740991,
"currency": "string",
"discountCents": -9007199254740991,
"feesCents": -9007199254740991,
"lines": [
{}
],
"taxesCents": -9007199254740991,
"totalCents": -9007199254740991
}
}
]
}Parameters
Selects the API contract date. Without it, the request is served as 2026-07-01.
The project being billed.
Body
One of: BillingPreviewFixedChargeChange
Category slug, e.g. analytics or messaging.
A quantity change made now, as a purchase or release makes it.
A promotion code the customer entered, previewed as the purchase redeems it, on an increase only: dueNow and upcomingInvoices are discounted by it. Needs billing:manage. A refused code fails the preview with PROMOTION_CODE_REJECTED, its reason as a refused purchase's failure detail.
One of: BillingPreviewPlanChange
Fixed charges added once an upgrade applies, each billed when it is added rather than with the upgrade. Priced as if added now on the target plan and returned in dueLater, outside dueNow. Each must be sold by the target plan and named once.
Category slug, e.g. analytics or messaging.
Plan to change to, as a purchase of it changes it.
A promotion code the customer entered, previewed as the purchase redeems it: dueNow and upcomingInvoices are discounted by it. Needs billing:manage. A refused code fails the preview with PROMOTION_CODE_REJECTED, its reason as a refused purchase's failure detail.
Returns
200 What the change would bill. PreviewProjectChangeResponse
Headers: Photon-Version. The raw response carries these headers; see Raw responses.
The payer's credit balance once dueNow is charged: the credit the change issues included, less what dueNow uses. In dueNow's currency. Null when the change charges nothing now (a downgrade).
What the change does beside what it bills, by the kind of change requested: fixed_charge for a fixed-charge change, plan_change for a plan change.
Billed later rather than with dueNow: one line per plan change addition, billed when it is added and priced as if added now; or, for an organization that pays by invoice, what a fixed-charge change adds to its next invoice. After coupons, before taxes; the balance left after dueNow applies to it first. nextCharge already includes it. No lines when nothing is billed later.
An invoice priced by the billing engine as it would bill it: its lines, then what coupons, taxes and credits change, and what the payer is charged. No lines when it bills nothing.
What is charged next for all that is held after the change: the first of upcomingInvoices, at its time and total, after coupons, with taxes, before credits. For a downgrade, the target plan's first charge at the period end. Usage and a minimum commitment are billed after the period. Null when nothing is charged, or the subscription ends first.
For an organization that pays by invoice: when its next monthly invoice is drafted, which bills the change instead of dueNow. A fixed-charge change's units go on it, in dueLater; an upgrade's new plan and dueLater too, while dueNow is the replaced plan's invoice, issued at once and due on the organization's terms. Null when dueNow is charged with the change.
The IANA time zone the payer is billed in, e.g. America/Los_Angeles. Billing periods start and end at its midnights, so read their calendar dates in it.
The invoices the subscription the change leaves issues in the following periods, assuming no later change: one, and another while a coupon with an end discounted the last, so the last listed is the price from then on. At most 24. For a change at the period end (a downgrade, or the held plan kept), the first is what the invoice due then bills for it.