Skip to main content

A Python 3 module to interact with the Green Invoice API.

Project description

Green Invoice API

A Python 3 module to interact with the Green Invoice API.

🛑 Versions below 2.0.0 are deprecated and unsupported. They authenticate against Green Invoice's retired /v1/account/token flow, which Morning has replaced with an OAuth 2.0 IdP. Upgrade to 2.0.0+ and provision OAuth client credentials — see Authentication and the Changelog.

Install

pip install green-invoice

Authentication

Authentication uses the OAuth 2.0 client-credentials flow against Morning's IdP host (https://api.morning.co/idp/v1/oauth/token for live, https://api.sandbox.morning.dev/idp/v1/oauth/token for sandbox), which is separate from the resource API host. The api_key_id / api_key_secret passed to configure(...) are your OAuth client id / client secret. The resulting access token is cached in memory and reused across requests until it nears expiry, so you do not need to manage tokens yourself.

Example

from datetime import datetime
import logging
import green_invoice
from green_invoice.models import (
    Currency,
    DocumentLanguage,
    DocumentType,
    DocumentVatType,
    PaymentCardType,
    PaymentDealType,
    PaymentType,
    IncomeVatType,
)
from green_invoice.resources import DocumentResource


def main():
    green_invoice.client.configure(
        env="sandbox",
        # Authentication
        api_key_id="YOUR_API_KEY_ID",
        api_key_secret="YOUR_API_KEY_SECRET",
        # Logger
        logger=logging.root,
    )

    order_amount = 50
    order_amount_currency = Currency.USD
    create_document_for_order(order_amount, order_amount_currency)


def create_document_for_order(amount, amount_currency):
    documentResource = DocumentResource()
    created_document = documentResource.create(
        {
            "type": DocumentType.TAX_INVOICE_RECEIPT,
            "client": {
                "name": "Tom Hanks",
                "add": False,
            },
            "currency": amount_currency,
            "lang": DocumentLanguage.ENGLISH,
            "vatType": DocumentVatType.DEFAULT,
            "signed": True,
            "rounding": False,
            "income": [
                {
                    "price": amount,
                    "currency": amount_currency,
                    "quantity": 1,
                    "description": "My Cool Product",
                    "vatType": IncomeVatType.INCLUDED,
                }
            ],
            "payment": [
                {
                    "type": PaymentType.CREDIT_CARD,
                    "date": datetime.today().strftime("%Y-%m-%d"),
                    "dealType": PaymentDealType.REGULAR,
                    "cardNum": "4242",
                    "cardType": PaymentCardType.VISA,
                    "price": amount,
                    "currency": amount_currency,
                }
            ],
        }
    )
    print(created_document)


if __name__ == "__main__":
    main()

Changelog

2.0.0

⚠️ Breaking change. This release switches authentication to Morning's new OAuth 2.0 IdP. Existing integrations must obtain OAuth client credentials (client id / secret) for their business and ensure network access to the new IdP host — credentials issued for the previous /v1/account/token flow no longer work. Upgrade to 2.0.0 only after the new credentials are provisioned.

  1. Change to Green Invoice / Morning API. Authentication migrated to the OAuth 2.0 client-credentials flow against Morning's IdP host (https://api.morning.co/idp/v1/oauth/token for live, https://api.sandbox.morning.dev/idp/v1/oauth/token for sandbox), replacing the previous /v1/account/token header-based token flow. See Authentication.
    • Access tokens are cached in memory and refreshed automatically near expiry.
    • The public configure(...) interface is unchanged — api_key_id / api_key_secret are now your OAuth client id / client secret.
    • Dependencies slimmed to direct requirements (requests, lxml); the transitive deps (certifi / chardet / idna / urllib3) are no longer pinned by this library.

Author

Yaniv Pinchas

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

green_invoice-2.0.0.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

green_invoice-2.0.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file green_invoice-2.0.0.tar.gz.

File metadata

  • Download URL: green_invoice-2.0.0.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for green_invoice-2.0.0.tar.gz
Algorithm Hash digest
SHA256 ad97394b18733f039544632b7be12a4f8e6f59d30850378468db54b1a52f621b
MD5 43772bb15a26274ae71c691fe0cba6c6
BLAKE2b-256 1e47d5437fd2175bba82b0d78005ed4928321c630961121abaa32cf10418987f

See more details on using hashes here.

File details

Details for the file green_invoice-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: green_invoice-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for green_invoice-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ec548e1b2b185d74c9a4e6faf6370354d9218676a4767b0c12d236c1764b921
MD5 0dbc05c7edd43d9a8af3988a51c34a8e
BLAKE2b-256 dce7c99b73fa250a8c8e1861ba2075c10de6285bf2d93bc1dc27fb7936f37d9b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page