mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Improvements to white label purchase
This commit is contained in:
parent
4bcdc155c0
commit
cf0889bc90
@ -11,6 +11,7 @@ use Exception;
|
||||
use Validator;
|
||||
use App\Models\Invitation;
|
||||
use App\Models\Account;
|
||||
use App\Models\Client;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Product;
|
||||
use App\Models\PaymentMethod;
|
||||
@ -283,22 +284,31 @@ class OnlinePaymentController extends BaseController
|
||||
return redirect()->to("{$failureUrl}/?error=invalid product");
|
||||
}
|
||||
|
||||
$rules = [
|
||||
'first_name' => 'string|max:100',
|
||||
'last_name' => 'string|max:100',
|
||||
'email' => 'email|string|max:100',
|
||||
];
|
||||
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return redirect()->to("{$failureUrl}/?error=" . $validator->errors()->first());
|
||||
// check for existing client using contact_key
|
||||
$client = false;
|
||||
if ($contactKey = Input::get('contact_key')) {
|
||||
$client = Client::scope()->whereHas('contacts', function ($query) use ($contactKey) {
|
||||
$query->where('contact_key', $contactKey);
|
||||
})->first();
|
||||
}
|
||||
if ( ! $client) {
|
||||
$rules = [
|
||||
'first_name' => 'string|max:100',
|
||||
'last_name' => 'string|max:100',
|
||||
'email' => 'email|string|max:100',
|
||||
];
|
||||
|
||||
$data = [
|
||||
'currency_id' => $account->currency_id,
|
||||
'contact' => Input::all()
|
||||
];
|
||||
$client = $clientRepo->save($data);
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return redirect()->to("{$failureUrl}/?error=" . $validator->errors()->first());
|
||||
}
|
||||
|
||||
$data = [
|
||||
'currency_id' => $account->currency_id,
|
||||
'contact' => Input::all()
|
||||
];
|
||||
$client = $clientRepo->save($data);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'client_id' => $client->id,
|
||||
|
@ -240,7 +240,7 @@ class UserController extends BaseController
|
||||
$user = User::where('confirmation_code', '=', $code)->get()->first();
|
||||
|
||||
if ($user) {
|
||||
$notice_msg = trans('texts.security.confirmation');
|
||||
$notice_msg = trans('texts.security_confirmation');
|
||||
|
||||
$user->confirmed = true;
|
||||
$user->confirmation_code = '';
|
||||
|
@ -275,6 +275,7 @@ class Client extends EntityModel
|
||||
} else {
|
||||
$contact = Contact::createNew();
|
||||
$contact->send_invoice = true;
|
||||
$contact->contact_key = isset($data['contact_key']) ? $data['contact_key'] : str_random(RANDOM_KEY_LENGTH);
|
||||
}
|
||||
|
||||
if (Utils::hasFeature(FEATURE_CLIENT_PORTAL_PASSWORD) && $this->account->enable_portal_password){
|
||||
|
@ -403,6 +403,11 @@ class User extends Authenticatable
|
||||
return (($entity && $this->can('edit', $entity))
|
||||
|| (!$entity && $this->can('create', $entityType)));
|
||||
}
|
||||
|
||||
public function primaryAccount()
|
||||
{
|
||||
return $this->account->company->accounts->sortBy('id')->first();
|
||||
}
|
||||
}
|
||||
|
||||
User::updating(function ($user) {
|
||||
|
@ -8,6 +8,7 @@ use Omnipay;
|
||||
use Exception;
|
||||
use CreditCard;
|
||||
use DateTime;
|
||||
use App\Models\License;
|
||||
use App\Models\AccountGatewayToken;
|
||||
use App\Models\AccountGatewaySettings;
|
||||
use App\Models\Account;
|
||||
@ -133,7 +134,12 @@ class BasePaymentDriver
|
||||
Session::reflash();
|
||||
} else {
|
||||
$this->completeOnsitePurchase();
|
||||
Session::flash('message', trans('texts.applied_payment'));
|
||||
if ($redirectUrl = session('redirect_url:' . $this->invitation->invitation_key)) {
|
||||
$separator = strpos($redirectUrl, '?') === false ? '?' : '&';
|
||||
return redirect()->to($redirectUrl . $separator . 'invoice_id=' . $this->invoice()->public_id);
|
||||
} else {
|
||||
Session::flash('message', trans('texts.applied_payment'));
|
||||
}
|
||||
}
|
||||
|
||||
return redirect()->to('view/' . $this->invitation->invitation_key);
|
||||
@ -613,9 +619,13 @@ class BasePaymentDriver
|
||||
|
||||
$payment->save();
|
||||
|
||||
$accountKey = $invoice->account->account_key;
|
||||
|
||||
if ($accountKey == env('NINJA_LICENSE_ACCOUNT_KEY')) {
|
||||
$this->createLicense($payment);
|
||||
// TODO move this code
|
||||
// enable pro plan for hosted users
|
||||
if ($invoice->account->account_key == NINJA_ACCOUNT_KEY) {
|
||||
} elseif ($accountKey == NINJA_ACCOUNT_KEY) {
|
||||
foreach ($invoice->invoice_items as $invoice_item) {
|
||||
// Hacky, but invoices don't have meta fields to allow us to store this easily
|
||||
if (1 == preg_match('/^Plan - (.+) \((.+)\)$/', $invoice_item->product_key, $matches)) {
|
||||
@ -679,6 +689,33 @@ class BasePaymentDriver
|
||||
return $payment;
|
||||
}
|
||||
|
||||
protected function createLicense($payment)
|
||||
{
|
||||
// TODO parse invoice to determine license
|
||||
if ($payment->amount == 20) {
|
||||
$affiliateId = 4;
|
||||
$productId = PRODUCT_WHITE_LABEL;
|
||||
} else {
|
||||
$affiliateId = 1;
|
||||
$productId = PRODUCT_ONE_CLICK_INSTALL;
|
||||
}
|
||||
|
||||
$license = new License();
|
||||
$license->first_name = $this->contact()->first_name;
|
||||
$license->last_name = $this->contact()->last_name;
|
||||
$license->email = $this->contact()->email;
|
||||
$license->transaction_reference = $payment->transaction_reference;
|
||||
$license->license_key = Utils::generateLicense();
|
||||
$license->affiliate_id = $affiliateId;
|
||||
$license->product_id = $productId;
|
||||
$license->save();
|
||||
|
||||
// Add the license key to the redirect URL
|
||||
$key = 'redirect_url:' . $payment->invitation->invitation_key;
|
||||
$redirectUrl = session($key);
|
||||
session([$key => "{$redirectUrl}?license_key={$license->license_key}&product_id={$productId}"]);
|
||||
}
|
||||
|
||||
protected function creatingPayment($payment, $paymentMethod)
|
||||
{
|
||||
return $payment;
|
||||
|
@ -2284,7 +2284,8 @@ $LANG = array(
|
||||
'debug' => 'Debug',
|
||||
'https' => 'HTTPS',
|
||||
'require' => 'Require',
|
||||
'license_expiring' => 'Note: Your license will expire in :count days, :link to renew it.'
|
||||
'license_expiring' => 'Note: Your license will expire in :count days, :link to renew it.',
|
||||
'security_confirmation' => 'Your email address has been confirmed.',
|
||||
|
||||
);
|
||||
|
||||
|
@ -6,8 +6,11 @@
|
||||
|
||||
@if (Auth::user()->account->hasFeature(FEATURE_WHITE_LABEL))
|
||||
{{ trans('texts.white_labeled') }}
|
||||
@if ($company->hasActivePlan() && $company->daysUntilPlanExpires() <= 10)
|
||||
- <b>{{ trans('texts.license_expiring', ['count' => $company->daysUntilPlanExpires(), 'link' => 'link']) }}</b>
|
||||
@if (false && $company->hasActivePlan() && $company->daysUntilPlanExpires() <= 10)
|
||||
- <b>{!! trans('texts.license_expiring', [
|
||||
'count' => $company->daysUntilPlanExpires(),
|
||||
'link' => '<a href="#" onclick="buyWhiteLabel()">' . trans('texts.click_here') . '</a>',
|
||||
]) !!}</b>
|
||||
@endif
|
||||
@else
|
||||
<a href="#" onclick="showWhiteLabelModal()">{{ trans('texts.white_label_link') }}</a>
|
||||
@ -37,7 +40,7 @@
|
||||
|
||||
<div class="modal-footer" id="signUpFooter" style="margin-top: 0px">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('texts.close') }} </button>
|
||||
<button type="button" class="btn btn-primary" onclick="buyProduct('{{ WHITE_LABEL_AFFILIATE_KEY }}', '{{ PRODUCT_WHITE_LABEL }}')">{{ trans('texts.buy_license') }} </button>
|
||||
<button type="button" class="btn btn-primary" onclick="buyWhiteLabel()">{{ trans('texts.buy_license') }} </button>
|
||||
<button type="button" class="btn btn-primary" onclick="showApplyLicense()">{{ trans('texts.apply_license') }} </button>
|
||||
</div>
|
||||
</div>
|
||||
@ -76,8 +79,13 @@
|
||||
$('#whiteLabelModal').modal('show');
|
||||
}
|
||||
|
||||
function buyWhiteLabel() {
|
||||
buyProduct('{{ WHITE_LABEL_AFFILIATE_KEY }}', '{{ PRODUCT_WHITE_LABEL }}');
|
||||
}
|
||||
|
||||
function buyProduct(affiliateKey, productId) {
|
||||
window.open('{{ Utils::isNinjaDev() ? '' : NINJA_APP_URL }}/license?affiliate_key=' + affiliateKey + '&product_id=' + productId + '&return_url=' + window.location);
|
||||
//window.open('{{ Utils::isNinjaDev() ? '' : NINJA_APP_URL }}/buy_now/?account_key={{ env('NINJA_LICENSE_ACCOUNT_KEY') }}&product_id=' + productId + '&contact_key={{ Auth::user()->primaryAccount()->account_key }}' + '&return_url=' + window.location);
|
||||
}
|
||||
|
||||
function showApplyLicense() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user