Skip to content

Commit 25549d6

Browse files
authored
Converted To Accepting Donations And Removes Payment Wall (#70)
* - wip * - wip * - Removed paywall and made some improvements to the landing page. * Removed motivational message. Removed logic pertaining to the payment wall and subscriptions. * Updated the images. * Added the ability to track donations. * Refactored the total goal progress. * Made some improvements to the landing page. * Removed donations as its no longer needed. Changed the text raise to raised. * Updated causes config to pull values from env.
1 parent 0bc632f commit 25549d6

35 files changed

+539
-1840
lines changed

.env.testing

-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,5 @@ STRIPE_WEBHOOK_SECRET=whsec_HVQMOzLKd6yDkGZySAVcA09n4kCrOlGf
6666
STRIPE_MONTHLY_PRICE=price_1OPzEOAolv7LEvcOTezGkc8i
6767
STRIPE_ANNUAL_PRICE=price_1OPzHgAolv7LEvcOPWEToKgJ
6868

69-
STUDENT_FREE_QUESTION_COUNT=300
70-
7169
SLACK_BOT_USER_OAUTH_TOKEN=xoxb-6433707239830-6457368612868-35qsIvwiLfFT83pWYYwLhCE8
7270
SLACK_BOT_USER_DEFAULT_CHANNEL=signups-cancellation-retention

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ Configuration:
3535
- STRIPE_WEBHOOK_SECRET
3636
- STRIPE_MONTHLY_PRICE
3737
- STRIPE_ANNUAL_PRICE
38-
- STUDENT_FREE_QUESTION_COUNT
3938
- NOVA_LICENSE_KEY
4039

4140
Notes: Most of the emails that are sent are sent via the queue system so you'll need to make sure to run `php artisan queue:work` if your QUEUE_CONNECTION variable is set to database.

app/Http/Controllers/Billing/BillingPortalController.php

-14
This file was deleted.

app/Http/Controllers/Billing/QuantityExceededController.php

-14
This file was deleted.

app/Http/Controllers/Guest/PlannerController.php

-14
This file was deleted.

app/Http/Controllers/LandingController.php

+12
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,26 @@
33
namespace App\Http\Controllers;
44

55
use App\Models\BlogPost;
6+
use App\Models\Donation;
7+
use Illuminate\Support\Number;
68
use Inertia\Inertia;
79

810
class LandingController extends Controller
911
{
1012
public function __invoke()
1113
{
14+
$donations = Donation::sumAmountByPaymentLink();
15+
1216
return Inertia::render('Landing/Index', [
1317
'blogCount' => BlogPost::count(),
18+
'paymentLinks' => config('services.stripe.payment_links'),
19+
'totalSumDonations' => Number::currency(Donation::totalSum() / 100),
20+
'causes' => collect(config('causes'))->map(function ($cause) use ($donations) {
21+
return array_merge($cause, [
22+
'raised' => Number::currency($donations->where('payment_link', $cause['plink'])->first()?->amount / 100 ?? 0),
23+
'progress' => Number::percentage((($donations->where('payment_link', $cause['plink'])->first()?->amount / 100) / $cause['goalValue']) * 100),
24+
]);
25+
}),
1426
]);
1527
}
1628
}

app/Http/Controllers/StripeCheckoutController.php

-26
This file was deleted.

app/Http/Controllers/StripeCheckoutOptionsController.php

-15
This file was deleted.

app/Http/Controllers/StripeCheckoutSuccessController.php

-14
This file was deleted.

app/Http/Controllers/Student/PromptController.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ class PromptController extends Controller
1212
{
1313
public function index(Request $request): Response
1414
{
15-
return Inertia::render('Student/Prompts/Index', [
16-
'canAskQuestions' => $request->user()->canAskQuestions(),
17-
]);
15+
return Inertia::render('Student/Prompts/Index');
1816
}
1917

2018
public function store(PromptRequest $request): Response
@@ -26,7 +24,6 @@ public function store(PromptRequest $request): Response
2624
$request->user()->parent->increment('total_questions_asked');
2725

2826
return Inertia::render('Student/Prompts/Index', [
29-
'canAskQuestions' => $request->user()->canAskQuestions(),
3027
'result' => [
3128
'flagged' => false,
3229
'message' => '',

app/Http/Controllers/StudentController.php

-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public function index(Request $request): Response
4545
)
4646
)
4747
->paginate(10),
48-
'showInitialPaymentPage' => $request->user()->showInitialPaymentPage(),
49-
'showExceededQuantityPage' => $request->user()->showExceededQuantityPage(),
5048
]);
5149
}
5250

