updates for db schema

This commit is contained in:
David Bomba 2022-11-25 23:30:03 +11:00
parent 204a686961
commit a11d2c88bc
5 changed files with 113 additions and 32 deletions

View File

@ -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);

View File

@ -40,7 +40,6 @@ class Task extends BaseModel
'number',
'is_date_based',
'status_order',
'invoice_lock'
];
protected $touches = [];

View File

@ -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,
);
}

View File

@ -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,
];
}
}

View File

@ -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);
}
// }