Merge pull request #5311 from turbo124/v5-develop

Fixes for subscriptions
This commit is contained in:
David Bomba 2021-04-01 21:05:41 +11:00 committed by GitHub
commit 277885879c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 42 additions and 12 deletions

View File

@ -54,7 +54,7 @@ class StoreSubscriptionRequest extends Request
'plan_map' => ['sometimes'], 'plan_map' => ['sometimes'],
'refund_period' => ['sometimes'], 'refund_period' => ['sometimes'],
'webhook_configuration' => ['array'], 'webhook_configuration' => ['array'],
'name' => Rule::unique('subscriptions')->where('company_id', auth()->user()->company()->id) 'name' => ['required', Rule::unique('subscriptions')->where('company_id', auth()->user()->company()->id)]
]; ];
} }
@ -62,12 +62,6 @@ class StoreSubscriptionRequest extends Request
{ {
$input = $this->all(); $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); $this->replace($input);
} }
} }

View File

@ -21,6 +21,7 @@ class Subscription extends BaseModel
use HasFactory, SoftDeletes; use HasFactory, SoftDeletes;
protected $fillable = [ protected $fillable = [
'assigned_user_id',
'product_ids', 'product_ids',
'recurring_product_ids', 'recurring_product_ids',
'frequency_id', 'frequency_id',

View File

@ -33,13 +33,13 @@ class SubscriptionTransformer extends EntityTransformer
public function transform(Subscription $subscription): array public function transform(Subscription $subscription): array
{ {
$std = new \stdClass;
return [ return [
'id' => $this->encodePrimaryKey($subscription->id), 'id' => $this->encodePrimaryKey($subscription->id),
'user_id' => $this->encodePrimaryKey($subscription->user_id), 'user_id' => $this->encodePrimaryKey($subscription->user_id),
'group_id' => $this->encodePrimaryKey($subscription->group_id), 'group_id' => $this->encodePrimaryKey($subscription->group_id),
'product_ids' => (string)$subscription->product_ids, 'product_ids' => (string)$subscription->product_ids,
'name' => (string)$subscription->name,
'recurring_product_ids' => (string)$subscription->recurring_product_ids, 'recurring_product_ids' => (string)$subscription->recurring_product_ids,
'assigned_user_id' => $this->encodePrimaryKey($subscription->assigned_user_id), 'assigned_user_id' => $this->encodePrimaryKey($subscription->assigned_user_id),
'company_id' => $this->encodePrimaryKey($subscription->company_id), 'company_id' => $this->encodePrimaryKey($subscription->company_id),
@ -60,7 +60,7 @@ class SubscriptionTransformer extends EntityTransformer
'allow_plan_changes' => (bool)$subscription->allow_plan_changes, 'allow_plan_changes' => (bool)$subscription->allow_plan_changes,
'plan_map' => (string)$subscription->plan_map, 'plan_map' => (string)$subscription->plan_map,
'refund_period' => (int)$subscription->refund_period, 'refund_period' => (int)$subscription->refund_period,
'webhook_configuration' => $subscription->webhook_configuration ?: $std, 'webhook_configuration' => $subscription->webhook_configuration ?: [],
'purchase_page' => (string)route('client.subscription.purchase', $subscription->hashed_id), 'purchase_page' => (string)route('client.subscription.purchase', $subscription->hashed_id),
'is_deleted' => (bool)$subscription->is_deleted, 'is_deleted' => (bool)$subscription->is_deleted,
'created_at' => (int)$subscription->created_at, 'created_at' => (int)$subscription->created_at,

View File

@ -192,6 +192,7 @@ class HtmlEngine
$data['$taxes'] = ['value' => Number::formatMoney($this->entity_calc->getItemTotalTaxes(), $this->client) ?: ' ', 'label' => ctrans('texts.taxes')]; $data['$taxes'] = ['value' => Number::formatMoney($this->entity_calc->getItemTotalTaxes(), $this->client) ?: ' ', 'label' => ctrans('texts.taxes')];
$data['$invoice.taxes'] = &$data['$taxes']; $data['$invoice.taxes'] = &$data['$taxes'];
$data['$user.name'] = ['value' => $this->entity->user->present()->name(), 'label' => ctrans('texts.name')];
$data['$user_iban'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'company1', $this->settings->custom_value1, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'company1')]; $data['$user_iban'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'company1', $this->settings->custom_value1, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'company1')];
$data['$invoice.custom1'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'invoice1', $this->entity->custom_value1, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice1')]; $data['$invoice.custom1'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'invoice1', $this->entity->custom_value1, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice1')];
$data['$invoice.custom2'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'invoice2', $this->entity->custom_value2, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice2')]; $data['$invoice.custom2'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'invoice2', $this->entity->custom_value2, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice2')];

View File

@ -79,6 +79,7 @@ class SystemHealth
'exec' => (bool)self::checkExecWorks(), 'exec' => (bool)self::checkExecWorks(),
'open_basedir' => (bool)self::checkOpenBaseDir(), 'open_basedir' => (bool)self::checkOpenBaseDir(),
'mail_mailer' => (string)self::checkMailMailer(), 'mail_mailer' => (string)self::checkMailMailer(),
'flutter_renderer' => (string)config('ninja.flutter_canvas_kit'),
]; ];
} }

View File

@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class ModifyColumnOnSubscriptionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('subscriptions', function (Blueprint $table) {
$table->unsignedInteger('assigned_user_id')->nullable()->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View File

@ -11,14 +11,15 @@
namespace Tests\Feature; namespace Tests\Feature;
use App\Models\Subscription;
use App\Models\Product; use App\Models\Product;
use App\Models\Subscription;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\Session;
use Illuminate\Support\Str;
use Tests\MockAccountData; use Tests\MockAccountData;
use Tests\TestCase; use Tests\TestCase;
@ -55,6 +56,7 @@ class SubscriptionApiTest extends TestCase
$billing_subscription = Subscription::factory()->create([ $billing_subscription = Subscription::factory()->create([
'product_ids' => $product->id, 'product_ids' => $product->id,
'company_id' => $this->company->id, 'company_id' => $this->company->id,
'name' => Str::random(5)
]); ]);
@ -78,7 +80,7 @@ class SubscriptionApiTest extends TestCase
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/subscriptions', ['product_ids' => $product->id, 'allow_cancellation' => true]); ])->post('/api/v1/subscriptions', ['product_ids' => $product->id, 'allow_cancellation' => true, 'name' => Str::random(5)]);
// nlog($response); // nlog($response);
$response->assertStatus(200); $response->assertStatus(200);
@ -93,7 +95,7 @@ class SubscriptionApiTest extends TestCase
$response1 = $this $response1 = $this
->withHeaders(['X-API-SECRET' => config('ninja.api_secret'),'X-API-TOKEN' => $this->token]) ->withHeaders(['X-API-SECRET' => config('ninja.api_secret'),'X-API-TOKEN' => $this->token])
->post('/api/v1/subscriptions', ['product_ids' => $product->id]) ->post('/api/v1/subscriptions', ['product_ids' => $product->id, 'name' => Str::random(5)])
->assertStatus(200) ->assertStatus(200)
->json(); ->json();
@ -126,6 +128,7 @@ class SubscriptionApiTest extends TestCase
$billing_subscription = Subscription::factory()->create([ $billing_subscription = Subscription::factory()->create([
'product_ids' => $product->id, 'product_ids' => $product->id,
'company_id' => $this->company->id, 'company_id' => $this->company->id,
'name' => Str::random(5)
]); ]);
$response = $this $response = $this