Skip to content

Commit

Permalink
Merge branch 'IG-005-c' : FB block product/item create if it is alrea…
Browse files Browse the repository at this point in the history
…dy exists
  • Loading branch information
sabinks committed Jan 12, 2021
2 parents 712bd37 + dd2aea6 commit 906f5ef
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/Repositories/Freshbooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,22 @@ public function createProduct($product = [], $invoice_number)
}
}

$data = $this->freshbooks->checkProductExist($product);
if($data->ok()){
$response = $data->json()['response']['result'];
if($response['items']){
\Log::debug('Freshbooks existing items used for user_id:' . $this->user_id, ['_trace' => $response]);

return [
'id' => $response['items'][0]['id'],
'name' => $response['items'][0]['name'],
'product' => $response['items'][0]
];
}
}
// $data = $this->freshbooks->checkProductExist($product);
// if($data->ok()){
// $response = $data->json()['response']['result'];
// \Log::Info($data->json()['response']);
// if($response['items']){
// $message = 'Fresbooks(FB) duplicate item message: FB does not support duplicate/repeated items. Please update the Job Title for this invoice. Save. And then try again.';
// throw FailedException::forProductCreate($message, 422);
// \Log::debug('Freshbooks existing items used for user_id:' . $this->user_id, ['_trace' => $response]);

// // return [
// // 'id' => $response['items'][0]['id'],
// // 'name' => $response['items'][0]['name'],
// // 'product' => $response['items'][0]
// // ];
// }
// }

$data = $this->freshbooks->createProduct($product);
if($data->ok()){
Expand All @@ -239,7 +242,9 @@ public function createProduct($product = [], $invoice_number)
throw UnauthenticatedException::forCustomerAll();
}else{
\Log::error('Product already created' . $this->user_id, ['_trace' => $error]);
throw FailedException::forProductCreate($error['message'], 422);
$message = 'Fresbooks(FB) duplicate item message: FB does not support duplicate/repeated items. Please update the Job Title for this invoice. Save. And then try again.';
throw FailedException::forProductCreate($message, 422);
// throw FailedException::forProductCreate($error['message'], 422);
}
}
}
Expand Down

0 comments on commit 906f5ef

Please sign in to comment.