Skip to content

Commit 3fd34e2

Browse files
committed
add command to create endpoints
1 parent 6d4711e commit 3fd34e2

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
}

src/CreateStripePlansServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class CreateStripePlansServiceProvider extends ServiceProvider
88
{
99
protected $commands = [
1010
\Gilbitron\Laravel\Spark\Console\Commands\CreateStripePlans::class,
11+
\Gilbitron\Laravel\Spark\Console\Commands\CreateStripeEndpoints::class,
1112
];
1213

1314
/**
@@ -29,4 +30,4 @@ public function register()
2930
{
3031
$this->commands($this->commands);
3132
}
32-
}
33+
}

0 commit comments

Comments
 (0)