Skip to content

Commit ed3b75b

Browse files
authored
Merge pull request #62 from eurofurence/integration-with-registration-system-and-split-status
Integration with registration system and split status
2 parents ddee42c + 561e72d commit ed3b75b

9 files changed

Lines changed: 131 additions & 26 deletions

File tree

app/Http/Controllers/AuthController.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public function loginCallback()
4848
'Please register for the Convention first before trying to obtain a fursuit badge.');
4949
}
5050

51+
$isNewUser = User::where('remote_id', $socialLiteUser->getId())->doesntExist();
52+
5153
$user = User::updateOrCreate([
5254
'remote_id' => $socialLiteUser->getId(),
5355
], [
@@ -76,6 +78,34 @@ public function loginCallback()
7678
expiresIn: 3500
7779
);
7880

81+
if ($isNewUser) {
82+
$fursuit = \Illuminate\Support\Facades\Http::attsrv()
83+
->withToken($socialLiteUser->token)
84+
->get('/attendees/' . $regId . '/packages/fursuit')
85+
->json();
86+
if ($fursuit['present'] && $fursuit['count'] > 0) {
87+
88+
$fursuitAdditional = \Illuminate\Support\Facades\Http::attsrv()
89+
->withToken($socialLiteUser->token)
90+
->get('/attendees/' . $regId . '/packages/fursuitadd')
91+
->json();
92+
93+
$copies = $fursuitAdditional['present'] ? $fursuitAdditional['count'] : 0;
94+
95+
$user->has_free_badge = true;
96+
$user->free_badge_copies = $copies;
97+
$user->save();
98+
99+
100+
\Illuminate\Support\Facades\Http::attsrv()
101+
->withToken($socialLiteUser->token)
102+
->post('/attendees/' . $regId . '/additional-info/fursuitbadge', [
103+
'created' => false,
104+
]);
105+
}
106+
107+
}
108+
79109
Auth::login($user, true);
80110
if(Session::exists('catch-em-all-redirect')) {
81111
Session::forget('catch-em-all-redirect');

app/Http/Controllers/BadgeController.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public function create(Request $request)
3333
Gate::authorize('create', Badge::class);
3434
return Inertia::render('Badges/BadgesCreate', [
3535
'species' => Species::has('fursuits', count: 5)->orWhere('checked', true)->get('name'),
36-
'isFree' => auth()->user()->badges()->where('is_free_badge', true)->doesntExist(),
36+
'isFree' => auth()->user()->hasFreeBadge(),
37+
'freeBadgeCopies' => auth()->user()->hasFreeBadge() ? auth()->user()->free_badge_copies : 0,
3738
]);
3839
}
3940

@@ -71,7 +72,7 @@ public function store(BadgeCreateRequest $request)
7172
]);
7273

7374
// is Free Badge
74-
$isFreeBadge = $request->user()->badges()->where('is_free_badge', true)->doesntExist();
75+
$isFreeBadge = $request->user()->hasFreeBadge();
7576

7677
// Returns in cents
7778
$total = BadgeCalculationService::calculate(
@@ -98,7 +99,32 @@ public function store(BadgeCreateRequest $request)
9899
// Pay for Badge (force pay as we allow negative balance)
99100
$request->user()->forcePay($badge);
100101

101-
if ($validated['upgrades']['spareCopy']) {
102+
if ($isFreeBadge) {
103+
$total = BadgeCalculationService::calculate(isSpareCopy: true);
104+
for ($i = 0; $i < $request->user()->free_badge_copies; $i++) {
105+
$clone = $badge->replicate();
106+
$clone->is_free_badge = false;
107+
$clone->extra_copy = true;
108+
$clone->total = round($total);
109+
$clone->subtotal = round($total / 1.19);
110+
$clone->tax = round($clone->total - $clone->subtotal);
111+
$clone->extra_copy_of = $badge->id;
112+
$clone->save();
113+
$request->user()->forcePay($clone->fresh());
114+
}
115+
$request->user()->wallet->deposit($total * $request->user()->free_badge_copies, ['title' => 'Fuirsuit Badge', 'description' => 'Already paid with the EF registration system']);
116+
$request->user()->free_badge_copies = 0;
117+
$request->user()->has_free_badge = false;
118+
$request->user()->save();
119+
120+
// Mark fursuitbadge as created
121+
\Illuminate\Support\Facades\Http::attsrv()
122+
->withToken($request->user()->token)
123+
->post('/attendees/' . $request->user()->attendee_id . '/additional-info/fursuitbadge', [
124+
'created' => true,
125+
]);
126+
127+
} elseif ($validated['upgrades']['spareCopy']) {
102128
$total = BadgeCalculationService::calculate(isSpareCopy: true);
103129
$clone = $badge->replicate();
104130
$clone->is_free_badge = false;

app/Models/Badge/Badge.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,13 @@ public function getActivitylogOptions(): LogOptions
8181
return LogOptions::defaults()
8282
->logOnly(['*']);
8383
}
84+
85+
public function isCopyOfFreeBadge(): bool
86+
{
87+
if ($this->extra_copy_of !== null) {
88+
$originalBadge = self::find($this->extra_copy_of);
89+
return $originalBadge ? $originalBadge->is_free_badge : false;
90+
}
91+
return false;
92+
}
8493
}

app/Models/User.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class User extends Authenticatable implements FilamentUser, Wallet, WalletFloat,
5151
'token' => 'encrypted',
5252
'token_expires_at' => 'datetime',
5353
'attendee_id' => 'integer',
54+
'has_free_badge' => 'bool',
55+
"free_badge_copies" => "integer",
5456
];
5557

