One-off invoices
This solution makes sense if all you want to do is generate a one-off invoice without having to create a price and subscription.
Install and import our clientCopied!
For this recipe, we will use the Python SDK, which you can install using pip install getopenpay
or poetry add getopenpay
from getopenpay.client import ApiKeys, OpenPayClient
OP_PUBLISHABLE_TOKEN = 'TODO_YOUR_PUBLISHABLE_TOKEN'
OP_SECRET_TOKEN = 'TODO_YOUR_SECRET_TOKEN'
api_keys = ApiKeys(publishable_key=OP_PUBLISHABLE_TOKEN, secret_key=OP_SECRET_TOKEN)
# sandbox/staging environment
sandbox_host = 'https://connto.openpaystaging.com'
# production environment
production_host = 'https://connto.getopenpay.com'
client = OpenPayClient(api_keys=api_keys, host=sandbox_host)
Create a draft invoiceCopied!
Creates an invoice for a specific customer and their payment method
invoice = op_client.invoices.create_invoice(
CreateInvoiceRequest(
customer_id='TODO_TARGET_CUSTOMER_ID',
payment_method_id='TODO_TARGET_PAYMENT_METHOD_ID',
invoice_type=InvoiceType.ONE_OFF,
collection_method=CollectionMethodEnum.CHARGE_AUTOMATICALLY,
net_d=1,
selected_product_price_quantity=[
SelectedPriceQuantity(price_id='TODO_TARGET_PRICE_1', quantity=1),
SelectedPriceQuantity(price_id='TODO_TARGET_PRICE_2', quantity=1),
]
)
)
invoice = op_client.invoices.finalize_invoice(invoice.id)
Finalize an invoiceCopied!
This marks and invoice OPEN
paid_invoice = op_client.invoices.pay_invoice(
Pay an invoiceCopied!
invoice.id,
pay_invoice_request=PayInvoiceRequest(comment='Paying invoice via API')
)