|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Gilbitron\Laravel\Spark\Console\Commands; |
| 4 | + |
| 5 | +use Illuminate\Console\Command; |
| 6 | +use Laravel\Cashier\Cashier; |
| 7 | +use Laravel\Spark\Spark; |
| 8 | +use Stripe; |
| 9 | + |
| 10 | +class CreateStripeEndpoints extends Command |
| 11 | +{ |
| 12 | + /** |
| 13 | + * The name and signature of the console command. |
| 14 | + * |
| 15 | + * @var string |
| 16 | + */ |
| 17 | + protected $signature = 'spark:create-stripe-endpoints'; |
| 18 | + |
| 19 | + /** |
| 20 | + * The console command description. |
| 21 | + * |
| 22 | + * @var string |
| 23 | + */ |
| 24 | + protected $description = 'Creates endpoiints in Stripe based on the Spark app'; |
| 25 | + |
| 26 | + /** |
| 27 | + * Create a new command instance. |
| 28 | + * |
| 29 | + * @return void |
| 30 | + */ |
| 31 | + public function __construct() |
| 32 | + { |
| 33 | + parent::__construct(); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Execute the console command. |
| 38 | + * |
| 39 | + * @return mixed |
| 40 | + */ |
| 41 | + public function handle() |
| 42 | + { |
| 43 | + Stripe\Stripe::setApiKey(config('services.stripe.secret')); |
| 44 | + |
| 45 | + $this->info('Creating endpoints ...'); |
| 46 | + $this->createEndpoints(); |
| 47 | + |
| 48 | + $this->info('Finished'); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Try and create endpoints in Stripe |
| 53 | + * |
| 54 | + * @param array $plans |
| 55 | + */ |
| 56 | + protected function createEndpoints() |
| 57 | + { |
| 58 | + $endpoint = \Stripe\WebhookEndpoint::create([ |
| 59 | + 'url' => config('app.url').'/webhook/stripe', |
| 60 | + 'enabled_events' => [ |
| 61 | + 'customer.subscription.updated', |
| 62 | + 'customer.subscription.deleted', |
| 63 | + 'customer.updated', |
| 64 | + 'customer.deleted', |
| 65 | + 'invoice.payment_action_required', |
| 66 | + 'invoice.payment_succeeded', |
| 67 | + ] |
| 68 | + ]); |
| 69 | + } |
| 70 | +} |
0 commit comments