Skip to content

Commit f95c179

Browse files
authored
Merge pull request #137 from NativePHP/store-anystack-license-id
Store the Anystack id of licenses
2 parents 81f3949 + ba80c4f commit f95c179

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

app/Jobs/CreateAnystackLicenseJob.php

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function handle(): void
3838
$licenseData = $this->createLicense($this->user->anystack_contact_id);
3939

4040
$license = License::create([
41+
'anystack_id' => $licenseData['id'],
4142
'user_id' => $this->user->id,
4243
'subscription_item_id' => $this->subscriptionItemId,
4344
'policy_name' => $this->subscription->value,

database/factories/LicenseFactory.php

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class LicenseFactory extends Factory
1919
public function definition(): array
2020
{
2121
return [
22+
'anystack_id' => fake()->uuid(),
2223
'user_id' => User::factory(),
2324
'subscription_item_id' => SubscriptionItem::factory(),
2425
'policy_name' => fake()->randomElement(Subscription::cases())->value,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('licenses', function (Blueprint $table) {
15+
$table->uuid('anystack_id')->nullable()->after('id');
16+
$table->uuid('key')->change();
17+
18+
$table->unique('anystack_id');
19+
$table->unique('key');
20+
});
21+
}
22+
23+
/**
24+
* Reverse the migrations.
25+
*/
26+
public function down(): void
27+
{
28+
Schema::table('licenses', function (Blueprint $table) {
29+
$table->dropUnique(['anystack_id']);
30+
$table->dropUnique(['key']);
31+
32+
$table->dropColumn(['anystack_id']);
33+
$table->string('key')->change();
34+
});
35+
}
36+
};

tests/Feature/Jobs/CreateAnystackLicenseJobTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public function it_stores_the_license_key_in_database()
140140
$job->handle();
141141

142142
$this->assertDatabaseHas('licenses', [
143+
'anystack_id' => 'license-123',
143144
'user_id' => $user->id,
144145
'subscription_item_id' => null,
145146
'policy_name' => 'max',

0 commit comments

Comments
 (0)