Skip to content

[RSDK-11532] Add create_invoice_and_charge_immediately function #971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/viam/app/billing_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
GetInvoicesSummaryResponse,
GetOrgBillingInformationRequest,
GetOrgBillingInformationResponse,
CreateInvoiceAndChargeImmediatelyRequest,
CreateInvoiceAndChargeImmediatelyResponse,
)

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -141,3 +143,21 @@ async def get_org_billing_information(self, org_id: str, timeout: Optional[float
"""
request = GetOrgBillingInformationRequest(org_id=org_id)
return await self._billing_client.GetOrgBillingInformation(request, metadata=self._metadata, timeout=timeout)

async def create_invoice_and_charge_immediately(self, org_id_to_charge: str, amount: float, description: Optional[str] = None, org_id_for_branding: Optional[str] = None, timeout: Optional[float] = None) -> None:
"""Create a flat fee invoice and charge the organization on the spot. The caller must be an owner of the organization being charged.
This function blocks until payment is confirmed, but will time out after 2 minutes if there is no confirmation. Avoid using a
timeout with this function.

::

await billing_client.create_invoice_and_charge_immediately("<ORG-ID-TO-CHARGE>", <AMOUNT>, <DESCRIPTION>, "<ORG-ID-FOR-BRANDING>")

Args:
org_id_to_charge (str): the organization to charge
amount (float): the amount of the charge
description (str): a short description of the charge to display on the invoice PDF (must be 100 characters or fewer)
org_id_for_branding (str): the organization whose branding to use in the invoice confirmation email
"""
request = CreateInvoiceAndChargeImmediatelyRequest(org_id_to_charge=org_id_to_charge, amount=amount, description=description, org_id_for_branding=org_id_for_branding)
_: CreateInvoiceAndChargeImmediatelyResponse = await self._billing_client.CreateInvoiceAndChargeImmediately(request, metadata=self._metadata, timeout=timeout)
Loading