forked from laravelcm/laravel.cm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:laravelcm/laravel.cm into develop
- Loading branch information
Showing
34 changed files
with
722 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,3 +82,5 @@ FORMS_FILESYSTEM_DRIVER=${MEDIA_DISK} | |
|
||
SENTRY_LARAVEL_DSN= | ||
SENTRY_TRACES_SAMPLE_RATE= | ||
|
||
NOTCHPAY_PUBLIC_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Enums; | ||
|
||
enum PaymentType: string | ||
{ | ||
case SUBSCRIPTION = 'subscription'; | ||
case SPONSORING = 'sponsoring'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Enums; | ||
|
||
enum TransactionStatus: string | ||
{ | ||
case PENDING = 'pending'; | ||
case COMPLETE = 'complete'; | ||
case CANCELED = 'canceled'; | ||
case Failed = 'failed'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Enums; | ||
|
||
enum TransactionType: string | ||
{ | ||
case ONETIME = 'one-time'; | ||
case RECURSIVE = 'recursive'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Transaction; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
|
||
class NotchPayCallBackController extends Controller | ||
{ | ||
public function __invoke(Request $request): RedirectResponse | ||
{ | ||
$transaction = Transaction::query() | ||
->where('transaction_reference', $request->get('reference')) | ||
->firstOrFail(); | ||
$transaction->update(['status' => $request->get('status')]); | ||
|
||
// @ToDO Envoie de mail de notification de remerciement pour le sponsoring si l'utilisateur est dans la base de données | ||
|
||
session()->flash('status', __('Votre paiement a été pris en compte merci de soutenir Laravel Cameroun.')); | ||
|
||
return redirect(route('sponsors')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Contracts\View\View; | ||
|
||
class SponsoringController extends Controller | ||
{ | ||
public function sponsors(): View | ||
{ | ||
return view('sponsors.index'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Livewire\Modals; | ||
|
||
use App\Enums\PaymentType; | ||
use App\Enums\TransactionType; | ||
use App\Models\Transaction; | ||
use App\Models\User; | ||
use Illuminate\Contracts\View\View; | ||
use LivewireUI\Modal\ModalComponent; | ||
use NotchPay\NotchPay; | ||
|
||
class AnonymousSponsors extends ModalComponent | ||
{ | ||
public ?string $amount = null; | ||
public ?string $option = null; | ||
public ?string $name = null; | ||
public ?string $email = null; | ||
public string $type = 'company'; | ||
public ?string $url = null; | ||
|
||
public function mount(string $amount, string $option): void | ||
{ | ||
$this->amount = $amount; | ||
$this->option = $option; | ||
} | ||
|
||
public function submit(): void | ||
{ | ||
$this->validate([ | ||
'name' => 'required', | ||
'email' => 'required|email', | ||
], [ | ||
'name.required' => 'Votre nom est requis', | ||
'email.required' => 'Une adresse e-mail est requise', | ||
'email.email' => 'Veuillez renseigner une adresse e-mail valide', | ||
]); | ||
|
||
$adminUser = User::findByEmailAddress('[email protected]'); | ||
|
||
$notchPay = new NotchPay(config('lcm.notch-pay-public-token')); | ||
|
||
try { | ||
// @phpstan-ignore-next-line | ||
$payload = $notchPay->payment->initialize([ | ||
'amount' => $this->amount, | ||
'email' => $this->email, | ||
'name' => $this->name, | ||
'currency' => 'XAF', | ||
'reference' => $adminUser->id . '-' . $adminUser->username() . '-' . uniqid(), | ||
'callback' => route('notchpay-callback'), | ||
]); | ||
|
||
Transaction::query()->create([ | ||
'amount' => $this->amount, | ||
'status' => $payload->transaction->status, | ||
'transaction_reference' => $payload->transaction->reference, | ||
'user_id' => $adminUser->id, | ||
'fees' => $payload->transaction->fee, | ||
'type' => $this->option === 'one-time' | ||
? TransactionType::ONETIME->value | ||
: TransactionType::RECURSIVE->value, | ||
'metadata' => [ | ||
'currency' => $payload->transaction->currency, | ||
'reference' => $payload->transaction->reference, | ||
'merchant' => [ | ||
'reference' => $payload->transaction->merchant_reference, | ||
'name' => $payload->transaction->customer->name, | ||
'email' => $payload->transaction->customer->email, | ||
'laravel_cm_id' => null, | ||
], | ||
'initiated_at' => $payload->transaction->initiated_at, | ||
'description' => $payload->transaction->description, | ||
'for' => PaymentType::SPONSORING->value, | ||
] | ||
]); | ||
|
||
$this->redirect($payload->authorization_url); | ||
} catch (NotchPay\Exception\ApiException $e) { | ||
session()->flash('error', __('Impossible de procéder au paiement, veuillez recommencer plus tard. Merci')); | ||
} | ||
} | ||
|
||
public static function modalMaxWidth(): string | ||
{ | ||
return 'xl'; | ||
} | ||
|
||
public function render(): View | ||
{ | ||
return view('livewire.modals.anonymous-sponsors'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Livewire; | ||
|
||
use App\Enums\PaymentType; | ||
use App\Enums\TransactionType; | ||
use App\Models\Transaction; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Support\Facades\Auth; | ||
use Livewire\Component; | ||
use NotchPay\NotchPay; | ||
|
||
class SponsorSubscription extends Component | ||
{ | ||
public string $option = 'one-time'; | ||
public string $amount = ''; | ||
|
||
public function chooseOption(string $option): void | ||
{ | ||
$this->option = $option; | ||
} | ||
|
||
public function subscribe(): void | ||
{ | ||
$this->validate( | ||
['amount' => 'required'], | ||
['amount.required' => __('Votre montant est requis')], | ||
); | ||
|
||
if (!Auth::check()) { | ||
$this->emit('openModal', 'modals.anonymous-sponsors', [ | ||
'amount' => $this->amount, | ||
'option' => $this->option, | ||
]); | ||
return; | ||
} | ||
|
||
$notchPay = new NotchPay(config('lcm.notch-pay-public-token')); | ||
|
||
try { | ||
// @phpstan-ignore-next-line | ||
$payload = $notchPay->payment->initialize([ | ||
'amount' => $this->amount, | ||
'email' => Auth::user()?->email, | ||
'name' => Auth::user()?->name, | ||
'currency' => 'XAF', | ||
'reference' => Auth::id() . '-' . Auth::user()?->username() . '-' . uniqid(), | ||
'callback' => route('notchpay-callback'), | ||
]); | ||
|
||
Transaction::query()->create([ | ||
'amount' => $this->amount, | ||
'status' => $payload->transaction->status, | ||
'transaction_reference' => $payload->transaction->reference, | ||
'user_id' => Auth::id(), | ||
'fees' => $payload->transaction->fee, | ||
'type' => $this->option === 'one-time' | ||
? TransactionType::ONETIME->value | ||
: TransactionType::RECURSIVE->value, | ||
'metadata' => [ | ||
'currency' => $payload->transaction->currency, | ||
'reference' => $payload->transaction->reference, | ||
'merchant' => [ | ||
'reference' => $payload->transaction->merchant_reference, | ||
'name' => $payload->transaction->customer->name, | ||
'email' => $payload->transaction->customer->email, | ||
'phone' => $payload->transaction->customer->phone, | ||
'laravel_cm_id' => Auth::id(), | ||
], | ||
'initiated_at' => $payload->transaction->initiated_at, | ||
'description' => $payload->transaction->description, | ||
'for' => PaymentType::SPONSORING->value, | ||
] | ||
]); | ||
|
||
$this->redirect($payload->authorization_url); | ||
} catch (NotchPay\Exception\ApiException $e) { | ||
session()->flash('error', __('Impossible de procéder au paiement, veuillez recommencer plus tard. Merci')); | ||
} | ||
} | ||
|
||
public function render(): View | ||
{ | ||
return view('livewire.sponsor-subscription'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Concerns\HasUuids; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
||
class Transaction extends Model | ||
{ | ||
use HasFactory; | ||
use HasUuids; | ||
|
||
public $guarded = []; | ||
|
||
public $casts = [ | ||
'metadata' => 'json', | ||
]; | ||
|
||
public function user(): BelongsTo | ||
{ | ||
return $this->belongsTo(User::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.