5658
public function badges()
@@ -72,4 +74,9 @@ public function canAccessPanel(Panel $panel): bool
7274
{
7375
return $this->is_admin || $this->is_reviewer;
7476
}
77+
78+
public function hasFreeBadge(): bool
79+
{
80+
return $this->has_free_badge;
81+
}
7582
}

app/Services/BadgeCalculationService.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ public static function calculate(
1919
return 200;
2020
}
2121

22-
$baseFee = $isFreeBadge ? 0 : 200;
22+
if ($isFreeBadge) {
23+
return 0;
24+
}
25+
26+
$baseFee = 200;
2327
if ($isLate) {
2428
$baseFee += 200;
2529
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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('users', function (Blueprint $table) {
15+
$table->boolean('has_free_badge')->default(false)->after('remember_token');
16+
$table->integer('free_badge_copies')->default(0)->after('has_free_badge');
17+
});
18+
}
19+
};

resources/js/Pages/Badges/BadgesCreate.vue

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ defineOptions({
2121
2222
const props = defineProps({
2323
species: Array,
24-
isFree: Boolean
24+
isFree: Boolean,
25+
freeBadgeCopies: Number,
2526
})
2627
2728
const imageModalOpen = ref(false)
@@ -36,7 +37,7 @@ const form = useForm('post', route('badges.store'), {
3637
publish: false,
3738
tos: false,
3839
upgrades: {
39-
spareCopy: false
40+
spareCopy: props.freeBadgeCopies > 0,
4041
}
4142
})
4243
@@ -62,17 +63,24 @@ const basePrice = computed(() => {
6263
})
6364
6465
const latePrice = computed(() => {
65-
if (dayjs().isAfter(dayjs(usePage().props.event.preorder_ends_at))) {
66+
if (dayjs().isAfter(dayjs(usePage().props.event.preorder_ends_at)) && props.isFree === false) {
6667
return 2;
6768
}
6869
return 0;
6970
})
7071
71-
const total = computed(() => {
72-
let total = basePrice.value + latePrice.value;
73-
if (form.upgrades.spareCopy) {
74-
total += 2;
72+
const copiesPrice = computed(() => {
73+
let price = 0
74+
if (props.freeBadgeCopies > 0) {
75+
price += props.freeBadgeCopies * 2;
76+
} else if (form.upgrades.spareCopy) {
77+
price += 2;
7578
}
79+
return price;
80+
})
81+
82+
const total = computed(() => {
83+
let total = basePrice.value + latePrice.value + copiesPrice.value;
7684
return total;
7785
})
7886
</script>
@@ -202,7 +210,7 @@ const total = computed(() => {
202210
<div class="flex gap-3">
203211
<div class="flex flex-row gap-2 mt-3">
204212
<InputSwitch v-model="form.upgrades.spareCopy" id="extra2"
205-
aria-describedby="extra2-help"/>
213+
aria-describedby="extra2-help" :disabled="props.isFree"/>
206214
</div>
207215
<div>
208216
<label class="font-semibold block" for="extra2">Spare Copy
@@ -254,9 +262,9 @@ const total = computed(() => {
254262
<small>Orders placed after the Preorder Deadline will be charged a late fee.</small>
255263
</div>
256264
<div v-if="form.upgrades.spareCopy"
257-
class="flex justify-between mb-4 border-b border-dotted border-gray-900">
258-
<span>Spare Copy</span>
259-
<span>2,00 €</span>
265+
class="flex justify-between mb-4 border-b border-dotted border-gray-900">
266+
<span>Spare Copy{{ props.freeBadgeCopies > 1 ? " x" + props.freeBadgeCopies : "" }}</span>
267+
<span>{{ copiesPrice }},00 €</span>
260268
</div>
261269
<!-- End Options -->
262270
<div class="flex justify-between text-2xl border-b border-double border-gray-900">
@@ -274,6 +282,4 @@ const total = computed(() => {
274282
</div>
275283
</template>
276284

277-
<style scoped>
278-
279-
</style>
285+
<style scoped></style>

resources/js/Pages/Welcome.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ const messages = computed(() => {
7878
<div v-if="messages.showButtons" class="w-full">
7979
<div class="flex flex-col md:flex-row gap-3 text-white w-full"
8080
v-if="usePage().props.auth.user !== null">
81-
<!-- Action Select -->
82-
<Button @click="router.visit(route('badges.create'))" icon="pi pi-id-card" class="w-full" v-if="usePage().props.auth.user.badges.length === 0 && showState === 'preorder'" label="Claim your first free Fursuit Badge!"/>
8381
<!-- Claim Additional Fursuit Badges -->
84-
<Button @click="router.visit(route('badges.create'))" icon="pi pi-id-card" class="w-full" v-else-if="usePage().props.auth.user.badges.length === 0">Get your first Fursuit Badge!</Button>
82+
<Button @click="router.visit(route('badges.create'))" icon="pi pi-id-card" class="w-full" v-if="usePage().props.auth.user.has_free_badge" label="Customize First Fursuit Badge"/>
83+
<Button @click="router.visit(route('badges.create'))" icon="pi pi-id-card" severity="warning" class="w-full" v-if="usePage().props.auth.user.badges.length === 0 && !usePage().props.auth.user.has_free_badge"
84+
label="Buy Fursuit Badges"/>
8585
<!-- Buy Additional Fursuit Badges -->
86-
<Button @click="router.visit(route('badges.create'))" icon="pi pi-id-card" severity="warning" v-if="usePage().props.auth.user.badges.length > 0" class="w-full"
86+
<Button @click="router.visit(route('badges.create'))" icon="pi pi-id-card" severity="warning" class="w-full" v-if="usePage().props.auth.user.badges.length > 0"
8787
label="Buy Additional Fursuit Badges"/>
8888
<!-- Manage Badges -->
8989
<Button @click="router.visit(route('badges.index'))" icon="pi pi-id-card" class="w-full" v-if="usePage().props.auth.user.badges.length > 0" label="Review Ordered Badges"/>
@@ -130,14 +130,14 @@ const messages = computed(() => {
130130
</p>
131131
<div class="mt-4">
132132
<h1 class="text-2xl font-semibold font-main">How to Get Your Badge:</h1>
133-
<ul class="list-disc pl-6 mt-2">
134-
<li class="mt-2">
133+
<ul class="list-disc pl-6 mt-2 gap-2 flex flex-col">
134+
<li>
135135
<strong>First Preoder Badge Free:</strong> Simply register for Eurofurence and get your first fursuit badge for free.
136136
</li>
137-
<li class="mt-2">
137+
<li>
138138
<strong>Additional Badges & Late Orders:</strong> Order more for just 2 € each.
139139
</li>
140-
<li class="mt-2">
140+
<li>
141141
<strong>On-Site Services:</strong> Need a last-minute badge? We’ve got you covered with our late printing service for a small fee.
142142
</li>
143143
</ul>

tests/Feature/BadgeTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
beforeEach(function () {
1818
$this->user = User::factory()->create();
19+
$this->user->update([
20+
'has_free_badge' => false,
21+
'free_badge_copies' => 0,
22+
]);
1923
$event = \App\Models\Event::factory()->create([
2024
'starts_at' => \Carbon\Carbon::parse('2024-06-01'),
2125
'ends_at' => \Carbon\Carbon::parse('2024-06-30'),

0 commit comments

Comments
 (0)