mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
commit
97885557bd
@ -38,6 +38,8 @@ class RecurringInvoiceToInvoiceFactory
|
|||||||
$invoice->tax_rate2 = $recurring_invoice->tax_rate2;
|
$invoice->tax_rate2 = $recurring_invoice->tax_rate2;
|
||||||
$invoice->tax_name3 = $recurring_invoice->tax_name3;
|
$invoice->tax_name3 = $recurring_invoice->tax_name3;
|
||||||
$invoice->tax_rate3 = $recurring_invoice->tax_rate3;
|
$invoice->tax_rate3 = $recurring_invoice->tax_rate3;
|
||||||
|
$invoice->total_taxes = $recurring_invoice->total_taxes;
|
||||||
|
$invoice->subscription_id = $recurring_invoice->subscription_id;
|
||||||
$invoice->custom_value1 = $recurring_invoice->custom_value1;
|
$invoice->custom_value1 = $recurring_invoice->custom_value1;
|
||||||
$invoice->custom_value2 = $recurring_invoice->custom_value2;
|
$invoice->custom_value2 = $recurring_invoice->custom_value2;
|
||||||
$invoice->custom_value3 = $recurring_invoice->custom_value3;
|
$invoice->custom_value3 = $recurring_invoice->custom_value3;
|
||||||
|
@ -47,6 +47,9 @@ class StoreCompanyGatewayRequest extends Request
|
|||||||
|
|
||||||
$gateway = Gateway::where('key', $input['gateway_key'])->first();
|
$gateway = Gateway::where('key', $input['gateway_key'])->first();
|
||||||
|
|
||||||
|
if($gateway);
|
||||||
|
{
|
||||||
|
|
||||||
$default_gateway_fields = json_decode($gateway->fields);
|
$default_gateway_fields = json_decode($gateway->fields);
|
||||||
|
|
||||||
/*Force gateway properties */
|
/*Force gateway properties */
|
||||||
@ -68,6 +71,8 @@ class StoreCompanyGatewayRequest extends Request
|
|||||||
if (isset($input['fees_and_limits']))
|
if (isset($input['fees_and_limits']))
|
||||||
$input['fees_and_limits'] = $this->cleanFeesAndLimits($input['fees_and_limits']);
|
$input['fees_and_limits'] = $this->cleanFeesAndLimits($input['fees_and_limits']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$this->replace($input);
|
$this->replace($input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +81,7 @@ class CreateAccount
|
|||||||
{
|
{
|
||||||
$sp794f3f->trial_started = now();
|
$sp794f3f->trial_started = now();
|
||||||
$sp794f3f->trial_plan = 'pro';
|
$sp794f3f->trial_plan = 'pro';
|
||||||
|
$sp794f3f->plan = 'pro';
|
||||||
$sp794f3f->save();
|
$sp794f3f->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ class InvoicePaidActivity implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle($event)
|
public function handle($event)
|
||||||
{
|
{
|
||||||
|
|
||||||
MultiDB::setDb($event->company->db);
|
MultiDB::setDb($event->company->db);
|
||||||
|
|
||||||
$fields = new stdClass;
|
$fields = new stdClass;
|
||||||
@ -51,6 +52,12 @@ class InvoicePaidActivity implements ShouldQueue
|
|||||||
|
|
||||||
$this->activity_repo->save($fields, $event->invoice, $event->event_vars);
|
$this->activity_repo->save($fields, $event->invoice, $event->event_vars);
|
||||||
|
|
||||||
|
if($event->invoice->subscription()->exists())
|
||||||
|
{
|
||||||
|
nlog("subscription exists");
|
||||||
|
$event->invoice->subscription->service()->planPaid($event->invoice);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$event->invoice->service()->touchPdf();
|
$event->invoice->service()->touchPdf();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -165,7 +165,7 @@ class Invoice extends BaseModel
|
|||||||
|
|
||||||
public function recurring_invoice()
|
public function recurring_invoice()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(RecurringInvoice::class)->withTrashed();
|
return $this->belongsTo(RecurringInvoice::class, 'recurring_id', 'id')->withTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function assigned_user()
|
public function assigned_user()
|
||||||
|
@ -695,10 +695,14 @@ nlog("handle plan change");
|
|||||||
*/
|
*/
|
||||||
public function triggerWebhook($context)
|
public function triggerWebhook($context)
|
||||||
{
|
{
|
||||||
|
nlog("trigger webook");
|
||||||
|
|
||||||
if (empty($this->subscription->webhook_configuration['post_purchase_url']) || is_null($this->subscription->webhook_configuration['post_purchase_url']) || strlen($this->subscription->webhook_configuration['post_purchase_url']) < 1) {
|
if (empty($this->subscription->webhook_configuration['post_purchase_url']) || is_null($this->subscription->webhook_configuration['post_purchase_url']) || strlen($this->subscription->webhook_configuration['post_purchase_url']) < 1) {
|
||||||
return ["message" => "Success", "status_code" => 200];
|
return ["message" => "Success", "status_code" => 200];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nlog("past first if");
|
||||||
|
|
||||||
$response = false;
|
$response = false;
|
||||||
|
|
||||||
$body = array_merge($context, [
|
$body = array_merge($context, [
|
||||||
@ -709,6 +713,8 @@ nlog("handle plan change");
|
|||||||
|
|
||||||
$response = $this->sendLoad($this->subscription, $body);
|
$response = $this->sendLoad($this->subscription, $body);
|
||||||
|
|
||||||
|
nlog("after response");
|
||||||
|
|
||||||
/* Append the response to the system logger body */
|
/* Append the response to the system logger body */
|
||||||
if(is_array($response)){
|
if(is_array($response)){
|
||||||
|
|
||||||
@ -732,6 +738,7 @@ nlog("handle plan change");
|
|||||||
$client->company,
|
$client->company,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
nlog("ready to fire back");
|
||||||
|
|
||||||
if(is_array($body))
|
if(is_array($body))
|
||||||
return $response;
|
return $response;
|
||||||
@ -906,4 +913,27 @@ nlog("handle plan change");
|
|||||||
|
|
||||||
return redirect($default_redirect);
|
return redirect($default_redirect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function planPaid($invoice)
|
||||||
|
{
|
||||||
|
nlog("this is a plan that has been paid");
|
||||||
|
|
||||||
|
$recurring_invoice_hashed_id = $invoice->recurring_invoice()->exists() ? $invoice->recurring_invoice->hashed_id : null;
|
||||||
|
|
||||||
|
$context = [
|
||||||
|
'context' => 'plan_paid',
|
||||||
|
'subscription' => $this->subscription->hashed_id,
|
||||||
|
'recurring_invoice' => $recurring_invoice_hashed_id,
|
||||||
|
'client' => $invoice->client->hashed_id,
|
||||||
|
'contact' => $invoice->client->primary_contact()->first()->hashed_id,
|
||||||
|
];
|
||||||
|
|
||||||
|
nlog($context);
|
||||||
|
|
||||||
|
$response = $this->triggerWebhook($context);
|
||||||
|
|
||||||
|
nlog($response);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
*/
|
*/
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Factory\InvoiceToRecurringInvoiceFactory;
|
||||||
|
use App\Factory\RecurringInvoiceToInvoiceFactory;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\ClientContact;
|
use App\Models\ClientContact;
|
||||||
use App\Models\RecurringInvoice;
|
use App\Models\RecurringInvoice;
|
||||||
@ -155,4 +157,59 @@ class RecurringInvoiceTest extends TestCase
|
|||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSubscriptionIdPassesToInvoice()
|
||||||
|
{
|
||||||
|
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
||||||
|
$recurring_invoice->user_id = $this->user->id;
|
||||||
|
$recurring_invoice->next_send_date = \Carbon\Carbon::now()->addDays(10);
|
||||||
|
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
||||||
|
$recurring_invoice->remaining_cycles = 2;
|
||||||
|
$recurring_invoice->next_send_date = \Carbon\Carbon::now()->addDays(10);
|
||||||
|
$recurring_invoice->save();
|
||||||
|
|
||||||
|
$recurring_invoice->number = $this->getNextRecurringInvoiceNumber($this->invoice->client, $this->invoice);
|
||||||
|
$recurring_invoice->subscription_id = 10;
|
||||||
|
$recurring_invoice->save();
|
||||||
|
|
||||||
|
$invoice = RecurringInvoiceToInvoiceFactory::create($recurring_invoice, $this->client);
|
||||||
|
|
||||||
|
$this->assertEquals(10, $invoice->subscription_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSubscriptionIdPassesToInvoiceIfNull()
|
||||||
|
{
|
||||||
|
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
||||||
|
$recurring_invoice->user_id = $this->user->id;
|
||||||
|
$recurring_invoice->next_send_date = \Carbon\Carbon::now()->addDays(10);
|
||||||
|
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
||||||
|
$recurring_invoice->remaining_cycles = 2;
|
||||||
|
$recurring_invoice->next_send_date = \Carbon\Carbon::now()->addDays(10);
|
||||||
|
$recurring_invoice->save();
|
||||||
|
|
||||||
|
$recurring_invoice->number = $this->getNextRecurringInvoiceNumber($this->invoice->client, $this->invoice);
|
||||||
|
$recurring_invoice->save();
|
||||||
|
|
||||||
|
$invoice = RecurringInvoiceToInvoiceFactory::create($recurring_invoice, $this->client);
|
||||||
|
|
||||||
|
$this->assertEquals(null, $invoice->subscription_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSubscriptionIdPassesToInvoiceIfNothingSet()
|
||||||
|
{
|
||||||
|
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
||||||
|
$recurring_invoice->user_id = $this->user->id;
|
||||||
|
$recurring_invoice->next_send_date = \Carbon\Carbon::now()->addDays(10);
|
||||||
|
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
||||||
|
$recurring_invoice->remaining_cycles = 2;
|
||||||
|
$recurring_invoice->next_send_date = \Carbon\Carbon::now()->addDays(10);
|
||||||
|
$recurring_invoice->save();
|
||||||
|
|
||||||
|
$recurring_invoice->number = $this->getNextRecurringInvoiceNumber($this->invoice->client, $this->invoice);
|
||||||
|
$recurring_invoice->save();
|
||||||
|
|
||||||
|
$invoice = RecurringInvoiceToInvoiceFactory::create($recurring_invoice, $this->client);
|
||||||
|
|
||||||
|
$this->assertEquals(null, $invoice->subscription_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
39
tests/Unit/SettingsSaverTest.php
Normal file
39
tests/Unit/SettingsSaverTest.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
namespace Tests\Unit;
|
||||||
|
|
||||||
|
use App\DataMapper\CompanySettings;
|
||||||
|
use App\Utils\Traits\SettingsSaver;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
class SettingsSaverTest extends TestCase
|
||||||
|
{
|
||||||
|
use SettingsSaver;
|
||||||
|
|
||||||
|
public function setUp() :void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNullValueForStringTest()
|
||||||
|
{
|
||||||
|
$key = 'show_all_tasks_client_portal';
|
||||||
|
$value = null;
|
||||||
|
|
||||||
|
$result = $this->checkAttribute($key, $value);
|
||||||
|
|
||||||
|
$this->assertFalse($result);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user