Skip to content

Commit 78be7bf

Browse files
committed
Merge branch 'develop' of github.com:laravelcm/laravel.cm into develop
2 parents 3f4045e + 63a1809 commit 78be7bf

16 files changed

+212
-36
lines changed

app/Events/ApiRegistered.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ class ApiRegistered
1111
{
1212
use SerializesModels;
1313

14-
/**
15-
* Create a new event instance.
16-
*
17-
* @return void
18-
*/
1914
public function __construct(public User $user)
2015
{
2116
}

app/Events/ArticleWasSubmittedForApproval.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ class ArticleWasSubmittedForApproval
1111
{
1212
use SerializesModels;
1313

14-
public function __construct(
15-
public Article $article
16-
) {
14+
public function __construct(public Article $article)
15+
{
1716
}
1817
}

app/Events/EmailAddressWasChanged.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ class EmailAddressWasChanged
1313
use Dispatchable;
1414
use SerializesModels;
1515

16-
/**
17-
* @var \App\Models\User
18-
*/
19-
public $user;
20-
21-
public function __construct(User $user)
16+
public function __construct(public User $user)
2217
{
23-
$this->user = $user;
2418
}
2519
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Events;
6+
7+
use App\Models\Transaction;
8+
use Illuminate\Queue\SerializesModels;
9+
10+
class SponsoringPaymentInitialize
11+
{
12+
use SerializesModels;
13+
14+
public function __construct(public Transaction $transaction)
15+
{
16+
}
17+
}

app/Http/Controllers/NotchPayCallBackController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace App\Http\Controllers;
66

77
use App\Enums\TransactionStatus;
8+
use App\Events\SponsoringPaymentInitialize;
89
use App\Models\Transaction;
910
use Illuminate\Http\RedirectResponse;
1011
use Illuminate\Http\Request;
@@ -13,6 +14,7 @@ class NotchPayCallBackController extends Controller
1314
{
1415
public function __invoke(Request $request): RedirectResponse
1516
{
17+
/** @var Transaction $transaction */
1618
$transaction = Transaction::query()
1719
->where('transaction_reference', $request->get('reference'))
1820
->firstOrFail();
@@ -22,7 +24,8 @@ public function __invoke(Request $request): RedirectResponse
2224
session()->flash('error', __('Votre paiement a été annulé veuillez relancer si vous souhaitez soutenir Laravel Cameroun, Merci.'));
2325
} else {
2426
// @ToDO Envoie de mail de notification de remerciement pour le sponsoring si l'utilisateur est dans la base de données
25-
// @ToDo Envoie de la notification dans le channel de soumission pour un nouveau paiement
27+
event(new SponsoringPaymentInitialize($transaction));
28+
2629
session()->flash('status', __('Votre paiement a été pris en compte merci de soutenir Laravel Cameroun.'));
2730
}
2831

app/Http/Livewire/SponsorSubscription.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class SponsorSubscription extends Component
1616
{
1717
public string $option = 'one-time';
1818
public string $amount = '';
19+
public string $currency = 'XAF';
1920

2021
public function chooseOption(string $option): void
2122
{
@@ -24,16 +25,14 @@ public function chooseOption(string $option): void
2425

2526
public function subscribe(): void
2627
{
27-
$this->validate(
28-
['amount' => 'required'],
29-
['amount.required' => __('Votre montant est requis')],
30-
);
28+
$this->validate(['amount' => 'required']);
3129

3230
if (!Auth::check()) {
3331
$this->emit('openModal', 'modals.anonymous-sponsors', [
3432
'amount' => $this->amount,
3533
'option' => $this->option,
3634
]);
35+
3736
return;
3837
}
3938

@@ -45,7 +44,7 @@ public function subscribe(): void
4544
'amount' => $this->amount,
4645
'email' => Auth::user()?->email,
4746
'name' => Auth::user()?->name,
48-
'currency' => 'XAF',
47+
'currency' => $this->currency,
4948
'reference' => Auth::id() . '-' . Auth::user()?->username() . '-' . uniqid(),
5049
'callback' => route('notchpay-callback'),
5150
]);
@@ -72,7 +71,7 @@ public function subscribe(): void
7271
'initiated_at' => $payload->transaction->initiated_at,
7372
'description' => $payload->transaction->description,
7473
'for' => PaymentType::SPONSORING->value,
75-
]
74+
],
7675
]);
7776

