mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 13:24:30 -04:00
Support coupon codes
This commit is contained in:
parent
7c1ab1bfca
commit
83ab8f0f60
@ -50,6 +50,8 @@ class StartupCheck
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
$company = Auth::user()->account->company;
|
||||
|
||||
// Check if a new version was installed
|
||||
if (! Utils::isNinja()) {
|
||||
$file = storage_path() . '/version.txt';
|
||||
@ -72,11 +74,37 @@ class StartupCheck
|
||||
}
|
||||
}
|
||||
|
||||
// Check the application is up to date and for any news feed messages
|
||||
if (Auth::check()) {
|
||||
$count = Session::get(SESSION_COUNTER, 0);
|
||||
Session::put(SESSION_COUNTER, ++$count);
|
||||
|
||||
if (Utils::isNinja()) {
|
||||
if ($coupon = request()->coupon) {
|
||||
if ($code = config('ninja.coupon_50_off')) {
|
||||
if (hash_equals($coupon, $code)) {
|
||||
$company->applyDiscount(.5);
|
||||
$company->save();
|
||||
Session::flash('message', trans('texts.applied_discount', ['discount' => 50]));
|
||||
}
|
||||
}
|
||||
if ($code = config('ninja.coupon_75_off')) {
|
||||
if (hash_equals($coupon, $code)) {
|
||||
$company->applyDiscount(.75);
|
||||
$company->save();
|
||||
Session::flash('message', trans('texts.applied_discount', ['discount' => 75]));
|
||||
}
|
||||
}
|
||||
if ($code = config('ninja.coupon_free_year')) {
|
||||
if (hash_equals($coupon, $code)) {
|
||||
$company->applyFreeYear();
|
||||
$company->save();
|
||||
Session::flash('message', trans('texts.applied_free_year'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check the application is up to date and for any news feed messages
|
||||
if (isset($_SERVER['REQUEST_URI']) && ! Utils::startsWith($_SERVER['REQUEST_URI'], '/news_feed') && ! Session::has('news_feed_id')) {
|
||||
$data = false;
|
||||
if (Utils::isNinja()) {
|
||||
@ -144,7 +172,6 @@ class StartupCheck
|
||||
if ($data == RESULT_FAILURE) {
|
||||
Session::flash('error', trans('texts.invalid_white_label_license'));
|
||||
} elseif ($data) {
|
||||
$company = Auth::user()->account->company;
|
||||
$company->plan_term = PLAN_TERM_YEARLY;
|
||||
$company->plan_paid = $data;
|
||||
$date = max(date_create($data), date_create($company->plan_expires));
|
||||
|
@ -185,6 +185,22 @@ class Company extends Eloquent
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function applyDiscount($amount)
|
||||
{
|
||||
$this->discount = $amount;
|
||||
$this->promo_expires = date_create()->modify('14 days')->format('Y-m-d');
|
||||
}
|
||||
|
||||
public function applyFreeYear()
|
||||
{
|
||||
$this->plan = PLAN_PRO;
|
||||
$this->plan_term = PLAN_TERM_YEARLY;
|
||||
$this->plan_price = PLAN_PRICE_PRO_MONTHLY;
|
||||
$this->plan_started = date_create()->format('Y-m-d');
|
||||
$this->plan_paid = date_create()->format('Y-m-d');
|
||||
$this->plan_expires = date_create()->modify('1 year')->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
|
||||
Company::deleted(function ($company)
|
||||
|
@ -42,17 +42,11 @@ class AccountRepository
|
||||
|
||||
if (Input::get('utm_campaign')) {
|
||||
if (env('PROMO_CAMPAIGN') && hash_equals(Input::get('utm_campaign'), env('PROMO_CAMPAIGN'))) {
|
||||
$company->discount = .75;
|
||||
$company->promo_expires = date_create()->modify('14 days')->format('Y-m-d');
|
||||
$company->applyDiscount(.75);
|
||||
}
|
||||
|
||||
if (env('PARTNER_CAMPAIGN') && hash_equals(Input::get('utm_campaign'), env('PARTNER_CAMPAIGN'))) {
|
||||
$company->plan = PLAN_PRO;
|
||||
$company->plan_term = PLAN_TERM_YEARLY;
|
||||
$company->plan_price = PLAN_PRICE_PRO_MONTHLY;
|
||||
$company->plan_started = date_create()->format('Y-m-d');
|
||||
$company->plan_paid = date_create()->format('Y-m-d');
|
||||
$company->plan_expires = date_create()->modify('1 year')->format('Y-m-d');
|
||||
$company->applyFreeYear();
|
||||
}
|
||||
}
|
||||
|
||||
|
10
config/ninja.php
Normal file
10
config/ninja.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
// Hosted plan coupons
|
||||
'coupon_50_off' => env('COUPON_50_OFF', false),
|
||||
'coupon_75_off' => env('COUPON_75_OFF', false),
|
||||
'coupon_free_year' => env('COUPON_FREE_YEAR', false),
|
||||
|
||||
];
|
@ -2418,6 +2418,10 @@ $LANG = array(
|
||||
'delete_company_help' => 'Permanently delete the company along with all data and setting.',
|
||||
'delete_company_message' => 'Warning: This will permanently delete your company, there is no undo.',
|
||||
|
||||
'applied_discount' => 'The coupon has been applied, the plan price has been reduced by :discount%.',
|
||||
'applied_free_year' => 'The coupon has been applied, your account has been upgraded to pro for one year.',
|
||||
|
||||
|
||||
);
|
||||
|
||||
return $LANG;
|
||||
|
Loading…
x
Reference in New Issue
Block a user