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 Validator;
|
||||||
use App\Models\Invitation;
|
use App\Models\Invitation;
|
||||||
use App\Models\Account;
|
use App\Models\Account;
|
||||||
|
use App\Models\Client;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use App\Models\PaymentMethod;
|
use App\Models\PaymentMethod;
|
||||||
@ -283,22 +284,31 @@ class OnlinePaymentController extends BaseController
|
|||||||
return redirect()->to("{$failureUrl}/?error=invalid product");
|
return redirect()->to("{$failureUrl}/?error=invalid product");
|
||||||
}
|
}
|
||||||
|
|
||||||
$rules = [
|
// check for existing client using contact_key
|
||||||
'first_name' => 'string|max:100',
|
$client = false;
|
||||||
'last_name' => 'string|max:100',
|
if ($contactKey = Input::get('contact_key')) {
|
||||||
'email' => 'email|string|max:100',
|
$client = Client::scope()->whereHas('contacts', function ($query) use ($contactKey) {
|
||||||
];
|
$query->where('contact_key', $contactKey);
|
||||||
|
})->first();
|
||||||
$validator = Validator::make(Input::all(), $rules);
|
|
||||||
if ($validator->fails()) {
|
|
||||||
return redirect()->to("{$failureUrl}/?error=" . $validator->errors()->first());
|
|
||||||
}
|
}
|
||||||
|
if ( ! $client) {
|
||||||
|
$rules = [
|
||||||
|
'first_name' => 'string|max:100',
|
||||||
|
'last_name' => 'string|max:100',
|
||||||
|
'email' => 'email|string|max:100',
|
||||||
|
];
|
||||||
|
|
||||||
$data = [
|
$validator = Validator::make(Input::all(), $rules);
|
||||||
'currency_id' => $account->currency_id,
|
if ($validator->fails()) {
|
||||||
'contact' => Input::all()
|
return redirect()->to("{$failureUrl}/?error=" . $validator->errors()->first());
|
||||||
];
|
}
|
||||||
$client = $clientRepo->save($data);
|
|
||||||
|
$data = [
|
||||||
|
'currency_id' => $account->currency_id,
|
||||||
|
'contact' => Input::all()
|
||||||
|
];
|
||||||
|
$client = $clientRepo->save($data);
|
||||||
|
}
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'client_id' => $client->id,
|
'client_id' => $client->id,
|
||||||
|
@ -240,7 +240,7 @@ class UserController extends BaseController
|
|||||||
$user = User::where('confirmation_code', '=', $code)->get()->first();
|
$user = User::where('confirmation_code', '=', $code)->get()->first();
|
||||||
|
|
||||||
if ($user) {
|
if ($user) {
|
||||||
$notice_msg = trans('texts.security.confirmation');
|
$notice_msg = trans('texts.security_confirmation');
|
||||||
|
|
||||||
$user->confirmed = true;
|
$user->confirmed = true;
|
||||||
$user->confirmation_code = '';
|
$user->confirmation_code = '';
|
||||||
|
@ -275,6 +275,7 @@ class Client extends EntityModel
|
|||||||
} else {
|
} else {
|
||||||
$contact = Contact::createNew();
|
$contact = Contact::createNew();
|
||||||
$contact->send_invoice = true;
|
$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){
|
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))
|
return (($entity && $this->can('edit', $entity))
|
||||||
|| (!$entity && $this->can('create', $entityType)));
|
|| (!$entity && $this->can('create', $entityType)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function primaryAccount()
|
||||||
|
{
|
||||||
|
return $this->account->company->accounts->sortBy('id')->first();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
User::updating(function ($user) {
|
User::updating(function ($user) {
|
||||||
|
@ -8,6 +8,7 @@ use Omnipay;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use CreditCard;
|
use CreditCard;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
use App\Models\License;
|
||||||
use App\Models\AccountGatewayToken;
|
use App\Models\AccountGatewayToken;
|
||||||
use App\Models\AccountGatewaySettings;
|
use App\Models\AccountGatewaySettings;
|
||||||
use App\Models\Account;
|
use App\Models\Account;
|
||||||
@ -133,7 +134,12 @@ class BasePaymentDriver
|
|||||||
Session::reflash();
|
Session::reflash();
|
||||||
} else {
|
} else {
|
||||||
$this->completeOnsitePurchase();
|
$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);
|
return redirect()->to('view/' . $this->invitation->invitation_key);
|
||||||
@ -613,9 +619,13 @@ class BasePaymentDriver
|
|||||||
|
|
||||||
$payment->save();
|
$payment->save();
|
||||||
|
|
||||||
|
$accountKey = $invoice->account->account_key;
|
||||||
|
|
||||||
|
if ($accountKey == env('NINJA_LICENSE_ACCOUNT_KEY')) {
|
||||||
|
$this->createLicense($payment);
|
||||||
// TODO move this code
|
// TODO move this code
|
||||||
// enable pro plan for hosted users
|
// 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) {
|
foreach ($invoice->invoice_items as $invoice_item) {
|
||||||
// Hacky, but invoices don't have meta fields to allow us to store this easily
|
// 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)) {
|
if (1 == preg_match('/^Plan - (.+) \((.+)\)$/', $invoice_item->product_key, $matches)) {
|
||||||
@ -679,6 +689,33 @@ class BasePaymentDriver
|
|||||||
return $payment;
|
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)
|
protected function creatingPayment($payment, $paymentMethod)
|
||||||
{
|
{
|
||||||
return $payment;
|
return $payment;
|
||||||
|
@ -2284,7 +2284,8 @@ $LANG = array(
|
|||||||
'debug' => 'Debug',
|
'debug' => 'Debug',
|
||||||
'https' => 'HTTPS',
|
'https' => 'HTTPS',
|
||||||
'require' => 'Require',
|
'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))
|
@if (Auth::user()->account->hasFeature(FEATURE_WHITE_LABEL))
|
||||||
{{ trans('texts.white_labeled') }}
|
{{ trans('texts.white_labeled') }}
|
||||||
@if ($company->hasActivePlan() && $company->daysUntilPlanExpires() <= 10)
|
@if (false && $company->hasActivePlan() && $company->daysUntilPlanExpires() <= 10)
|
||||||
- <b>{{ trans('texts.license_expiring', ['count' => $company->daysUntilPlanExpires(), 'link' => 'link']) }}</b>
|
- <b>{!! trans('texts.license_expiring', [
|
||||||
|
'count' => $company->daysUntilPlanExpires(),
|
||||||
|
'link' => '<a href="#" onclick="buyWhiteLabel()">' . trans('texts.click_here') . '</a>',
|
||||||
|
]) !!}</b>
|
||||||
@endif
|
@endif
|
||||||
@else
|
@else
|
||||||
<a href="#" onclick="showWhiteLabelModal()">{{ trans('texts.white_label_link') }}</a>
|
<a href="#" onclick="showWhiteLabelModal()">{{ trans('texts.white_label_link') }}</a>
|
||||||
@ -37,7 +40,7 @@
|
|||||||
|
|
||||||
<div class="modal-footer" id="signUpFooter" style="margin-top: 0px">
|
<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-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>
|
<button type="button" class="btn btn-primary" onclick="showApplyLicense()">{{ trans('texts.apply_license') }} </button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -76,8 +79,13 @@
|
|||||||
$('#whiteLabelModal').modal('show');
|
$('#whiteLabelModal').modal('show');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buyWhiteLabel() {
|
||||||
|
buyProduct('{{ WHITE_LABEL_AFFILIATE_KEY }}', '{{ PRODUCT_WHITE_LABEL }}');
|
||||||
|
}
|
||||||
|
|
||||||
function buyProduct(affiliateKey, productId) {
|
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 }}/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() {
|
function showApplyLicense() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user