mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 18:44:28 -04:00
Don’t require changing back to free to be refunded
This commit is contained in:
parent
dad4afff45
commit
42357bcd3d
@ -180,22 +180,8 @@ class AccountController extends BaseController
|
|||||||
$newPlan['price'] = Utils::getPlanPrice($newPlan);
|
$newPlan['price'] = Utils::getPlanPrice($newPlan);
|
||||||
$credit = 0;
|
$credit = 0;
|
||||||
|
|
||||||
if (! empty($planDetails['started']) && $plan == PLAN_FREE) {
|
if ($plan == PLAN_FREE && $company->processRefund(Auth::user())) {
|
||||||
// Downgrade
|
Session::flash('warning', trans('texts.plan_refunded'));
|
||||||
$refund_deadline = clone $planDetails['started'];
|
|
||||||
$refund_deadline->modify('+30 days');
|
|
||||||
|
|
||||||
if ($plan == PLAN_FREE && $refund_deadline >= date_create()) {
|
|
||||||
if ($payment = $account->company->payment) {
|
|
||||||
$ninjaAccount = $this->accountRepo->getNinjaAccount();
|
|
||||||
$paymentDriver = $ninjaAccount->paymentDriver();
|
|
||||||
$paymentDriver->refundPayment($payment);
|
|
||||||
Session::flash('message', trans('texts.plan_refunded'));
|
|
||||||
\Log::info("Refunded Plan Payment: {$account->name} - {$user->email} - Deadline: {$refund_deadline->format('Y-m-d')}");
|
|
||||||
} else {
|
|
||||||
Session::flash('message', trans('texts.updated_plan'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$hasPaid = false;
|
$hasPaid = false;
|
||||||
@ -235,6 +221,8 @@ class AccountController extends BaseController
|
|||||||
$company->plan = $plan;
|
$company->plan = $plan;
|
||||||
$company->save();
|
$company->save();
|
||||||
|
|
||||||
|
Session::flash('message', trans('texts.updated_plan'));
|
||||||
|
|
||||||
return Redirect::to('settings/account_management');
|
return Redirect::to('settings/account_management');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1341,6 +1329,9 @@ class AccountController extends BaseController
|
|||||||
$account = Auth::user()->account;
|
$account = Auth::user()->account;
|
||||||
\Log::info("Canceled Account: {$account->name} - {$user->email}");
|
\Log::info("Canceled Account: {$account->name} - {$user->email}");
|
||||||
|
|
||||||
|
$company = $account->company;
|
||||||
|
$refunded = $company->processRefund(Auth::user());
|
||||||
|
|
||||||
Document::scope()->each(function ($item, $key) {
|
Document::scope()->each(function ($item, $key) {
|
||||||
$item->delete();
|
$item->delete();
|
||||||
});
|
});
|
||||||
@ -1356,6 +1347,10 @@ class AccountController extends BaseController
|
|||||||
Auth::logout();
|
Auth::logout();
|
||||||
Session::flush();
|
Session::flush();
|
||||||
|
|
||||||
|
if ($refunded) {
|
||||||
|
Session::flash('warning', trans('texts.plan_refunded'));
|
||||||
|
}
|
||||||
|
|
||||||
return Redirect::to('/')->with('clearGuestKey', true);
|
return Redirect::to('/')->with('clearGuestKey', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,4 +140,32 @@ class Company extends Eloquent
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function processRefund($user)
|
||||||
|
{
|
||||||
|
if (! $this->payment) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$account = $this->accounts()->first();
|
||||||
|
$planDetails = $account->getPlanDetails(false, false);
|
||||||
|
|
||||||
|
if (! empty($planDetails['started'])) {
|
||||||
|
$deadline = clone $planDetails['started'];
|
||||||
|
$deadline->modify('+30 days');
|
||||||
|
|
||||||
|
if ($deadline >= date_create()) {
|
||||||
|
$accountRepo = app('App\Ninja\Repositories\AccountRepository');
|
||||||
|
$ninjaAccount = $accountRepo->getNinjaAccount();
|
||||||
|
$paymentDriver = $ninjaAccount->paymentDriver();
|
||||||
|
$paymentDriver->refundPayment($this->payment);
|
||||||
|
|
||||||
|
\Log::info("Refunded Plan Payment: {$account->name} - {$user->email} - Deadline: {$deadline->format('Y-m-d')}");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,10 +127,11 @@
|
|||||||
@endif
|
@endif
|
||||||
@else
|
@else
|
||||||
{!! Button::normal(trans('texts.download_pdf'))->withAttributes(['onclick' => 'onDownloadClick()'])->large() !!}
|
{!! Button::normal(trans('texts.download_pdf'))->withAttributes(['onclick' => 'onDownloadClick()'])->large() !!}
|
||||||
@if ($account->isNinjaAccount())
|
|
||||||
{!! Button::primary(trans('texts.return_to_app'))->asLinkTo(URL::to('/settings/account_management'))->large() !!}
|
|
||||||
@endif
|
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
@if ($account->isNinjaAccount())
|
||||||
|
{!! Button::primary(trans('texts.return_to_app'))->asLinkTo(URL::to('/settings/account_management'))->large() !!}
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user