Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing test #52

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
283 changes: 283 additions & 0 deletions src/Api/Settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
<?php

namespace OfflineAgency\LaravelFattureInCloudV2\Api;

use Illuminate\Support\Facades\Validator;
use OfflineAgency\LaravelFattureInCloudV2\Entities\Error;
use OfflineAgency\LaravelFattureInCloudV2\Entities\Settings\Settings as AccountEntity;
use OfflineAgency\LaravelFattureInCloudV2\Entities\Settings\Settings as MethodEntity;
use OfflineAgency\LaravelFattureInCloudV2\Entities\Settings\Settings as VatTypeEntity;

class Settings extends Api
{
//===Method===
public function mCreate(
array $body = []
) {
$validator = Validator::make($body, [
'data' => 'required',
'data.name' => 'required',
]);
if ($validator->fails()) {
return $validator->errors();
}

$response = $this->post(
'c/'.$this->company_id.'/settings/payment_methods',
$body
);

if (! $response->success) {
return new Error($response->data);
}

$settings = $response->data->data;

return new MethodEntity($settings);
}
public function mDetail(
int $payment_method_id,
?array $additional_data = []
) {
$additional_data = $this->data($additional_data, [
'fields', 'fieldset',
]);

$response = $this->get(
'c/'.$this->company_id.'/settings/payment_methods'.$payment_method_id,
$additional_data
);

if (! $response->success) {
return new Error($response->data);
}

$settings = $response->data->data;

return new MethodEntity($settings);
}

public function mEdit(
int $payment_method_id,
?array $body = []
){
$validator = Validator::make($body, [
'data' => 'required',
'data.name' => 'required',
]);

if ($validator->fails()) {
return $validator->errors();
}

$response = $this->put(
'c/' . $this->company_id . '/settings/payment_methods/' . $payment_method_id,
$body
);

if (!$response->success) {
return new Error($response->data);
}

$payment_method_id = $response->data->data;

return new MethodEntity($payment_method_id);
}

public function mDelete(
int $payment_method_id
)
{
$response = $this->destroy(
'c/' . $this->company_id . '/settings/payment_methods/' . $payment_method_id
);

if (!$response->success) {
return new Error($response->data);
}

return 'Payment method deleted';
}

//===Account===

public function aCreate(
array $body = []
) {
$validator = Validator::make($body, [
'data' => 'required',
'data.name' => 'required',
]);

if ($validator->fails()) {
return $validator->errors();
}

$response = $this->post(
'c/'.$this->company_id.'/settings/payment_accounts',
$body
);

if (! $response->success) {
return new Error($response->data);
}

$settings = $response->data->data;

return new AccountEntity($settings);
}

public function aDetail(
int $payment_account_id,
?array $additional_data = []
) {
$additional_data = $this->data($additional_data, [
'fields', 'fieldset',
]);

$response = $this->get(
'c/'.$this->company_id.'/settings/payment_accounts' . $payment_account_id,
$additional_data
);

if (! $response->success) {
return new Error($response->data);
}

$settings = $response->data->data;

return new AccountEntity($settings);
}

public function aEdit(
int $payment_account_id,
?array $body = []
){
$validator = Validator::make($body, [
'data' => 'required',
'data.name' => 'required',
]);

if ($validator->fails()) {
return $validator->errors();
}

$response = $this->put(
'c/' . $this->company_id . '/settings/payment_accounts/' . $payment_account_id,
$body
);

if (!$response->success) {
return new Error($response->data);
}

$payment_account_id = $response->data->data;

return new AccountEntity($payment_account_id);
}

public function aDelete(
int $payment_account_id
)
{
$response = $this->destroy(
'c/' . $this->company_id . '/settings/payment_accounts/' . $payment_account_id
);

if (!$response->success) {
return new Error($response->data);
}

return 'Payment method deleted';
}

//===Vat_Type===
public function vtCreate(
array $body = []
) {
$validator = Validator::make($body, [
'data' => 'required',
'data.name' => 'required',
]);

if ($validator->fails()) {
return $validator->errors();
}

$response = $this->post(
'c/'.$this->company_id.'/settings/vat_types',
$body
);

if (! $response->success) {
return new Error($response->data);
}

$settings = $response->data->data;

return new VatTypeEntity($settings);
}

public function vtDetail(
int $vat_type_id,
?array $additional_data = []
) {
$additional_data = $this->data($additional_data, [
'fields', 'fieldset',
]);

$response = $this->get(
'c/'.$this->company_id.'/settings/vat_types'.$vat_type_id,
$additional_data
);

if (! $response->success) {
return new Error($response->data);
}

$settings = $response->data->data;

return new VatTypeEntity($settings);
}

public function vtEdit(
int $vat_type_id,
?array $body = []
){
$validator = Validator::make($body, [
'data' => 'required',
'data.name' => 'required',
]);

if ($validator->fails()) {
return $validator->errors();
}

$response = $this->put(
'c/' . $this->company_id . '/settings/vat_types/' . $vat_type_id,
$body
);

if (!$response->success) {
return new Error($response->data);
}

$vat_type_id = $response->data->data;

return new VatTypeEntity($vat_type_id);
}

public function vtDelete(
int $vat_type_id
){
$response = $this->destroy(
'c/' . $this->company_id . '/settings/vat_types/' . $vat_type_id
);

if (!$response->success) {
return new Error($response->data);
}

return 'Vat type deleted';
}
}
93 changes: 93 additions & 0 deletions src/Entities/Settings/Settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace OfflineAgency\LaravelFattureInCloudV2\Entities\Settings;

use OfflineAgency\LaravelFattureInCloudV2\Entities\AbstractEntity;

class Settings extends AbstractEntity
{
/**
* @var int
*/
public $id;

/**
* @var string
*/
public $name;

/**
* @var bool
*/
public $is_default;

/**
* @var string
*/
public $type;

/**
* @var array
*/
public $details;

/**
* @var object
*/
public $default_payment_account;

/**
* @var string
*/
public $iban;

/**
* @var string
*/
public $sia;

/**
* @var bool
*/
public $virtual;

/**
* @var string
*/
public $description;

/**
* @var int
*/
public $value;

/**
* @var string
*/
public $notes;

/**
* @var bool
*/
public $e_invoice;

/**
* @var int
*/
public $ei_type;

/**
* @var string
*/
public $ei_description;

/**
* @var bool
*/
public $editable;

/**
* @var bool
*/
public $is_disabled;
}
Loading