Merge pull request #5284 from turbo124/v5-develop

Subscriptions
This commit is contained in:
David Bomba 2021-03-30 20:37:28 +11:00 committed by GitHub
commit 32fd16dfb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 75 additions and 22 deletions

View File

@ -98,6 +98,7 @@ class BaseController extends Controller
'company.vendors.contacts.company',
'company.vendors.documents',
'company.webhooks',
'company.system_logs',
];
private $mini_load = [

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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