Billing
Charges and refunds for your end customers.
Overview
Base path:
/v1/billingPython namespace:
infra.billingtext
# Python
from infrai import infra
# TypeScript
import { InfraiClient } from "@infrai/sdk";
const client = new InfraiClient({ apiKey: process.env.INFRAI_API_KEY! });
// → client.billingMethods
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
| Name | Type | Required | Description |
|---|---|---|---|
amount | number | Required | Amount in the smallest currency unit. |
currency | string | Required | ISO currency code. |
customer_id | string | Optional | Customer id to charge. |
payment_method_id | string | Optional | Payment method id. |
idempotency_key | string | Optional | Optional 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
| Name | Type | Required | Description |
|---|---|---|---|
id | string | Required | The charge id. |
Returns
ChargeExample
一次性前置(每个范例都假定已完成):
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
| Name | Type | Required | Description |
|---|---|---|---|
charge_id | string | Required | The charge id. |
amount | number | Optional | Amount in the smallest currency unit. |
idempotency_key | string | Optional | Optional 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"))