Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:laravelcm/laravel.cm into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mckenziearts committed May 8, 2023
2 parents 3f4045e + 63a1809 commit 78be7bf
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 36 deletions.
5 changes: 0 additions & 5 deletions app/Events/ApiRegistered.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ class ApiRegistered
{
use SerializesModels;

/**
* Create a new event instance.
*
* @return void
*/
public function __construct(public User $user)
{
}
Expand Down
5 changes: 2 additions & 3 deletions app/Events/ArticleWasSubmittedForApproval.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class ArticleWasSubmittedForApproval
{
use SerializesModels;

public function __construct(
public Article $article
) {
public function __construct(public Article $article)
{
}
}
8 changes: 1 addition & 7 deletions app/Events/EmailAddressWasChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ class EmailAddressWasChanged
use Dispatchable;
use SerializesModels;

/**
* @var \App\Models\User
*/
public $user;

public function __construct(User $user)
public function __construct(public User $user)
{
$this->user = $user;
}
}
17 changes: 17 additions & 0 deletions app/Events/SponsoringPaymentInitialize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Events;

use App\Models\Transaction;
use Illuminate\Queue\SerializesModels;

class SponsoringPaymentInitialize
{
use SerializesModels;

public function __construct(public Transaction $transaction)
{
}
}
5 changes: 4 additions & 1 deletion app/Http/Controllers/NotchPayCallBackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Http\Controllers;

use App\Enums\TransactionStatus;
use App\Events\SponsoringPaymentInitialize;
use App\Models\Transaction;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
Expand All @@ -13,6 +14,7 @@ class NotchPayCallBackController extends Controller
{
public function __invoke(Request $request): RedirectResponse
{
/** @var Transaction $transaction */
$transaction = Transaction::query()
->where('transaction_reference', $request->get('reference'))
->firstOrFail();
Expand All @@ -22,7 +24,8 @@ public function __invoke(Request $request): RedirectResponse
session()->flash('error', __('Votre paiement a été annulé veuillez relancer si vous souhaitez soutenir Laravel Cameroun, Merci.'));
} else {
// @ToDO Envoie de mail de notification de remerciement pour le sponsoring si l'utilisateur est dans la base de données
// @ToDo Envoie de la notification dans le channel de soumission pour un nouveau paiement
event(new SponsoringPaymentInitialize($transaction));

session()->flash('status', __('Votre paiement a été pris en compte merci de soutenir Laravel Cameroun.'));
}

Expand Down
11 changes: 5 additions & 6 deletions app/Http/Livewire/SponsorSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SponsorSubscription extends Component
{
public string $option = 'one-time';
public string $amount = '';
public string $currency = 'XAF';

public function chooseOption(string $option): void
{
Expand All @@ -24,16 +25,14 @@ public function chooseOption(string $option): void

public function subscribe(): void
{
$this->validate(
['amount' => 'required'],
['amount.required' => __('Votre montant est requis')],
);
$this->validate(['amount' => 'required']);

if (!Auth::check()) {
$this->emit('openModal', 'modals.anonymous-sponsors', [
'amount' => $this->amount,
'option' => $this->option,
]);

return;
}

Expand All @@ -45,7 +44,7 @@ public function subscribe(): void
'amount' => $this->amount,
'email' => Auth::user()?->email,
'name' => Auth::user()?->name,
'currency' => 'XAF',
'currency' => $this->currency,
'reference' => Auth::id() . '-' . Auth::user()?->username() . '-' . uniqid(),
'callback' => route('notchpay-callback'),
]);
Expand All @@ -72,7 +71,7 @@ public function subscribe(): void
'initiated_at' => $payload->transaction->initiated_at,
'description' => $payload->transaction->description,
'for' => PaymentType::SPONSORING->value,
]
],
]);

$this->redirect($payload->authorization_url);
Expand Down
21 changes: 21 additions & 0 deletions app/Listeners/SendPaymentNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Listeners;

use App\Events\SponsoringPaymentInitialize;
use App\Notifications\NewSponsorPaymentNotification;
use Illuminate\Notifications\AnonymousNotifiable;

final readonly class SendPaymentNotification
{
public function __construct(private AnonymousNotifiable $notifiable)
{
}

public function handle(SponsoringPaymentInitialize $event): void
{
$this->notifiable->notify(new NewSponsorPaymentNotification($event->transaction));
}
}
25 changes: 24 additions & 1 deletion app/Models/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
* @mixin IdeHelperTransaction
*/
class Transaction extends Model
{
use HasFactory;
Expand All @@ -17,11 +20,31 @@ class Transaction extends Model
public $guarded = [];

public $casts = [
'metadata' => 'json',
'metadata' => 'array',
];

public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}

public function getMetadata(string $name, string $default = ''): string | array
{
if ($this->metadata && array_key_exists($name, $this->metadata)) {
return $this->metadata[$name];
}

return $default;
}

public function setMetadata(array $revisions, bool $save = true): self
{
$this->metadata = array_merge($this->metadata ?? [], $revisions);

if ($save) {
$this->save();
}

return $this;
}
}
57 changes: 57 additions & 0 deletions app/Notifications/NewSponsorPaymentNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace App\Notifications;

