Fixes for inbound validation of payments

This commit is contained in:
David Bomba 2024-09-26 16:06:16 +10:00
parent 6afcb90ba4
commit 5732794681
3 changed files with 45 additions and 8 deletions

View File

@ -107,7 +107,7 @@ class StorePaymentRequest extends Request
$input['invoices'][$key]['invoice_id'] = $this->decodePrimaryKey($value['invoice_id']); $input['invoices'][$key]['invoice_id'] = $this->decodePrimaryKey($value['invoice_id']);
} }
if (array_key_exists('amount', $value)) { if (array_key_exists('amount', $value) && is_numeric($value['amount'])) {
$invoices_total += $value['amount']; $invoices_total += $value['amount'];
} }
} }
@ -121,10 +121,13 @@ class StorePaymentRequest extends Request
foreach ($input['credits'] as $key => $value) { foreach ($input['credits'] as $key => $value) {
if (isset($value['credit_id']) && is_string($value['credit_id'])) { if (isset($value['credit_id']) && is_string($value['credit_id'])) {
$input['credits'][$key]['credit_id'] = $this->decodePrimaryKey($value['credit_id']); $input['credits'][$key]['credit_id'] = $this->decodePrimaryKey($value['credit_id']);
if (array_key_exists('amount', $value) && is_numeric($value['amount'])) {
$credits_total += $value['amount']; $credits_total += $value['amount'];
} }
} }
} }
}
if (isset($input['credits']) && is_array($input['credits']) === false) { if (isset($input['credits']) && is_array($input['credits']) === false) {
$input['credits'] = null; $input['credits'] = null;

View File

@ -52,13 +52,15 @@ class QuickbooksTest extends TestCase
$this->faker = \Faker\Factory::create(); $this->faker = \Faker\Factory::create();
} }
public function createQbProduct() public function createQbProduct()
{ {
$service_product = Product::factory()->create([ $service_product = Product::factory()->create([
'company_id' => $this->company->id, 'company_id' => $this->company->id,
'user_id' => $this->company->owner()->id, 'user_id' => $this->company->owner()->id,
'notes' => $this->faker->sentence(), 'notes' => $this->faker->sentence(),
'product_key' => $this->faker->word(63), 'product_key' => \Illuminate\Support\Str::random(64),
'tax_id' => 2, 'tax_id' => 2,
]); ]);
@ -67,7 +69,7 @@ class QuickbooksTest extends TestCase
'company_id' => $this->company->id, 'company_id' => $this->company->id,
'user_id' => $this->company->owner()->id, 'user_id' => $this->company->owner()->id,
'notes' => $this->faker->sentence(), 'notes' => $this->faker->sentence(),
'product_key' => $this->faker->word(63), 'product_key' => \Illuminate\Support\Str::random(64),
'tax_id' => 1, 'tax_id' => 1,
]); ]);
@ -347,14 +349,14 @@ class QuickbooksTest extends TestCase
"DueDate" => $i->due_date, "DueDate" => $i->due_date,
"TotalAmt" => $i->amount, "TotalAmt" => $i->amount,
"DocNumber" => $i->number, "DocNumber" => $i->number,
"ApplyTaxAfterDiscount" => false, // "ApplyTaxAfterDiscount" => false,
"GlobalTaxCalculation" => "TaxExcluded", // This tells QuickBooks to calculate taxes "GlobalTaxCalculation" => "TaxExcluded", // This tells QuickBooks to calculate taxes
"TxnTaxDetail" => [ "TxnTaxDetail" => [
"UseAutomatedSalesTax" => true, "UseAutomatedSalesTax" => true,
// "TxnTaxCodeRef" => [ "TxnTaxCodeRef" => [
// "value" => "TAX" // Use the appropriate tax code for your QuickBooks account "value" => "SALES_TAX_STUB" // Use the appropriate tax code for your QuickBooks account
// "DefaultTaxRateRef" => [ // "DefaultTaxRateRef" => [
// ] ],
] ]
// "Note" => $this->invoice->public_notes, // "Note" => $this->invoice->public_notes,
]; ];

View File

@ -62,6 +62,38 @@ class PaymentTest extends TestCase
); );
} }
public function testNullPaymentAmounts()
{
$data = [
'amount' => "null",
'client_id' => "null",
'invoices' => [
[
'invoice_id' => $this->invoice->hashed_id,
'amount' => "null",
],
],
'credits' => [
[
'credit_id' => $this->invoice->hashed_id,
'amount' => "null",
],
],
'date' => '2020/12/11',
'idempotency_key' => 'xx',
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/payments/', $data);
$response->assertStatus(422);
}
public function testIdempotencyTrigger() public function testIdempotencyTrigger()
{ {