idvlab / laravel-yookassa
Laravel的Yookassa
1.1.9
2024-06-28 15:05 UTC
Requires
- php: >=8.2
- ext-json: *
- guzzlehttp/guzzle: ^7.2
- illuminate/support: ~9|~10
- imjonos/laravel-base-service: *
- yoomoney/yookassa-sdk-php: ^3.2
This package is not auto-updated.
Last update: 2024-09-20 16:05:56 UTC
README
安装
composer require idvlab/laravel-yookassa
php artisan vendor:publish --tag=yookassa.migrations php artisan migrate
php artisan vendor:publish --tag=yookassa.config
php artisan vendor:publish --provider=idvLab\LaravelYookassa\YooKassaServiceProvider
// Facade use idvLab\LaravelYookassa\Facades\YooKassaFacade; $yookassaPayment = YookassaFacade::createPayment(10000, 'test payment'); // Service $service = app(idvLab\LaravelYookassa\Services\PaymentService::class); $yookassaPayment = $service->createPayment(10000, 'test payment');
要接收请求,您需要添加URL
并订阅事件idvLab\LaravelYookassa\Events\YookassaPaymentNotification
namespace App\Providers; class EventServiceProvider extends ServiceProvider ... protected $listen = [ YookassaPaymentNotification::class => [ YookassaPaymentStatus::class ] ]; ...
namespace App\Listeners; class YookassaPaymentStatus implements ShouldQueue ... public function handle(YookassaPaymentNotification $event): void { if ($event->payment->status === PaymentStatus::SUCCEEDED->value) { } }
如果使用doctrine,实体位于Entities文件夹
.env
YOOKASSA_SHOP_ID= YOOKASSA_SECRET_KEY= YOOKASSA_REDIRECT=
使用通知
$yooKassa = new YooKassa([]); $paymentRepository = new PaymentRepository(); $paymentService = new PaymentService($yooKassa, $paymentRepository); $requestBody = $request->all(); if (!isset($requestBody['event'])) { throw new \Exception('event not found'); } if (($requestBody['event'] === NotificationEventType::PAYMENT_SUCCEEDED)) { $notification = new NotificationSucceeded($requestBody); } elseif ($requestBody['event'] === NotificationEventType::PAYMENT_WAITING_FOR_CAPTURE) { $notification = new NotificationWaitingForCapture($requestBody); } else { $notification = new NotificationCanceled($requestBody); } $payment = $notification->getObject(); $status = PaymentStatus::tryFrom($payment->getStatus()); $paymentService->setStatus($payment->getId(), $status); $yooKassaPayment = $paymentService->findByPaymentId($payment->getId()); YookassaPaymentNotification::dispatch($yooKassaPayment); return response()->json();
MIT许可证
版权所有 (c) 2024 Vitaliy Edifanov
在此,任何人免费获得本软件及其相关文档副本(“软件”),在不限制包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件副本的权利,并允许向软件提供方提供软件的人这样做,前提是遵守以下条件:
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、特定目的适用性和非侵权性保证。在任何情况下,作者或版权所有者不对任何索赔、损害或其他责任负责,无论是基于合同、侵权或其他方式引起的,无论是由于软件或其使用或其他方式与软件相关。