mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Updates for stripe lookup
This commit is contained in:
parent
ccf8b57f30
commit
9846effc47
@ -93,7 +93,7 @@ class InvoiceTransformer extends BaseTransformer
|
||||
'invoice.custom_value4'
|
||||
),
|
||||
'footer' => $this->getString($invoice_data, 'invoice.footer'),
|
||||
'partial' => $this->getFloat($invoice_data, 'invoice.partial') > 0 ?: null,
|
||||
'partial' => $this->getFloat($invoice_data, 'invoice.partial') > 0 ? $this->getFloat($invoice_data, 'invoice.partial') : null,
|
||||
'partial_due_date' => isset($invoice_data['invoice.partial_due_date']) ? $this->parseDate($invoice_data['invoice.partial_due_date']) : null,
|
||||
'custom_surcharge1' => $this->getFloat(
|
||||
$invoice_data,
|
||||
|
@ -99,7 +99,7 @@ class RecurringInvoiceTransformer extends BaseTransformer
|
||||
'invoice.custom_value4'
|
||||
),
|
||||
'footer' => $this->getString($invoice_data, 'invoice.footer'),
|
||||
'partial' => $this->getFloat($invoice_data, 'invoice.partial') > 0 ?: null,
|
||||
'partial' => $this->getFloat($invoice_data, 'invoice.partial') > 0 ? $this->getFloat($invoice_data, 'invoice.partial') : null,
|
||||
'partial_due_date' => isset($invoice_data['invoice.partial_due_date']) ? $this->parseDate($invoice_data['invoice.partial_due_date']) : null,
|
||||
'custom_surcharge1' => $this->getString(
|
||||
$invoice_data,
|
||||
|
@ -57,20 +57,17 @@ class PaymentIntentFailureWebhook implements ShouldQueue
|
||||
$company = Company::query()->where('company_key', $this->company_key)->first();
|
||||
|
||||
foreach ($this->stripe_request as $transaction) {
|
||||
if (array_key_exists('payment_intent', $transaction)) {
|
||||
$payment = Payment::query()
|
||||
->where('company_id', $company->id)
|
||||
->where(function ($query) use ($transaction) {
|
||||
$query->where('transaction_reference', $transaction['payment_intent'])
|
||||
->orWhere('transaction_reference', $transaction['id']);
|
||||
})
|
||||
->first();
|
||||
} else {
|
||||
$payment = Payment::query()
|
||||
->where('company_id', $company->id)
|
||||
->where('transaction_reference', $transaction['id'])
|
||||
->first();
|
||||
}
|
||||
|
||||
|
||||
$payment = Payment::query()
|
||||
->where('company_id', $company->id)
|
||||
->when(isset($transaction['payment_intent']), function ($query) use ($transaction) {
|
||||
$query->where('transaction_reference', $transaction['payment_intent']);
|
||||
})
|
||||
->when(isset($transaction['id']), function ($query) use ($transaction) {
|
||||
$query->where('transaction_reference', $transaction['id']);
|
||||
})
|
||||
->first();
|
||||
|
||||
if ($payment) {
|
||||
$client = $payment->client;
|
||||
|
@ -64,17 +64,17 @@ class PaymentIntentProcessingWebhook implements ShouldQueue
|
||||
$company = Company::query()->where('company_key', $this->company_key)->first();
|
||||
|
||||
foreach ($this->stripe_request as $transaction) {
|
||||
if (array_key_exists('payment_intent', $transaction)) {
|
||||
$payment = Payment::query()
|
||||
->where('company_id', $company->id)
|
||||
->where('transaction_reference', $transaction['payment_intent'])
|
||||
->first();
|
||||
} else {
|
||||
$payment = Payment::query()
|
||||
->where('company_id', $company->id)
|
||||
->where('transaction_reference', $transaction['id'])
|
||||
->first();
|
||||
}
|
||||
|
||||
$payment = Payment::query()
|
||||
->where('company_id', $company->id)
|
||||
->when(isset($transaction['payment_intent']), function ($query) use ($transaction) {
|
||||
$query->where('transaction_reference', $transaction['payment_intent']);
|
||||
})
|
||||
->when(isset($transaction['id']), function ($query) use ($transaction) {
|
||||
$query->where('transaction_reference', $transaction['id']);
|
||||
})
|
||||
->first();
|
||||
|
||||
|
||||
if ($payment) {
|
||||
$payment->status_id = Payment::STATUS_PENDING;
|
||||
|
@ -63,17 +63,17 @@ class PaymentIntentWebhook implements ShouldQueue
|
||||
$company = Company::query()->where('company_key', $this->company_key)->first();
|
||||
|
||||
foreach ($this->stripe_request as $transaction) {
|
||||
if (array_key_exists('payment_intent', $transaction)) {
|
||||
$payment = Payment::query()
|
||||
->where('company_id', $company->id)
|
||||
->where('transaction_reference', $transaction['payment_intent'])
|
||||
->first();
|
||||
} else {
|
||||
$payment = Payment::query()
|
||||
->where('company_id', $company->id)
|
||||
->where('transaction_reference', $transaction['id'])
|
||||
->first();
|
||||
}
|
||||
|
||||
$payment = Payment::query()
|
||||
->where('company_id', $company->id)
|
||||
->when(isset($transaction['payment_intent']), function ($query) use ($transaction) {
|
||||
$query->where('transaction_reference', $transaction['payment_intent']);
|
||||
})
|
||||
->when(isset($transaction['id']), function ($query) use ($transaction) {
|
||||
$query->where('transaction_reference', $transaction['id']);
|
||||
})
|
||||
->first();
|
||||
|
||||
|
||||
if ($payment) {
|
||||
$payment->status_id = Payment::STATUS_COMPLETED;
|
||||
|
@ -705,19 +705,17 @@ class StripePaymentDriver extends BaseDriver
|
||||
|
||||
if ($request->type === 'charge.succeeded') {
|
||||
foreach ($request->data as $transaction) {
|
||||
if (array_key_exists('payment_intent', $transaction) && $transaction['payment_intent']) {
|
||||
$payment = Payment::query()
|
||||
// ->where('company_id', $request->getCompany()->id)
|
||||
->where(function ($query) use ($transaction) {
|
||||
$query->where('transaction_reference', $transaction['payment_intent'])
|
||||
->orWhere('transaction_reference', $transaction['id']);
|
||||
})
|
||||
->first();
|
||||
} else {
|
||||
$payment = Payment::query()
|
||||
->where('transaction_reference', $transaction['id'])
|
||||
->first();
|
||||
}
|
||||
|
||||
$payment = Payment::query()
|
||||
->where('company_id', $this->company_gateway->company_id)
|
||||
->when(isset($transaction['payment_intent']), function ($query) use ($transaction) {
|
||||
$query->where('transaction_reference', $transaction['payment_intent']);
|
||||
})
|
||||
->when(isset($transaction['id']), function ($query) use ($transaction) {
|
||||
$query->where('transaction_reference', $transaction['id']);
|
||||
})
|
||||
->first();
|
||||
|
||||
|
||||
if ($payment) {
|
||||
|
||||
@ -744,19 +742,17 @@ class StripePaymentDriver extends BaseDriver
|
||||
], $this->stripe_connect_auth);
|
||||
|
||||
if ($charge->captured) {
|
||||
$payment = false;
|
||||
|
||||
$payment = Payment::query()
|
||||
->where('company_id', $this->company_gateway->company_id)
|
||||
->when(isset($transaction['payment_intent']), function ($query) use ($transaction) {
|
||||
$query->where('transaction_reference', $transaction['payment_intent']);
|
||||
})
|
||||
->when(isset($transaction['id']), function ($query) use ($transaction) {
|
||||
$query->where('transaction_reference', $transaction['id']);
|
||||
})
|
||||
->first();
|
||||
|
||||
if (isset($transaction['payment_intent'])) {
|
||||
$payment = Payment::query()
|
||||
->where('transaction_reference', $transaction['payment_intent'])
|
||||
->where('company_id', $request->getCompany()->id)
|
||||
->first();
|
||||
} elseif (isset($transaction['id'])) {
|
||||
$payment = Payment::query()
|
||||
->where('transaction_reference', $transaction['id'])
|
||||
->where('company_id', $request->getCompany()->id)
|
||||
->first();
|
||||
}
|
||||
|
||||
if ($payment) {
|
||||
$payment->status_id = Payment::STATUS_COMPLETED;
|
||||
|
@ -5303,7 +5303,7 @@ $lang = array(
|
||||
'always_show_required_fields' => 'Allows show required fields form',
|
||||
'always_show_required_fields_help' => 'Displays the required fields form always at checkout',
|
||||
'advanced_cards' => 'Advanced Cards',
|
||||
'activity_140' => 'Statement sent to :client - [:notes]',
|
||||
'activity_140' => 'Statement sent to :client',
|
||||
);
|
||||
|
||||
return $lang;
|
||||
|
@ -104,6 +104,33 @@ class TaskApiTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testTimeLogWithSameStartAndStopTimes()
|
||||
{
|
||||
$settings = ClientSettings::defaults();
|
||||
$settings->default_task_rate = 41;
|
||||
|
||||
$c = Client::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'company_id' => $this->company->id,
|
||||
'settings' => $settings,
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'client_id' => $c->hashed_id,
|
||||
'description' => 'Test Task',
|
||||
'time_log' => '[[1681165417,1681165432,"sumtin",true],[1681165446,1681165446]]',
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->postJson("/api/v1/tasks", $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
$arr = $response->json();
|
||||
|
||||
}
|
||||
|
||||
public function testRoundingViaApi()
|
||||
{
|
||||
|
||||
|
73
tests/Unit/TaskRoundingTest.php
Normal file
73
tests/Unit/TaskRoundingTest.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
class TaskRoundingTest extends TestCase
|
||||
{
|
||||
|
||||
public int $task_round_to_nearest = 1;
|
||||
|
||||
public bool $task_round_up = true;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
}
|
||||
|
||||
public function testRoundUp()
|
||||
{
|
||||
$start_time = 1714942800;
|
||||
$end_time = 1714943220; //7:07am
|
||||
$this->task_round_to_nearest = 600;
|
||||
|
||||
//calculated time = 7:10am
|
||||
$rounded = 1714943400;
|
||||
|
||||
$this->assertEquals($rounded, $this->roundTimeLog($start_time, $end_time));
|
||||
|
||||
}
|
||||
|
||||
public function testRoundDown()
|
||||
{
|
||||
$start_time = 1714942800;
|
||||
$end_time = 1714943220; //7:07am
|
||||
$this->task_round_to_nearest = 600;
|
||||
$this->task_round_up = false;
|
||||
|
||||
//calculated time = 7:10am
|
||||
$rounded = $start_time;
|
||||
|
||||
$this->assertEquals($rounded, $this->roundTimeLog($start_time, $end_time));
|
||||
|
||||
}
|
||||
|
||||
public function roundTimeLog(int $start_time, int $end_time): int
|
||||
{
|
||||
if($this->task_round_to_nearest == 1)
|
||||
return $end_time;
|
||||
|
||||
$interval = $end_time - $start_time;
|
||||
|
||||
if($this->task_round_up)
|
||||
return $start_time + (int)ceil($interval/$this->task_round_to_nearest)*$this->task_round_to_nearest;
|
||||
|
||||
return $start_time - (int)floor($interval/$this->task_round_to_nearest) * $this->task_round_to_nearest;
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user