3
3
namespace App \Jobs ;
4
4
5
5
use App \Enums \Subscription ;
6
+ use App \Models \License ;
6
7
use App \Models \User ;
7
8
use App \Notifications \LicenseKeyGenerated ;
8
9
use Illuminate \Bus \Queueable ;
11
12
use Illuminate \Http \Client \PendingRequest ;
12
13
use Illuminate \Queue \InteractsWithQueue ;
13
14
use Illuminate \Queue \SerializesModels ;
14
- use Illuminate \Support \Facades \Cache ;
15
15
use Illuminate \Support \Facades \Http ;
16
16
17
17
class CreateAnystackLicenseJob implements ShouldQueue
@@ -21,6 +21,7 @@ class CreateAnystackLicenseJob implements ShouldQueue
21
21
public function __construct (
22
22
public User $ user ,
23
23
public Subscription $ subscription ,
24
+ public ?string $ subscriptionItemId = null ,
24
25
public ?string $ firstName = null ,
25
26
public ?string $ lastName = null ,
26
27
) {}
@@ -34,12 +35,20 @@ public function handle(): void
34
35
$ this ->user ->save ();
35
36
}
36
37
37
- $ license = $ this ->createLicense ($ this ->user ->anystack_contact_id );
38
+ $ licenseData = $ this ->createLicense ($ this ->user ->anystack_contact_id );
38
39
39
- Cache::put ($ this ->user ->email .'.license_key ' , $ license ['key ' ], now ()->addDay ());
40
+ $ license = License::create ([
41
+ 'user_id ' => $ this ->user ->id ,
42
+ 'subscription_item_id ' => $ this ->subscriptionItemId ,
43
+ 'policy_name ' => $ this ->subscription ->value ,
44
+ 'key ' => $ licenseData ['key ' ],
45
+ 'expires_at ' => $ licenseData ['expires_at ' ],
46
+ 'created_at ' => $ licenseData ['created_at ' ],
47
+ 'updated_at ' => $ licenseData ['updated_at ' ],
48
+ ]);
40
49
41
50
$ this ->user ->notify (new LicenseKeyGenerated (
42
- $ license[ ' key ' ] ,
51
+ $ license-> key ,
43
52
$ this ->subscription ,
44
53
$ this ->firstName
45
54
));
0 commit comments