class ServiceStripePlan{
public static function delete(Service $service){
Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
$plan = Stripe\Plan::retrieve($service->id);
return $plan->delete();
}
public static function create(Service $service){
Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
$plan = Stripe\Plan::create([
"amount" => $service->rate * 100,
"name" => $service->name,
"id" => $service->id,
"interval" => $service->interval,
"currency" => "gbp",
]);
return $plan;
}
}
It seems a bit weird to initialize Stripe with the Stripe\Stripe::setApiKey(env('STRIPE_SECRET')); in two different places. Am I doing something wrong / is there a nicer way of doing this? As this class gets bigger then I'll need this in every single function.
I would definitely put Stripe\Stripe::setApiKey(env('STRIPE_SECRET')); into a ServiceProvider. Either make a StripeServiceProvider or just simply use the AppServiceProvider.
This way Stripe is ready to use everywhere in your application and so much easier to maintain.