7877
$this->redirect($payload->authorization_url);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Listeners;
6+
7+
use App\Events\SponsoringPaymentInitialize;
8+
use App\Notifications\NewSponsorPaymentNotification;
9+
use Illuminate\Notifications\AnonymousNotifiable;
10+
11+
final readonly class SendPaymentNotification
12+
{
13+
public function __construct(private AnonymousNotifiable $notifiable)
14+
{
15+
}
16+
17+
public function handle(SponsoringPaymentInitialize $event): void
18+
{
19+
$this->notifiable->notify(new NewSponsorPaymentNotification($event->transaction));
20+
}
21+
}

app/Models/Transaction.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use Illuminate\Database\Eloquent\Model;
1010
use Illuminate\Database\Eloquent\Relations\BelongsTo;
1111

12+
/**
13+
* @mixin IdeHelperTransaction
14+
*/
1215
class Transaction extends Model
1316
{
1417
use HasFactory;
@@ -17,11 +20,31 @@ class Transaction extends Model
1720
public $guarded = [];
1821

1922
public $casts = [
20-
'metadata' => 'json',
23+
'metadata' => 'array',
2124
];
2225

2326
public function user(): BelongsTo
2427
{
2528
return $this->belongsTo(User::class);
2629
}
30+
31+
public function getMetadata(string $name, string $default = ''): string | array
32+
{
33+
if ($this->metadata && array_key_exists($name, $this->metadata)) {
34+
return $this->metadata[$name];
35+
}
36+
37+
return $default;
38+
}
39+
40+
public function setMetadata(array $revisions, bool $save = true): self
41+
{
42+
$this->metadata = array_merge($this->metadata ?? [], $revisions);
43+
44+
if ($save) {
45+
$this->save();
46+
}
47+
48+
return $this;
49+
}
2750
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Notifications;
6+
7+
use App\Models\Transaction;
8+
use Illuminate\Bus\Queueable;
9+
use Illuminate\Contracts\Queue\ShouldQueue;
10+
use Illuminate\Notifications\Notification;
11+
use NotificationChannels\Telegram\TelegramChannel;
12+
use NotificationChannels\Telegram\TelegramMessage;
13+
14+
class NewSponsorPaymentNotification extends Notification implements ShouldQueue
15+
{
16+
use Queueable;
17+
18+
public function __construct(public readonly Transaction $transaction)
19+
{
20+
}
21+
22+
/**
23+
* @return array|string[]
24+
*/
25+
public function via(mixed $notifiable): array
26+
{
27+
if (
28+
! empty(config('services.telegram-bot-api.token')) &&
29+
! empty(config('services.telegram-bot-api.channel'))
30+
) {
31+
return [TelegramChannel::class];
32+
}
33+
34+
return [];
35+
}
36+
37+
public function toTelegram(): TelegramMessage
38+
{
39+
return TelegramMessage::create()
40+
->to(config('services.telegram-bot-api.channel'))
41+
->content($this->content())
42+
->button('Voir les sponsors', route('sponsors'));
43+
}
44+
45+
private function content(): string
46+
{
47+
$content = "*Nouveau paiement de Sponsoring enregistré!*\n\n";
48+
$content .= 'Auteur: '.$this->transaction->getMetadata('merchant')['name']."\n";
49+
$content .= 'Montant: '. $this->transaction->amount;
50+
51+
if ($this->transaction->getMetadata('merchant')['laravel_cm_id']) {
52+
$content .= 'Profil Laravel Cameroun: [@'.$this->transaction->user?->username.']('.route('profile', $this->transaction->user?->username).')';
53+
}
54+
55+
return $content;
56+
}
57+
}

app/Providers/EventServiceProvider.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\Events\ArticleWasSubmittedForApproval;
99
use App\Events\CommentWasAdded;
1010
use App\Events\ReplyWasCreated;
11+
use App\Events\SponsoringPaymentInitialize;
1112
use App\Events\ThreadWasCreated;
1213
use App\Listeners\NotifyMentionedUsers;
1314
use App\Listeners\PostNewThreadNotification;
@@ -16,6 +17,7 @@
1617
use App\Listeners\SendNewCommentNotification;
1718
use App\Listeners\SendNewReplyNotification;
1819
use App\Listeners\SendNewThreadNotification;
20+
use App\Listeners\SendPaymentNotification;
1921
use App\Listeners\SendWelcomeCompanyNotification;
2022
use App\Listeners\SendWelcomeMailNotification;
2123
use Illuminate\Auth\Events\Registered;
@@ -54,5 +56,9 @@ final class EventServiceProvider extends ServiceProvider
5456
SendCompanyEmailVerificationNotification::class,
5557
SendWelcomeCompanyNotification::class,
5658
],
59+
60+
SponsoringPaymentInitialize::class => [
61+
SendPaymentNotification::class,
62+
],
5763
];
5864
}

