Skip to content

Commit

Permalink
Migrate notchpay (laravelcm#122)
Browse files Browse the repository at this point in the history
* Add new tags

* Delete telescope styles

* Update NotchPay payment process

* Update phpstan error
  • Loading branch information
mckenziearts authored Jul 1, 2023
1 parent 2057888 commit 3ccbebb
Show file tree
Hide file tree
Showing 23 changed files with 126,130 additions and 734 deletions.
44 changes: 35 additions & 9 deletions app/Http/Controllers/NotchPayCallBackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
use App\Models\Transaction;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
use NotchPay\NotchPay;
use NotchPay\Payment;

class NotchPayCallBackController extends Controller
{
Expand All @@ -18,18 +22,40 @@ public function __invoke(Request $request): RedirectResponse
$transaction = Transaction::query()
->where('transaction_reference', $request->get('reference'))
->firstOrFail();
$transaction->update(['status' => $request->get('status')]);

if ($request->get('status') === TransactionStatus::CANCELED->value) {
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
event(new SponsoringPaymentInitialize($transaction));

session()->flash('status', __('Votre paiement a été pris en compte merci de soutenir Laravel Cameroun.'));
NotchPay::setApiKey(
apiKey: config('lcm.notch-pay-public-token')
);

try {
$verifyTransaction = Payment::verify(reference: $request->get('reference'));
$transaction->update(['status' => $verifyTransaction->transaction->status]); // @phpstan-ignore-line

// @phpstan-ignore-next-line
if ($verifyTransaction->transaction->status === TransactionStatus::CANCELED->value) {
session()->flash(
key: 'error',
value: __('Votre paiement a été annulé veuillez relancer pour 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
event(new SponsoringPaymentInitialize($transaction));
Cache::forget(key: 'sponsors');

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

} catch (\NotchPay\Exceptions\ApiException $e) {
Log::error($e->getMessage());
session()->flash(
key: 'error',
value: __('Une erreur s\'est produite lors de votre paiement. Veuillez relancer Merci.')
);
}


return redirect(route('sponsors'));
}
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/SponsoringController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class SponsoringController extends Controller
public function sponsors(): View
{
$sponsors = Cache::remember(
'sponsors',
3600,
fn () => Transaction::with(['user', 'user.media'])
key: 'sponsors',
ttl: 3600,
callback: fn () => Transaction::with(['user', 'user.media'])
->scopes('complete')
->get(['id', 'user_id', 'metadata'])
);
Expand Down
42 changes: 27 additions & 15 deletions app/Http/Livewire/Modals/AnonymousSponsors.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
use App\Models\Transaction;
use App\Models\User;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Log;
use LivewireUI\Modal\ModalComponent;
use NotchPay\NotchPay;
use NotchPay\Payment;

class AnonymousSponsors extends ModalComponent
{
Expand All @@ -31,22 +33,28 @@ public function mount(string $amount, string $option, string $currency): void

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'),
]);
$this->validate(
rules: [
'name' => 'required',
'email' => 'required|email',
],
messages: [
'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]');
$adminUser = User::findByEmailAddress(
emailAddress: app()->environment('production') ? '[email protected]' : '[email protected]'
);

$notchPay = new NotchPay(config('lcm.notch-pay-public-token'));
NotchPay::setApiKey(
apiKey: config('lcm.notch-pay-public-token')
);

try {
// @phpstan-ignore-next-line
$payload = $notchPay->payment->initialize([
$payload = Payment::initialize([
'amount' => $this->amount,
'email' => $this->email,
'name' => $this->name,
Expand Down Expand Up @@ -80,9 +88,13 @@ public function submit(): void
]
]);

$this->redirect($payload->authorization_url);
} catch (NotchPay\Exception\ApiException $e) {
session()->flash('error', __('Impossible de procéder au paiement, veuillez recommencer plus tard. Merci'));
$this->redirect($payload->authorization_url); // @phpstan-ignore-line
} catch (\NotchPay\Exceptions\ApiException $e) {
Log::error($e->getMessage());
session()->flash(
key: 'error',
value: __('Impossible de procéder au paiement, veuillez recommencer plus tard. Merci')
);
}
}

Expand Down
12 changes: 7 additions & 5 deletions app/Http/Livewire/SponsorSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
use App\Models\Transaction;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Livewire\Component;
use NotchPay\NotchPay;
use NotchPay\Payment;

class SponsorSubscription extends Component
{
Expand All @@ -37,11 +39,10 @@ public function subscribe(): void
return;
}

$notchPay = new NotchPay(config('lcm.notch-pay-public-token'));
NotchPay::setApiKey(apiKey: config('lcm.notch-pay-public-token'));

try {
// @phpstan-ignore-next-line
$payload = $notchPay->payment->initialize([
$payload = Payment::initialize([
'amount' => $this->amount,
'email' => Auth::user()?->email,
'name' => Auth::user()?->name,
Expand Down Expand Up @@ -76,8 +77,9 @@ public function subscribe(): void
],
]);

$this->redirect($payload->authorization_url);
} catch (NotchPay\Exception\ApiException $e) {
$this->redirect($payload->authorization_url); // @phpstan-ignore-line
} catch (\NotchPay\Exceptions\ApiException $e) {
Log::error($e->getMessage());
session()->flash('error', __('Impossible de procéder au paiement, veuillez recommencer plus tard. Merci'));
}
}
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ class Authenticate extends Middleware
* @param \Illuminate\Http\Request $request
* @return string|null
*/
protected function redirectTo($request)
protected function redirectTo($request): ?string
{
if (! $request->expectsJson()) {
return route('login');
}

return null;
}
}
96 changes: 48 additions & 48 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,62 @@
"ext-fileinfo": "*",
"ext-json": "*",
"archtechx/laravel-seo": "^0.5.1",
"arrilot/laravel-widgets": "^3.13",
"bensampo/laravel-enum": "^6.0",
"arrilot/laravel-widgets": "^3.13.2",
"bensampo/laravel-enum": "^6.3.3",
"blade-ui-kit/blade-heroicons": "^1.4",
"blade-ui-kit/blade-ui-kit": "^0.3",
"blade-ui-kit/blade-ui-kit": "^0.3.4",
"cyrildewit/eloquent-viewable": "^6.1",
"doctrine/dbal": "^3.5",
"filament/notifications": "^2.17",
"doctrine/dbal": "^3.6.4",
"filament/notifications": "^2.17.49",
"francescomalatesta/laravel-feature": "^3.0",
"graham-campbell/markdown": "^14.0",
"guzzlehttp/guzzle": "^7.0.1",
"jenssegers/agent": "^2.6",
"laravel-notification-channels/telegram": "^2.0",
"laravel-notification-channels/twitter": "^6.0",
"laravel/fortify": "^1.13",
"laravel/framework": "^9.47",
"laravel/sanctum": "^3.2",
"laravel/slack-notification-channel": "^2.4",
"laravel/socialite": "^5.2",
"laravel/tinker": "^2.5",
"livewire/livewire": "^2.11",
"lorisleiva/laravel-actions": "^2.5",
"nnjeim/world": "^1.1",
"notchpay/php-sdk": "^2.2",
"qcod/laravel-gamify": "^1.0.6",
"ramsey/uuid": "^4.2",
"guzzlehttp/guzzle": "^7.7.0",
"jenssegers/agent": "^2.6.4",
"laravel-notification-channels/telegram": "^2.1",
"laravel-notification-channels/twitter": "^6.2",
"laravel/fortify": "^1.17.4",
"laravel/framework": "^9.52.10",
"laravel/sanctum": "^3.2.5",
"laravel/slack-notification-channel": "^2.5",
"laravel/socialite": "^5.6.3",
"laravel/tinker": "^2.8.1",
"livewire/livewire": "^2.12.3",
"lorisleiva/laravel-actions": "^2.6",
"nnjeim/world": "^1.1.27",
"notchpay/notchpay-php": "^1.3",
"qcod/laravel-gamify": "^1.0.7",
"ramsey/uuid": "^4.7.4",
"rinvex/laravel-subscriptions": "^6.1",
"sentry/sentry-laravel": "^2.10",
"socialiteproviders/twitter": "^4.1",
"spatie/laravel-feed": "^4.1",
"spatie/laravel-google-fonts": "^1.2",
"spatie/laravel-medialibrary": "^10.4.3",
"spatie/laravel-permission": "^5.1",
"spatie/laravel-sitemap": "^6.1",
"stevebauman/location": "^6.2",
"symfony/http-client": "^6.0",
"symfony/mailgun-mailer": "^6.0",
"sentry/sentry-laravel": "^2.14.2",
"socialiteproviders/twitter": "^4.1.2",
"spatie/laravel-feed": "^4.2.1",
"spatie/laravel-google-fonts": "^1.2.3",
"spatie/laravel-medialibrary": "^10.10.0",
"spatie/laravel-permission": "^5.10.1",
"spatie/laravel-sitemap": "^6.3.1",
"stevebauman/location": "^6.6.2",
"symfony/http-client": "^6.3.1",
"symfony/mailgun-mailer": "^6.3",
"torchlight/torchlight-commonmark": "^0.5.5",
"wire-elements/modal": "^1.0",
"wire-elements/spotlight": "^1.0",
"yarri/link-finder": "^2.7"
"wire-elements/modal": "^1.0.8",
"wire-elements/spotlight": "^1.0.7",
"yarri/link-finder": "^2.7.10"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.7",
"barryvdh/laravel-ide-helper": "^2.12",
"brianium/paratest": "^6.3",
"fakerphp/faker": "^1.9.1",
"laravel/pint": "^1.1",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.2",
"nunomaduro/collision": "^6.0",
"nunomaduro/larastan": "^2.0",
"pestphp/pest-plugin-laravel": "^1.2.0",
"barryvdh/laravel-debugbar": "^3.8.1",
"barryvdh/laravel-ide-helper": "^2.13",
"brianium/paratest": "^6.10",
"fakerphp/faker": "^1.23.0",
"laravel/pint": "^1.10.3",
"laravel/sail": "^1.23.0",
"mockery/mockery": "^1.6.2",
"nunomaduro/collision": "^6.4",
"nunomaduro/larastan": "^2.6.3",
"pestphp/pest-plugin-laravel": "^1.4.0",
"pestphp/pest-plugin-livewire": "^1.0",
"phpunit/phpunit": "^9.5.20",
"spatie/laravel-ignition": "^1.0",
"spatie/test-time": "^1.2"
"phpunit/phpunit": "^9.6.9",
"spatie/laravel-ignition": "^1.6.4",
"spatie/test-time": "^1.3.2"
},
"autoload": {
"files": [
Expand Down Expand Up @@ -106,7 +106,7 @@
"./vendor/bin/pint"
],
"stan": [
"./vendor/bin/phpstan analyse"
"./vendor/bin/phpstan analyse --memory-limit=3g"
],
"test": [
"@php artisan test"
Expand Down
Loading

0 comments on commit 3ccbebb

Please sign in to comment.