mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-31 18:07:35 -04:00 
			
		
		
		
	einvoice
This commit is contained in:
		
							parent
							
								
									329044dccc
								
							
						
					
					
						commit
						c46936c9f3
					
				| @ -9,12 +9,11 @@ | |||||||
|  * @license https://www.elastic.co/licensing/elastic-license |  * @license https://www.elastic.co/licensing/elastic-license | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| namespace App\Services\EDocument\Gateway; | namespace App\Services\EDocument\Gateway\Storecove; | ||||||
| 
 | 
 | ||||||
| use App\Models\Company; | use App\Models\Company; | ||||||
| use Illuminate\Support\Facades\Http; | use Illuminate\Support\Facades\Http; | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| enum HttpVerb: string | enum HttpVerb: string | ||||||
| { | { | ||||||
|     case POST = 'post'; |     case POST = 'post'; | ||||||
| @ -26,7 +25,7 @@ enum HttpVerb: string | |||||||
| 
 | 
 | ||||||
| class Storecove { | class Storecove { | ||||||
| 
 | 
 | ||||||
|     private string $base_url = 'https://api.storecove.com/'; |     private string $base_url = 'https://api.storecove.com/api/v2/'; | ||||||
| 
 | 
 | ||||||
|     private array $peppol_discovery = [ |     private array $peppol_discovery = [ | ||||||
|         "documentTypes" =>  ["invoice"], |         "documentTypes" =>  ["invoice"], | ||||||
| @ -102,16 +101,35 @@ class Storecove { | |||||||
|     { |     { | ||||||
| 
 | 
 | ||||||
|         $payload = [ |         $payload = [ | ||||||
|             'documentType' => 'invoice', |             "legalEntityId"=> 290868, | ||||||
|             'rawDocumentData' => base64_encode($document), |             "idempotencyGuid"=> "61b37456-5f9e-4d56-b63b-3b1a23fa5c73", | ||||||
|             'parse' => true, |             "routing"=>  [ | ||||||
|             'parseStrategy', 'ubl' |                 "eIdentifiers" => [ | ||||||
|  |                     [ | ||||||
|  |                         "scheme"=> "DE:LWID", | ||||||
|  |                         "id"=> "10101010-STO-10" | ||||||
|  |                     ], | ||||||
|  |                 ], | ||||||
|  |                 "emails"=> [ | ||||||
|  |                 "david@invoiceninja.com" | ||||||
|  |                 ], | ||||||
|  |                 "eIdentifiers"=> [] | ||||||
|  |             ], | ||||||
|  |             "document"=> [ | ||||||
|  |                 'documentType' => 'invoice', | ||||||
|  |                 'rawDocumentData' => ['document' => base64_encode($document)], | ||||||
|  |                 'parse' => true, | ||||||
|  |                 'parseStrategy', 'ubl' | ||||||
|  |             ], | ||||||
|         ]; |         ]; | ||||||
| 
 | 
 | ||||||
|         $uri = "api/v2/document_submissions"; |         $uri = "document_submissions"; | ||||||
|          |          | ||||||
|         $r = $this->httpClient($uri, (HttpVerb::POST)->value, $payload, $this->getHeaders()); |         $r = $this->httpClient($uri, (HttpVerb::POST)->value, $payload, $this->getHeaders()); | ||||||
| 
 | 
 | ||||||
|  |         nlog($r->body()); | ||||||
|  |         nlog($r->json()); | ||||||
|  | 
 | ||||||
|         if($r->successful()) |         if($r->successful()) | ||||||
|             return $r->json()['guid']; |             return $r->json()['guid']; | ||||||
| 
 | 
 | ||||||
| @ -122,7 +140,7 @@ class Storecove { | |||||||
|     //document submission sending evidence
 |     //document submission sending evidence
 | ||||||
|     public function getSendingEvidence(string $guid) |     public function getSendingEvidence(string $guid) | ||||||
|     { |     { | ||||||
|         $uri = "api/v2/document_submissions/{$guid}"; |         $uri = "document_submissions/{$guid}"; | ||||||
|         $r = $this->httpClient($uri, (HttpVerb::GET)->value, [], $this->getHeaders()); |         $r = $this->httpClient($uri, (HttpVerb::GET)->value, [], $this->getHeaders()); | ||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
| @ -214,6 +232,21 @@ class Storecove { | |||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public function getLegalEntity($id) | ||||||
|  |     { | ||||||
|  | 
 | ||||||
|  |         $uri = "legal_entities/{$id}"; | ||||||
|  | 
 | ||||||
|  |         $r = $this->httpClient($uri, (HttpVerb::GET)->value, []); | ||||||
|  | 
 | ||||||
|  |         if($r->successful()) { | ||||||
|  |             return $r->json(); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return $r; | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public function updateLegalEntity($id, array $data) |     public function updateLegalEntity($id, array $data) | ||||||
|     { |     { | ||||||
| 
 | 
 | ||||||
| @ -242,7 +275,7 @@ class Storecove { | |||||||
| 
 | 
 | ||||||
|     private function httpClient(string $uri, string $verb, array $data, ?array $headers = []) |     private function httpClient(string $uri, string $verb, array $data, ?array $headers = []) | ||||||
|     { |     { | ||||||
| 
 | nlog("{$this->base_url}{$uri}"); | ||||||
|         $r = Http::withToken(config('ninja.storecove_api_key')) |         $r = Http::withToken(config('ninja.storecove_api_key')) | ||||||
|                 ->withHeaders($this->getHeaders($headers)) |                 ->withHeaders($this->getHeaders($headers)) | ||||||
|                 ->{$verb}("{$this->base_url}{$uri}", $data); |                 ->{$verb}("{$this->base_url}{$uri}", $data); | ||||||
|  | |||||||
| @ -15,6 +15,7 @@ use App\Models\Invoice; | |||||||
| use App\Services\AbstractService; | use App\Services\AbstractService; | ||||||
| use App\Helpers\Invoice\InvoiceSum; | use App\Helpers\Invoice\InvoiceSum; | ||||||
| use App\Helpers\Invoice\InvoiceSumInclusive; | use App\Helpers\Invoice\InvoiceSumInclusive; | ||||||
|  | use InvoiceNinja\EInvoice\EInvoice; | ||||||
| use InvoiceNinja\EInvoice\Models\Peppol\ItemType\Item; | use InvoiceNinja\EInvoice\Models\Peppol\ItemType\Item; | ||||||
| use InvoiceNinja\EInvoice\Models\Peppol\PartyType\Party; | use InvoiceNinja\EInvoice\Models\Peppol\PartyType\Party; | ||||||
| use InvoiceNinja\EInvoice\Models\Peppol\PriceType\Price; | use InvoiceNinja\EInvoice\Models\Peppol\PriceType\Price; | ||||||
| @ -78,6 +79,12 @@ class Peppol extends AbstractService | |||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public function toXml(): string | ||||||
|  |     { | ||||||
|  |         $e = new EInvoice(); | ||||||
|  |         return $e->encode($this->p_invoice, 'xml'); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public function run() |     public function run() | ||||||
|     { |     { | ||||||
|         $this->p_invoice->ID = $this->invoice->number; |         $this->p_invoice->ID = $this->invoice->number; | ||||||
|  | |||||||
							
								
								
									
										200
									
								
								tests/Integration/Einvoice/Storecove/StorecoveTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										200
									
								
								tests/Integration/Einvoice/Storecove/StorecoveTest.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,200 @@ | |||||||
|  | <?php | ||||||
|  | /** | ||||||
|  |  * Invoice Ninja (https://invoiceninja.com). | ||||||
|  |  * | ||||||
|  |  * @link https://github.com/invoiceninja/invoiceninja source repository | ||||||
|  |  * | ||||||
|  |  * @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com) | ||||||
|  |  * | ||||||
|  |  * @license https://www.elastic.co/licensing/elastic-license | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | namespace Tests\Integration\Einvoice\Storecove; | ||||||
|  | 
 | ||||||
|  | use Tests\TestCase; | ||||||
|  | use Tests\MockAccountData; | ||||||
|  | use Illuminate\Foundation\Testing\DatabaseTransactions; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class StorecoveTest extends TestCase | ||||||
|  | { | ||||||
|  |     use MockAccountData; | ||||||
|  |     use DatabaseTransactions; | ||||||
|  | 
 | ||||||
|  |     protected function setUp(): void | ||||||
|  |     { | ||||||
|  |         parent::setUp(); | ||||||
|  | 
 | ||||||
|  |         $this->makeTestData(); | ||||||
|  | 
 | ||||||
|  |         if (config('ninja.testvars.travis') !== false || !config('ninja.storecove_api_key'))  | ||||||
|  |             $this->markTestSkipped("do not run in CI"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public function teseateLegalEntity() | ||||||
|  |     { | ||||||
|  | 
 | ||||||
|  |         $data = [ | ||||||
|  |             'acts_as_receiver' => true, | ||||||
|  |             'acts_as_sender' => true, | ||||||
|  |             'advertisements' => ['invoice'], | ||||||
|  |             'city' => $this->company->settings->city, | ||||||
|  |             'country' => 'DE', | ||||||
|  |             'county' => $this->company->settings->state, | ||||||
|  |             'line1' => $this->company->settings->address1, | ||||||
|  |             'line2' => $this->company->settings->address2, | ||||||
|  |             'party_name' => $this->company->present()->name(), | ||||||
|  |             'tax_registered' => true, | ||||||
|  |             'tenant_id' => $this->company->company_key, | ||||||
|  |             'zip' => $this->company->settings->postal_code, | ||||||
|  |         ]; | ||||||
|  | 
 | ||||||
|  |         $sc = new \App\Services\EDocument\Gateway\Storecove\Storecove(); | ||||||
|  |         $r = $sc->createLegalEntity($data, $this->company); | ||||||
|  | 
 | ||||||
|  |         $this->assertIsArray($r); | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     public function testGetLegalEntity() | ||||||
|  |     { | ||||||
|  | 
 | ||||||
|  |          | ||||||
|  |         $sc = new \App\Services\EDocument\Gateway\Storecove\Storecove(); | ||||||
|  |         $r = $sc->getLegalEntity(290868); | ||||||
|  | 
 | ||||||
|  |         $this->assertIsArray($r); | ||||||
|  | 
 | ||||||
|  |         // nlog($r);
 | ||||||
|  | 
 | ||||||
|  |     }     | ||||||
|  | 
 | ||||||
|  |     public function testSendDocument() | ||||||
|  |     { | ||||||
|  | 
 | ||||||
|  |         $x = '<?xml version="1.0"?>
 | ||||||
|  |             <cbc:ID>0061</cbc:ID> | ||||||
|  |             <cbc:IssueDate>2024-07-15</cbc:IssueDate> | ||||||
|  |             <cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode> | ||||||
|  |             <cac:AccountingSupplierParty> | ||||||
|  |             <cac:Party> | ||||||
|  |                 <cac:PartyName> | ||||||
|  |                 <cbc:Name>Eladio Ullrich I</cbc:Name> | ||||||
|  |                 </cac:PartyName> | ||||||
|  |                 <cac:PostalAddress> | ||||||
|  |                 <cbc:StreetName>Jasper Brook</cbc:StreetName> | ||||||
|  |                 <cbc:CityName>Kodychester</cbc:CityName> | ||||||
|  |                 <cbc:PostalZone>73445-5131</cbc:PostalZone> | ||||||
|  |                 <cbc:CountrySubentity>South Dakota</cbc:CountrySubentity> | ||||||
|  |                 <cac:Country> | ||||||
|  |                     <cbc:IdentificationCode>AT</cbc:IdentificationCode> | ||||||
|  |                 </cac:Country> | ||||||
|  |                 </cac:PostalAddress> | ||||||
|  |                 <cac:PhysicalLocation> | ||||||
|  |                 <cbc:StreetName>Jasper Brook</cbc:StreetName> | ||||||
|  |                 <cbc:CityName>Kodychester</cbc:CityName> | ||||||
|  |                 <cbc:PostalZone>73445-5131</cbc:PostalZone> | ||||||
|  |                 <cbc:CountrySubentity>South Dakota</cbc:CountrySubentity> | ||||||
|  |                 <cac:Country> | ||||||
|  |                     <cbc:IdentificationCode>AT</cbc:IdentificationCode> | ||||||
|  |                 </cac:Country> | ||||||
|  |                 </cac:PhysicalLocation> | ||||||
|  |                 <cac:Contact> | ||||||
|  |                 <cbc:ElectronicMail>small@example.com</cbc:ElectronicMail> | ||||||
|  |                 </cac:Contact> | ||||||
|  |             </cac:Party> | ||||||
|  |             </cac:AccountingSupplierParty> | ||||||
|  |             <cac:AccountingCustomerParty> | ||||||
|  |             <cac:Party> | ||||||
|  |                 <cac:PartyName> | ||||||
|  |                 <cbc:Name>Beispiel GmbH</cbc:Name> | ||||||
|  |                 </cac:PartyName> | ||||||
|  |                 <cac:PostalAddress> | ||||||
|  |                 <cbc:StreetName>45 Hauptstraße</cbc:StreetName>
 | ||||||
|  |                 <cbc:CityName>Berlin</cbc:CityName> | ||||||
|  |                 <cbc:PostalZone>10115</cbc:PostalZone> | ||||||
|  |                 <cbc:CountrySubentity>Berlin</cbc:CountrySubentity> | ||||||
|  |                 <cac:Country> | ||||||
|  |                     <cbc:IdentificationCode>DE</cbc:IdentificationCode> | ||||||
|  |                 </cac:Country> | ||||||
|  |                 </cac:PostalAddress> | ||||||
|  |                 <cac:PhysicalLocation> | ||||||
|  |                 <cbc:StreetName>45 Hauptstraße</cbc:StreetName>
 | ||||||
|  |                 <cbc:CityName>Berlin</cbc:CityName> | ||||||
|  |                 <cbc:PostalZone>10115</cbc:PostalZone> | ||||||
|  |                 <cbc:CountrySubentity>Berlin</cbc:CountrySubentity> | ||||||
|  |                 <cac:Country> | ||||||
|  |                     <cbc:IdentificationCode>DE</cbc:IdentificationCode> | ||||||
|  |                 </cac:Country> | ||||||
|  |                 </cac:PhysicalLocation> | ||||||
|  |                 <cac:Contact> | ||||||
|  |                 <cbc:ElectronicMail>TTKGjKW9Rv00LEr@example.com</cbc:ElectronicMail> | ||||||
|  |                 </cac:Contact> | ||||||
|  |             </cac:Party> | ||||||
|  |             </cac:AccountingCustomerParty> | ||||||
|  |             <cac:TaxTotal/> | ||||||
|  |             <cac:LegalMonetaryTotal> | ||||||
|  |             <cbc:LineExtensionAmount currencyID="EUR">215</cbc:LineExtensionAmount> | ||||||
|  |             <cbc:TaxExclusiveAmount currencyID="EUR">215</cbc:TaxExclusiveAmount> | ||||||
|  |             <cbc:TaxInclusiveAmount currencyID="EUR">215.00</cbc:TaxInclusiveAmount> | ||||||
|  |             <cbc:PayableAmount currencyID="EUR">215.00</cbc:PayableAmount> | ||||||
|  |             </cac:LegalMonetaryTotal> | ||||||
|  |             <cac:InvoiceLine> | ||||||
|  |             <cbc:ID>1</cbc:ID> | ||||||
|  |             <cbc:InvoicedQuantity>1</cbc:InvoicedQuantity> | ||||||
|  |             <cbc:LineExtensionAmount currencyID="EUR">10</cbc:LineExtensionAmount> | ||||||
|  |             <cac:TaxTotal> | ||||||
|  |                 <cbc:TaxAmount currencyID="EUR">0.5</cbc:TaxAmount> | ||||||
|  |                 <cac:TaxSubtotal> | ||||||
|  |                 <cbc:TaxableAmount currencyID="EUR">10</cbc:TaxableAmount> | ||||||
|  |                 <cbc:TaxAmount currencyID="EUR">0.5</cbc:TaxAmount> | ||||||
|  |                 <cac:TaxCategory> | ||||||
|  |                     <cbc:ID>C62</cbc:ID> | ||||||
|  |                     <cbc:Percent>20</cbc:Percent> | ||||||
|  |                     <cac:TaxScheme> | ||||||
|  |                     <cbc:ID>USt</cbc:ID> | ||||||
|  |                     </cac:TaxScheme> | ||||||
|  |                 </cac:TaxCategory> | ||||||
|  |                 </cac:TaxSubtotal> | ||||||
|  |             </cac:TaxTotal> | ||||||
|  |             <cac:Item> | ||||||
|  |                 <cbc:Description>The Pro Plan NO MORE</cbc:Description> | ||||||
|  |                 <cbc:Name>ee</cbc:Name> | ||||||
|  |             </cac:Item> | ||||||
|  |             <cac:Price> | ||||||
|  |                 <cbc:PriceAmount currencyID="EUR">10</cbc:PriceAmount> | ||||||
|  |             </cac:Price> | ||||||
|  |             </cac:InvoiceLine> | ||||||
|  |             <cac:InvoiceLine> | ||||||
|  |             <cbc:ID>2</cbc:ID> | ||||||
|  |             <cbc:InvoicedQuantity>1</cbc:InvoicedQuantity> | ||||||
|  |             <cbc:LineExtensionAmount currencyID="EUR">14</cbc:LineExtensionAmount> | ||||||
|  |             <cac:Item> | ||||||
|  |                 <cbc:Description>The Enterprise Plan</cbc:Description> | ||||||
|  |                 <cbc:Name>eee</cbc:Name> | ||||||
|  |             </cac:Item> | ||||||
|  |             <cac:Price> | ||||||
|  |                 <cbc:PriceAmount currencyID="EUR">14</cbc:PriceAmount> | ||||||
|  |             </cac:Price> | ||||||
|  |             </cac:InvoiceLine> | ||||||
|  |             <cac:InvoiceLine> | ||||||
|  |             <cbc:ID>3</cbc:ID> | ||||||
|  |             <cbc:InvoicedQuantity>1</cbc:InvoicedQuantity> | ||||||
|  |             <cbc:LineExtensionAmount currencyID="EUR">191</cbc:LineExtensionAmount> | ||||||
|  |             <cac:Item> | ||||||
|  |                 <cbc:Description>Soluta provident.</cbc:Description> | ||||||
|  |                 <cbc:Name>k</cbc:Name> | ||||||
|  |             </cac:Item> | ||||||
|  |             <cac:Price> | ||||||
|  |                 <cbc:PriceAmount currencyID="EUR">191</cbc:PriceAmount> | ||||||
|  |             </cac:Price> | ||||||
|  |             </cac:InvoiceLine>'; | ||||||
|  | 
 | ||||||
|  |          | ||||||
|  |         $sc = new \App\Services\EDocument\Gateway\Storecove\Storecove(); | ||||||
|  |         $sc->sendDocument($x); | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user