33namespace App \Jobs ;
44
55use App \Enums \Subscription ;
6+ use App \Models \License ;
67use App \Models \User ;
78use App \Notifications \LicenseKeyGenerated ;
89use Illuminate \Bus \Queueable ;
1112use Illuminate \Http \Client \PendingRequest ;
1213use Illuminate \Queue \InteractsWithQueue ;
1314use Illuminate \Queue \SerializesModels ;
14- use Illuminate \Support \Facades \Cache ;
1515use Illuminate \Support \Facades \Http ;
1616
1717class CreateAnystackLicenseJob implements ShouldQueue
@@ -21,6 +21,7 @@ class CreateAnystackLicenseJob implements ShouldQueue
2121 public function __construct (
2222 public User $ user ,
2323 public Subscription $ subscription ,
24+ public ?string $ subscriptionItemId = null ,
2425 public ?string $ firstName = null ,
2526 public ?string $ lastName = null ,
2627 ) {}
@@ -34,12 +35,20 @@ public function handle(): void
3435 $ this ->user ->save ();
3536 }
3637
37- $ license = $ this ->createLicense ($ this ->user ->anystack_contact_id );
38+ $ licenseData = $ this ->createLicense ($ this ->user ->anystack_contact_id );
3839
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+ ]);
4049
4150 $ this ->user ->notify (new LicenseKeyGenerated (
42- $ license[ ' key ' ] ,
51+ $ license-> key ,
4352 $ this ->subscription ,
4453 $ this ->firstName
4554 ));
0 commit comments