PHP code to Connect Your Books
Under construction.
This gateway will let you connect various data sources and sinks for bookkeeping data in the domains of:
- time tracking
- issue tracking
- invoicing
- mutual credit networks
- budget tracking
The name CYB stands for "Connect Your Books".
See Federated Bookkeeping for more info on the vision behind it.
cd cyb-app
chmod u+x ./run-docker.sh
./run-docker.sh dev pull
./run-docker.sh dev up --detach
cd cyb-app
chmod u+x ./run-docker.sh
./run-docker.sh gitpod pull
./run-docker.sh gitpod up --detach
cd cyb-app
chmod u+x ./run-docker.sh
./run-docker.sh prod pull
./run-docker.sh prod up --detach
- Pick a name for your connector. Must be all lowercase and url safe. Ex. time_mld, github
- Create a new folder under
app/Connectors
and name it in the studly form of your connector name. Ex. TimeMld, Github - Put an implementation of
\app\Core\Connector
in the newly created folder. Ex. GithubConnector.php - Modify
\app\Core\ApplicationManager::getConnectors
and add an instance of your Connector to it.
In order to support custom routes for your connector, create a folder named routes
under your connector's root folder. Then you can create api.php
and web.php
files there to define your routes. The newly added routes will be under /api/connector/{connector name}
and /connector/{connector name}
respectively. And the routes can be addressed under the name connector.{connector name}
.
Suggested approach is to create a resources\views
folder under your connector's root folder. Then you can reference those views by using the View facade (Illuminate\Support\Facades\View
) and calling View::file
method with the full address to your view file.
Let's peppol is a CYB connector that provides free access to the PEPPOL network.
In order to take advantage of Let's Peppol in your software you have to create a CYB connector for invoice
data type. This connector should be included in the main running CYB instance. Then for each user, go through the following steps:
- Call
POST /api/register
withname
,email
andpassword
in the request body. - Call
POST /api/generateToken
withemail
andpassword
to get a permanent bearer authorization token for all the other calls. - Call
POST /api/connector/lets_peppol/identity
withname
,address
,city
,region
,country
code,zip
in the request body. You will get the createdIdentity
object in the response. You'll need to store the Identity id. - Keep calling
GET /api/connector/lets_peppol/identity/{identity_id}
to check thekyc_status
.0
means pending approval,1
means rejected and2
means approved. Approval is currently a manual process that takes time. After being approved, you can retrieveidentifier_scheme
andidentifier_value
from the identity object. - After getting approved, call
GET /api/authentication?app_code_name=lets_peppol&app_user_id={identity_id}
to get the relevantAuthentication
object for the created Let's Peppol Identity and store its id. - Call
POST /api/read/{authentication_id}/invoice
withread
set astrue
in the request body to enable receiving invoices for Let's Peppol. - Call
POST /api/write/{authentication_id}/invoice
withwrite
set astrue
in the request body to enable auto sending of out going invoices? - You can always call
GET /api/function/{auth_id}/invoice
to check theread
andwrite
status of the authentication. - Create an authentication in your connector for the user. To do this you'll need to define your own API endpoints and eventually call
ApplicationManager::createAuthentication($auth_info)
. - Repeat steps 6 and 7 for your application's authentication to enable read and write functionalities.
- You can always call
POST /api/connector/lets_peppoo/message/{identity_id}
with an UBL as the request body to directly send invoices through Let's Peppol. Ifread
is turned on, you'll receive the event upon delivery of the invoice.
A sample UBL invoice looks like the following:
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
<cbc:UBLVersionID>2.1</cbc:UBLVersionID>
<cbc:CustomizationID>urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0</cbc:CustomizationID>
<cbc:ProfileID>urn:fdc:peppol.eu:2017:poacc:billing:01:1.0</cbc:ProfileID>
<cbc:ID>1234</cbc:ID>
<cbc:IssueDate>2022-09-06</cbc:IssueDate>
<cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode>
<cbc:Note>invoice note</cbc:Note>
<cbc:DocumentCurrencyCode>EUR</cbc:DocumentCurrencyCode>
<cbc:AccountingCost>4217:2323:2323</cbc:AccountingCost>
<cbc:BuyerReference>BUYER_REF</cbc:BuyerReference>
<cac:InvoicePeriod>
<cbc:StartDate>2022-09-06</cbc:StartDate>
</cac:InvoicePeriod>
<cac:OrderReference>
<cbc:ID>5009567</cbc:ID>
<cbc:SalesOrderID>tRST-tKhM</cbc:SalesOrderID>
</cac:OrderReference>
<cac:AccountingSupplierParty>
<cac:Party>
<cbc:EndpointID schemeID="9915">asdffbddsf</cbc:EndpointID>
<cac:PartyIdentification>
<cbc:ID>99887766</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name>PonderSource</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:StreetName>Lisk Center Utreht</cbc:StreetName>
<cbc:AdditionalStreetName>De Burren</cbc:AdditionalStreetName>
<cbc:CityName>Utreht</cbc:CityName>
<cbc:PostalZone>3521</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>NL</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
<cac:PartyTaxScheme>
<cbc:CompanyID>NL123456789</cbc:CompanyID>
<cac:TaxScheme>
<cbc:ID>VAT</cbc:ID>
</cac:TaxScheme>
</cac:PartyTaxScheme>
<cac:PartyLegalEntity>
<cbc:RegistrationName>PonderSource</cbc:RegistrationName>
<cbc:CompanyID>NL123456789</cbc:CompanyID>
</cac:PartyLegalEntity>
</cac:Party>
</cac:AccountingSupplierParty>
<cac:AccountingCustomerParty>
<cac:Party>
<cbc:EndpointID schemeID="9915">phase4-test-sender</cbc:EndpointID>
<cac:PartyIdentification>
<cbc:ID>9988217</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name>Client Company Name</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:StreetName>Lisk Center Utreht</cbc:StreetName>
<cbc:AdditionalStreetName>De Burren</cbc:AdditionalStreetName>
<cbc:CityName>Utreht</cbc:CityName>
<cbc:PostalZone>3521</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>NL</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
<cac:PartyTaxScheme>
<cbc:CompanyID>BE123456789</cbc:CompanyID>
<cac:TaxScheme>
<cbc:ID>VAT</cbc:ID>
</cac:TaxScheme>
</cac:PartyTaxScheme>
<cac:PartyLegalEntity>
<cbc:RegistrationName>Client Company Name</cbc:RegistrationName>
<cbc:CompanyID>Client Company Registration</cbc:CompanyID>
</cac:PartyLegalEntity>
<cac:Contact>
<cbc:Name>Client name</cbc:Name>
<cbc:Telephone>908-99-74-74</cbc:Telephone>
</cac:Contact>
</cac:Party>
</cac:AccountingCustomerParty>
<cac:Delivery>
<cbc:ActualDeliveryDate>2022-09-06</cbc:ActualDeliveryDate>
<cac:DeliveryLocation>
<cac:Address>
<cbc:StreetName>Delivery street 2</cbc:StreetName>
<cbc:AdditionalStreetName>Building 56</cbc:AdditionalStreetName>
<cbc:CityName>Utreht</cbc:CityName>
<cbc:PostalZone>3521</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>NL</cbc:IdentificationCode>
</cac:Country>
</cac:Address>
</cac:DeliveryLocation>
</cac:Delivery>
<cac:PaymentMeans>
<cbc:PaymentMeansCode>31</cbc:PaymentMeansCode>
<cbc:PaymentID>our invoice 1234</cbc:PaymentID>
<cac:PayeeFinancialAccount>
<cbc:ID>NL00RABO0000000000</cbc:ID>
<cbc:Name>Customer Account Holder</cbc:Name>
<cac:FinancialInstitutionBranch>
<cbc:ID>RABONL2U</cbc:ID>
</cac:FinancialInstitutionBranch>
</cac:PayeeFinancialAccount>
</cac:PaymentMeans>
<cac:PaymentTerms>
<cbc:Note>30 days net</cbc:Note>
</cac:PaymentTerms>
<cac:TaxTotal>
<cbc:TaxAmount currencyID="EUR">2.10</cbc:TaxAmount>
<cac:TaxSubtotal>
<cbc:TaxableAmount currencyID="EUR">10.00</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="EUR">2.10</cbc:TaxAmount>
<cac:TaxCategory>
<cbc:ID>S</cbc:ID>
<cbc:Percent>21.00</cbc:Percent>
<cac:TaxScheme>
<cbc:ID>VAT</cbc:ID>
</cac:TaxScheme>
</cac:TaxCategory>
</cac:TaxSubtotal>
</cac:TaxTotal>
<cac:LegalMonetaryTotal>
<cbc:LineExtensionAmount currencyID="EUR">10.00</cbc:LineExtensionAmount>
<cbc:TaxExclusiveAmount currencyID="EUR">10.00</cbc:TaxExclusiveAmount>
<cbc:TaxInclusiveAmount currencyID="EUR">12.10</cbc:TaxInclusiveAmount>
<cbc:AllowanceTotalAmount currencyID="EUR">0.00</cbc:AllowanceTotalAmount>
<cbc:PayableAmount currencyID="EUR">12.10</cbc:PayableAmount>
</cac:LegalMonetaryTotal>
<cac:InvoiceLine>
<cbc:ID>0</cbc:ID>
<cbc:InvoicedQuantity unitCode="C62">1.00</cbc:InvoicedQuantity>
<cbc:LineExtensionAmount currencyID="EUR">10.00</cbc:LineExtensionAmount>
<cac:InvoicePeriod>
<cbc:StartDate>2022-09-06</cbc:StartDate>
</cac:InvoicePeriod>
<cac:Item>
<cbc:Description>Product Description</cbc:Description>
<cbc:Name>Product Name</cbc:Name>
<cac:ClassifiedTaxCategory>
<cbc:ID>S</cbc:ID>
<cbc:Percent>21.00</cbc:Percent>
<cac:TaxScheme>
<cbc:ID>VAT</cbc:ID>
</cac:TaxScheme>
</cac:ClassifiedTaxCategory>
</cac:Item>
<cac:Price>
<cbc:PriceAmount currencyID="EUR">10.00</cbc:PriceAmount>
<cbc:BaseQuantity unitCode="C62">1.00</cbc:BaseQuantity>
</cac:Price>
</cac:InvoiceLine>
</Invoice>