mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 00:02:15 +00:00
frontend & backend update
This commit is contained in:
@@ -5,6 +5,8 @@ namespace App\Http\Controllers\Admin;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\GatewayCollection;
|
||||
use App\Http\Resources\GatewayResource;
|
||||
use App\Http\Resources\InvoiceCollection;
|
||||
use App\Invoice;
|
||||
use App\PaymentGateway;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -33,6 +35,19 @@ class GatewayController extends Controller
|
||||
return new GatewayResource($gateway);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single payment gateway by slug
|
||||
*
|
||||
* @param $slug
|
||||
* @return InvoiceCollection
|
||||
*/
|
||||
public function show_transactions($slug)
|
||||
{
|
||||
return new InvoiceCollection(
|
||||
Invoice::where('provider', $slug)->get()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update payment gateway options
|
||||
*
|
||||
|
||||
@@ -8,12 +8,21 @@ use App\Http\Resources\PlanResource;
|
||||
use App\Http\Resources\UserResource;
|
||||
use App\Http\Resources\UsersCollection;
|
||||
use App\Plan;
|
||||
use App\Services\StripeService;
|
||||
use App\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Rinvex\Subscriptions\Models\PlanFeature;
|
||||
|
||||
class PlanController extends Controller
|
||||
{
|
||||
/**
|
||||
* PlanController constructor.
|
||||
*/
|
||||
public function __construct(StripeService $stripe)
|
||||
{
|
||||
$this->stripe = $stripe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plans
|
||||
*
|
||||
@@ -22,7 +31,7 @@ class PlanController extends Controller
|
||||
public function index()
|
||||
{
|
||||
return new PlanCollection(
|
||||
app('rinvex.subscriptions.plan')->all()
|
||||
$this->stripe->getPlans()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -35,7 +44,7 @@ class PlanController extends Controller
|
||||
public function show($id)
|
||||
{
|
||||
return new PlanResource(
|
||||
app('rinvex.subscriptions.plan')->find($id)
|
||||
$this->stripe->getPlan($id)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -47,26 +56,9 @@ class PlanController extends Controller
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$plan = app('rinvex.subscriptions.plan')->create([
|
||||
'description' => $request->input('attributes.description'),
|
||||
'price' => $request->input('attributes.price'),
|
||||
'name' => $request->input('attributes.name'),
|
||||
'currency' => 'USD',
|
||||
'invoice_period' => 1,
|
||||
'sort_order' => 1,
|
||||
'signup_fee' => 0,
|
||||
]);
|
||||
|
||||
// Create multiple plan features at once
|
||||
$plan->features()->saveMany([
|
||||
new PlanFeature([
|
||||
'name' => 'Storage capacity',
|
||||
'value' => $request->input('attributes.capacity'),
|
||||
'sort_order' => 1
|
||||
]),
|
||||
]);
|
||||
|
||||
return new PlanResource($plan);
|
||||
return new PlanResource(
|
||||
$this->stripe->createPlan($request)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,18 +70,24 @@ class PlanController extends Controller
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
// TODO: validation request
|
||||
$plan = app('rinvex.subscriptions.plan')->find($id);
|
||||
|
||||
if ($request->name === 'capacity') {
|
||||
$plan->getFeatureBySlug('storage-capacity')->update(['value' => $request->value]);
|
||||
} else {
|
||||
$plan->update(make_single_input($request));
|
||||
}
|
||||
$this->stripe->updatePlan($request, $id);
|
||||
|
||||
return response('Saved!', 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete plan
|
||||
*
|
||||
* @param $id
|
||||
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$this->stripe->deletePlan($id);
|
||||
|
||||
return response('Done!', 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subscriptions
|
||||
*
|
||||
|
||||
@@ -258,11 +258,6 @@ class EditItemsController extends Controller
|
||||
return Demo::upload($request);
|
||||
}
|
||||
|
||||
// Check if user can upload
|
||||
if (config('vuefilemanager.limit_storage_by_capacity') && user_storage_percentage() >= 100) {
|
||||
abort(423, 'You exceed your storage limit!');
|
||||
}
|
||||
|
||||
// Check permission to upload for authenticated editor
|
||||
if ($request->user()->tokenCan('editor')) {
|
||||
|
||||
|
||||
@@ -4,19 +4,32 @@ namespace App\Http\Controllers\General;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\PricingCollection;
|
||||
use App\Services\StripeService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PricingController extends Controller
|
||||
{
|
||||
/**
|
||||
* PlanController constructor.
|
||||
*/
|
||||
public function __construct(StripeService $stripe)
|
||||
{
|
||||
$this->stripe = $stripe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all active plans
|
||||
*
|
||||
* @return PricingCollection
|
||||
*/
|
||||
public function index() {
|
||||
|
||||
return new PricingCollection(
|
||||
app('rinvex.subscriptions.plan')->where('is_active', 1)->get()
|
||||
public function index()
|
||||
{
|
||||
$collection = new PricingCollection(
|
||||
$this->stripe->getActivePlans()
|
||||
);
|
||||
|
||||
return $collection->sortBy('product.metadata.capacity')
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
}
|
||||
|
||||
107
app/Http/Controllers/User/PaymentCardsController.php
Normal file
107
app/Http/Controllers/User/PaymentCardsController.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\PaymentCardCollection;
|
||||
use App\Http\Resources\PaymentCardResource;
|
||||
use App\Http\Resources\PaymentDefaultCardResource;
|
||||
use App\Services\PaymentService;
|
||||
use App\UserCard;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Laravel\Cashier\PaymentMethod;
|
||||
|
||||
class PaymentCardsController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var PaymentService
|
||||
*/
|
||||
private $payment;
|
||||
|
||||
/**
|
||||
* PaymentCardsController constructor.
|
||||
*/
|
||||
public function __construct(PaymentService $payment)
|
||||
{
|
||||
$this->payment = $payment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update card detail
|
||||
*
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
// Update DefaultPayment Method
|
||||
$user->updateDefaultPaymentMethod($id);
|
||||
|
||||
// Sync default payment method
|
||||
$user->updateDefaultPaymentMethodFromStripe();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user credit card
|
||||
*
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
// Get payment method
|
||||
$paymentMethod = $user->findPaymentMethod($id);
|
||||
|
||||
// Delete payment method
|
||||
$paymentMethod->delete();
|
||||
|
||||
// Sync default payment method
|
||||
$user->updateDefaultPaymentMethodFromStripe();
|
||||
|
||||
return response('Done!', 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user payment methods sorted by default and others
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function payment_methods()
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
// Get default payment method
|
||||
$defaultPaymentMethodObject = $user->defaultPaymentMethod();
|
||||
|
||||
$defaultPaymentMethod = $defaultPaymentMethodObject instanceof PaymentMethod
|
||||
? $defaultPaymentMethodObject->asStripePaymentMethod()
|
||||
: $defaultPaymentMethodObject;
|
||||
|
||||
// filter payment methods without default payment
|
||||
$paymentMethods = $user->paymentMethods()->filter(function ($paymentMethod) use ($defaultPaymentMethod) {
|
||||
return $paymentMethod->id !== $defaultPaymentMethod->id;
|
||||
});
|
||||
|
||||
// Get payment methods
|
||||
$paymentMethodsMapped = $paymentMethods->map(function ($paymentMethod) {
|
||||
return $paymentMethod->asStripePaymentMethod();
|
||||
})->values()->all();
|
||||
|
||||
if (is_null($paymentMethodsMapped) && is_null($paymentMethodsMapped)) {
|
||||
return [
|
||||
'default' => null,
|
||||
'others' => [],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'default' => $defaultPaymentMethod instanceof PaymentMethod
|
||||
? new PaymentCardResource($defaultPaymentMethod)
|
||||
: new PaymentDefaultCardResource($defaultPaymentMethod),
|
||||
'others' => new PaymentCardCollection($paymentMethodsMapped),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -3,53 +3,82 @@
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Subscription\StoreUpgradeAccountRequest;
|
||||
use App\Http\Resources\UserSubscription;
|
||||
use App\Invoice;
|
||||
use App\Services\PaymentService;
|
||||
use App\Services\StripeService;
|
||||
use Auth;
|
||||
use Cartalyst\Stripe\Exception\CardErrorException;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Illuminate\Http\Request;
|
||||
use Laravel\Cashier\Exceptions\IncompletePayment;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class SubscriptionController extends Controller
|
||||
{
|
||||
private $stripe;
|
||||
|
||||
/**
|
||||
* SubscriptionController constructor.
|
||||
* @param $payment
|
||||
*/
|
||||
public function __construct(StripeService $stripe)
|
||||
{
|
||||
$this->stripe = $stripe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate setup intent
|
||||
*
|
||||
* @return \Stripe\SetupIntent
|
||||
*/
|
||||
public function stripe_setup_intent()
|
||||
{
|
||||
// Get user
|
||||
$user = Auth::user();
|
||||
|
||||
// Create stripe customer if not exist
|
||||
$user->createOrGetStripeCustomer();
|
||||
|
||||
// Return setup intent
|
||||
return $user->createSetupIntent();
|
||||
}
|
||||
|
||||
public function show()
|
||||
{
|
||||
return new UserSubscription(
|
||||
Auth::user()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade account to subscription
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
|
||||
* @param StoreUpgradeAccountRequest $request
|
||||
* @return ResponseFactory|\Illuminate\Http\Response
|
||||
*/
|
||||
public function upgrade(Request $request)
|
||||
public function upgrade(StoreUpgradeAccountRequest $request)
|
||||
{
|
||||
// TODO: validation request
|
||||
|
||||
// Get user
|
||||
$user = Auth::user();
|
||||
|
||||
// Get requested plan
|
||||
$plan = app('rinvex.subscriptions.plan')
|
||||
->find($request->input('plan.data.id'));
|
||||
$plan = $this->stripe->getPlan($request->input('plan.data.id'));
|
||||
|
||||
// Check if user have subscription
|
||||
if ($user->activeSubscriptions()->count() !== 0) {
|
||||
// Set user billing
|
||||
$user->setBilling($request->input('billing'));
|
||||
|
||||
// Get old subscription
|
||||
$subscription = $user->subscription('main');
|
||||
|
||||
// Change subscription plan
|
||||
$subscription->changePlan($plan);
|
||||
|
||||
} else {
|
||||
|
||||
// Create subscription
|
||||
$user->newSubscription('main', $plan);
|
||||
}
|
||||
// Make subscription
|
||||
$this->stripe->createOrReplaceSubscription($request, $user);
|
||||
|
||||
// Update user storage limit
|
||||
$user->settings()->update([
|
||||
'storage_capacity' => $plan->features->first()->value
|
||||
'storage_capacity' => $plan['product']['metadata']['capacity']
|
||||
]);
|
||||
|
||||
// Store invoice
|
||||
Invoice::create(
|
||||
get_invoice_data($user, $plan)
|
||||
);
|
||||
Invoice::create(get_invoice_data($user, $plan, 'stripe'));
|
||||
|
||||
return response('Done!', 204);
|
||||
}
|
||||
@@ -57,15 +86,25 @@ class SubscriptionController extends Controller
|
||||
/**
|
||||
* Cancel Subscription
|
||||
*
|
||||
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
|
||||
* @return ResponseFactory|\Illuminate\Http\Response
|
||||
*/
|
||||
public function cancel() {
|
||||
|
||||
// Get user
|
||||
$user = Auth::user();
|
||||
|
||||
public function cancel()
|
||||
{
|
||||
// Cancel subscription
|
||||
$user->subscription('main')->cancel();
|
||||
Auth::user()->subscription('main')->cancel();
|
||||
|
||||
return response('Done!', 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resume Subscription
|
||||
*
|
||||
* @return ResponseFactory|\Illuminate\Http\Response
|
||||
*/
|
||||
public function resume()
|
||||
{
|
||||
// Resume subscription
|
||||
Auth::user()->subscription('main')->resume();
|
||||
|
||||
return response('Done!', 204);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user