escolalms / payments
Escola LMS Payments Package.
Installs: 16 150
Dependents: 4
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Type:package
Requires
- php: >=7.4
- escolalms/core: ^1
- escolalms/przelewy24-php: ^0
- laravel/framework: >=8.0
- league/omnipay: ^3
- maatwebsite/excel: ^3.1
- omnipay/stripe: ^3.1
Requires (Dev)
- barryvdh/laravel-ide-helper: ^2.10
- escolalms/settings: ^0.1.7
- nunomaduro/collision: ^5.4
- nunomaduro/larastan: ^0.7.6
- orchestra/testbench: ~5|~6
- php-http/message-factory: ^1.1
- phpunit/phpunit: ^9.0
Suggests
- escolalms/settings: For settings to work
- dev-main / 0.x-dev
- 0.2.20
- 0.2.19
- 0.2.18
- 0.2.17
- 0.2.16
- 0.2.15
- 0.2.14
- 0.2.13
- 0.2.12
- 0.2.11
- 0.2.10
- 0.2.9
- 0.2.8
- 0.2.7
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.14
- 0.1.13
- 0.1.12
- 0.1.11
- 0.1.10
- 0.1.9
- 0.1.8
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- 0.0.9
- 0.0.8
- 0.0.7
- 0.0.6
- 0.0.5
- 0.0.4
- 0.0.3
- 0.0.2
- 0.0.1
- dev-feature/WELLMS-389
This package is auto-updated.
Last update: 2024-12-10 07:39:48 UTC
README
Purpose
This package lets you create Payments and process them using integrations with external payment providers (gateways).
Dependencies
- Stripe integration is based on
league/omnipay
andomnipay/stripe
packages. - Przelewy24 integration is based on
mnastalski/przelewy24-php
package. - Optional integration with
escolalms/settings
package enables changing payment gateway api keys & secrets using Settings API (and Admin Panel).
Installation
composer require escolalms/payments
php artisan migrate
php artisan db:seed --class="EscolaLms\Cart\Database\Seeders\CartPermissionSeeder"
Usage
Facades
Payments Facade
Use EscolaLms\Payments\Facades\Payments
for starting payment processing.
You can create PaymentProcessor` either from a model using Payable trait or from precreated Payment object.
use EscolaLms\Cart\Models\Cart; use EscolaLms\Payments\Dtos\PaymentMethodDto; use EscolaLms\Payments\Facades\Payments; $payable = Cart::find($id); // Cart must implement Payable interface and use Payable trait $paymentMethodDto = PaymentMethodDto::instantiateFromRequest($request); $processor = Payments::processPayment($payable); $processor->purchase($paymentMethodDto); // will emit PaymentPaid event on success if($payment->status->is(PaymentStatus::PAID)){ // ... }
PaymentGateway Facade
With EscolaLms\Payments\Facades\PaymentGateway
you can call payment provider gateways directly.
For existing payment you can for example do:
use EscolaLms\Payments\Dtos\PaymentMethodDto; use EscolaLms\Payments\Facades\PaymentGateway; use EscolaLms\Payments\Models\Payment; $payment = Payment::find($id); $paymentMethodDto = PaymentMethodDto::instantiateFromRequest($request); $paymentDto = PaymentDto::instantiateFromPayment($payment); // or you can create it manually PaymentGateway::purchase($paymentDto, $paymentMethodDto); // will use default payment driver
Important: This will not save Payment
object.
To use specific driver, you can call
PaymentGateway::driver('stripe')->purchase($paymentDto, $paymentMethodDto);
Available payment drivers
- stripe (using
Stripe Payment Intent
) - free
- przelewy24
- TODO: stripe-checkout
Payable Trait & Interface
Payable
trait and interface are the core of this package, enabling simplified calling of PaymentsService
and GatewayManager
.
When you include it in your model that represents a Payable
(for example Cart
or Order
or Product
) you can begin payment processing for that Payable
by calling $payable->process()
which calls Payments::processPayable($this)
and automatically creates a Payment
and returns a PaymentProcessor
instance for that Payment.
EscolaLms\Cart
package uses this trait and interface in EscolaLms\Cart\Models\Order
.
Payment Processor
EscolaLms\Payments\Entities\PaymentProcessor
is a special class which wraps around Payment
and contains functionality related to processing that payment, for example generating links to payment gateways, automatically setting payment status after purchase, emiting events related to payment status, etc.
use EscolaLms\Payments\Dtos\PaymentMethodDto; use EscolaLms\Payments\Entities\PaymentProcessor; use EscolaLms\Payments\Models\Payment; $payment = Payment::find($id); $paymentMethodDto = PaymentMethodDto::instantiateFromRequest($request); $processor = new PaymentProcessor($payment); // instead of using Payments facade $processor->purchase($paymentMethodDto);
PaymentProcessor
automatically selects free
driver when payment amount equals 0.
Payment Model
This package defines a EscolaLms\Payments\Models\Payment
which contains all data abount given payment required for payment gateways to work.
Endpoints
All the endpoints are defined in .
Tests
Run ./vendor/bin/phpunit
to run tests. See tests/Mocks/Payable as an example how a Payable is defined.
Events
EscolaLms\Payments\Events\PaymentCancelled
- - emited after payment processing is cancelled (by user action or possibly by timeout sent from payment gateway)EscolaLms\Payments\Events\PaymentFailed
- emited after payment has failed (payment gateway returns error)EscolaLms\Payments\Events\PaymentRegistered
- emited when new Payment is createdEscolaLms\Payments\Events\PaymentSuccess
- emited when payment gateway returns success
Listeners
No Listeners are defined in this package.
How to use this package on Frontend
Admin Panel
Left Menu
List of Payments
Permissions
Permissions are defined in Enum and seeded in Seeder.
Roadmap. Todo. Troubleshooting
- ???