1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

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']);
}
if (array_key_exists('amount', $value)) {
if (array_key_exists('amount', $value) && is_numeric($value['amount'])) {
$invoices_total += $value['amount'];
}
}
@ -121,7 +121,10 @@ class StorePaymentRequest extends Request
foreach ($input['credits'] as $key => $value) {
if (isset($value['credit_id']) && is_string($value['credit_id'])) {
$input['credits'][$key]['credit_id'] = $this->decodePrimaryKey($value['credit_id']);
$credits_total += $value['amount'];
if (array_key_exists('amount', $value) && is_numeric($value['amount'])) {
$credits_total += $value['amount'];
}
}
}
}

View File

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