mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #8806 from turbo124/v5-develop
Checks for missing props
This commit is contained in:
commit
e0dcc9c117
@ -36,6 +36,7 @@ class RecurringExpenseFactory
|
||||
$recurring_expense->tax_amount3 = 0;
|
||||
$recurring_expense->date = now()->format('Y-m-d');
|
||||
$recurring_expense->next_send_date = now()->format('Y-m-d');
|
||||
$recurring_expense->next_send_date_client = now()->format('Y-m-d');
|
||||
$recurring_expense->payment_date = null;
|
||||
$recurring_expense->amount = 0;
|
||||
$recurring_expense->foreign_amount = 0;
|
||||
|
@ -11,13 +11,14 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Exceptions\FilePermissionsFailure;
|
||||
use App\Utils\Ninja;
|
||||
use App\Models\Company;
|
||||
use App\Utils\Traits\AppSetup;
|
||||
use App\Utils\Traits\ClientGroupSettingsSaver;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Exceptions\FilePermissionsFailure;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use App\Utils\Traits\ClientGroupSettingsSaver;
|
||||
|
||||
class SelfUpdateController extends BaseController
|
||||
{
|
||||
@ -109,11 +110,33 @@ class SelfUpdateController extends BaseController
|
||||
|
||||
$this->buildCache(true);
|
||||
|
||||
$this->runModelChecks();
|
||||
|
||||
nlog('Called Artisan commands');
|
||||
|
||||
return response()->json(['message' => 'Update completed'], 200);
|
||||
}
|
||||
|
||||
private function runModelChecks()
|
||||
{
|
||||
Company::query()
|
||||
->cursor()
|
||||
->each(function ($company){
|
||||
|
||||
$settings = $company->settings;
|
||||
|
||||
if(property_exists($settings->pdf_variables, 'purchase_order_details'))
|
||||
return;
|
||||
|
||||
$pdf_variables = $settings->pdf_variables;
|
||||
$pdf_variables->purchase_order_details = [];
|
||||
$settings->pdf_variables = $pdf_variables;
|
||||
$company->settings = $settings;
|
||||
$company->save();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private function clearCacheDir()
|
||||
{
|
||||
$directoryIterator = new \RecursiveDirectoryIterator(base_path('bootstrap/cache'), \RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
|
@ -195,15 +195,15 @@ class PdfSlot extends Component
|
||||
|
||||
}
|
||||
elseif($this->entity_type == 'quote'){
|
||||
foreach($this->settings->pdf_variables->quote_details as $variable)
|
||||
foreach($this->settings->pdf_variables->quote_details ?? [] as $variable)
|
||||
$entity_details .= "<div class='flex px-5 block'><p class= w-36 block'>{$variable}_label</p><p class='pl-5 w-36 block entity-field'>{$variable}</p></div>";
|
||||
}
|
||||
elseif($this->entity_type == 'credit') {
|
||||
foreach($this->settings->pdf_variables->credit_details as $variable)
|
||||
foreach($this->settings->pdf_variables->credit_details ?? [] as $variable)
|
||||
$entity_details .= "<div class='flex px-5 block'><p class= w-36 block'>{$variable}_label</p><p class='pl-5 w-36 block entity-field'>{$variable}</p></div>";
|
||||
}
|
||||
elseif($this->entity_type == 'purchase_order'){
|
||||
foreach($this->settings->pdf_variables->purchase_order_details as $variable)
|
||||
foreach($this->settings->pdf_variables->purchase_order_details ?? [] as $variable)
|
||||
$entity_details .= "<div class='flex px-5 block'><p class= w-36 block'>{$variable}_label</p><p class='pl-5 w-36 block entity-field'>{$variable}</p></div>";
|
||||
}
|
||||
|
||||
|
@ -90,6 +90,12 @@ class PaymentAppliedValidAmount implements Rule
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(count($this->input['invoices']) >=1 && $payment->status_id == Payment::STATUS_PENDING){
|
||||
$this->message = 'Cannot apply a payment until the status is completed.';
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (round($payment_amounts, 3) >= round($invoice_amounts, 3)) {
|
||||
|
@ -175,10 +175,10 @@ class Gateway extends StaticModel
|
||||
];
|
||||
case 52:
|
||||
return [
|
||||
GatewayType::BANK_TRANSFER => ['refund' => false, 'token_billing' => true, 'webhooks' => [' ']], // GoCardless
|
||||
GatewayType::DIRECT_DEBIT => ['refund' => false, 'token_billing' => true, 'webhooks' => [' ']],
|
||||
GatewayType::SEPA => ['refund' => false, 'token_billing' => true, 'webhooks' => [' ']],
|
||||
GatewayType::INSTANT_BANK_PAY => ['refund' => false, 'token_billing' => true, 'webhooks' => [' ']],
|
||||
GatewayType::BANK_TRANSFER => ['refund' => false, 'token_billing' => true, 'webhooks' => ['confirmed','paid_out','failed','fulfilled']], // GoCardless
|
||||
GatewayType::DIRECT_DEBIT => ['refund' => false, 'token_billing' => true, 'webhooks' => ['confirmed','paid_out','failed','fulfilled']],
|
||||
GatewayType::SEPA => ['refund' => false, 'token_billing' => true, 'webhooks' => ['confirmed','paid_out','failed','fulfilled']],
|
||||
GatewayType::INSTANT_BANK_PAY => ['refund' => false, 'token_billing' => true, 'webhooks' => ['confirmed','paid_out','failed','fulfilled']],
|
||||
];
|
||||
case 58:
|
||||
return [
|
||||
|
@ -75,18 +75,20 @@ class TaxProvider
|
||||
*/
|
||||
public function updateCompanyTaxData(): self
|
||||
{
|
||||
$this->configureProvider($this->provider, $this->company->country()->iso_3166_2); //hard coded for now to one provider, but we'll be able to swap these out later
|
||||
|
||||
$company_details = [
|
||||
'address2' => $this->company->settings->address2,
|
||||
'address1' => $this->company->settings->address1,
|
||||
'city' => $this->company->settings->city,
|
||||
'state' => $this->company->settings->state,
|
||||
'postal_code' => $this->company->settings->postal_code,
|
||||
'country' => $this->company->country()->name,
|
||||
];
|
||||
|
||||
try {
|
||||
|
||||
$this->configureProvider($this->provider, $this->company->country()->iso_3166_2); //hard coded for now to one provider, but we'll be able to swap these out later
|
||||
|
||||
$company_details = [
|
||||
'address2' => $this->company->settings->address2,
|
||||
'address1' => $this->company->settings->address1,
|
||||
'city' => $this->company->settings->city,
|
||||
'state' => $this->company->settings->state,
|
||||
'postal_code' => $this->company->settings->postal_code,
|
||||
'country' => $this->company->country()->name,
|
||||
];
|
||||
|
||||
$tax_provider = new $this->provider($company_details);
|
||||
|
||||
$tax_provider->setApiCredentials($this->api_credentials);
|
||||
@ -143,7 +145,7 @@ class TaxProvider
|
||||
|
||||
$tax_data = $tax_provider->run();
|
||||
|
||||
nlog($tax_data);
|
||||
// nlog($tax_data);
|
||||
|
||||
if($tax_data) {
|
||||
$this->client->tax_data = $tax_data;
|
||||
|
48
composer.lock
generated
48
composer.lock
generated
@ -525,16 +525,16 @@
|
||||
},
|
||||
{
|
||||
"name": "aws/aws-sdk-php",
|
||||
"version": "3.281.7",
|
||||
"version": "3.281.8",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/aws/aws-sdk-php.git",
|
||||
"reference": "926cea9a41a545ca9801ac304f2a9ffd23ac68c9"
|
||||
"reference": "eb349b9f31502a05c70362f57913b9fed6b65b1f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/926cea9a41a545ca9801ac304f2a9ffd23ac68c9",
|
||||
"reference": "926cea9a41a545ca9801ac304f2a9ffd23ac68c9",
|
||||
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/eb349b9f31502a05c70362f57913b9fed6b65b1f",
|
||||
"reference": "eb349b9f31502a05c70362f57913b9fed6b65b1f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -614,9 +614,9 @@
|
||||
"support": {
|
||||
"forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
|
||||
"issues": "https://github.com/aws/aws-sdk-php/issues",
|
||||
"source": "https://github.com/aws/aws-sdk-php/tree/3.281.7"
|
||||
"source": "https://github.com/aws/aws-sdk-php/tree/3.281.8"
|
||||
},
|
||||
"time": "2023-09-14T18:05:11+00:00"
|
||||
"time": "2023-09-15T18:34:59+00:00"
|
||||
},
|
||||
{
|
||||
"name": "bacon/bacon-qr-code",
|
||||
@ -8062,16 +8062,16 @@
|
||||
},
|
||||
{
|
||||
"name": "phpseclib/phpseclib",
|
||||
"version": "3.0.21",
|
||||
"version": "3.0.22",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpseclib/phpseclib.git",
|
||||
"reference": "4580645d3fc05c189024eb3b834c6c1e4f0f30a1"
|
||||
"reference": "b6bd1c5f79b2c39e144770eb6d9180fbdb00d09b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/4580645d3fc05c189024eb3b834c6c1e4f0f30a1",
|
||||
"reference": "4580645d3fc05c189024eb3b834c6c1e4f0f30a1",
|
||||
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/b6bd1c5f79b2c39e144770eb6d9180fbdb00d09b",
|
||||
"reference": "b6bd1c5f79b2c39e144770eb6d9180fbdb00d09b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -8152,7 +8152,7 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/phpseclib/phpseclib/issues",
|
||||
"source": "https://github.com/phpseclib/phpseclib/tree/3.0.21"
|
||||
"source": "https://github.com/phpseclib/phpseclib/tree/3.0.22"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@ -8168,7 +8168,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2023-07-09T15:24:48+00:00"
|
||||
"time": "2023-09-16T11:49:37+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpstan/phpdoc-parser",
|
||||
@ -10112,16 +10112,16 @@
|
||||
},
|
||||
{
|
||||
"name": "spatie/laravel-data",
|
||||
"version": "3.8.1",
|
||||
"version": "3.9.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/spatie/laravel-data.git",
|
||||
"reference": "7ead3d8f761846185a94d06e584bfe17e43b9239"
|
||||
"reference": "21bad55113a1e1e5180a0f89b695f02ce1732aef"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/spatie/laravel-data/zipball/7ead3d8f761846185a94d06e584bfe17e43b9239",
|
||||
"reference": "7ead3d8f761846185a94d06e584bfe17e43b9239",
|
||||
"url": "https://api.github.com/repos/spatie/laravel-data/zipball/21bad55113a1e1e5180a0f89b695f02ce1732aef",
|
||||
"reference": "21bad55113a1e1e5180a0f89b695f02ce1732aef",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -10183,7 +10183,7 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/spatie/laravel-data/issues",
|
||||
"source": "https://github.com/spatie/laravel-data/tree/3.8.1"
|
||||
"source": "https://github.com/spatie/laravel-data/tree/3.9.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@ -10191,7 +10191,7 @@
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2023-08-11T11:59:07+00:00"
|
||||
"time": "2023-09-15T12:04:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "spatie/laravel-package-tools",
|
||||
@ -15793,16 +15793,16 @@
|
||||
},
|
||||
{
|
||||
"name": "phpmyadmin/sql-parser",
|
||||
"version": "5.8.0",
|
||||
"version": "5.8.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpmyadmin/sql-parser.git",
|
||||
"reference": "db1b3069b5dbc220d393d67ff911e0ae76732755"
|
||||
"reference": "b877ee6262a00f0f498da5e01335e8a5dc01d203"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpmyadmin/sql-parser/zipball/db1b3069b5dbc220d393d67ff911e0ae76732755",
|
||||
"reference": "db1b3069b5dbc220d393d67ff911e0ae76732755",
|
||||
"url": "https://api.github.com/repos/phpmyadmin/sql-parser/zipball/b877ee6262a00f0f498da5e01335e8a5dc01d203",
|
||||
"reference": "b877ee6262a00f0f498da5e01335e8a5dc01d203",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -15824,7 +15824,7 @@
|
||||
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
|
||||
"psalm/plugin-phpunit": "^0.16.1",
|
||||
"vimeo/psalm": "^4.11",
|
||||
"zumba/json-serializer": "^3.0"
|
||||
"zumba/json-serializer": "~3.0.2"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "For best performance",
|
||||
@ -15876,7 +15876,7 @@
|
||||
"type": "other"
|
||||
}
|
||||
],
|
||||
"time": "2023-06-05T18:19:38+00:00"
|
||||
"time": "2023-09-15T18:21:22+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpstan/phpstan",
|
||||
|
@ -42,6 +42,8 @@ class PaymentTest extends TestCase
|
||||
use DatabaseTransactions;
|
||||
use MockAccountData;
|
||||
|
||||
public $faker;
|
||||
|
||||
protected function setUp() :void
|
||||
{
|
||||
parent::setUp();
|
||||
@ -53,13 +55,80 @@ class PaymentTest extends TestCase
|
||||
Model::reguard();
|
||||
|
||||
$this->makeTestData();
|
||||
$this->withoutExceptionHandling();
|
||||
// $this->withoutExceptionHandling();
|
||||
|
||||
$this->withoutMiddleware(
|
||||
ThrottleRequests::class
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function testCompletedPaymentLogic()
|
||||
{
|
||||
$payment = Payment::factory()->create([
|
||||
'company_id' => $this->company->id,
|
||||
'user_id' => $this->user->id,
|
||||
'client_id' => $this->client->id,
|
||||
'status_id' => Payment::STATUS_COMPLETED,
|
||||
'amount' => 100
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'amount' => $this->invoice->amount,
|
||||
'client_id' => $this->client->hashed_id,
|
||||
'invoices' => [
|
||||
[
|
||||
'invoice_id' => $this->invoice->hashed_id,
|
||||
'amount' => $this->invoice->amount,
|
||||
],
|
||||
],
|
||||
'date' => '2020/12/11',
|
||||
'idempotency_key' => 'dsjafhajklsfhlaksjdhlkajsdjdfjdfljasdfhkjlsafhljfkfhsjlfhiuwayerfiuwaskjgbzmvnjzxnjcbgfkjhdgfoiwwrasdfasdfkashjdfkaskfjdasfda'
|
||||
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->putJson('/api/v1/payments/'.$payment->hashed_id, $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
public function testPendingPaymentLogic()
|
||||
{
|
||||
$payment = Payment::factory()->create([
|
||||
'company_id' => $this->company->id,
|
||||
'user_id' => $this->user->id,
|
||||
'client_id' => $this->client->id,
|
||||
'status_id' => Payment::STATUS_PENDING,
|
||||
'amount' => 100
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'amount' => $this->invoice->amount,
|
||||
'client_id' => $this->client->hashed_id,
|
||||
'invoices' => [
|
||||
[
|
||||
'invoice_id' => $this->invoice->hashed_id,
|
||||
'amount' => $this->invoice->amount,
|
||||
],
|
||||
],
|
||||
'date' => '2020/12/11',
|
||||
'idempotency_key' => 'dsjafhajklsfhlaksjdhlkajsdjdfjdfljasdfhkjlsafhljfkfhsjlfhiuwayerfiuwaskjgbzmvnjzxnjcbgfkjhdgfoiwwrasdfasdfkashjdfkaskfjdasfda'
|
||||
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->putJson('/api/v1/payments/'.$payment->hashed_id, $data);
|
||||
|
||||
$response->assertStatus(422);
|
||||
|
||||
}
|
||||
|
||||
public function testPaymentGetBetweenQuery1()
|
||||
{
|
||||
$response = $this->withHeaders([
|
||||
@ -185,16 +254,15 @@ class PaymentTest extends TestCase
|
||||
];
|
||||
|
||||
$response = false;
|
||||
try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments/', $data);
|
||||
} catch (ValidationException $e) {
|
||||
// $message = json_decode($e->validator->getMessageBag(), 1);
|
||||
}
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->postJson('/api/v1/payments/', $data);
|
||||
|
||||
$response->assertStatus(422);
|
||||
|
||||
$this->assertFalse($response);
|
||||
// $this->assertFalse($response);
|
||||
}
|
||||
|
||||
|
||||
@ -245,7 +313,7 @@ class PaymentTest extends TestCase
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/payments/'.$this->encodePrimaryKey($Payment->id), $Payment->toArray());
|
||||
])->putJson('/api/v1/payments/'.$this->encodePrimaryKey($Payment->id), $Payment->toArray());
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
@ -287,16 +355,17 @@ class PaymentTest extends TestCase
|
||||
|
||||
];
|
||||
|
||||
try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments/', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
])->postJson('/api/v1/payments/', $data);
|
||||
// } catch (ValidationException $e) {
|
||||
// $message = json_decode($e->validator->getMessageBag(), 1);
|
||||
|
||||
$this->assertTrue(array_key_exists('client_id', $message));
|
||||
}
|
||||
$response->assertStatus(422);
|
||||
|
||||
// $this->assertTrue(array_key_exists('client_id', $message));
|
||||
// }
|
||||
}
|
||||
|
||||
public function testStorePaymentWithClientId()
|
||||
@ -339,15 +408,17 @@ class PaymentTest extends TestCase
|
||||
|
||||
$response = null;
|
||||
|
||||
try {
|
||||
// try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments?include=invoices,paymentables', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
$this->assertNotNull($message);
|
||||
}
|
||||
])->postJson('/api/v1/payments?include=invoices,paymentables', $data);
|
||||
// } catch (ValidationException $e) {
|
||||
// $message = json_decode($e->validator->getMessageBag(), 1);
|
||||
// $this->assertNotNull($message);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
if ($response) {
|
||||
$arr = $response->json();
|
||||
@ -399,19 +470,19 @@ class PaymentTest extends TestCase
|
||||
|
||||
$response = false;
|
||||
|
||||
try {
|
||||
// try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments?include=invoices', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
$this->assertNotNull($message);
|
||||
}
|
||||
])->postJson('/api/v1/payments?include=invoices', $data);
|
||||
// } catch (ValidationException $e) {
|
||||
// $message = json_decode($e->validator->getMessageBag(), 1);
|
||||
// $this->assertNotNull($message);
|
||||
// }
|
||||
|
||||
if ($response) {
|
||||
// if ($response) {
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
public function testPartialPaymentAmount()
|
||||
@ -455,37 +526,29 @@ class PaymentTest extends TestCase
|
||||
'date' => '2019/12/12',
|
||||
];
|
||||
|
||||
$response = false;
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->postJson('/api/v1/payments?include=invoices', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments?include=invoices', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
$this->assertNotNull($message);
|
||||
}
|
||||
$arr = $response->json();
|
||||
|
||||
if ($response) {
|
||||
$response->assertStatus(200);
|
||||
$payment_id = $arr['data']['id'];
|
||||
|
||||
$arr = $response->json();
|
||||
$payment = Payment::whereId($this->decodePrimaryKey($payment_id))->first();
|
||||
|
||||
$payment_id = $arr['data']['id'];
|
||||
$this->assertNotNull($payment);
|
||||
$this->assertNotNull($payment->invoices());
|
||||
$this->assertEquals(1, $payment->invoices()->count());
|
||||
|
||||
$payment = Payment::whereId($this->decodePrimaryKey($payment_id))->first();
|
||||
|
||||
$this->assertNotNull($payment);
|
||||
$this->assertNotNull($payment->invoices());
|
||||
$this->assertEquals(1, $payment->invoices()->count());
|
||||
|
||||
$pivot_invoice = $payment->invoices()->first();
|
||||
$this->assertEquals($pivot_invoice->pivot->amount, 2);
|
||||
$this->assertEquals($pivot_invoice->partial, 0);
|
||||
$this->assertEquals($pivot_invoice->amount, 10.0000);
|
||||
$this->assertEquals($pivot_invoice->balance, 8.0000);
|
||||
}
|
||||
$pivot_invoice = $payment->invoices()->first();
|
||||
$this->assertEquals($pivot_invoice->pivot->amount, 2);
|
||||
$this->assertEquals($pivot_invoice->partial, 0);
|
||||
$this->assertEquals($pivot_invoice->amount, 10.0000);
|
||||
$this->assertEquals($pivot_invoice->balance, 8.0000);
|
||||
|
||||
}
|
||||
|
||||
public function testPaymentGreaterThanPartial()
|
||||
@ -539,14 +602,14 @@ class PaymentTest extends TestCase
|
||||
|
||||
$response = false;
|
||||
|
||||
try {
|
||||
// try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments?include=invoices', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
}
|
||||
])->postJson('/api/v1/payments?include=invoices', $data);
|
||||
// } catch (ValidationException $e) {
|
||||
// $message = json_decode($e->validator->getMessageBag(), 1);
|
||||
// }
|
||||
|
||||
$arr = $response->json();
|
||||
$response->assertStatus(200);
|
||||
@ -618,7 +681,7 @@ class PaymentTest extends TestCase
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments?include=invoices', $data);
|
||||
])->postJson('/api/v1/payments?include=invoices', $data);
|
||||
|
||||
$arr = $response->json();
|
||||
$response->assertStatus(200);
|
||||
@ -691,16 +754,17 @@ class PaymentTest extends TestCase
|
||||
'date' => '2019/12/12',
|
||||
];
|
||||
|
||||
try {
|
||||
// try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments?include=invoices', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
])->postJson('/api/v1/payments?include=invoices', $data);
|
||||
// } catch (ValidationException $e) {
|
||||
// $message = json_decode($e->validator->getMessageBag(), 1);
|
||||
$response->assertStatus(422);
|
||||
|
||||
$this->assertTrue(array_key_exists('amount', $message));
|
||||
}
|
||||
// $this->assertTrue(array_key_exists('amount', $message));
|
||||
// }
|
||||
}
|
||||
|
||||
public function testPaymentChangesBalancesCorrectly()
|
||||
@ -745,18 +809,18 @@ class PaymentTest extends TestCase
|
||||
|
||||
$response = false;
|
||||
|
||||
try {
|
||||
// try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments?include=invoices', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
])->postJson('/api/v1/payments?include=invoices', $data);
|
||||
// } catch (ValidationException $e) {
|
||||
// $message = json_decode($e->validator->getMessageBag(), 1);
|
||||
|
||||
$this->assertTrue(array_key_exists('amount', $message));
|
||||
}
|
||||
// $this->assertTrue(array_key_exists('amount', $message));
|
||||
// }
|
||||
|
||||
if ($response) {
|
||||
// if ($response) {
|
||||
$response->assertStatus(200);
|
||||
|
||||
$invoice = Invoice::find($this->decodePrimaryKey($invoice->hashed_id));
|
||||
@ -766,7 +830,7 @@ class PaymentTest extends TestCase
|
||||
$payment = $invoice->payments()->first();
|
||||
|
||||
$this->assertEquals($payment->applied, 2);
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
public function testUpdatePaymentValidationWorks()
|
||||
@ -812,20 +876,20 @@ class PaymentTest extends TestCase
|
||||
|
||||
$response = false;
|
||||
|
||||
try {
|
||||
// try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/payments/'.$this->encodePrimaryKey($payment->id), $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
])->putJson('/api/v1/payments/'.$this->encodePrimaryKey($payment->id), $data);
|
||||
// } catch (ValidationException $e) {
|
||||
// $message = json_decode($e->validator->getMessageBag(), 1);
|
||||
|
||||
$this->assertTrue(array_key_exists('invoices', $message));
|
||||
}
|
||||
// $this->assertTrue(array_key_exists('invoices', $message));
|
||||
// }/
|
||||
|
||||
if ($response) {
|
||||
// if ($response) {
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
public function testUpdatePaymentValidationPasses()
|
||||
@ -876,21 +940,21 @@ class PaymentTest extends TestCase
|
||||
|
||||
$response = false;
|
||||
|
||||
try {
|
||||
// try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/payments/'.$this->encodePrimaryKey($payment->id), $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
\Log::error(print_r($e->validator->getMessageBag(), 1));
|
||||
])->putJson('/api/v1/payments/'.$this->encodePrimaryKey($payment->id), $data);
|
||||
// } catch (ValidationException $e) {
|
||||
// $message = json_decode($e->validator->getMessageBag(), 1);
|
||||
// \Log::error(print_r($e->validator->getMessageBag(), 1));
|
||||
|
||||
$this->assertTrue(array_key_exists('invoices', $message));
|
||||
}
|
||||
// $this->assertTrue(array_key_exists('invoices', $message));
|
||||
// }
|
||||
|
||||
if ($response) {
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
// if ($response) {
|
||||
$response->assertStatus(422);
|
||||
// }
|
||||
}
|
||||
|
||||
public function testDoublePaymentTestWithInvalidAmounts()
|
||||
@ -935,15 +999,15 @@ class PaymentTest extends TestCase
|
||||
|
||||
$response = false;
|
||||
|
||||
try {
|
||||
// try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments/', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
\Log::error(print_r($e->validator->getMessageBag(), 1));
|
||||
}
|
||||
])->postJson('/api/v1/payments/', $data);
|
||||
// } catch (ValidationException $e) {
|
||||
// $message = json_decode($e->validator->getMessageBag(), 1);
|
||||
// \Log::error(print_r($e->validator->getMessageBag(), 1));
|
||||
// }
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
@ -990,7 +1054,7 @@ class PaymentTest extends TestCase
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/payments/'.$this->encodePrimaryKey($payment->id), $data);
|
||||
])->putJson('/api/v1/payments/'.$this->encodePrimaryKey($payment->id), $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
|
||||
@ -1040,7 +1104,7 @@ class PaymentTest extends TestCase
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments/', $data);
|
||||
])->postJson('/api/v1/payments/', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
@ -1099,7 +1163,7 @@ class PaymentTest extends TestCase
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments?include=invoices', $data);
|
||||
])->postJson('/api/v1/payments?include=invoices', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
$this->assertNotNull($message);
|
||||
@ -1163,7 +1227,7 @@ class PaymentTest extends TestCase
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments?include=invoices', $data);
|
||||
])->postJson('/api/v1/payments?include=invoices', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
$this->assertNotNull($message);
|
||||
@ -1250,7 +1314,7 @@ class PaymentTest extends TestCase
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments?include=invoices', $data);
|
||||
])->postJson('/api/v1/payments?include=invoices', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
$this->assertNotNull($message);
|
||||
@ -1299,19 +1363,15 @@ class PaymentTest extends TestCase
|
||||
|
||||
];
|
||||
|
||||
$response = null;
|
||||
|
||||
try {
|
||||
$response = $this->withHeaders([
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments?include=invoices', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
$this->assertNotNull($message);
|
||||
}
|
||||
])->postJson('/api/v1/payments?include=invoices', $data);
|
||||
|
||||
$response->assertStatus(422);
|
||||
|
||||
$this->assertNull($response);
|
||||
|
||||
}
|
||||
|
||||
public function testStorePaymentWithCredits()
|
||||
@ -1351,7 +1411,7 @@ class PaymentTest extends TestCase
|
||||
$credit_calc = new InvoiceSum($credit);
|
||||
$credit_calc->build();
|
||||
|
||||
$credit = $this->credit_calc->getCredit();
|
||||
$credit = $credit_calc->getCredit();
|
||||
$credit->save(); //$10 credit
|
||||
|
||||
$data = [
|
||||
@ -1365,7 +1425,7 @@ class PaymentTest extends TestCase
|
||||
],
|
||||
'credits' => [
|
||||
[
|
||||
'credit_id' => $credit->id,
|
||||
'credit_id' => $credit->hashed_id,
|
||||
'amount' => 5,
|
||||
],
|
||||
],
|
||||
@ -1373,30 +1433,22 @@ class PaymentTest extends TestCase
|
||||
|
||||
];
|
||||
|
||||
$response = null;
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->postJson('/api/v1/payments?include=invoices', $data);
|
||||
|
||||
try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments?include=invoices', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
$this->assertNotNull($message);
|
||||
}
|
||||
$arr = $response->json();
|
||||
$response->assertStatus(200);
|
||||
|
||||
if ($response) {
|
||||
$arr = $response->json();
|
||||
$response->assertStatus(200);
|
||||
$payment_id = $arr['data']['id'];
|
||||
|
||||
$payment_id = $arr['data']['id'];
|
||||
$payment = Payment::find($this->decodePrimaryKey($payment_id));
|
||||
|
||||
$this->assertNotNull($payment);
|
||||
$this->assertNotNull($payment->invoices());
|
||||
$this->assertEquals(1, $payment->invoices()->count());
|
||||
|
||||
$payment = Payment::find($this->decodePrimaryKey($payment_id))->first();
|
||||
|
||||
$this->assertNotNull($payment);
|
||||
$this->assertNotNull($payment->invoices());
|
||||
$this->assertEquals(1, $payment->invoices()->count());
|
||||
}
|
||||
}
|
||||
|
||||
public function testStorePaymentExchangeRate()
|
||||
@ -1443,30 +1495,22 @@ class PaymentTest extends TestCase
|
||||
|
||||
];
|
||||
|
||||
$response = null;
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->postJson('/api/v1/payments?include=invoices', $data);
|
||||
|
||||
try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments?include=invoices', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
$this->assertNotNull($message);
|
||||
}
|
||||
$arr = $response->json();
|
||||
$response->assertStatus(200);
|
||||
|
||||
if ($response) {
|
||||
$arr = $response->json();
|
||||
$response->assertStatus(200);
|
||||
$payment_id = $arr['data']['id'];
|
||||
|
||||
$payment_id = $arr['data']['id'];
|
||||
$payment = Payment::find($this->decodePrimaryKey($payment_id));
|
||||
|
||||
$payment = Payment::find($this->decodePrimaryKey($payment_id));
|
||||
$this->assertNotNull($payment);
|
||||
$this->assertNotNull($payment->invoices());
|
||||
$this->assertEquals(1, $payment->invoices()->count());
|
||||
|
||||
$this->assertNotNull($payment);
|
||||
$this->assertNotNull($payment->invoices());
|
||||
$this->assertEquals(1, $payment->invoices()->count());
|
||||
}
|
||||
}
|
||||
|
||||
public function testPaymentActionArchive()
|
||||
@ -1512,7 +1556,7 @@ class PaymentTest extends TestCase
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments/', $data);
|
||||
])->postJson('/api/v1/payments/', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
@ -1529,7 +1573,7 @@ class PaymentTest extends TestCase
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments/bulk?action=archive', $data);
|
||||
])->postJson('/api/v1/payments/bulk?action=archive', $data);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
@ -1538,7 +1582,7 @@ class PaymentTest extends TestCase
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments/bulk?action=restore', $data);
|
||||
])->postJson('/api/v1/payments/bulk?action=restore', $data);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
@ -1547,7 +1591,7 @@ class PaymentTest extends TestCase
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments/bulk?action=delete', $data);
|
||||
])->postJson('/api/v1/payments/bulk?action=delete', $data);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
@ -1618,17 +1662,11 @@ class PaymentTest extends TestCase
|
||||
],
|
||||
];
|
||||
|
||||
$response = false;
|
||||
|
||||
try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments/refund', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
nlog($message);
|
||||
}
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->postJson('/api/v1/payments/refund', $data);
|
||||
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
@ -1644,7 +1682,7 @@ class PaymentTest extends TestCase
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments/bulk?action=delete', $data);
|
||||
])->postJson('/api/v1/payments/bulk?action=delete', $data);
|
||||
|
||||
$this->assertEquals(10, $invoice->fresh()->balance);
|
||||
$this->assertEquals(10, $invoice->fresh()->balance);
|
||||
@ -1659,34 +1697,18 @@ class PaymentTest extends TestCase
|
||||
'number' => 'duplicate',
|
||||
];
|
||||
|
||||
try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
nlog($message);
|
||||
}
|
||||
|
||||
$arr = $response->json();
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->postJson('/api/v1/payments', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$response = false;
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->postJson('/api/v1/payments', $data);
|
||||
|
||||
try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
nlog($message);
|
||||
}
|
||||
|
||||
if ($response) {
|
||||
$response->assertStatus(302);
|
||||
}
|
||||
$response->assertStatus(422);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user