diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index e40eda3a4556..ea5b8d97deb5 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -98,6 +98,7 @@ class BaseController extends Controller 'company.vendors.contacts.company', 'company.vendors.documents', 'company.webhooks', + 'company.system_logs', ]; private $mini_load = [ diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 9c037e92286d..e64bac17a292 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -392,7 +392,7 @@ class InvoiceController extends BaseController } if ($invoice->isLocked()) { - return response()->json(['message' => ctrans('texts.locked_invoice')]); + return response()->json(['message' => ctrans('texts.locked_invoice')], 403); } $invoice = $this->invoice_repo->save($request->all(), $invoice); diff --git a/app/Http/Controllers/SelfUpdateController.php b/app/Http/Controllers/SelfUpdateController.php index 1ecc2ae675ba..7daf38feed40 100644 --- a/app/Http/Controllers/SelfUpdateController.php +++ b/app/Http/Controllers/SelfUpdateController.php @@ -66,10 +66,16 @@ class SelfUpdateController extends BaseController $repo = new GitRepository(base_path()); nlog('Are there changes to pull? '.$repo->hasChanges()); + $output = ''; try { - $res = $repo->pull(); + // $res = $repo->pull(); + + $output = $repo->execute('pull origin'); + } catch (GitException $e) { + + nlog($output); nlog($e->getMessage()); return response()->json(['message'=>$e->getMessage()], 500); } @@ -78,7 +84,7 @@ class SelfUpdateController extends BaseController Artisan::call('ninja:post-update'); }); - return response()->json(['message' => ''], 200); + return response()->json(['message' => $output], 200); } public function checkVersion() diff --git a/app/Http/Requests/Invoice/ActionInvoiceRequest.php b/app/Http/Requests/Invoice/ActionInvoiceRequest.php index fbe5c8c9c222..17c27ad7ab90 100644 --- a/app/Http/Requests/Invoice/ActionInvoiceRequest.php +++ b/app/Http/Requests/Invoice/ActionInvoiceRequest.php @@ -45,8 +45,6 @@ class ActionInvoiceRequest extends Request { $input = $this->all(); - $this->invoice = Invoice::find($this->decodePrimary($invoice_id)); - if (!array_key_exists('action', $input)) { $this->error_msg = 'Action is a required field'; } elseif (!$this->invoiceDeletable($this->invoice)) { diff --git a/app/Http/Requests/Subscription/StoreSubscriptionRequest.php b/app/Http/Requests/Subscription/StoreSubscriptionRequest.php index f3a8c280b3e6..fe8de051fcd2 100644 --- a/app/Http/Requests/Subscription/StoreSubscriptionRequest.php +++ b/app/Http/Requests/Subscription/StoreSubscriptionRequest.php @@ -57,4 +57,17 @@ class StoreSubscriptionRequest extends Request 'name' => Rule::unique('subscriptions')->where('company_id', auth()->user()->company()->id) ]; } + + protected function prepareForValidation() + { + $input = $this->all(); + + if(array_key_exists('webhook_configuration', $input) && (!is_object(json_decode($input['webhook_configuration'])))) + $input['webhook_configuration'] = new \stdClass; + + if(!array_key_exists('webhook_configuration', $input)) + $input['webhook_configuration'] = new \stdClass; + + $this->replace($input); + } } diff --git a/app/Jobs/Cron/RecurringInvoicesCron.php b/app/Jobs/Cron/RecurringInvoicesCron.php index 0a04f8761946..06bdd4db1599 100644 --- a/app/Jobs/Cron/RecurringInvoicesCron.php +++ b/app/Jobs/Cron/RecurringInvoicesCron.php @@ -42,6 +42,7 @@ class RecurringInvoicesCron if (! config('ninja.db.multi_db_enabled')) { $recurring_invoices = RecurringInvoice::whereDate('next_send_date', '<=', now()) + ->whereNotNull('next_send_date') ->where('status_id', RecurringInvoice::STATUS_ACTIVE) ->where('remaining_cycles', '!=', '0') ->with('company') @@ -62,6 +63,7 @@ class RecurringInvoicesCron MultiDB::setDB($db); $recurring_invoices = RecurringInvoice::whereDate('next_send_date', '<=', now()) + ->whereNotNull('next_send_date') ->where('status_id', RecurringInvoice::STATUS_ACTIVE) ->where('remaining_cycles', '!=', '0') ->with('company') diff --git a/app/Jobs/RecurringInvoice/SendRecurring.php b/app/Jobs/RecurringInvoice/SendRecurring.php index 39712889fc3b..e0dec9726c3e 100644 --- a/app/Jobs/RecurringInvoice/SendRecurring.php +++ b/app/Jobs/RecurringInvoice/SendRecurring.php @@ -35,6 +35,8 @@ class SendRecurring implements ShouldQueue protected $db; + public $tries = 1; + /** * Create a new job instance. * @@ -64,7 +66,6 @@ class SendRecurring implements ShouldQueue ->applyNumber() ->createInvitations() ->fillDefaults() - ->setExchangeRate() ->save(); nlog("Invoice {$invoice->number} created"); @@ -76,16 +77,6 @@ class SendRecurring implements ShouldQueue } }); - //Admin notification for recurring invoice sent. - if ($invoice->invitations->count() >= 1) { - $invoice->entityEmailEvent($invoice->invitations->first(), 'invoice', 'email_template_invoice'); - } - - if ($invoice->client->getSetting('auto_bill_date') == 'on_send_date' && $this->recurring_invoice->auto_bill_enabled) { - nlog("attempting to autobill {$invoice->number}"); - $invoice->service()->autoBill()->save(); - } - nlog("updating recurring invoice dates"); /* Set next date here to prevent a recurring loop forming */ $this->recurring_invoice->next_send_date = $this->recurring_invoice->nextSendDate()->format('Y-m-d'); @@ -103,6 +94,17 @@ class SendRecurring implements ShouldQueue $this->recurring_invoice->save(); + //Admin notification for recurring invoice sent. + if ($invoice->invitations->count() >= 1) { + $invoice->entityEmailEvent($invoice->invitations->first(), 'invoice', 'email_template_invoice'); + } + + if ($invoice->client->getSetting('auto_bill_date') == 'on_send_date' && $this->recurring_invoice->auto_bill_enabled) { + nlog("attempting to autobill {$invoice->number}"); + $invoice->service()->autoBill()->save(); + } + + } public function failed($exception = null) diff --git a/app/Models/Company.php b/app/Models/Company.php index e2edb0d28314..73f2d1e8c954 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -391,7 +391,7 @@ class Company extends BaseModel public function system_logs() { - return $this->hasMany(SystemLog::class)->orderBy('id', 'DESC')->take(50); + return $this->hasMany(SystemLog::class)->orderBy('id', 'DESC')->take(100); } public function system_log_relation() diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index a8edbbca6579..67903e2309d2 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -211,12 +211,20 @@ class AuthorizeCreditCard { $response = $data['response']; + $code = ''; + $description = ''; + + if($response->getTransactionResponse()->getMessages() !== null){ + $code = $response->getTransactionResponse()->getMessages()[0]->getCode(); + $description = $response->getTransactionResponse()->getMessages()[0]->getDescription(); + } + return [ 'transaction_reference' => $response->getTransactionResponse()->getTransId(), 'amount' => $vars['amount'], 'auth_code' => $response->getTransactionResponse()->getAuthCode(), - 'code' => $response->getTransactionResponse()->getMessages()[0]->getCode(), - 'description' => $response->getTransactionResponse()->getMessages()[0]->getDescription(), + 'code' => $code, + 'description' => $description, 'invoices' => $vars['invoices'], ]; } diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index ac4981a210fd..5979fa33342b 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -21,6 +21,7 @@ use App\Models\ClientSubscription; use App\Models\Invoice; use App\Models\PaymentHash; use App\Models\Product; +use App\Models\RecurringInvoice; use App\Models\Subscription; use App\Models\SystemLog; use App\Repositories\InvoiceRepository; @@ -80,7 +81,7 @@ class SubscriptionService $recurring_invoice->client_id = $client_contact->client_id; $recurring_invoice->line_items = $subscription_repo->generateLineItems($this->subscription, true); $recurring_invoice->subscription_id = $this->subscription->id; - $recurring_invoice->frequency_id = $this->subscription->frequency_id; + $recurring_invoice->frequency_id = $this->subscription->frequency_id ?: RecurringInvoice::FREQUENCY_MONTHLY; $recurring_invoice->date = now(); $recurring_invoice->next_send_date = now()->addSeconds($this->subscription->trial_duration); $recurring_invoice->remaining_cycles = -1; @@ -102,7 +103,7 @@ class SubscriptionService //execute any webhooks $this->triggerWebhook(); - if(strlen($this->subscription->webhook_configuration->post_purchase_url) >=1) + if(property_exists($this->subscription->webhook_configuration, 'post_purchase_url') && strlen($this->subscription->webhook_configuration->post_purchase_url) >=1) return redirect($this->subscription->webhook_configuration->post_purchase_url); return redirect('/client/recurring_invoices/'.$recurring_invoice->hashed_id); diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 60d56574750c..ff4ceaa17eba 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -260,7 +260,7 @@ class HtmlEngine $data['$contact.email'] = ['value' => $this->contact->email, 'label' => ctrans('texts.email')]; $data['$contact.phone'] = ['value' => $this->contact->phone, 'label' => ctrans('texts.phone')]; - $data['$contact.name'] = ['value' => isset($this->contact) ? $this->contact->present()->name() : 'no contact name on record', 'label' => ctrans('texts.contact_name')]; + $data['$contact.name'] = ['value' => isset($this->contact) ? $this->contact->present()->name() : $this->client->present()->name(), 'label' => ctrans('texts.contact_name')]; $data['$contact.first_name'] = ['value' => isset($this->contact) ? $this->contact->first_name : '', 'label' => ctrans('texts.first_name')]; $data['$contact.last_name'] = ['value' => isset($this->contact) ? $this->contact->last_name : '', 'label' => ctrans('texts.last_name')]; diff --git a/tests/Integration/PaymentDrivers/AuthorizeTest.php b/tests/Integration/PaymentDrivers/AuthorizeTest.php index 54928a2beef2..33934756a289 100644 --- a/tests/Integration/PaymentDrivers/AuthorizeTest.php +++ b/tests/Integration/PaymentDrivers/AuthorizeTest.php @@ -310,6 +310,28 @@ class AuthorizeTest extends TestCase $controller = new CreateTransactionController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); + // nlog($response); + nlog($response->getTransactionResponse()->getMessages() !== null); + nlog($response->getTransactionResponse()->getMessages()); + nlog($response->getTransactionResponse()->getMessages()[0]); + //nlog($response->getTransactionResponse()->getMessages()[0]->getCode()); + + $code = ''; + $description = ''; + + if($response->getTransactionResponse()->getMessages() !== null){ + $code = $response->getTransactionResponse()->getMessages()[0]->getCode(); + $description = $response->getTransactionResponse()->getMessages()[0]->getDescription(); + } + + $log = [ + 'transaction_reference' => $response->getTransactionResponse()->getTransId(), + 'auth_code' => $response->getTransactionResponse()->getAuthCode(), + 'code' => $code, + 'description' => $description, + ]; + + if ($response != null) { if ($response->getMessages()->getResultCode() == 'Ok') { $tresponse = $response->getTransactionResponse();