如何使用 Laravel 5 在 Stripe 上试用或不试用过滤计划


How do filter plans with or without trial on Stripe with Laravel 5?

我想检索这个。所有计划。所有计划都没有试用日。所有计划仅试用日。但我不知道在 api 条纹上进行过滤器的过程。https://stripe.com/docs/api#plans

use Illuminate'Http'Request;
use App'Http'Requests;
use App'Http'Controllers'Controller;
use Stripe'Plan;
use Stripe'Stripe;
class PlanController extends Controller {
    public function index(Request $request) 
    {
        Stripe::setApiKey(env('STRIPE_SECRET'));
        $param = ['limit' => 20]; 
        $opt = ['livemode' => false];
        $plans = Plan::all($param,$opt);
        return plans;
    }
}

获取所有内容后,可以通过 php 对其进行过滤

use Illuminate'Http'Request;
use App'Http'Requests;
use App'Http'Controllers'Controller;
use Stripe'Plan;
use Stripe'Stripe;
class PlanController extends Controller {
    public function index(Request $request) 
    {
        Stripe::setApiKey(env('STRIPE_SECRET'));
        $param = ['limit' => 20]; 
        $opt = ['livemode' => false];
        $all_plans = Plan::all($param,$opt);
        $trial_plans = [];
        $no_trial_plans = []
        foreach ($all_plans['data'] as $plan) {
            if ($plan['trial_period_days'] == null) {
                $no_trial_plans[] = $plan;
            }
            else {
                $trial_plans[] = $plan;
            }
        }
        return [$all_plans, $trial_plans, $no_trial_plans];
    }
}