mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Validation rules for subscriptions
This commit is contained in:
parent
8dedfa4cb5
commit
2e139a633b
@ -13,6 +13,7 @@ namespace App\Http\Requests\Subscription;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Subscription;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreSubscriptionRequest extends Request
|
||||
{
|
||||
@ -34,10 +35,8 @@ class StoreSubscriptionRequest extends Request
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'user_id' => ['sometimes'],
|
||||
'product_id' => ['sometimes'],
|
||||
'assigned_user_id' => ['sometimes'],
|
||||
'company_id' => ['sometimes'],
|
||||
'is_recurring' => ['sometimes'],
|
||||
'frequency_id' => ['sometimes'],
|
||||
'auto_bill' => ['sometimes'],
|
||||
@ -55,6 +54,7 @@ class StoreSubscriptionRequest extends Request
|
||||
'plan_map' => ['sometimes'],
|
||||
'refund_period' => ['sometimes'],
|
||||
'webhook_configuration' => ['sometimes'],
|
||||
'name' => Rule::unique('subscriptions')->where('company_id', auth()->user()->company()->id)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -21,10 +21,8 @@ class Subscription extends BaseModel
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'product_ids',
|
||||
'recurring_product_ids',
|
||||
'company_id',
|
||||
'frequency_id',
|
||||
'auto_bill',
|
||||
'promo_code',
|
||||
@ -44,6 +42,7 @@ class Subscription extends BaseModel
|
||||
'currency_id',
|
||||
'group_id',
|
||||
'price',
|
||||
'name',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
|
@ -242,7 +242,7 @@ class BaseDriver extends AbstractPaymentDriver
|
||||
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
|
||||
|
||||
if (property_exists($this->payment_hash->data, 'billing_context')) {
|
||||
$billing_subscription = \App\Models\Subscription::find($this->payment_hash->data->billing_context->billing_subscription_id);
|
||||
$billing_subscription = \App\Models\Subscription::find($this->payment_hash->data->billing_context->subscription_id);
|
||||
|
||||
(new SubscriptionService($billing_subscription))->completePurchase($this->payment_hash);
|
||||
}
|
||||
|
@ -99,7 +99,8 @@ class SubscriptionService
|
||||
|
||||
$invoice = InvoiceFactory::create($this->subscription->company_id, $this->subscription->user_id);
|
||||
$invoice->line_items = $subscription_repo->generateLineItems($this->subscription);
|
||||
|
||||
$invoice->subscription_id = $this->subscription->id;
|
||||
|
||||
if(strlen($data['coupon']) >=1 && ($data['coupon'] == $this->subscription->promo_code) && $this->subscription->promo_discount > 0)
|
||||
{
|
||||
$invoice->discount = $subscription->promo_discount;
|
||||
|
Loading…
Reference in New Issue
Block a user