Merge pull request #8806 from turbo124/v5-develop

Checks for missing props
This commit is contained in:
David Bomba 2023-09-18 11:20:22 +10:00 committed by GitHub
commit e0dcc9c117
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 297 additions and 243 deletions

View File

@ -36,6 +36,7 @@ class RecurringExpenseFactory
$recurring_expense->tax_amount3 = 0; $recurring_expense->tax_amount3 = 0;
$recurring_expense->date = now()->format('Y-m-d'); $recurring_expense->date = now()->format('Y-m-d');
$recurring_expense->next_send_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->payment_date = null;
$recurring_expense->amount = 0; $recurring_expense->amount = 0;
$recurring_expense->foreign_amount = 0; $recurring_expense->foreign_amount = 0;

View File

@ -11,13 +11,14 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Exceptions\FilePermissionsFailure;
use App\Utils\Ninja; use App\Utils\Ninja;
use App\Models\Company;
use App\Utils\Traits\AppSetup; use App\Utils\Traits\AppSetup;
use App\Utils\Traits\ClientGroupSettingsSaver;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use App\Exceptions\FilePermissionsFailure;
use Illuminate\Foundation\Bus\DispatchesJobs;
use App\Utils\Traits\ClientGroupSettingsSaver;
class SelfUpdateController extends BaseController class SelfUpdateController extends BaseController
{ {
@ -109,11 +110,33 @@ class SelfUpdateController extends BaseController
$this->buildCache(true); $this->buildCache(true);
$this->runModelChecks();
nlog('Called Artisan commands'); nlog('Called Artisan commands');
return response()->json(['message' => 'Update completed'], 200); 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() private function clearCacheDir()
{ {
$directoryIterator = new \RecursiveDirectoryIterator(base_path('bootstrap/cache'), \RecursiveDirectoryIterator::SKIP_DOTS); $directoryIterator = new \RecursiveDirectoryIterator(base_path('bootstrap/cache'), \RecursiveDirectoryIterator::SKIP_DOTS);

View File

@ -195,15 +195,15 @@ class PdfSlot extends Component
} }
elseif($this->entity_type == 'quote'){ 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>"; $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') { 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>"; $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'){ 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>"; $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>";
} }

View File

@ -90,6 +90,12 @@ class PaymentAppliedValidAmount implements Rule
return false; 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)) { if (round($payment_amounts, 3) >= round($invoice_amounts, 3)) {

View File

@ -175,10 +175,10 @@ class Gateway extends StaticModel
]; ];
case 52: case 52:
return [ return [
GatewayType::BANK_TRANSFER => ['refund' => false, 'token_billing' => true, 'webhooks' => [' ']], // GoCardless GatewayType::BANK_TRANSFER => ['refund' => false, 'token_billing' => true, 'webhooks' => ['confirmed','paid_out','failed','fulfilled']], // GoCardless
GatewayType::DIRECT_DEBIT => ['refund' => false, 'token_billing' => true, 'webhooks' => [' ']], GatewayType::DIRECT_DEBIT => ['refund' => false, 'token_billing' => true, 'webhooks' => ['confirmed','paid_out','failed','fulfilled']],
GatewayType::SEPA => ['refund' => false, 'token_billing' => true, 'webhooks' => [' ']], GatewayType::SEPA => ['refund' => false, 'token_billing' => true, 'webhooks' => ['confirmed','paid_out','failed','fulfilled']],
GatewayType::INSTANT_BANK_PAY => ['refund' => false, 'token_billing' => true, 'webhooks' => [' ']], GatewayType::INSTANT_BANK_PAY => ['refund' => false, 'token_billing' => true, 'webhooks' => ['confirmed','paid_out','failed','fulfilled']],
]; ];
case 58: case 58:
return [ return [

View File

@ -75,18 +75,20 @@ class TaxProvider
*/ */
public function updateCompanyTaxData(): self 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 { 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 = new $this->provider($company_details);
$tax_provider->setApiCredentials($this->api_credentials); $tax_provider->setApiCredentials($this->api_credentials);
@ -143,7 +145,7 @@ class TaxProvider
$tax_data = $tax_provider->run(); $tax_data = $tax_provider->run();
nlog($tax_data); // nlog($tax_data);
if($tax_data) { if($tax_data) {
$this->client->tax_data = $tax_data; $this->client->tax_data = $tax_data;

48
composer.lock generated
View File

@ -525,16 +525,16 @@
}, },
{ {
"name": "aws/aws-sdk-php", "name": "aws/aws-sdk-php",
"version": "3.281.7", "version": "3.281.8",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/aws/aws-sdk-php.git", "url": "https://github.com/aws/aws-sdk-php.git",
"reference": "926cea9a41a545ca9801ac304f2a9ffd23ac68c9" "reference": "eb349b9f31502a05c70362f57913b9fed6b65b1f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/926cea9a41a545ca9801ac304f2a9ffd23ac68c9", "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/eb349b9f31502a05c70362f57913b9fed6b65b1f",
"reference": "926cea9a41a545ca9801ac304f2a9ffd23ac68c9", "reference": "eb349b9f31502a05c70362f57913b9fed6b65b1f",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -614,9 +614,9 @@
"support": { "support": {
"forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
"issues": "https://github.com/aws/aws-sdk-php/issues", "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", "name": "bacon/bacon-qr-code",
@ -8062,16 +8062,16 @@
}, },
{ {
"name": "phpseclib/phpseclib", "name": "phpseclib/phpseclib",
"version": "3.0.21", "version": "3.0.22",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpseclib/phpseclib.git", "url": "https://github.com/phpseclib/phpseclib.git",
"reference": "4580645d3fc05c189024eb3b834c6c1e4f0f30a1" "reference": "b6bd1c5f79b2c39e144770eb6d9180fbdb00d09b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/4580645d3fc05c189024eb3b834c6c1e4f0f30a1", "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/b6bd1c5f79b2c39e144770eb6d9180fbdb00d09b",
"reference": "4580645d3fc05c189024eb3b834c6c1e4f0f30a1", "reference": "b6bd1c5f79b2c39e144770eb6d9180fbdb00d09b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -8152,7 +8152,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/phpseclib/phpseclib/issues", "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": [ "funding": [
{ {
@ -8168,7 +8168,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-07-09T15:24:48+00:00" "time": "2023-09-16T11:49:37+00:00"
}, },
{ {
"name": "phpstan/phpdoc-parser", "name": "phpstan/phpdoc-parser",
@ -10112,16 +10112,16 @@
}, },
{ {
"name": "spatie/laravel-data", "name": "spatie/laravel-data",
"version": "3.8.1", "version": "3.9.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/spatie/laravel-data.git", "url": "https://github.com/spatie/laravel-data.git",
"reference": "7ead3d8f761846185a94d06e584bfe17e43b9239" "reference": "21bad55113a1e1e5180a0f89b695f02ce1732aef"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/spatie/laravel-data/zipball/7ead3d8f761846185a94d06e584bfe17e43b9239", "url": "https://api.github.com/repos/spatie/laravel-data/zipball/21bad55113a1e1e5180a0f89b695f02ce1732aef",
"reference": "7ead3d8f761846185a94d06e584bfe17e43b9239", "reference": "21bad55113a1e1e5180a0f89b695f02ce1732aef",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -10183,7 +10183,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/spatie/laravel-data/issues", "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": [ "funding": [
{ {
@ -10191,7 +10191,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2023-08-11T11:59:07+00:00" "time": "2023-09-15T12:04:39+00:00"
}, },
{ {
"name": "spatie/laravel-package-tools", "name": "spatie/laravel-package-tools",
@ -15793,16 +15793,16 @@
}, },
{ {
"name": "phpmyadmin/sql-parser", "name": "phpmyadmin/sql-parser",
"version": "5.8.0", "version": "5.8.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpmyadmin/sql-parser.git", "url": "https://github.com/phpmyadmin/sql-parser.git",
"reference": "db1b3069b5dbc220d393d67ff911e0ae76732755" "reference": "b877ee6262a00f0f498da5e01335e8a5dc01d203"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpmyadmin/sql-parser/zipball/db1b3069b5dbc220d393d67ff911e0ae76732755", "url": "https://api.github.com/repos/phpmyadmin/sql-parser/zipball/b877ee6262a00f0f498da5e01335e8a5dc01d203",
"reference": "db1b3069b5dbc220d393d67ff911e0ae76732755", "reference": "b877ee6262a00f0f498da5e01335e8a5dc01d203",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -15824,7 +15824,7 @@
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
"psalm/plugin-phpunit": "^0.16.1", "psalm/plugin-phpunit": "^0.16.1",
"vimeo/psalm": "^4.11", "vimeo/psalm": "^4.11",
"zumba/json-serializer": "^3.0" "zumba/json-serializer": "~3.0.2"
}, },
"suggest": { "suggest": {
"ext-mbstring": "For best performance", "ext-mbstring": "For best performance",
@ -15876,7 +15876,7 @@
"type": "other" "type": "other"
} }
], ],
"time": "2023-06-05T18:19:38+00:00" "time": "2023-09-15T18:21:22+00:00"
}, },
{ {
"name": "phpstan/phpstan", "name": "phpstan/phpstan",

View File

@ -42,6 +42,8 @@ class PaymentTest extends TestCase
use DatabaseTransactions; use DatabaseTransactions;
use MockAccountData; use MockAccountData;
public $faker;
protected function setUp() :void protected function setUp() :void
{ {
parent::setUp(); parent::setUp();
@ -53,13 +55,80 @@ class PaymentTest extends TestCase
Model::reguard(); Model::reguard();
$this->makeTestData(); $this->makeTestData();
$this->withoutExceptionHandling(); // $this->withoutExceptionHandling();
$this->withoutMiddleware( $this->withoutMiddleware(
ThrottleRequests::class 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() public function testPaymentGetBetweenQuery1()
{ {
$response = $this->withHeaders([ $response = $this->withHeaders([
@ -185,16 +254,15 @@ class PaymentTest extends TestCase
]; ];
$response = false; $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);
}
$this->assertFalse($response); $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);
} }
@ -245,7 +313,7 @@ class PaymentTest extends TestCase
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, '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); $response->assertStatus(200);
@ -287,16 +355,17 @@ class PaymentTest extends TestCase
]; ];
try {
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments/', $data); ])->postJson('/api/v1/payments/', $data);
} catch (ValidationException $e) { // } catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1); // $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() public function testStorePaymentWithClientId()
@ -339,15 +408,17 @@ class PaymentTest extends TestCase
$response = null; $response = null;
try { // try {
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments?include=invoices,paymentables', $data); ])->postJson('/api/v1/payments?include=invoices,paymentables', $data);
} catch (ValidationException $e) { // } catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1); // $message = json_decode($e->validator->getMessageBag(), 1);
$this->assertNotNull($message); // $this->assertNotNull($message);
} // }
if ($response) { if ($response) {
$arr = $response->json(); $arr = $response->json();
@ -399,19 +470,19 @@ class PaymentTest extends TestCase
$response = false; $response = false;
try { // try {
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments?include=invoices', $data); ])->postJson('/api/v1/payments?include=invoices', $data);
} catch (ValidationException $e) { // } catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1); // $message = json_decode($e->validator->getMessageBag(), 1);
$this->assertNotNull($message); // $this->assertNotNull($message);
} // }
if ($response) { // if ($response) {
$response->assertStatus(200); $response->assertStatus(200);
} // }
} }
public function testPartialPaymentAmount() public function testPartialPaymentAmount()
@ -455,37 +526,29 @@ class PaymentTest extends TestCase
'date' => '2019/12/12', '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);
try { $response->assertStatus(200);
$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);
}
if ($response) { $arr = $response->json();
$response->assertStatus(200);
$arr = $response->json(); $payment_id = $arr['data']['id'];
$payment_id = $arr['data']['id']; $payment = Payment::whereId($this->decodePrimaryKey($payment_id))->first();
$payment = Payment::whereId($this->decodePrimaryKey($payment_id))->first(); $this->assertNotNull($payment);
$this->assertNotNull($payment->invoices());
$this->assertEquals(1, $payment->invoices()->count());
$this->assertNotNull($payment); $pivot_invoice = $payment->invoices()->first();
$this->assertNotNull($payment->invoices()); $this->assertEquals($pivot_invoice->pivot->amount, 2);
$this->assertEquals(1, $payment->invoices()->count()); $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() public function testPaymentGreaterThanPartial()
@ -539,14 +602,14 @@ class PaymentTest extends TestCase
$response = false; $response = false;
try { // try {
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments?include=invoices', $data); ])->postJson('/api/v1/payments?include=invoices', $data);
} catch (ValidationException $e) { // } catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1); // $message = json_decode($e->validator->getMessageBag(), 1);
} // }
$arr = $response->json(); $arr = $response->json();
$response->assertStatus(200); $response->assertStatus(200);
@ -618,7 +681,7 @@ class PaymentTest extends TestCase
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments?include=invoices', $data); ])->postJson('/api/v1/payments?include=invoices', $data);
$arr = $response->json(); $arr = $response->json();
$response->assertStatus(200); $response->assertStatus(200);
@ -691,16 +754,17 @@ class PaymentTest extends TestCase
'date' => '2019/12/12', 'date' => '2019/12/12',
]; ];
try { // try {
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments?include=invoices', $data); ])->postJson('/api/v1/payments?include=invoices', $data);
} catch (ValidationException $e) { // } catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1); // $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() public function testPaymentChangesBalancesCorrectly()
@ -745,18 +809,18 @@ class PaymentTest extends TestCase
$response = false; $response = false;
try { // try {
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments?include=invoices', $data); ])->postJson('/api/v1/payments?include=invoices', $data);
} catch (ValidationException $e) { // } catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1); // $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); $response->assertStatus(200);
$invoice = Invoice::find($this->decodePrimaryKey($invoice->hashed_id)); $invoice = Invoice::find($this->decodePrimaryKey($invoice->hashed_id));
@ -766,7 +830,7 @@ class PaymentTest extends TestCase
$payment = $invoice->payments()->first(); $payment = $invoice->payments()->first();
$this->assertEquals($payment->applied, 2); $this->assertEquals($payment->applied, 2);
} // }
} }
public function testUpdatePaymentValidationWorks() public function testUpdatePaymentValidationWorks()
@ -812,20 +876,20 @@ class PaymentTest extends TestCase
$response = false; $response = false;
try { // try {
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, '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) { // } catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1); // $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); $response->assertStatus(200);
} // }
} }
public function testUpdatePaymentValidationPasses() public function testUpdatePaymentValidationPasses()
@ -876,21 +940,21 @@ class PaymentTest extends TestCase
$response = false; $response = false;
try { // try {
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, '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) { // } catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1); // $message = json_decode($e->validator->getMessageBag(), 1);
\Log::error(print_r($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) { // if ($response) {
$response->assertStatus(200); $response->assertStatus(422);
} // }
} }
public function testDoublePaymentTestWithInvalidAmounts() public function testDoublePaymentTestWithInvalidAmounts()
@ -935,15 +999,15 @@ class PaymentTest extends TestCase
$response = false; $response = false;
try { // try {
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments/', $data); ])->postJson('/api/v1/payments/', $data);
} catch (ValidationException $e) { // } catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1); // $message = json_decode($e->validator->getMessageBag(), 1);
\Log::error(print_r($e->validator->getMessageBag(), 1)); // \Log::error(print_r($e->validator->getMessageBag(), 1));
} // }
$response->assertStatus(200); $response->assertStatus(200);
@ -990,7 +1054,7 @@ class PaymentTest extends TestCase
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, '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) { } catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1); $message = json_decode($e->validator->getMessageBag(), 1);
@ -1040,7 +1104,7 @@ class PaymentTest extends TestCase
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments/', $data); ])->postJson('/api/v1/payments/', $data);
$response->assertStatus(200); $response->assertStatus(200);
@ -1099,7 +1163,7 @@ class PaymentTest extends TestCase
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments?include=invoices', $data); ])->postJson('/api/v1/payments?include=invoices', $data);
} catch (ValidationException $e) { } catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1); $message = json_decode($e->validator->getMessageBag(), 1);
$this->assertNotNull($message); $this->assertNotNull($message);
@ -1163,7 +1227,7 @@ class PaymentTest extends TestCase
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments?include=invoices', $data); ])->postJson('/api/v1/payments?include=invoices', $data);
} catch (ValidationException $e) { } catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1); $message = json_decode($e->validator->getMessageBag(), 1);
$this->assertNotNull($message); $this->assertNotNull($message);
@ -1250,7 +1314,7 @@ class PaymentTest extends TestCase
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments?include=invoices', $data); ])->postJson('/api/v1/payments?include=invoices', $data);
} catch (ValidationException $e) { } catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1); $message = json_decode($e->validator->getMessageBag(), 1);
$this->assertNotNull($message); $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-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, '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); $response->assertStatus(422);
$this->assertNotNull($message);
}
$this->assertNull($response);
} }
public function testStorePaymentWithCredits() public function testStorePaymentWithCredits()
@ -1351,7 +1411,7 @@ class PaymentTest extends TestCase
$credit_calc = new InvoiceSum($credit); $credit_calc = new InvoiceSum($credit);
$credit_calc->build(); $credit_calc->build();
$credit = $this->credit_calc->getCredit(); $credit = $credit_calc->getCredit();
$credit->save(); //$10 credit $credit->save(); //$10 credit
$data = [ $data = [
@ -1365,7 +1425,7 @@ class PaymentTest extends TestCase
], ],
'credits' => [ 'credits' => [
[ [
'credit_id' => $credit->id, 'credit_id' => $credit->hashed_id,
'amount' => 5, '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 { $arr = $response->json();
$response = $this->withHeaders([ $response->assertStatus(200);
'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);
}
if ($response) { $payment_id = $arr['data']['id'];
$arr = $response->json();
$response->assertStatus(200);
$payment_id = $arr['data']['id']; $payment = Payment::find($this->decodePrimaryKey($payment_id));
$payment = Payment::find($this->decodePrimaryKey($payment_id))->first(); $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 testStorePaymentExchangeRate() 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 { $arr = $response->json();
$response = $this->withHeaders([ $response->assertStatus(200);
'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);
}
if ($response) { $payment_id = $arr['data']['id'];
$arr = $response->json();
$response->assertStatus(200);
$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() public function testPaymentActionArchive()
@ -1512,7 +1556,7 @@ class PaymentTest extends TestCase
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments/', $data); ])->postJson('/api/v1/payments/', $data);
$response->assertStatus(200); $response->assertStatus(200);
@ -1529,7 +1573,7 @@ class PaymentTest extends TestCase
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments/bulk?action=archive', $data); ])->postJson('/api/v1/payments/bulk?action=archive', $data);
$arr = $response->json(); $arr = $response->json();
@ -1538,7 +1582,7 @@ class PaymentTest extends TestCase
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments/bulk?action=restore', $data); ])->postJson('/api/v1/payments/bulk?action=restore', $data);
$arr = $response->json(); $arr = $response->json();
@ -1547,7 +1591,7 @@ class PaymentTest extends TestCase
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments/bulk?action=delete', $data); ])->postJson('/api/v1/payments/bulk?action=delete', $data);
$arr = $response->json(); $arr = $response->json();
@ -1618,17 +1662,11 @@ class PaymentTest extends TestCase
], ],
]; ];
$response = false; $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/payments/refund', $data);
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);
}
$arr = $response->json(); $arr = $response->json();
@ -1644,7 +1682,7 @@ class PaymentTest extends TestCase
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, '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);
$this->assertEquals(10, $invoice->fresh()->balance); $this->assertEquals(10, $invoice->fresh()->balance);
@ -1659,34 +1697,18 @@ class PaymentTest extends TestCase
'number' => 'duplicate', 'number' => 'duplicate',
]; ];
try { $response = $this->withHeaders([
$response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token,
'X-API-TOKEN' => $this->token, ])->postJson('/api/v1/payments', $data);
])->post('/api/v1/payments', $data);
} catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1);
nlog($message);
}
$arr = $response->json();
$response->assertStatus(200); $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->assertStatus(422);
$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);
}
} }
} }