Laravel Spark订阅页面异常:无法查看取消/更换套餐视图
Laravel Spark + Paddle 订阅页面异常问题
沙箱环境下可成功创建订阅并完成支付,但无法查看取消/更换套餐的视图。官方支持反馈数据接收不完整,但Paddle的Webhook已成功向本地ngrok环境发送通知,说明认证密钥等配置无误。
SparkServiceProvider.php 代码
<?php namespace App\Providers; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\ServiceProvider; use Illuminate\Validation\ValidationException; use Spark\Plan; use Spark\Spark; class SparkServiceProvider extends ServiceProvider { /** * Bootstrap any application services. */ public function boot(): void { Spark::billable(User::class)->resolve(function (Request $request) { return $request->user(); }); Spark::billable(User::class)->authorize(function (User $billable, Request $request) { return $request->user() && $request->user()->id == $billable->id; }); Spark::billable(User::class)->checkPlanEligibility(function (User $billable, Plan $plan) { // if ($billable->projects > 5 && $plan->name == 'Basic') { // throw ValidationException::withMessages([ // 'plan' => 'You have too many projects for the selected plan.' // ]); // } }); } }
User 模型代码
<?php namespace App\Models; // use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use LaraZeus\Bolt\Models\Concerns\BelongToBolt; use Spark\Billable; class User extends Authenticatable { /** @use HasFactory<Database\Factories\UserFactory> */ use Billable, HasFactory, Notifiable; /** * The attributes that are mass assignable. * * @var list<string> */ protected $fillable = [ 'name', 'email', 'password', ]; /** * The attributes that should be hidden for serialization. * * @var list<string> */ protected $hidden = [ 'password', 'remember_token', ]; /** * Get the attributes that should be cast. * * @return array<string, string> */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; } }
订阅页面截图

内容的提问来源于stack exchange,提问作者Filip Rastovic
相关产品推荐
相关产品推荐

