diff --git a/app/Http/Requests/Task/UpdateTaskRequest.php b/app/Http/Requests/Task/UpdateTaskRequest.php index 3b4bf5416c8a..9214a2beaa3c 100644 --- a/app/Http/Requests/Task/UpdateTaskRequest.php +++ b/app/Http/Requests/Task/UpdateTaskRequest.php @@ -31,7 +31,7 @@ class UpdateTaskRequest extends Request public function authorize() : bool { //prevent locked tasks from updating - if($this->task->invoice_lock && $this->task->invoice_id) + if($this->task->invoice_id && $this->task->company->invoice_task_lock) return false; return auth()->user()->can('edit', $this->task); diff --git a/app/Models/Task.php b/app/Models/Task.php index 024bba00c154..4e463e575c88 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -40,7 +40,6 @@ class Task extends BaseModel 'number', 'is_date_based', 'status_order', - 'invoice_lock' ]; protected $touches = []; diff --git a/app/PaymentDrivers/Stripe/Jobs/PaymentIntentWebhook.php b/app/PaymentDrivers/Stripe/Jobs/PaymentIntentWebhook.php index 196b29bbc813..5d9d4ede8614 100644 --- a/app/PaymentDrivers/Stripe/Jobs/PaymentIntentWebhook.php +++ b/app/PaymentDrivers/Stripe/Jobs/PaymentIntentWebhook.php @@ -159,17 +159,101 @@ class PaymentIntentWebhook implements ShouldQueue $this->updateAchPayment($payment_hash, $client); } + + SystemLogger::dispatch( + ['response' => $this->stripe_request, 'data' => []], + SystemLog::CATEGORY_GATEWAY_RESPONSE, + SystemLog::EVENT_GATEWAY_SUCCESS, + SystemLog::TYPE_STRIPE, + null, + $company, + ); + + return; + } + if(isset($this->stripe_request['object']['latest_charge'])) + { + $pi = \Stripe\PaymentIntent::retrieve($this->stripe_request['object']['id'], $this->stripe_driver->stripe_connect_auth); + + $charge = reset($pi->charges->data); + + $company = Company::where('company_key', $this->company_key)->first(); + + $payment = Payment::query() + ->where('company_id', $company->id) + ->where('transaction_reference', $charge['id']) + ->first(); + + //return early + if($payment && $payment->status_id == Payment::STATUS_COMPLETED){ + nlog(" payment found and status correct - returning "); + return; + } + elseif($payment){ + $payment->status_id = Payment::STATUS_COMPLETED; + $payment->save(); + } + + $hash = optional($charge['metadata']['payment_hash']); + + $payment_hash = PaymentHash::where('hash', $hash)->first(); + + if(!$payment_hash) + return; + + if(isset($pi['allowed_source_types']) && in_array('card', $pi['allowed_source_types'])) + { + nlog("hash found"); + + $hash = $this->stripe_request['object']['charges']['data'][0]['metadata']['payment_hash']; + + $payment_hash = PaymentHash::where('hash', $hash)->first(); + $invoice = Invoice::with('client')->find($payment_hash->fee_invoice_id); + $client = $invoice->client; + + $this->updateCreditCardPayment($payment_hash, $client); + } + elseif(isset($pi['payment_method_types']) && in_array('card', $pi['payment_method_types'])) + { + nlog("hash found"); + + $hash = $this->stripe_request['object']['charges']['data'][0]['metadata']['payment_hash']; + + $payment_hash = PaymentHash::where('hash', $hash)->first(); + $invoice = Invoice::with('client')->find($payment_hash->fee_invoice_id); + $client = $invoice->client; + + $this->updateCreditCardPayment($payment_hash, $client); + } + elseif(isset($pi['payment_method_types']) && in_array('us_bank_account', $pi['payment_method_types'])) + { + nlog("hash found"); + + $hash = $this->stripe_request['object']['charges']['data'][0]['metadata']['payment_hash']; + + $payment_hash = PaymentHash::where('hash', $hash)->first(); + $invoice = Invoice::with('client')->find($payment_hash->fee_invoice_id); + $client = $invoice->client; + + $this->updateAchPayment($payment_hash, $client); + } + + SystemLogger::dispatch( + ['response' => $this->stripe_request, 'data' => []], + SystemLog::CATEGORY_GATEWAY_RESPONSE, + SystemLog::EVENT_GATEWAY_SUCCESS, + SystemLog::TYPE_STRIPE, + null, + $company, + ); + + + + + } - SystemLogger::dispatch( - ['response' => $this->stripe_request, 'data' => []], - SystemLog::CATEGORY_GATEWAY_RESPONSE, - SystemLog::EVENT_GATEWAY_SUCCESS, - SystemLog::TYPE_STRIPE, - null, - $company, - ); } diff --git a/app/Transformers/TaskTransformer.php b/app/Transformers/TaskTransformer.php index ed8b2700eb40..3408721545db 100644 --- a/app/Transformers/TaskTransformer.php +++ b/app/Transformers/TaskTransformer.php @@ -92,7 +92,6 @@ class TaskTransformer extends EntityTransformer 'status_sort_order' => (int) $task->status_sort_order, //deprecated 5.0.34 'is_date_based' => (bool) $task->is_date_based, 'status_order' => is_null($task->status_order) ? null : (int) $task->status_order, - 'invoice_lock' => (bool) $task->invoice_lock, ]; } } diff --git a/tests/Feature/TaskApiTest.php b/tests/Feature/TaskApiTest.php index b2bb253172cf..0f4c025232f3 100644 --- a/tests/Feature/TaskApiTest.php +++ b/tests/Feature/TaskApiTest.php @@ -81,9 +81,9 @@ class TaskApiTest extends TestCase $response->assertStatus(200); $task = Task::find($this->decodePrimaryKey($arr['data']['id'])); - $task->invoice_lock =true; + $task->company->invoice_task_lock = true; $task->invoice_id = $this->invoice->id; - $task->save(); + $task->push(); $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), @@ -97,32 +97,31 @@ class TaskApiTest extends TestCase } - public function testTaskLocking() - { - $data = [ - 'timelog' => [[1,2],[3,4]], - 'invoice_lock' => true - ]; + // public function testTaskLocking() + // { + // $data = [ + // 'timelog' => [[1,2],[3,4]], + // ]; - $response = $this->withHeaders([ - 'X-API-SECRET' => config('ninja.api_secret'), - 'X-API-TOKEN' => $this->token, - ])->post('/api/v1/tasks', $data); + // $response = $this->withHeaders([ + // 'X-API-SECRET' => config('ninja.api_secret'), + // 'X-API-TOKEN' => $this->token, + // ])->post('/api/v1/tasks', $data); - $arr = $response->json(); - $response->assertStatus(200); + // $arr = $response->json(); + // $response->assertStatus(200); - $response = $this->withHeaders([ - 'X-API-SECRET' => config('ninja.api_secret'), - 'X-API-TOKEN' => $this->token, - ])->putJson('/api/v1/tasks/' . $arr['data']['id'], $data); + // $response = $this->withHeaders([ + // 'X-API-SECRET' => config('ninja.api_secret'), + // 'X-API-TOKEN' => $this->token, + // ])->putJson('/api/v1/tasks/' . $arr['data']['id'], $data); - $arr = $response->json(); + // $arr = $response->json(); - $response->assertStatus(200); + // $response->assertStatus(200); - } + // }