1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 12:12:48 +01:00

In app purchase

This commit is contained in:
Hillel Coren 2019-08-28 10:14:05 +03:00
parent c1fa41ee30
commit 0ee357e97a
3 changed files with 84 additions and 0 deletions

View File

@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use App\Events\UserSignedUp; use App\Events\UserSignedUp;
use App\Http\Requests\RegisterRequest; use App\Http\Requests\RegisterRequest;
use App\Http\Requests\UpdateAccountRequest; use App\Http\Requests\UpdateAccountRequest;
use App\Models\Company;
use App\Models\Account; use App\Models\Account;
use App\Models\User; use App\Models\User;
use App\Ninja\OAuth\OAuth; use App\Ninja\OAuth\OAuth;
@ -14,6 +15,7 @@ use App\Ninja\Transformers\UserAccountTransformer;
use App\Services\AuthService; use App\Services\AuthService;
use Auth; use Auth;
use Cache; use Cache;
use Carbon;
use Exception; use Exception;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
@ -287,4 +289,53 @@ class AccountApiController extends BaseAPIController
} }
public function upgrade(Request $request)
{
$user = Auth::user();
$account = $user->account;
$company = $account->company;
$orderId = $request->order_id;
$timestamp = $request->timestamp;
$productId = $request->product_id;
if (Company::where('app_store_order_id', '=', $orderId)->first()) {
return 'Order Id has already been used';
}
if (Carbon::createFromTimestamp($timestamp) < Carbon::now()->subYear()) {
return 'The order is expired';
}
if ($productId == 'v1_pro_yearly') {
$company->plan = PLAN_PRO;
$company->num_users = 1;
$company->plan_price = PLAN_PRICE_PRO_MONTHLY * 10;
} else if ($productId == 'v1_enterprise_2_yearly') {
$company->plan = PLAN_ENTERPRISE;
$company->num_users = 2;
$company->plan_price = PLAN_PRICE_ENTERPRISE_MONTHLY_2 * 10;
} else if ($productId == 'v1_enterprise_5_yearly') {
$company->plan = PLAN_ENTERPRISE;
$company->num_users = 5;
$company->plan_price = PLAN_PRICE_ENTERPRISE_MONTHLY_5 * 10;
} else if ($productId == 'v1_enterprise_10_yearly') {
$company->plan = PLAN_ENTERPRISE;
$company->num_users = 10;
$company->plan_price = PLAN_PRICE_ENTERPRISE_MONTHLY_10 * 10;
} else if ($productId == 'v1_enterprise_20_yearly') {
$company->plan = PLAN_ENTERPRISE;
$company->num_users = 20;
$company->plan_price = PLAN_PRICE_ENTERPRISE_MONTHLY_20 * 10;
}
$company->app_store_order_id = $orderId;
$company->plan_term = PLAN_TERM_YEARLY;
$company->plan_started = $company->plan_started ?: date('Y-m-d');
$company->plan_paid = date('Y-m-d');
$company->plan_expires = Carbon::createFromTimestamp($timestamp)->addYear()->format('Y-m-d');
$company->trial_plan = null;
$company->save();
return RESULT_SUCCESS;
}
} }

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddAppStoreOrderId extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('companies', function ($table) {
$table->string('app_store_order_id')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('companies', function ($table) {
$table->dropColumn('app_store_order_id');
});
}
}

View File

@ -8,6 +8,7 @@ Route::get('static', 'AccountApiController@getStaticData');
Route::get('accounts', 'AccountApiController@show'); Route::get('accounts', 'AccountApiController@show');
Route::put('accounts', 'AccountApiController@update'); Route::put('accounts', 'AccountApiController@update');
Route::post('refresh', 'AccountApiController@refresh'); Route::post('refresh', 'AccountApiController@refresh');
Route::post('upgrade', 'AccountApiController@upgrade');
Route::resource('clients', 'ClientApiController'); Route::resource('clients', 'ClientApiController');
Route::resource('contacts', 'ContactApiController'); Route::resource('contacts', 'ContactApiController');