app/Traits/HasSettings.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
trait HasSettings
88
{
9-
/**
10-
* Retrieve a setting with a given name or fall back to the default.
11-
*/
129
public function setting(string $name, string $default): string
1310
{
1411
if ($this->settings && array_key_exists($name, $this->settings)) {
@@ -18,10 +15,6 @@ public function setting(string $name, string $default): string
1815
return $default;
1916
}
2017

21-
/**
22-
* @param array<string> $revisions
23-
* @param bool $save
24-
*/
2518
public function settings(array $revisions, bool $save = true): self
2619
{
2720
$this->settings = array_merge($this->settings ?? [], $revisions);

helpers/ModelHelper.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,41 @@ class IdeHelperThread
729729
}
730730
}
731731

732+
namespace App\Models{
733+
/**
734+
* App\Models\Transaction
735+
*
736+
* @property string $id
737+
* @property string $type
738+
* @property int $user_id
739+
* @property int $amount
740+
* @property int|null $fees
741+
* @property string $transaction_reference
742+
* @property string $status
743+
* @property array|null $metadata
744+
* @property \Illuminate\Support\Carbon|null $created_at
745+
* @property \Illuminate\Support\Carbon|null $updated_at
746+
* @property-read \App\Models\User $user
747+
* @method static \Illuminate\Database\Eloquent\Builder|Transaction newModelQuery()
748+
* @method static \Illuminate\Database\Eloquent\Builder|Transaction newQuery()
749+
* @method static \Illuminate\Database\Eloquent\Builder|Transaction query()
750+
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereAmount($value)
751+
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereCreatedAt($value)
752+
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereFees($value)
753+
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereId($value)
754+
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereMetadata($value)
755+
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereStatus($value)
756+
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereTransactionReference($value)
757+
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereType($value)
758+
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereUpdatedAt($value)
759+
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereUserId($value)
760+
* @mixin \Eloquent
761+
*/
762+
class IdeHelperTransaction
763+
{
764+
}
765+
}
766+
732767
namespace App\Models{
733768
/**
734769
* App\Models\User
@@ -793,6 +828,8 @@ class IdeHelperThread
793828
* @property-read int|null $threads_count
794829
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Laravel\Sanctum\PersonalAccessToken> $tokens
795830
* @property-read int|null $tokens_count
831+
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Transaction> $transactions
832+
* @property-read int|null $transactions_count
796833
* @method static \Database\Factories\UserFactory factory($count = null, $state = [])
797834
* @method static \Illuminate\Database\Eloquent\Builder|User hasActivity()
798835
* @method static \Illuminate\Database\Eloquent\Builder|User moderators()

public/css/app.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/mix-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"/js/app.js": "/js/app.js?id=0953d0b23f555fd811dda52086298222",
3-
"/css/app.css": "/css/app.css?id=8d5c4c1a62a59a2ffc28ea3c57562b38"
3+
"/css/app.css": "/css/app.css?id=9209b1a63d8215ae6346440a2aa9477f"
44
}

resources/css/forms.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66
padding: 0 10px;
77
}
88

9+
10+
input[type=number] {
11+
-moz-appearance: textfield; /* Firefox */
12+
}
13+
14+
input::-webkit-outer-spin-button,
15+
input::-webkit-inner-spin-button {
16+
/* display: none; <- Crashes Chrome on hover */
17+
-webkit-appearance: none;
18+
margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
19+
}
20+
921
/** Choices.js **/
1022
.choices {
1123
margin-top: 8px;

0 commit comments

Comments
 (0)