small / swoole-payment
0.1.0
2025-06-30 22:41 UTC
Requires
- php: >=8.3
- ext-bcmath: *
- nyholm/psr7: *
- small/collection: >=2.10
- small/swoole-symfony-http-client: >=1.3.1
- stripe/stripe-php: *
Requires (Dev)
- mockery/mockery: *
- pestphp/pest: 2.*
- pestphp/pest-plugin-mock: *
- phpstan/phpstan: 2.*
- rector/rector: *
- swoole/ide-helper: 5.1.7
This package is not auto-updated.
Last update: 2025-07-01 05:02:04 UTC
README
small/swoole-payment
Modular payment abstraction layer with support for Stripe, manual payments, and billing logic. Designed to run with high-performance Swoole environments using PSR-18 HTTP clients.
Features
- Stripe and manual payment drivers
- PSR-18 HTTP client integration
- Full or partial payments
- Payment notifications
- Billing builder with sold-out detection
- Seamless adaptation of PaymentInterface objects
Installation
composer require small/swoole-payment
Usage
1. Manual Payment
use Small\SwoolePayment\Payment\Driver\Concrete\PaymentManualDriver;
$driver = new PaymentManualDriver();
$payment = $driver->payOrder($order);
2. Stripe Payment
use Small\SwoolePayment\Payment\Driver\Concrete\PaymentStripeDriver;
$driver = new PaymentStripeDriver($stripeSecretKey, 'https://app.example.com/payment-return');
$payment = $driver->payOrder($order);
3. Confirm 3D Secure (Stripe)
try {
$driver->confirm3DSecure($payment);
} catch (RedirectException $e) {
header('Location: ' . $e->getRedirectUrl());
exit;
}
4. Partial Payment
$partial = $driver->partialPayOrder($order, 50.0);
5. Notification ingestion
$updated = $driver->ingestNotification($order, 'ext_123', PaymentInterface::PAYMENT_STATUS_AUTHORIZED);
6. Bill Generation
use Small\SwoolePayment\Bill\Builder\BillFromOrderBuilder;
$builder = new BillFromOrderBuilder();
$bill = $builder($order);
7. Adapt to Another Payment Class
use Small\SwoolePayment\Payment\Adapter\PaymentAdapter;
$adapter = new PaymentAdapter(MyCustomPayment::class);
$new = $adapter($oldPayment);
Tests
Run unit tests with Pest:
vendor/bin/pest
License
GPL V3 License