mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-23 09:40:39 +00:00
Merge remote-tracking branch 'origin/master' into oasis
# Conflicts: # app/Console/Commands/SetupDevEnvironment.php # app/Console/Kernel.php # app/Http/Resources/InvoiceResource.php # app/Http/Resources/UserResource.php # app/Models/User.php # composer.lock # config/app.php # config/custom-language-translations.php # config/language-translations.php # public/chunks/admin.js # public/chunks/app-language.js # public/chunks/dashboard.js # public/chunks/files.js # public/chunks/files~chunks/shared-files~chunks/shared/file-browser.js # public/chunks/files~chunks/shared-files~chunks/shared/file-browser~chunks/shared/single-file.js # public/chunks/invoices.js # public/chunks/pages.js # public/chunks/plan-subscribers.js # public/chunks/plans.js # public/chunks/platform.js # public/chunks/settings-invoices.js # public/chunks/settings-payment-methods.js # public/chunks/settings-subscription.js # public/chunks/shared-files.js # public/chunks/shared.js # public/chunks/shared/file-browser.js # public/chunks/user-invoices.js # public/chunks/user-subscription.js # public/chunks/users.js # public/js/main.js # public/mix-manifest.json # resources/js/components/FilesView/FileItemGrid.vue # resources/js/components/FilesView/FileItemList.vue
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Stripe;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Http\Request;
|
||||
use Laravel\Cashier\Cashier;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Laravel\Cashier\Exceptions\IncompletePayment;
|
||||
use Laravel\Cashier\Exceptions\PaymentActionRequired;
|
||||
use Stripe;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class StripeService
|
||||
@@ -61,18 +59,19 @@ class StripeService
|
||||
$rates_public = [];
|
||||
|
||||
foreach ($this->getTaxRates() as $rate) {
|
||||
|
||||
// Continue when is not active
|
||||
if (!$rate['active']) continue;
|
||||
if (! $rate['active']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Calculate tax
|
||||
$tax = $amount * ($rate['percentage'] / 100);
|
||||
|
||||
array_push($rates_public, [
|
||||
'id' => $rate['id'],
|
||||
'active' => $rate['active'],
|
||||
'country' => $rate['country'],
|
||||
'percentage' => $rate['percentage'],
|
||||
'id' => $rate['id'],
|
||||
'active' => $rate['active'],
|
||||
'country' => $rate['country'],
|
||||
'percentage' => $rate['percentage'],
|
||||
'plan_price_formatted' => Cashier::formatAmount(round($amount + $tax)),
|
||||
]);
|
||||
}
|
||||
@@ -90,8 +89,7 @@ class StripeService
|
||||
public function getOrSetDefaultPaymentMethod($request, $user)
|
||||
{
|
||||
// Check payment method
|
||||
if (!$request->has('payment.meta.pm') && $user->hasDefaultPaymentMethod()) {
|
||||
|
||||
if (! $request->has('payment.meta.pm') && $user->hasDefaultPaymentMethod()) {
|
||||
// Get default payment
|
||||
return $user->defaultPaymentMethod()->paymentMethod;
|
||||
}
|
||||
@@ -99,23 +97,18 @@ class StripeService
|
||||
// Clear cached payment methods
|
||||
cache_forget_many([
|
||||
'payment-methods-user-' . $user->id,
|
||||
'default-payment-methods-user-' . $user->id
|
||||
'default-payment-methods-user-' . $user->id,
|
||||
]);
|
||||
|
||||
if ($request->has('payment.meta.pm') && $user->hasDefaultPaymentMethod()) {
|
||||
|
||||
// Set new payment
|
||||
return $user->addPaymentMethod($request->input('payment.meta.pm'))->paymentMethod;
|
||||
|
||||
} else if ($request->has('payment.meta.pm') && !$user->hasDefaultPaymentMethod()) {
|
||||
|
||||
} elseif ($request->has('payment.meta.pm') && ! $user->hasDefaultPaymentMethod()) {
|
||||
// Set new payment
|
||||
return $user->updateDefaultPaymentMethod($request->input('payment.meta.pm'))->paymentMethod;
|
||||
|
||||
} else {
|
||||
|
||||
throw new HttpException(400, 'Something went wrong.');
|
||||
}
|
||||
|
||||
throw new HttpException(400, 'Something went wrong.');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,7 +123,7 @@ class StripeService
|
||||
// Clear cached payment methods
|
||||
cache_forget_many([
|
||||
'payment-methods-user-' . $user->id,
|
||||
'default-payment-methods-user-' . $user->id
|
||||
'default-payment-methods-user-' . $user->id,
|
||||
]);
|
||||
|
||||
// Set new payment method
|
||||
@@ -153,33 +146,25 @@ class StripeService
|
||||
public function createOrReplaceSubscription($request, $user)
|
||||
{
|
||||
try {
|
||||
|
||||
// Get payment method
|
||||
$paymentMethod = $this->getOrSetDefaultPaymentMethod($request, $user);
|
||||
|
||||
// Check if user have subscription
|
||||
if ($user->subscribed('main')) {
|
||||
|
||||
// Change subscription plan
|
||||
$user->subscription('main')->skipTrial()->swap($request->input('plan.data.id'));
|
||||
|
||||
} else {
|
||||
|
||||
// Create subscription
|
||||
$user->newSubscription('main', $request->input('plan.data.id'))->create($paymentMethod);
|
||||
}
|
||||
|
||||
} catch (IncompletePayment $exception) {
|
||||
|
||||
if ($exception instanceof PaymentActionRequired) {
|
||||
|
||||
$cashier_route = route('cashier.payment', [$exception->payment->id, 'redirect' => url('/settings/subscription')]);
|
||||
|
||||
throw new HttpException(402, $cashier_route);
|
||||
} else {
|
||||
throw new HttpException(400, $exception->getMessage());
|
||||
}
|
||||
|
||||
throw new HttpException(400, $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,18 +176,18 @@ class StripeService
|
||||
public function updateCustomerDetails($user)
|
||||
{
|
||||
$user->updateStripeCustomer([
|
||||
'name' => $user->settings->name,
|
||||
'phone' => $user->settings->phone_number,
|
||||
'name' => $user->settings->name,
|
||||
'phone' => $user->settings->phone_number,
|
||||
'address' => [
|
||||
'line1' => $user->settings->address,
|
||||
'city' => $user->settings->city,
|
||||
'country' => $user->settings->country,
|
||||
'line1' => $user->settings->address,
|
||||
'city' => $user->settings->city,
|
||||
'country' => $user->settings->country,
|
||||
'postal_code' => $user->settings->postal_code,
|
||||
'state' => $user->settings->state,
|
||||
'state' => $user->settings->state,
|
||||
],
|
||||
'preferred_locales' => [
|
||||
$user->settings->country, 'en'
|
||||
]
|
||||
$user->settings->country, 'en',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -220,14 +205,13 @@ class StripeService
|
||||
$plans = [];
|
||||
|
||||
foreach ($stripe_plans['data'] as $plan) {
|
||||
|
||||
// Get stripe product
|
||||
$product = $this->stripe->products()->find($plan['product']);
|
||||
|
||||
// Push data to $plan container
|
||||
if ($product['active'] && isset($product['metadata']['capacity'])) {
|
||||
array_push($plans, [
|
||||
'plan' => $plan,
|
||||
'plan' => $plan,
|
||||
'product' => $product,
|
||||
]);
|
||||
}
|
||||
@@ -250,16 +234,14 @@ class StripeService
|
||||
$plans = [];
|
||||
|
||||
foreach ($stripe_plans['data'] as $plan) {
|
||||
|
||||
if ($plan['active']) {
|
||||
|
||||
// Get stripe product
|
||||
$product = $this->stripe->products()->find($plan['product']);
|
||||
|
||||
// Push data to $plan container
|
||||
if ($product['active'] && isset($product['metadata']['capacity'])) {
|
||||
array_push($plans, [
|
||||
'plan' => $plan,
|
||||
'plan' => $plan,
|
||||
'product' => $product,
|
||||
]);
|
||||
}
|
||||
@@ -282,12 +264,11 @@ class StripeService
|
||||
}
|
||||
|
||||
return Cache::rememberForever("plan-$id", function () use ($id) {
|
||||
|
||||
$plan = $this->stripe->plans()->find($id);
|
||||
$product = $this->stripe->products()->find($plan['product']);
|
||||
|
||||
return [
|
||||
'plan' => $plan,
|
||||
'plan' => $plan,
|
||||
'product' => $product,
|
||||
];
|
||||
});
|
||||
@@ -303,34 +284,34 @@ class StripeService
|
||||
{
|
||||
if ($data instanceof Request) {
|
||||
$plan = [
|
||||
'name' => $data->input('attributes.name'),
|
||||
'name' => $data->input('attributes.name'),
|
||||
'description' => $data->input('attributes.description'),
|
||||
'price' => $data->input('attributes.price'),
|
||||
'capacity' => $data->input('attributes.capacity'),
|
||||
'price' => $data->input('attributes.price'),
|
||||
'capacity' => $data->input('attributes.capacity'),
|
||||
];
|
||||
} else {
|
||||
$plan = [
|
||||
'name' => $data['attributes']['name'],
|
||||
'name' => $data['attributes']['name'],
|
||||
'description' => $data['attributes']['description'],
|
||||
'price' => $data['attributes']['price'],
|
||||
'capacity' => $data['attributes']['capacity'],
|
||||
'price' => $data['attributes']['price'],
|
||||
'capacity' => $data['attributes']['capacity'],
|
||||
];
|
||||
}
|
||||
|
||||
$product = $this->stripe->products()->create([
|
||||
'name' => $plan['name'],
|
||||
'name' => $plan['name'],
|
||||
'description' => $plan['description'],
|
||||
'metadata' => [
|
||||
'capacity' => $plan['capacity']
|
||||
]
|
||||
'metadata' => [
|
||||
'capacity' => $plan['capacity'],
|
||||
],
|
||||
]);
|
||||
|
||||
$plan = $this->stripe->plans()->create([
|
||||
'id' => Str::slug($plan['name']),
|
||||
'amount' => $plan['price'],
|
||||
'id' => Str::slug($plan['name']),
|
||||
'amount' => $plan['price'],
|
||||
'currency' => config('cashier.currency'),
|
||||
'interval' => 'month',
|
||||
'product' => $product['id'],
|
||||
'product' => $product['id'],
|
||||
]);
|
||||
|
||||
return compact('plan', 'product');
|
||||
@@ -351,13 +332,14 @@ class StripeService
|
||||
|
||||
// Update product
|
||||
if (in_array($request->name, $product_colls)) {
|
||||
|
||||
if ($request->name === 'capacity') {
|
||||
$this->stripe->products()->update($plan['product'], ['metadata' => ['capacity' => $request->value]]);
|
||||
}
|
||||
|
||||
if ($request->name === 'name') {
|
||||
$this->stripe->products()->update($plan['product'], ['name' => $request->value]);
|
||||
}
|
||||
|
||||
if ($request->name === 'description') {
|
||||
$this->stripe->products()->update($plan['product'], ['description' => $request->value]);
|
||||
}
|
||||
@@ -365,7 +347,6 @@ class StripeService
|
||||
|
||||
// Update plan
|
||||
if (in_array($request->name, $plan_colls)) {
|
||||
|
||||
if ($request->name === 'is_active') {
|
||||
$this->stripe->plans()->update($id, ['active' => $request->value]);
|
||||
}
|
||||
@@ -422,7 +403,7 @@ class StripeService
|
||||
->stripe
|
||||
->invoices()
|
||||
->all([
|
||||
'limit' => 20
|
||||
'limit' => 20,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user