Verifactu feature tests
This commit is contained in:
parent
97f2e70f5d
commit
14fd4063f5
|
|
@ -44,7 +44,7 @@ class AeatAuthority
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run(string $client_nif): bool
|
public function run(string $client_nif): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$sender_nif = config('services.verifactu.sender_nif');
|
$sender_nif = config('services.verifactu.sender_nif');
|
||||||
|
|
@ -94,7 +94,7 @@ XML;
|
||||||
nlog($response->body());
|
nlog($response->body());
|
||||||
nlog($parsedResponse);
|
nlog($parsedResponse);
|
||||||
|
|
||||||
return $parsedResponse['success'];
|
return $parsedResponse;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -43,46 +43,14 @@ class AeatClient
|
||||||
*
|
*
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setTestMode(): self
|
public function setTestMode(?string $base_url = null): self
|
||||||
{
|
{
|
||||||
$this->base_url = $this->sandbox_url;
|
$this->base_url = $base_url ?? $this->sandbox_url;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* run
|
|
||||||
*
|
|
||||||
* @param mixed $entity
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function run($entity): void
|
|
||||||
{
|
|
||||||
// build the payload
|
|
||||||
|
|
||||||
// harvest any previous hashes
|
public function send($xml): array
|
||||||
|
|
||||||
// send the payload to the AEAT
|
|
||||||
|
|
||||||
// await the response and insert new row into the verifactu_logs table
|
|
||||||
|
|
||||||
// write an activity (success or failure)
|
|
||||||
|
|
||||||
// on success, add a reference to invoice->backup->guid
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private function buildPayload($entity): string
|
|
||||||
{
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
private function harvestPreviousHashes($entity): array
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
private function send($xml)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
$response = Http::withHeaders([
|
$response = Http::withHeaders([
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,166 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\EInvoice\Verifactu;
|
||||||
|
|
||||||
|
use Tests\TestCase;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\Client;
|
||||||
|
use App\Models\Account;
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use Faker\Factory as Faker;
|
||||||
|
use App\Models\CompanyToken;
|
||||||
|
use App\Models\ClientContact;
|
||||||
|
use App\DataMapper\InvoiceItem;
|
||||||
|
use App\DataMapper\ClientSettings;
|
||||||
|
use App\DataMapper\CompanySettings;
|
||||||
|
use App\Factory\CompanyUserFactory;
|
||||||
|
|
||||||
|
class VerifactuFeatureTest extends TestCase
|
||||||
|
{
|
||||||
|
private $account;
|
||||||
|
private $company;
|
||||||
|
private $user;
|
||||||
|
private $cu;
|
||||||
|
private $token;
|
||||||
|
private $client;
|
||||||
|
private $faker;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->faker = Faker::create();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildData($settings = null)
|
||||||
|
{
|
||||||
|
$this->account = Account::factory()->create([
|
||||||
|
'hosted_client_count' => 1000,
|
||||||
|
'hosted_company_count' => 1000,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->account->num_users = 3;
|
||||||
|
$this->account->save();
|
||||||
|
|
||||||
|
$this->user = User::factory()->create([
|
||||||
|
'account_id' => $this->account->id,
|
||||||
|
'confirmation_code' => 'xyz123',
|
||||||
|
'email' => $this->faker->unique()->safeEmail(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if(!$settings) {
|
||||||
|
$settings = CompanySettings::defaults();
|
||||||
|
$settings->client_online_payment_notification = false;
|
||||||
|
$settings->client_manual_payment_notification = false;
|
||||||
|
$settings->country_id = 724;
|
||||||
|
$settings->currency_id = 3;
|
||||||
|
$settings->address1 = 'Calle Mayor 123'; // Main Street 123
|
||||||
|
$settings->city = 'Madrid';
|
||||||
|
$settings->state = 'Madrid';
|
||||||
|
$settings->postal_code = '28001';
|
||||||
|
$settings->vat_number = 'B12345678'; // Spanish VAT number format
|
||||||
|
$settings->payment_terms = '10';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->company = Company::factory()->create([
|
||||||
|
'account_id' => $this->account->id,
|
||||||
|
'settings' => $settings,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->company->settings = $settings;
|
||||||
|
$this->company->save();
|
||||||
|
|
||||||
|
$this->cu = CompanyUserFactory::create($this->user->id, $this->company->id, $this->account->id);
|
||||||
|
$this->cu->is_owner = true;
|
||||||
|
$this->cu->is_admin = true;
|
||||||
|
$this->cu->is_locked = false;
|
||||||
|
$this->cu->save();
|
||||||
|
|
||||||
|
$this->token = \Illuminate\Support\Str::random(64);
|
||||||
|
|
||||||
|
$company_token = new CompanyToken();
|
||||||
|
$company_token->user_id = $this->user->id;
|
||||||
|
$company_token->company_id = $this->company->id;
|
||||||
|
$company_token->account_id = $this->account->id;
|
||||||
|
$company_token->name = 'test token';
|
||||||
|
$company_token->token = $this->token;
|
||||||
|
$company_token->is_system = true;
|
||||||
|
|
||||||
|
$company_token->save();
|
||||||
|
|
||||||
|
$client_settings = ClientSettings::defaults();
|
||||||
|
$client_settings->currency_id = '3';
|
||||||
|
|
||||||
|
$this->client = Client::factory()->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'is_deleted' => 0,
|
||||||
|
'name' => 'bob',
|
||||||
|
'address1' => 'Calle Mayor 123',
|
||||||
|
'city' => 'Madrid',
|
||||||
|
'state' => 'Madrid',
|
||||||
|
'postal_code' => '28001',
|
||||||
|
'country_id' => 724,
|
||||||
|
'vat_number' => 'B12545678',
|
||||||
|
'balance' => 0,
|
||||||
|
'paid_to_date' => 0,
|
||||||
|
'settings' => $client_settings,
|
||||||
|
]);
|
||||||
|
|
||||||
|
ClientContact::factory()->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'client_id' => $this->client->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'is_primary' => 1,
|
||||||
|
'first_name' => 'john',
|
||||||
|
'last_name' => 'doe',
|
||||||
|
'email' => 'john@doe.com',
|
||||||
|
'send_email' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$line_items = [];
|
||||||
|
|
||||||
|
$item = new InvoiceItem();
|
||||||
|
$item->product_key = '1234567890';
|
||||||
|
$item->qty = 1;
|
||||||
|
$item->cost = 100;
|
||||||
|
$item->notes = 'Test item';
|
||||||
|
$item->tax_name1 = 'IVA';
|
||||||
|
$item->tax_rate1 = 21;
|
||||||
|
|
||||||
|
$line_items[] = $item;
|
||||||
|
|
||||||
|
$invoice = Invoice::factory()->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'client_id' => $this->client->id,
|
||||||
|
'date' => now()->addSeconds($this->client->timezone_offset())->format('Y-m-d'),
|
||||||
|
'next_send_date' => null,
|
||||||
|
'due_date' => now()->addSeconds($this->client->timezone_offset())->addDays(5)->format('Y-m-d'),
|
||||||
|
'last_sent_date' => now()->addSeconds($this->client->timezone_offset()),
|
||||||
|
'reminder_last_sent' => null,
|
||||||
|
'status_id' => Invoice::STATUS_DRAFT,
|
||||||
|
'amount' => 10,
|
||||||
|
'balance' => 10,
|
||||||
|
'line_items' => $line_items,
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
$invoice = $invoice->calc()
|
||||||
|
->getInvoice()
|
||||||
|
->service()
|
||||||
|
->markSent()
|
||||||
|
->save();
|
||||||
|
|
||||||
|
return $invoice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_construction_and_validation()
|
||||||
|
{
|
||||||
|
|
||||||
|
$invoice = $this->buildData();
|
||||||
|
|
||||||
|
$this->assertNotNull($invoice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature\EInvoice\Verifactu\Models;
|
namespace Tests\Feature\EInvoice\Verifactu;
|
||||||
|
|
||||||
use App\Services\EDocument\Standards\Verifactu\Models\Cupon;
|
use App\Services\EDocument\Standards\Verifactu\Models\Cupon;
|
||||||
use App\Services\EDocument\Standards\Verifactu\Models\Invoice;
|
use App\Services\EDocument\Standards\Verifactu\Models\Invoice;
|
||||||
|
|
@ -13,7 +13,7 @@ use App\Services\EDocument\Standards\Verifactu\Models\PersonaFisicaJuridica;
|
||||||
use App\Services\EDocument\Standards\Verifactu\Models\FacturaRectificativa;
|
use App\Services\EDocument\Standards\Verifactu\Models\FacturaRectificativa;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class VerifactuInvoiceTest extends TestCase
|
class VerifactuModelTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testCreateAndSerializeCompleteInvoice(): void
|
public function testCreateAndSerializeCompleteInvoice(): void
|
||||||
{
|
{
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature\EInvoice\Verifactu\Models;
|
namespace Tests\Feature\EInvoice\Verifactu;
|
||||||
|
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use App\Services\EDocument\Standards\Verifactu\Models\Invoice;
|
use App\Services\EDocument\Standards\Verifactu\Models\Invoice;
|
||||||
|
|
@ -13,7 +13,7 @@ use App\Services\EDocument\Standards\Verifactu\Models\InvoiceModification;
|
||||||
use App\Services\EDocument\Standards\Verifactu\Models\RegistroModificacion;
|
use App\Services\EDocument\Standards\Verifactu\Models\RegistroModificacion;
|
||||||
use App\Services\EDocument\Standards\Verifactu\Models\PersonaFisicaJuridica;
|
use App\Services\EDocument\Standards\Verifactu\Models\PersonaFisicaJuridica;
|
||||||
|
|
||||||
class InvoiceModificationTest extends TestCase
|
class VerifactuModificationTest extends TestCase
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
|
|
@ -93,6 +93,7 @@ class InvoiceModificationTest extends TestCase
|
||||||
'BaseImponibleOimporteNoSujeto' => '100.00',
|
'BaseImponibleOimporteNoSujeto' => '100.00',
|
||||||
'CuotaRepercutida' => '21.00'
|
'CuotaRepercutida' => '21.00'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$modification->setDesglose($desglose);
|
$modification->setDesglose($desglose);
|
||||||
|
|
||||||
// Add encadenamiento
|
// Add encadenamiento
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature\EInvoice\Verifactu\Models;
|
namespace Tests\Feature\EInvoice\Verifactu;
|
||||||
|
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
Loading…
Reference in New Issue