Skip to content

Billing

Charges and refunds for your end customers.

Overview

Base path: /v1/billing
Python namespace: infra.billing
text
# Python
from infrai import infra

# TypeScript
import { InfraiClient } from "@infrai/sdk";
const client = new InfraiClient({ apiKey: process.env.INFRAI_API_KEY! });
// → client.billing

Methods

billing.charge.create

POST /v1/billing/charges

Create a charge against a customer or payment method.

Python

python
infra.billing.charge.create(amount=..., currency=..., customer_id=None, idempotency_key=None)

TypeScript

typescript
client.billing.charge(opts: ChargeOptions): Promise<Charge>

Parameters

NameTypeRequiredDescription
amountnumber
Required
Amount in the smallest currency unit.
currencystring
Required
ISO currency code.
customer_idstringOptionalCustomer id to charge.
payment_method_idstringOptionalPayment method id.
idempotency_keystringOptionalOptional dedup key; identical retries return the same result.

Returns

Charge { charge_id, amount, currency, state, customer_id? }

Example

一次性前置(每个范例都假定已完成):

bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...
python
from infrai import infra

charge = infra.billing.charge.create(amount=19.99, currency="USD", customer_id="cus_123")
print("charge:", charge.get("charge_id"), "| state:", charge.get("state"))

billing.charge.get

GET /v1/billing/charges/{id}

Fetch a charge by id.

Python

python
infra.billing.charge.get(id=charge_id)

TypeScript

typescript
client.billing.getCharge(chargeId: string): Promise<Charge>

Parameters

NameTypeRequiredDescription
idstring
Required
The charge id.

Returns

Charge

Example

一次性前置(每个范例都假定已完成):

bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...
python
from infrai import infra

c = infra.billing.charge.get(id="ch_...")
print("state:", c.get("state"), "| amount:", c.get("amount"))

billing.refund.create

POST /v1/billing/refunds

Refund a charge, fully or partially.

Python

python
infra.billing.refund.create(charge_id=..., amount=None, idempotency_key=None)

TypeScript

typescript
client.billing.refund(opts): Promise<Refund>

Parameters

NameTypeRequiredDescription
charge_idstring
Required
The charge id.
amountnumberOptionalAmount in the smallest currency unit.
idempotency_keystringOptionalOptional dedup key; identical retries return the same result.

Returns

Refund { refund_id, charge_id, amount, state }

Example

一次性前置(每个范例都假定已完成):

bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...
python
from infrai import infra

r = infra.billing.refund.create(charge_id="ch_...", amount=5.0)
print("refund:", r.get("refund_id"), "| state:", r.get("state"))