Update
This commit is contained in:
@@ -43,7 +43,6 @@ public static function getSubscriptionPlanByStripePriceID($stripe_price_id)
|
||||
|
||||
foreach ($plans as $plan) {
|
||||
|
||||
|
||||
if ($plan['id'] == 'free') {
|
||||
continue;
|
||||
}
|
||||
@@ -76,10 +75,10 @@ public static function getPlanSystemProperty($plan, $property)
|
||||
// Inject environment into the path
|
||||
// stripe.product_id.month becomes system.stripe.product_id.{env}.month
|
||||
array_splice($propertyParts, 2, 0, $environment);
|
||||
$fullPath = 'system.' . implode('.', $propertyParts);
|
||||
$fullPath = 'system.'.implode('.', $propertyParts);
|
||||
} else {
|
||||
// For non-stripe properties, just prepend 'system.'
|
||||
$fullPath = 'system.' . $property;
|
||||
$fullPath = 'system.'.$property;
|
||||
}
|
||||
|
||||
return data_get($plan, $fullPath);
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
use App\Helpers\FirstParty\Stripe\StripeHelper;
|
||||
use App\Models\Plan;
|
||||
use App\Models\UserPlan;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Laravel\Cashier\Events\WebhookReceived;
|
||||
|
||||
class SubscriptionHelper
|
||||
@@ -28,7 +27,7 @@ private static function handleSubscriptionUpsert(WebhookReceived $event)
|
||||
{
|
||||
$object = $event->payload['data']['object'];
|
||||
|
||||
//dump($object);
|
||||
// dump($object);
|
||||
|
||||
$ignore_statuses = ['incomplete_expired', 'incomplete'];
|
||||
|
||||
@@ -41,7 +40,7 @@ private static function handleSubscriptionUpsert(WebhookReceived $event)
|
||||
if ($user) {
|
||||
foreach ($object['items']['data'] as $line_item) {
|
||||
|
||||
//dump($line_item);
|
||||
// dump($line_item);
|
||||
|
||||
$stripe_price_id = $line_item['plan']['id'];
|
||||
$current_period_end = $line_item['current_period_end'];
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
use App\Helpers\FirstParty\Stripe\StripeHelper;
|
||||
use App\Models\UserUsage;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Laravel\Cashier\Events\WebhookReceived;
|
||||
|
||||
class WatermarkUsageHelper
|
||||
@@ -22,11 +21,11 @@ private static function handleInvoicePaid(WebhookReceived $event)
|
||||
{
|
||||
$object = $event->payload['data']['object'];
|
||||
|
||||
//dump($object);
|
||||
// dump($object);
|
||||
|
||||
$accept_statuses = ['paid', 'partially_paid'];
|
||||
|
||||
if (!in_array($object['status'], $accept_statuses)) {
|
||||
if (! in_array($object['status'], $accept_statuses)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,7 +35,7 @@ private static function handleInvoicePaid(WebhookReceived $event)
|
||||
foreach ($object['lines']['data'] as $line_item) {
|
||||
$stripe_price_id = $line_item['pricing']['price_details']['price'];
|
||||
|
||||
//dd($stripe_price_id);
|
||||
// dd($stripe_price_id);
|
||||
|
||||
$subscription_config = PurchaseHelper::getSubscriptionPlanByStripePriceID($stripe_price_id);
|
||||
|
||||
@@ -57,7 +56,7 @@ private static function handleInvoicePaid(WebhookReceived $event)
|
||||
}
|
||||
}
|
||||
|
||||
//dd($subscription_config);
|
||||
// dd($subscription_config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Helpers\FirstParty\Stripe;
|
||||
|
||||
use App\Models\User;
|
||||
use Laravel\Cashier\Events\WebhookReceived;
|
||||
|
||||
class StripeHelper
|
||||
{
|
||||
|
||||
@@ -65,7 +65,7 @@ public function handleGoogleCallback()
|
||||
return redirect()->intended(route('home'))->with('success', "You're now logged in!");
|
||||
} catch (\Exception $e) {
|
||||
|
||||
//throw $e;
|
||||
// throw $e;
|
||||
$error_message = 'Google login failed. Please try again.';
|
||||
if (config('app.debug')) {
|
||||
$error_message = $e->getMessage();
|
||||
|
||||
28
app/Http/Controllers/UserAccountController.php
Normal file
28
app/Http/Controllers/UserAccountController.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class UserAccountController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
|
||||
$user = Auth::user();
|
||||
$user->load('user_usage');
|
||||
$user->load('plan');
|
||||
|
||||
return response()->json([
|
||||
'success' => [
|
||||
'data' => [
|
||||
'user' => $user,
|
||||
'billing' => [
|
||||
'provider' => 'stripe',
|
||||
'portal' => Auth::user()->billingPortalUrl(route('home'))
|
||||
]
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -26,4 +26,11 @@ class Plan extends Model
|
||||
'name',
|
||||
'tier',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'laravel_through_key',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
@@ -14,7 +16,7 @@
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasApiTokens, HasFactory, Notifiable, SoftDeletes, Billable;
|
||||
use Billable, HasApiTokens, HasFactory, Notifiable, SoftDeletes;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
@@ -37,8 +39,28 @@ class User extends Authenticatable
|
||||
'password',
|
||||
'remember_token',
|
||||
'id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'uuid',
|
||||
'stripe_id',
|
||||
'google_id',
|
||||
'email_verified_at',
|
||||
'pm_last_four',
|
||||
'pm_type',
|
||||
'trial_ends_at',
|
||||
'email',
|
||||
];
|
||||
|
||||
protected $appends = ['ids'];
|
||||
|
||||
protected function ids(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn($value, $attributes) => hashids_encode($attributes['id']),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
@@ -61,4 +83,19 @@ protected static function booted(): void
|
||||
$model->uuid = $model->uuid ?? (string) Str::uuid();
|
||||
});
|
||||
}
|
||||
|
||||
public function user_usage()
|
||||
{
|
||||
return $this->hasOne(UserUsage::class, 'user_id');
|
||||
}
|
||||
|
||||
public function user_plan()
|
||||
{
|
||||
return $this->hasOne(UserPlan::class, 'user_id');
|
||||
}
|
||||
|
||||
public function plan()
|
||||
{
|
||||
return $this->hasOneThrough(Plan::class, UserPlan::class, 'user_id', 'id', 'id', 'plan_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,4 +40,14 @@ class UserPlan extends Model
|
||||
'cancel_at',
|
||||
'canceled_at',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function plan()
|
||||
{
|
||||
return $this->belongsTo(Plan::class, 'plan_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,30 +7,45 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class UserUsage
|
||||
*
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property int $non_watermark_videos_left
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class UserUsage extends Model
|
||||
{
|
||||
protected $table = 'user_usages';
|
||||
protected $table = 'user_usages';
|
||||
|
||||
protected $casts = [
|
||||
'user_id' => 'int',
|
||||
'non_watermark_videos_left' => 'int'
|
||||
];
|
||||
protected $casts = [
|
||||
'user_id' => 'int',
|
||||
'non_watermark_videos_left' => 'int',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'non_watermark_videos_left'
|
||||
];
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'non_watermark_videos_left',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'id',
|
||||
'user_id',
|
||||
];
|
||||
|
||||
protected $appends = ['ids'];
|
||||
|
||||
protected function ids(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn($value, $attributes) => hashids_encode($attributes['id']),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user