use App\Models\Transaction;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use NotificationChannels\Telegram\TelegramChannel;
use NotificationChannels\Telegram\TelegramMessage;

class NewSponsorPaymentNotification extends Notification implements ShouldQueue
{
use Queueable;

public function __construct(public readonly Transaction $transaction)
{
}

/**
* @return array|string[]
*/
public function via(mixed $notifiable): array
{
if (
! empty(config('services.telegram-bot-api.token')) &&
! empty(config('services.telegram-bot-api.channel'))
) {
return [TelegramChannel::class];
}

return [];
}

public function toTelegram(): TelegramMessage
{
return TelegramMessage::create()
->to(config('services.telegram-bot-api.channel'))
->content($this->content())
->button('Voir les sponsors', route('sponsors'));
}

private function content(): string
{
$content = "*Nouveau paiement de Sponsoring enregistré!*\n\n";
$content .= 'Auteur: '.$this->transaction->getMetadata('merchant')['name']."\n";
$content .= 'Montant: '. $this->transaction->amount;

if ($this->transaction->getMetadata('merchant')['laravel_cm_id']) {
$content .= 'Profil Laravel Cameroun: [@'.$this->transaction->user?->username.']('.route('profile', $this->transaction->user?->username).')';
}

return $content;
}
}
6 changes: 6 additions & 0 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Events\ArticleWasSubmittedForApproval;
use App\Events\CommentWasAdded;
use App\Events\ReplyWasCreated;
use App\Events\SponsoringPaymentInitialize;
use App\Events\ThreadWasCreated;
use App\Listeners\NotifyMentionedUsers;
use App\Listeners\PostNewThreadNotification;
Expand All @@ -16,6 +17,7 @@
use App\Listeners\SendNewCommentNotification;
use App\Listeners\SendNewReplyNotification;
use App\Listeners\SendNewThreadNotification;
use App\Listeners\SendPaymentNotification;
use App\Listeners\SendWelcomeCompanyNotification;
use App\Listeners\SendWelcomeMailNotification;
use Illuminate\Auth\Events\Registered;
Expand Down Expand Up @@ -54,5 +56,9 @@ final class EventServiceProvider extends ServiceProvider
SendCompanyEmailVerificationNotification::class,
SendWelcomeCompanyNotification::class,
],

SponsoringPaymentInitialize::class => [
SendPaymentNotification::class,
],
];
}
7 changes: 0 additions & 7 deletions app/Traits/HasSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

trait HasSettings
{
/**
* Retrieve a setting with a given name or fall back to the default.
*/
public function setting(string $name, string $default): string
{
if ($this->settings && array_key_exists($name, $this->settings)) {
Expand All @@ -18,10 +15,6 @@ public function setting(string $name, string $default): string
return $default;
}

/**
* @param array<string> $revisions
* @param bool $save
*/
public function settings(array $revisions, bool $save = true): self
{
$this->settings = array_merge($this->settings ?? [], $revisions);
Expand Down
37 changes: 37 additions & 0 deletions helpers/ModelHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,41 @@ class IdeHelperThread
}
}

namespace App\Models{
/**
* App\Models\Transaction
*
* @property string $id
* @property string $type
* @property int $user_id
* @property int $amount
* @property int|null $fees
* @property string $transaction_reference
* @property string $status
* @property array|null $metadata
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Models\User $user
* @method static \Illuminate\Database\Eloquent\Builder|Transaction newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Transaction newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Transaction query()
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereAmount($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereFees($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereMetadata($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereTransactionReference($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereType($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Transaction whereUserId($value)
* @mixin \Eloquent
*/
class IdeHelperTransaction
{
}
}

namespace App\Models{
/**
* App\Models\User
Expand Down Expand Up @@ -793,6 +828,8 @@ class IdeHelperThread
* @property-read int|null $threads_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Laravel\Sanctum\PersonalAccessToken> $tokens
* @property-read int|null $tokens_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Transaction> $transactions
* @property-read int|null $transactions_count
* @method static \Database\Factories\UserFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|User hasActivity()
* @method static \Illuminate\Database\Eloquent\Builder|User moderators()
Expand Down
4 changes: 2 additions & 2 deletions public/css/app.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/js/app.js": "/js/app.js?id=0953d0b23f555fd811dda52086298222",
"/css/app.css": "/css/app.css?id=8d5c4c1a62a59a2ffc28ea3c57562b38"
"/css/app.css": "/css/app.css?id=9209b1a63d8215ae6346440a2aa9477f"
}
12 changes: 12 additions & 0 deletions resources/css/forms.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
padding: 0 10px;
}


input[type=number] {
-moz-appearance: textfield; /* Firefox */
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
/* display: none; <- Crashes Chrome on hover */
-webkit-appearance: none;
margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
}

/** Choices.js **/
.choices {
margin-top: 8px;
Expand Down
Loading

0 comments on commit 78be7bf

Please sign in to comment.