makeTestData(); if (config('ninja.testvars.travis') !== false || !config('ninja.storecove_api_key')) $this->markTestSkipped("do not run in CI"); } // public function testCreateLegalEntity() // { // $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, // 'peppol_identifiers' => [ // 'scheme' => 'DE:VAT', // 'id' => 'DE:VAT' // ], // ]; // $sc = new \App\Services\EDocument\Gateway\Storecove\Storecove(); // $r = $sc->createLegalEntity($data, $this->company); // $this->assertIsArray($r); // } // public function testAddPeppolIdentifier() // { // $sc = new \App\Services\EDocument\Gateway\Storecove\Storecove(); // $r = $sc->addIdentifier(291394, "DE923356489", "DE:VAT"); // nlog($r); // } // public function testUpdateLegalEntity() // { // $data = [ // 'peppol_identifiers' => [ // 'scheme' => 'DE:VAT', // 'id' => 'DE:VAT' // ], // ]; // $sc = new \App\Services\EDocument\Gateway\Storecove\Storecove(); // $r = $sc->updateLegalEntity(290868, $data); // $this->assertIsArray($r); // nlog($r); // } /* public function testGetLegalEntity() { $sc = new \App\Services\EDocument\Gateway\Storecove\Storecove(); $r = $sc->getLegalEntity(290868); $this->assertIsArray($r); } public function testSendDocument() { $x = ' DE-77323 2024-07-18 380 Untitled Company Dudweilerstr. 34b Ost Alessa 98060 Bayern DE Dudweilerstr. 34b Ost Alessa 98060 Bayern DE owner@gmail.com German Client Name Kinderhausen 96b Süd Jessestadt 33323 Bayern DE Kinderhausen 96b Süd Jessestadt 33323 Bayern DE No Email Set DE89370400440532013000 PFA-NAME PFA-Alias CHECKING IBAN EUR DEUTDEMMXXX Deutsche Bank 100 100 119.00 119.00 1 10 100 19 100 19 C62 19 mwst Product Description Product Key 10 '; //inclusive $x = ' DE-93090 2024-07-18 380 Untitled Company Dudweilerstr. 34b Ost Alessa 98060 Bayern DE Dudweilerstr. 34b Ost Alessa 98060 Bayern DE owner@gmail.com German Client Name Kinderhausen 96b Süd Jessestadt 33323 Bayern DE Kinderhausen 96b Süd Jessestadt 33323 Bayern DE No Email Set DE89370400440532013000 PFA-NAME PFA-Alias CHECKING IBAN EUR DEUTDEMMXXX Deutsche Bank 15.97 84.03 15.97 C62 0 84.03 84.03 100.00 100.00 1 10 84.03 15.97 84.03 15.97 C62 19 mwst Product Description Product Key 8.403 '; $sc = new \App\Services\EDocument\Gateway\Storecove\Storecove(); $sc->sendDocument($x, 290868); } */ public function XXestCreateCHClient() { Client::unguard(); $c = Client::create([ 'company_id' => $this->company->id, 'user_id' => $this->user->id, 'name' => 'Test Company AG', 'website' => 'https://www.testcompany.ch', 'private_notes' => 'These are some private notes about the test client.', 'balance' => 0, 'paid_to_date' => 0, 'vat_number' => '654321987', 'id_number' => 'CH9300762011623852957', // Sample Swiss IBAN 'custom_value1' => '2024-07-22 10:00:00', 'custom_value2' => 'blue', 'custom_value3' => 'sampleword', 'custom_value4' => 'test@example.com', 'address1' => '123', 'address2' => 'Test Street 45', 'city' => 'Zurich', 'state' => 'Zurich', 'postal_code' => '8001', 'country_id' => '756', // Switzerland 'shipping_address1' => '123', 'shipping_address2' => 'Test Street 45', 'shipping_city' => 'Zurich', 'shipping_state' => 'Zurich', 'shipping_postal_code' => '8001', 'shipping_country_id' => '756', // Switzerland 'settings' => ClientSettings::Defaults(), 'client_hash' => \Illuminate\Support\Str::random(32), 'routing_id' => '', ]); $this->assertInstanceOf(\App\Models\Client::class, $c); } private function createESData() { $this->routing_id = 293098; $settings = CompanySettings::defaults(); $settings->company_logo = 'https://pdf.invoicing.co/favicon-v2.png'; $settings->website = 'www.invoiceninja.de'; $settings->address1 = 'Calle Gran Vía, 28'; $settings->address2 = 'Edificio Telefónica'; $settings->city = 'Madrid'; $settings->state = 'Madrid'; $settings->postal_code = '28013'; $settings->phone = '030 1234567'; $settings->email = $this->faker->unique()->safeEmail(); $settings->country_id = '724'; // Germany's ISO country code $settings->vat_number = 'ESB16645678'; $settings->id_number = 'HRB 12345'; $settings->use_credits_payment = 'always'; $settings->timezone_id = '1'; // CET (Central European Time) $settings->entity_send_time = 0; $settings->e_invoice_type = 'PEPPOL'; $settings->currency_id = '3'; $settings->classification = 'business'; $company = Company::factory()->create([ 'account_id' => $this->account->id, 'settings' => $settings, ]); $this->user->companies()->attach($company->id, [ 'account_id' => $this->account->id, 'is_owner' => true, 'is_admin' => 1, 'is_locked' => 0, 'permissions' => '', 'notifications' => CompanySettings::notificationAdminDefaults(), 'settings' => null, ]); Client::unguard(); $c = Client::create([ 'company_id' => $company->id, 'user_id' => $this->user->id, 'name' => 'Empresa Ejemplo S.A.', 'website' => 'https://www.empresa-ejemplo.es', 'private_notes' => 'Estas son notas privadas para el cliente de prueba.', 'balance' => 0, 'paid_to_date' => 0, 'vat_number' => 'ESB12345678', // Spanish VAT number with ES prefix 'id_number' => 'B12345678', // Typical format for Spanish company registration numbers 'custom_value1' => '2024-07-22 10:00:00', 'custom_value2' => 'azul', // Spanish for blue 'custom_value3' => 'palabraejemplo', // Spanish for sample word 'custom_value4' => 'test@ejemplo.com', 'address1' => 'Calle Ejemplo 123', 'address2' => '2ª Planta, Oficina 45', 'city' => 'Madrid', 'state' => 'Madrid', 'postal_code' => '28013', 'country_id' => '724', // Spain 'shipping_address1' => 'Calle Ejemplo 123', 'shipping_address2' => '2ª Planta, Oficina 45', 'shipping_city' => 'Madrid', 'shipping_state' => 'Madrid', 'shipping_postal_code' => '28013', 'shipping_country_id' => '724', // Spain 'settings' => ClientSettings::Defaults(), 'client_hash' => \Illuminate\Support\Str::random(32), 'routing_id' => '', ]); $item = new InvoiceItem(); $item->product_key = "Product Key"; $item->notes = "Product Description"; $item->cost = 10; $item->quantity = 10; $item->tax_rate1 = 21; $item->tax_name1 = 'IVA'; $invoice = Invoice::factory()->create([ 'company_id' => $company->id, 'user_id' => $this->user->id, 'client_id' => $c->id, 'discount' => 0, 'uses_inclusive_taxes' => false, 'status_id' => 1, 'tax_rate1' => 0, 'tax_name1' => '', 'tax_rate2' => 0, 'tax_rate3' => 0, 'tax_name2' => '', 'tax_name3' => '', 'line_items' => [$item], 'number' => 'ES-'.rand(1000, 100000), 'date' => now()->format('Y-m-d'), 'due_date' => now()->addDays(14)->format('Y-m-d'), ]); $invoice = $invoice->calc()->getInvoice(); $invoice->service()->markSent()->save(); return $invoice; } private function createFRData() { $this->routing_id = 293338; $settings = CompanySettings::defaults(); $settings->company_logo = 'https://pdf.invoicing.co/favicon-v2.png'; $settings->website = 'www.invoiceninja.de'; $settings->address1 = '10 Rue de la Paix'; $settings->address2 = 'Bâtiment A, Bureau 5'; $settings->city = 'Paris'; $settings->state = 'Île-de-France'; $settings->postal_code = '75002'; $settings->phone = '01 23456789'; $settings->email = $this->faker->unique()->safeEmail(); $settings->country_id = '250'; // France's ISO country code $settings->vat_number = 'FR82345678911'; $settings->id_number = '12345678900010'; $settings->classification = 'business'; $settings->use_credits_payment = 'always'; $settings->timezone_id = '1'; // CET (Central European Time) $settings->entity_send_time = 0; $settings->e_invoice_type = 'PEPPOL'; $settings->currency_id = '3'; $company = Company::factory()->create([ 'account_id' => $this->account->id, 'settings' => $settings, ]); $this->user->companies()->attach($company->id, [ 'account_id' => $this->account->id, 'is_owner' => true, 'is_admin' => 1, 'is_locked' => 0, 'permissions' => '', 'notifications' => CompanySettings::notificationAdminDefaults(), 'settings' => null, ]); Client::unguard(); $c = Client::create([ 'company_id' => $company->id, 'user_id' => $this->user->id, 'name' => 'Exemple Société S.A.', 'website' => 'https://www.exemple-societe.fr', 'private_notes' => 'Ceci est une note privée pour le client test.', 'balance' => 0, 'paid_to_date' => 0, 'vat_number' => 'FR12345678901', 'id_number' => '12345678900010', // Typical format for French company registration numbers 'custom_value1' => '2024-07-22 10:00:00', 'custom_value2' => 'bleu', 'custom_value3' => 'motexemple', 'custom_value4' => 'test@example.com', 'address1' => '123 Rue de l\'Exemple', 'address2' => '2ème étage, Bureau 45', 'city' => 'Paris', 'state' => 'Île-de-France', 'postal_code' => '75001', 'country_id' => '250', // France 'shipping_address1' => '123 Rue de l\'Exemple', 'shipping_address2' => '2ème étage, Bureau 45', 'shipping_city' => 'Paris', 'shipping_state' => 'Île-de-France', 'shipping_postal_code' => '75001', 'shipping_country_id' => '250', // France 'classification' => 'business', 'settings' => ClientSettings::Defaults(), 'client_hash' => \Illuminate\Support\Str::random(32), 'routing_id' => '', ]); $item = new InvoiceItem(); $item->product_key = "Product Key"; $item->notes = "Product Description"; $item->cost = 10; $item->quantity = 10; $item->tax_rate1 = 20; $item->tax_name1 = 'VAT'; $invoice = Invoice::factory()->create([ 'company_id' => $company->id, 'user_id' => $this->user->id, 'client_id' => $c->id, 'discount' => 0, 'uses_inclusive_taxes' => false, 'status_id' => 1, 'tax_rate1' => 0, 'tax_name1' => '', 'tax_rate2' => 0, 'tax_rate3' => 0, 'tax_name2' => '', 'tax_name3' => '', 'line_items' => [$item], 'number' => 'DE-'.rand(1000, 100000), 'date' => now()->format('Y-m-d'), 'due_date' => now()->addDays(14)->format('Y-m-d'), ]); $invoice = $invoice->calc()->getInvoice(); $invoice->service()->markSent()->save(); return $invoice; } private function createATData(bool $is_gov = false) { $this->routing_id = 293801; $settings = CompanySettings::defaults(); $settings->company_logo = 'https://pdf.invoicing.co/favicon-v2.png'; $settings->website = 'www.invoiceninja.at'; $settings->address1 = 'Musterstraße 1'; $settings->address2 = 'Stockwerk 2, Büro 3'; $settings->city = 'Vienna'; $settings->state = 'Vienna'; $settings->postal_code = '1010'; $settings->phone = '+43 1 23456789'; $settings->email = $this->faker->unique()->safeEmail(); $settings->country_id = '40'; // Austria's ISO country code $settings->vat_number = 'ATU92335648'; $settings->id_number = 'FN 123456x'; $settings->use_credits_payment = 'always'; $settings->timezone_id = '1'; // CET (Central European Time) $settings->entity_send_time = 0; $settings->e_invoice_type = 'PEPPOL'; $settings->currency_id = '3'; $company = Company::factory()->create([ 'account_id' => $this->account->id, 'settings' => $settings, ]); $this->user->companies()->attach($company->id, [ 'account_id' => $this->account->id, 'is_owner' => true, 'is_admin' => 1, 'is_locked' => 0, 'permissions' => '', 'notifications' => CompanySettings::notificationAdminDefaults(), 'settings' => null, ]); Client::unguard(); $c = Client::create([ 'company_id' => $company->id, 'user_id' => $this->user->id, 'name' => 'Beispiel Firma GmbH', 'website' => 'https://www.beispiel-firma.at', 'private_notes' => 'Dies sind private Notizen zum Testkunden.', 'balance' => 0, 'paid_to_date' => 0, 'vat_number' => 'ATU87654321', 'id_number' => $is_gov ? 'ATU12312321' : 'FN 123456x', // Example format for Austrian company registration numbers 'custom_value1' => '2024-07-22 10:00:00', 'custom_value2' => 'blau', 'custom_value3' => 'musterwort', 'custom_value4' => 'test@example.com', 'address1' => 'Musterstraße 123', 'address2' => '2. Etage, Büro 45', 'city' => 'Vienna', 'state' => 'Vienna', 'postal_code' => '1010', 'country_id' => '40', // Austria 'shipping_address1' => 'Musterstraße 123', 'shipping_address2' => '2. Etage, Büro 45', 'shipping_city' => 'Vienna', 'shipping_state' => 'Vienna', 'shipping_postal_code' => '1010', 'shipping_country_id' => '40', // Austria 'settings' => ClientSettings::Defaults(), 'client_hash' => \Illuminate\Support\Str::random(32), 'routing_id' => '', 'classification' => $is_gov ? 'government' : 'business', ]); $item = new InvoiceItem(); $item->product_key = "Product Key"; $item->notes = "Product Description"; $item->cost = 10; $item->quantity = 10; $item->tax_rate1 = 20; $item->tax_name1 = 'VAT'; $invoice = Invoice::factory()->create([ 'company_id' => $company->id, 'user_id' => $this->user->id, 'client_id' => $c->id, 'discount' => 0, 'uses_inclusive_taxes' => false, 'status_id' => 1, 'tax_rate1' => 0, 'tax_name1' => '', 'tax_rate2' => 0, 'tax_rate3' => 0, 'tax_name2' => '', 'tax_name3' => '', 'line_items' => [$item], 'number' => 'DE-'.rand(1000, 100000), 'date' => now()->format('Y-m-d'), 'due_date' => now()->addDays(14)->format('Y-m-d'), ]); $invoice = $invoice->calc()->getInvoice(); $invoice->service()->markSent()->save(); return $invoice; } public function testAtGovernmentRules() { $this->routing_id = 293801; $invoice = $this->createATData(true); $e_invoice = new \InvoiceNinja\EInvoice\Models\Peppol\Invoice(); $stub = json_decode('{"Invoice":{"Note":"Nooo","PaymentMeans":[{"ID":{"value":"afdasfasdfasdfas"},"PayeeFinancialAccount":{"Name":"PFA-NAME","ID":{"value":"DE89370400440532013000"},"AliasName":"PFA-Alias","AccountTypeCode":{"value":"CHECKING"},"AccountFormatCode":{"value":"IBAN"},"CurrencyCode":{"value":"EUR"},"FinancialInstitutionBranch":{"ID":{"value":"DEUTDEMMXXX"},"Name":"Deutsche Bank"}}}]}}'); foreach($stub as $key => $value) { $e_invoice->{$key} = $value; } $invoice->e_invoice = $e_invoice; $invoice->save(); $this->assertInstanceOf(Invoice::class, $invoice); $this->assertInstanceof(\InvoiceNinja\EInvoice\Models\Peppol\Invoice::class, $e_invoice); $p = new Peppol($invoice); $p->run(); $xml = $p->toXml(); nlog($xml); $identifiers = $p->getStorecoveMeta(); $sc = new \App\Services\EDocument\Gateway\Storecove\Storecove(); $sc->sendDocument($xml, $this->routing_id, $identifiers); } public function PestAtRules() { $this->routing_id = 293801; $invoice = $this->createATData(); $e_invoice = new \InvoiceNinja\EInvoice\Models\Peppol\Invoice(); $stub = json_decode('{"Invoice":{"Note":"Nooo","PaymentMeans":[{"ID":{"value":"afdasfasdfasdfas"},"PayeeFinancialAccount":{"Name":"PFA-NAME","ID":{"value":"DE89370400440532013000"},"AliasName":"PFA-Alias","AccountTypeCode":{"value":"CHECKING"},"AccountFormatCode":{"value":"IBAN"},"CurrencyCode":{"value":"EUR"},"FinancialInstitutionBranch":{"ID":{"value":"DEUTDEMMXXX"},"Name":"Deutsche Bank"}}}]}}'); foreach($stub as $key => $value) { $e_invoice->{$key} = $value; } $invoice->e_invoice = $e_invoice; $invoice->save(); $this->assertInstanceOf(Invoice::class, $invoice); $this->assertInstanceof(\InvoiceNinja\EInvoice\Models\Peppol\Invoice::class, $e_invoice); $p = new Peppol($invoice); $p->run(); $xml = $p->toXml(); nlog($xml); $identifiers = $p->getStorecoveMeta(); $sc = new \App\Services\EDocument\Gateway\Storecove\Storecove(); $sc->sendDocument($xml, $this->routing_id, $identifiers); } public function RestFrRules() { $invoice = $this->createFRData(); $e_invoice = new \InvoiceNinja\EInvoice\Models\Peppol\Invoice(); $stub = json_decode('{"Invoice":{"Note":"Nooo","PaymentMeans":[{"ID":{"value":"afdasfasdfasdfas"},"PayeeFinancialAccount":{"Name":"PFA-NAME","ID":{"value":"DE89370400440532013000"},"AliasName":"PFA-Alias","AccountTypeCode":{"value":"CHECKING"},"AccountFormatCode":{"value":"IBAN"},"CurrencyCode":{"value":"EUR"},"FinancialInstitutionBranch":{"ID":{"value":"DEUTDEMMXXX"},"Name":"Deutsche Bank"}}}]}}'); foreach($stub as $key => $value) { $e_invoice->{$key} = $value; } $invoice->e_invoice = $e_invoice; $invoice->save(); $this->assertInstanceOf(Invoice::class, $invoice); $this->assertInstanceof(\InvoiceNinja\EInvoice\Models\Peppol\Invoice::class, $e_invoice); $p = new Peppol($invoice); $p->run(); $xml = $p->toXml(); nlog($xml); $identifiers = $p->getStorecoveMeta(); $sc = new \App\Services\EDocument\Gateway\Storecove\Storecove(); $sc->sendDocument($xml, $this->routing_id, $identifiers); } public function RtestEsRules() { $invoice = $this->createESData(); $e_invoice = new \InvoiceNinja\EInvoice\Models\Peppol\Invoice(); $stub = json_decode('{"Invoice":{"Note":"Nooo","PaymentMeans":[{"ID":{"value":"afdasfasdfasdfas"},"PayeeFinancialAccount":{"Name":"PFA-NAME","ID":{"value":"DE89370400440532013000"},"AliasName":"PFA-Alias","AccountTypeCode":{"value":"CHECKING"},"AccountFormatCode":{"value":"IBAN"},"CurrencyCode":{"value":"EUR"},"FinancialInstitutionBranch":{"ID":{"value":"DEUTDEMMXXX"},"Name":"Deutsche Bank"}}}]}}'); foreach($stub as $key => $value) { $e_invoice->{$key} = $value; } $invoice->e_invoice = $e_invoice; $invoice->save(); $this->assertInstanceOf(Invoice::class, $invoice); $this->assertInstanceof(\InvoiceNinja\EInvoice\Models\Peppol\Invoice::class, $e_invoice); $p = new Peppol($invoice); $p->run(); $xml = $p->toXml(); nlog($xml); $identifiers = [ "routing" => [ "eIdentifiers" => [ [ 'scheme' => 'ES:VAT', 'id' => 'ESB53625999' ], ] ] ]; $sc = new \App\Services\EDocument\Gateway\Storecove\Storecove(); $sc->sendDocument($xml, $this->routing_id, $identifiers); } public function RtestDeRules() { $invoice = $this->createDEData(); $e_invoice = new \InvoiceNinja\EInvoice\Models\Peppol\Invoice(); $stub = json_decode('{"Invoice":{"Note":"Nooo","PaymentMeans":[{"ID":{"value":"afdasfasdfasdfas"},"PayeeFinancialAccount":{"Name":"PFA-NAME","ID":{"value":"DE89370400440532013000"},"AliasName":"PFA-Alias","AccountTypeCode":{"value":"CHECKING"},"AccountFormatCode":{"value":"IBAN"},"CurrencyCode":{"value":"EUR"},"FinancialInstitutionBranch":{"ID":{"value":"DEUTDEMMXXX"},"Name":"Deutsche Bank"}}}]}}'); foreach($stub as $key => $value) $e_invoice->{$key} = $value; $invoice->e_invoice = $e_invoice; $invoice->save(); $this->assertInstanceOf(Invoice::class, $invoice); $this->assertInstanceof(\InvoiceNinja\EInvoice\Models\Peppol\Invoice::class, $e_invoice); $p = new Peppol($invoice); $p->run(); $xml = $p->toXml(); nlog($xml); $identifiers = [ "routing" => [ "eIdentifiers" => [ [ 'scheme' => 'DE:VAT', 'id' => 'DE010101010' ] ] ] ]; $sc = new \App\Services\EDocument\Gateway\Storecove\Storecove(); $sc->sendDocument($xml, $this->routing_id, $identifiers); } }