{"id":18326866,"url":"https://github.com/codatio/demo-invoice-finance","last_synced_at":"2025-04-13T02:27:47.419Z","repository":{"id":155075601,"uuid":"621797365","full_name":"codatio/demo-invoice-finance","owner":"codatio","description":"Demo project that lets you experience the invoice financing process flow supported by Codat's Accounting API.","archived":false,"fork":false,"pushed_at":"2025-01-24T14:43:30.000Z","size":44,"stargazers_count":1,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-26T19:51:17.277Z","etag":null,"topics":["accounts-receivable","build-guide","codat","demo","dotnet","invoices","underwriting"],"latest_commit_sha":null,"homepage":"https://docs.codat.io/guides/invoice-finance/introduction","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codatio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-03-31T12:07:38.000Z","updated_at":"2025-01-24T14:43:34.000Z","dependencies_parsed_at":"2023-12-20T07:57:28.612Z","dependency_job_id":"6c0d5b1e-17e7-4d85-aaf6-eb6d652c1fc3","html_url":"https://github.com/codatio/demo-invoice-finance","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codatio%2Fdemo-invoice-finance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codatio%2Fdemo-invoice-finance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codatio%2Fdemo-invoice-finance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codatio%2Fdemo-invoice-finance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codatio","download_url":"https://codeload.github.com/codatio/demo-invoice-finance/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248657424,"owners_count":21140835,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["accounts-receivable","build-guide","codat","demo","dotnet","invoices","underwriting"],"created_at":"2024-11-05T19:08:31.423Z","updated_at":"2025-04-13T02:27:47.398Z","avatar_url":"https://github.com/codatio.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Demo invoice financing\r\n\r\n## Introduction\r\n\r\nWith our demo app, you will go through the invoice financing process flow and see how Codat makes it easier for the borrower to raise capital against the amounts due from customers, and for the lender to make an invoice financing decision.\r\n\r\nThe project is implemented in [.NET 7.0](https://dotnet.microsoft.com/en-us/download/dotnet/7.0) as a backend API that uses features of Codat's [Accounting API](https://docs.codat.io/accounting-api/overview?utm_medium=referral\u0026utm_source=linked_website\u0026utm_campaign=2023_github_invoice_financing_code_demo) product. You can configure and run the demo app in the terminal, or use your preferred IDE or code editor.\r\n\r\nIn the process, you will:\r\n- Establish a connection with our test accounting platform\r\n- Pull invoice data required for the financing assessment\r\n- Check the invoices' eligibility based on a set of criteria we defined in the app\r\n- Issue a decision on eligible invoices\r\n\r\n## Prerequisites\r\n\r\nYou need these to run and test the code locally: \r\n- A Codat account that you can [create for free](https://signup.codat.io/?utm_medium=referral\u0026utm_source=linked_website\u0026utm_campaign=2023_github_invoice_financing_code_demo)\r\n- Your Codat [API keys](https://app.codat.io/developers/api-keys?utm_medium=referral\u0026utm_source=linked_website\u0026utm_campaign=2023_github_invoice_financing_code_demo)\r\n- A way to access remote systems from your locally hosted server (we used [ngrok](https://ngrok.com/))\r\n\r\n## Getting started\r\n\r\nTo run the demo app:\r\n\r\n1. Add your API key (`CodatApiKey`) and local machine's publicly available base url (`BaseWebhookUrl`) to the `appSettings.json` file.\r\n\r\n3. Start your local application and use [Swagger](http://localhost:7278/swagger/index.html) to call the demo's endpoints.\r\n\r\n5. Call `POST applications/start` to start a new invoice financing application. This returns an application id and a `linkUrl`. \r\n\r\n7. Provide access to your test company's demo accounting data using the `linkUrl`.\r\n\r\n9. Call the `GET applications/{applicationId}` endpoint to check the outcome of the application.\r\n\r\nFor detailed walkthorough of prerequisites and setup steps, you can refer to our [Invoice finance build guide](https://docs.codat.io/guides/invoice-finance/setting-up).\r\n\r\n## Details of the solution\r\n\r\nIn this demo app, we use information about a company's invoices and customers to perform risk assessment and issue an array of invoice financing decisions. In this project, we demonstrate how Codat enables you to access this data. It will help you undestand how you may implement your own automated invoice financing solution.\r\n\r\nOur example app contains several endpoints:\r\n* Two public endpoints allow the prospective borrower to submit a new application and retrieve the status of that application via an imaginary front end.\r\n* Two webhook endpoints trigger the assessment process once a data connection is established and Invoice and Customer data types are fetched.\r\n\r\n### Demo app process flow\r\n\r\nReview the sequence diagram to visualize the steps performed by the app. We used solid arrows to depict public endpoints and dotted arrows for webhooks. \r\n\r\n```mermaid\r\n  sequenceDiagram\r\n    participant frontend as Invoice Financing Frontend \r\n    participant backend as Invoice Financing Backend \r\n    participant codat as Codat API\r\n    frontend -\u003e\u003e backend: Request new application\r\n    backend -\u003e\u003e codat: Create company\r\n    codat -\u003e\u003e backend: New company\r\n    backend -\u003e\u003e frontend: New application\r\n    frontend -\u003e\u003e codat: Link accounting platform\r\n    par\r\n        break when status is Complete/ProcessingError\r\n        loop\r\n            frontend -\u003e\u003e backend: Get application\r\n            backend -\u003e\u003e frontend: application\r\n        end\r\n        end\r\n    and\r\n        par \r\n            codat --\u003e\u003e backend: Data connection status \r\n        and \r\n            codat --\u003e\u003e backend: Data type sync complete\r\n        end\r\n        par\r\n            backend -\u003e\u003e codat: Get invoices\r\n            codat -\u003e\u003e backend: Invoices\r\n        and\r\n            backend -\u003e\u003e codat: Get customers\r\n            codat -\u003e\u003e backend: Customers\r\n        end\r\n        backend -\u003e\u003e backend: Assess eligable invoices\r\n        backend -\u003e\u003e frontend: Array of decisions per valid invoice\r\n    end\r\n```\r\n\r\n### Applying for a loan\r\n\r\nWe begin when the applicant initiates a new invoice financing application by calling the `application/start` endpoint. In the background, the app creates a company using Codat's `POST /companies` endpoint, with the application Id as the company name. Codat returns the company and application Ids in the endpoint response together with a `linkUrl`. \r\n\r\n#### Example response returned by the `start` endpoint\r\n\r\n```json\r\n  {\r\n    \"id\": \"1c727866-6923-4f81-aa7b-c7fd8c533586\",\r\n    \"codatCompanyId\": \"a9e28b79-6a98-4190-948d-3bd4d60e7c0a\",\r\n    \"status\": \"Started\", \r\n    \"linkUrl\": \"https://link.codat.io/company/a9e28b79-6a98-4190-948d-3bd4d60e7c0a\"\r\n  }\r\n```\r\nNext, we need to get access to an accounting platform so we can fetch the data required to assess the risk of the loan application. Open the `linkUrl` returned in the response from POST /applications/start in your browser. Follow the flow built using [Link](https://docs.codat.io/auth-flow/authorize-embedded-link?utm_medium=referral\u0026utm_source=linked_website\u0026utm_campaign=2023_github_invoice_financing_code_demo), our hosted or embedded integrated authorization flow.\r\n\r\nSelect the Codat Sandbox as the source of accounting data and choose the **Invoice Financing US Company** company type. You don't need to enter any credentials to authorize this connection.\r\n\r\n### Listening to Codat's webhooks\r\n\r\nWhen the accounting platform is connected, the remaining steps will update the data requirements of the application. These are activated by Codat's webhooks that trigger specific `POST` endpoints in our example app:\r\n* `webhooks/codat/data-connection-status` listens to the [DataConnectionStatusChanged](https://docs.codat.io/introduction/webhooks/core-rules-types#company-data-connection-status-changed?utm_medium=referral\u0026utm_source=linked_website\u0026utm_campaign=2023_github_invoice_financing_code_demo) webhook.\r\n\r\nIt verifies that the received data connection is an accounting platform, and assigns it to the related application via the Codat company id. \r\n\r\n* `webhooks/codat/datatype-sync-complete` listens to the [Data sync completed](https://docs.codat.io/introduction/webhooks/core-rules-types#data-sync-completed?utm_medium=referral\u0026utm_source=linked_website\u0026utm_campaign=2023_github_invoice_financing_code_demo) webhook.\r\n\r\nIt verifies the successful fetching of the `customers` and `invoices` data types from the underlying platform. In our demo, we focus on unpaid and partially paid invoices valued between 50 and 1000 USD, using the `query` parameter:\r\n\r\n```\r\nquery = {status=submitted||status=partiallyPaid}\u0026\u0026currency=USD\u0026\u0026{amountDue\u003e50\u0026\u0026amountDue\u003c=1000}\r\n```\r\n\r\nFrom this data set, we pick up a list of unique customer Ids (`customerRef.id`) for the unpaid invoices, and then the associated customer details. Finally, we fetch all paid invoices for each of these customers to assess their previous payment behavior.\r\n\r\n### Assessing customers and invoices\r\n\r\nOnce both data types have been filtered and fetched, they are passed to the [CustomerRiskAssessor.cs](Codat.Demos.InvoiceFinancing.Api/Services/CustomerRiskAssessor.cs) and [InvoiceFinanceAssessor.cs](Codat.Demos.InvoiceFinancing.Api/Services/InvoiceFinanceAssessor.cs) services. This is to perform risk assessment of customers and invoices, and provide a financing proposal for each eligible invoice. \r\n\r\nFinally, the InvoiceFinanceAssessor service returns an array of decisions to show the applicant which invoices we agree to lend against, and under what terms and conditions. The applicant can poll the `GET applications/{applicationId}` endpoint periodically to see the result once the processing is complete.\r\n\r\nYou can learn more about the decisioning logic, risk assessment criteria, and data filtering queries used by our app in our detailed [Invoice finance build guide]((https://docs.codat.io/guides/invoice-finance/inv-fin-decision).\r\n\r\n## Next steps\r\n\r\n🗣️ Anything unclear in this guide? Got feedback? We're working on a whole host of new content for you, so [let us know](https://github.com/orgs/codatio/discussions/new?category=general).\r\n\r\n🔍 For detailed walkthorough of the app and its logic, refer to our [Invoice finance build guide](https://docs.codat.io/guides/invoice-finance/setting-up).\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodatio%2Fdemo-invoice-finance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodatio%2Fdemo-invoice-finance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodatio%2Fdemo-invoice-finance/lists"}