Skip to content

Commit

Permalink
Participant Payment
Browse files Browse the repository at this point in the history
  • Loading branch information
rahmanramsi committed Jan 21, 2025
1 parent 996931f commit ae9c50f
Show file tree
Hide file tree
Showing 21 changed files with 800 additions and 496 deletions.
48 changes: 36 additions & 12 deletions app/Classes/ManualPaymentPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
use App\Facades\Hook;
use App\Forms\Form;
use App\Models\Payment;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Placeholder;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
use Filament\Forms\Get;
use Filament\Notifications\Notification;
use Illuminate\Support\HtmlString;

class ManualPaymentPlugin extends Plugin
{
Expand All @@ -24,31 +27,52 @@ public function boot()
return false;
});

Hook::add('Forms::Form::components::paymentConfirmation', function ($hookName, array &$components, Form $form) {
Hook::add('Forms::Form::components::paymentForm', function ($hookName, array &$components, Form $form) {

$components[] = SpatieMediaLibraryFileUpload::make('payment_proof')
->label('Payment Proof')
$components[] = Grid::make(1)
->visible(fn(Get $get) => $get('payment_method') == 'manual')
->required()
->downloadable()
->collection('manual_payment_proof');
->schema([
Placeholder::make('manual_payment_instructions')
->label('Payment Instructions')
->content(fn() => new HtmlString(app()->getCurrentScheduledConference()->getMeta('manual_payment_instructions')))
->visible(fn() => app()->getCurrentScheduledConference()->getMeta('manual_payment_instructions')),
SpatieMediaLibraryFileUpload::make('payment_proof')
->label('Payment Proof')
->required()
->downloadable()
->collection('manual_payment_proof')
]);

return false;
});
Hook::add('Forms::Form::components::submissionPayment', function ($hookName, array &$components, Form $form) {

Hook::add('Frontend::PaymentForm::submit', function($hookName, Payment $payment, array &$data, string &$requestUrl){

if($data['payment_method'] == 'manual'){
$components[] = Grid::make(1)
->visible(fn(Get $get) => $get('payment_method') == 'manual')
->schema([
SpatieMediaLibraryFileUpload::make('payment_proof')
->label('Payment Proof')
->required()
->downloadable()
->collection('manual_payment_proof')
])
->disabled();

return false;
});

Hook::add('Frontend::Payment::handleRequestUrl', function ($hookName, Payment $payment, array &$data, string &$requestUrl) {

if ($data['payment_method'] == 'manual') {
Notification::make()
->title('Submit successfully')
->success()
->send();
}


return false;
});

}
}

Expand Down
186 changes: 186 additions & 0 deletions app/Frontend/ScheduledConference/Pages/ParticipantForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<?php

namespace App\Frontend\ScheduledConference\Pages;

use App\Facades\Hook;
use App\Forms\Form;
use App\Frontend\Website\Pages\Page;
use App\Managers\PaymentManager;
use App\Models\Participant;
use App\Models\Payment;
use App\Models\PaymentFee;
use App\Models\PaymentFeeFormItem;
use Awcodes\Shout\Components\Shout;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Placeholder;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\HtmlString;
use Rahmanramsi\LivewirePageGroup\PageGroup;

class ParticipantForm extends Page implements HasForms, HasActions
{
use InteractsWithForms, InteractsWithActions;

protected static string $view = 'frontend.scheduledConference.pages.participant-form';

protected static string $layout = 'filament-panels::components.layout.base';

public PaymentFee $paymentFee;

/**
* @var array<string, mixed> | null
*/
public ?array $data = [];

public function mount(PaymentFee $paymentFee)
{
if($paymentFee->type !== PaymentManager::TYPE_PARTICIPANT_FEE){
abort('403', 'Invalid payment fee type');
}

$this->form->fill([

]);
}

public function getTitle(): string|Htmlable
{
return "Participant Registration";
}

public static function getLayout(): string
{
return static::$layout;
}

/**
* @return array<string, mixed>
*/
protected function getViewData(): array
{
return [

];
}

public function form(Form $form): Form
{
$paymentManager = PaymentManager::get();

return $form
->id('paymentForm')
->statePath('data')
->model(Participant::class)
->schema([
Placeholder::make('name')
->content($this->paymentFee->name),
Placeholder::make('type')
->content($this->paymentFee->getPaymentType()),
Placeholder::make('amount')
->content($this->paymentFee->getFormattedFee())
->extraAttributes([
'style' => 'font-size:1rem;',
]),
Placeholder::make('description')
->content($this->paymentFee->getMeta('description'))
->visible($this->paymentFee->getMeta('description') ?? false),
Grid::make()
->schema([
TextInput::make('given_name')
->label(__('general.given_name'))
->required(),
TextInput::make('family_name')
->label(__('general.family_name')),
]),
TextInput::make('public_name')
->label(__('general.public_name')),
TextInput::make('email')
->email()
->label(__('general.email'))
->required(),
...$this->paymentFee->formItems->map(fn(PaymentFeeFormItem $item) => $item->getFormField())->toArray(),
Radio::make('payment_method')
->required()
->reactive()
->options($paymentManager->getPaymentMethodOptions())
]);
}

public function submitAction()
{
return Action::make('submitAction')
->label('Submit')
->submit('submit')
->button();
}

public function submit()
{
$data = $this->form->getState();

try {
DB::beginTransaction();

$participant = new Participant();
$participant->fill(Arr::only($data, ['given_name', 'family_name', 'email']));
$participant->save();

$this->form->model($participant)->saveRelationships();

$paymentManager = PaymentManager::get();
$payment = $paymentManager->queue($participant, $this->paymentFee, auth()->user(), PaymentManager::TYPE_PARTICIPANT_FEE, $this->paymentFee->name, $this->paymentFee->getMeta('description'));
$payment->payment_method = $data['payment_method'];
$payment->save();

if($meta = data_get($data, 'meta')){
$payment->setManyMeta($meta);
}

$requestUrl = $payment->getMeta('request_url');

Hook::call('Frontend::Payment::handleRequestUrl', [$payment, &$data, &$requestUrl]);

DB::commit();

return redirect()->to($requestUrl);
} catch (\Throwable $th) {
DB::rollBack();
throw $th;
}
}

public static function routes(PageGroup $pageGroup): void
{
$slug = static::getSlug();
Route::get("/{$slug}/{paymentFee}", static::class)
->middleware(static::getRouteMiddleware($pageGroup))
->withoutMiddleware(static::getWithoutRouteMiddleware($pageGroup))
->name((string) str($slug)->replace('/', '.'));
}

/**
* @return array<string>
*/
public function getRenderHookScopes(): array
{
return [static::class];
}

/**
* @return array<mixed>
*/
public function getExtraBodyAttributes(): array
{
return [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Frontend\ScheduledConference\Pages;

use App\Frontend\Website\Pages\Page;
use App\Models\Participant;
use Illuminate\Support\Facades\Route;
use Rahmanramsi\LivewirePageGroup\PageGroup;

class ParticipantSuccessRegister extends Page
{
protected static string $view = 'frontend.scheduledConference.pages.participant-success-register';

public function mount()
{
//
}

public function getBreadcrumbs(): array
{
return [
route(Home::getRouteName()) => __('general.home'),
'Participant Success Register',
];
}

/**
* @return array<string, mixed>
*/
protected function getViewData(): array
{
return [

];
}

// public static function routes(PageGroup $pageGroup): void
// {
// $slug = static::getSlug();
// Route::get("/{$slug}/{payment}", static::class)
// ->middleware(static::getRouteMiddleware($pageGroup))
// ->withoutMiddleware(static::getWithoutRouteMiddleware($pageGroup))
// ->name((string) str($slug)->replace('/', '.'));
// }
}
42 changes: 8 additions & 34 deletions app/Frontend/ScheduledConference/Pages/PaymentForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,16 @@ class PaymentForm extends Page implements HasForms, HasActions

public function mount(Payment $payment)
{
// dd($payment, $payment->getAllMeta());
if($payment->isPaid()){
abort('403', 'Payment fee already paid');
}

if ($payment->isExpired()) {
$payment->delete();

abort('403', 'Payment is expired');
}

if($payment->isPaid()){
abort('403', 'Payment fee already paid');
}

$this->form->fill([
...$this->payment->attributesToArray(),
'meta' => $this->payment->getAllMeta()->toArray(),
Expand All @@ -75,34 +74,18 @@ public function getBreadcrumbs(): array
];
}

/**
* @return array<string, mixed>
*/
protected function getViewData(): array
{
$currentScheduledConference = app()->getCurrentScheduledConference();

return [
'heading' => "Pay",
'paymentDetails' => $this->paymentMethod(),
'payment' => $this->payment,
'paymentInformation' => $currentScheduledConference->getMeta('payment_information'),
];
}

public function form(Form $form): Form
{
$paymentManager = PaymentManager::get();

return $form
->id('paymentConfirmation')
->id('paymentForm')
->statePath('data')
->model($this->payment)
->schema([
Shout::make('policy')
->icon(fn() => null)
->content(fn() => new HtmlString(app()->getCurrentScheduledConference()?->getMeta('submission_payment_policy')))
->visible(app()->getCurrentScheduledConference()?->getMeta('submission_payment_policy') ?? false),
->content(fn() => new HtmlString(app()->getCurrentScheduledConference()?->getMeta('payment_policy')))
->visible(app()->getCurrentScheduledConference()?->getMeta('payment_policy') ?? false),
Placeholder::make('title')
->content($this->payment->getMeta('title')),
Placeholder::make('type')
Expand Down Expand Up @@ -146,23 +129,14 @@ public function submit()

$requestUrl = $this->payment->getMeta('request_url');

Hook::call('Frontend::PaymentForm::submit', [$this->payment, &$data, &$requestUrl]);
Hook::call('Frontend::Payment::handleRequestUrl', [$this->payment, &$data, &$requestUrl]);

return redirect()->to($requestUrl);
} catch (\Throwable $th) {
throw $th;
}
}

protected function paymentMethod()
{
$paymentMethods = [];

Hook::call('Frontend::PaymentForm::getPaymentMethod', [$this->payment, &$paymentMethods]);

return $paymentMethods;
}

public static function routes(PageGroup $pageGroup): void
{
$slug = static::getSlug();
Expand Down
Loading

0 comments on commit ae9c50f

Please sign in to comment.