app/Listeners/StripeEventListener.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\Listeners;
4+
5+
use App\Models\Donation;
6+
7+
class StripeEventListener
8+
{
9+
public function handle(object $event): void
10+
{
11+
if ($event->payload['type'] === 'checkout.session.completed') {
12+
$object = $event->payload['data']['object'];
13+
14+
\Illuminate\Support\Facades\Log::info($object);
15+
16+
if (isset($object['payment_status']) && $object['payment_status'] === 'paid') {
17+
Donation::create([
18+
'name' => $object['customer_details']['name'],
19+
'email' => $object['customer_details']['email'],
20+
'amount' => $object['amount_total'],
21+
'payment_link' => $object['payment_link'],
22+
]);
23+
}
24+
}
25+
}
26+
}

app/Models/Donation.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Support\Collection;
8+
9+
class Donation extends Model
10+
{
11+
use HasFactory;
12+
13+
protected $fillable = [
14+
'email',
15+
'name',
16+
'amount',
17+
'payment_link',
18+
];
19+
20+
protected $casts = [
21+
'email' => 'string',
22+
'name' => 'string',
23+
'amount' => 'integer',
24+
'payment_link' => 'string',
25+
];
26+
27+
public static function totalSum(): int
28+
{
29+
return Donation::sum('amount');
30+
}
31+
32+
public static function sumAmountByPaymentLink(): Collection
33+
{
34+
return Donation::selectRaw('SUM(amount) as amount, payment_link')->groupBy('payment_link')->get();
35+
}
36+
}

app/Models/Student.php

-13
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,4 @@ protected function timezone(): Attribute
5959
get: fn (?string $value) => $value ?? config('app.timezone')
6060
);
6161
}
62-
63-
public function canAskQuestions(): bool
64-
{
65-
if ($this->user->subscribed()) {
66-
return true;
67-
}
68-
69-
if (! $this->user->subscribed() && $this->user->total_questions_asked < config('app.student_free_question_count')) {
70-
return true;
71-
}
72-
73-
return false;
74-
}
7562
}

app/Models/User.php

-30
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,6 @@ protected function timezone(): Attribute
8383
);
8484
}
8585

86-
public function subscriptionQuantity(): int
87-
{
88-
$subscriptionItem = $this->subscription('default')->items->first();
89-
90-
return $subscriptionItem->quantity;
91-
}
92-
93-
public function showInitialPaymentPage(): bool
94-
{
95-
return ! $this->subscribed() && $this->students->count() >= 1;
96-
}
97-
98-
public function showExceededQuantityPage(): bool
99-
{
100-
return $this->subscribed() && $this->students->count() >= $this->subscriptionQuantity();
101-
}
102-
10386
public function activeTime(): HasMany
10487
{
10588
return $this->hasMany(ActiveTime::class);
@@ -114,17 +97,4 @@ public function isStudent(): bool
11497
{
11598
return ! is_null($this->parent_id);
11699
}
117-
118-
public function canAskQuestions(): bool
119-
{
120-
if ($this->parent->subscribed()) {
121-
return true;
122-
}
123-
124-
if (! $this->parent->subscribed() && $this->parent->total_questions_asked < config('app.student_free_question_count')) {
125-
return true;
126-
}
127-
128-
return false;
129-
}
130100
}

app/Providers/EventServiceProvider.php

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Providers;
44

5+
use App\Listeners\StripeEventListener;
56
use App\Models\Feedback;
67
use App\Models\NewsletterList;
78
use App\Models\PromptQuestion;
@@ -13,6 +14,7 @@
1314
use Illuminate\Auth\Events\Registered;
1415
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
1516
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
17+
use Laravel\Cashier\Events\WebhookReceived;
1618

1719
class EventServiceProvider extends ServiceProvider
1820
{
@@ -25,6 +27,9 @@ class EventServiceProvider extends ServiceProvider
2527
Registered::class => [
2628
SendEmailVerificationNotification::class,
2729
],
30+
WebhookReceived::class => [
31+
StripeEventListener::class,
32+
],
2833
];
2934

3035
/**

app/Services/MotivationalMessageService.php

-63
This file was deleted.

app/Services/StudentInertiaRequests.php

-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ public function __invoke(Request $request): array
1919
'navigation' => $this->navigation(),
2020
'subjects' => $this->subjects(),
2121
'isImpersonated' => $impersonator->impersonating($request),
22-
'motivationalMessage' => $request->routeIs('student.dashboard')
23-
? (new MotivationalMessageService($request->user()))->generate()
24-
: null,
2522
],
2623
];
2724
}

0 commit comments

Comments
 (0)