yansongda/pay
A popular PHP payment library for Laravel and other frameworks, integrating Alipay and WeChat Pay with a clean API. Supports common payment flows, refunds, queries, callbacks/notifications, and flexible configuration for multi-app and sandbox use.
laravel-pay extension) and adheres to PSR standards (PSR-2, PSR-4, PSR-7, PSR-11, PSR-14, PSR-18), ensuring seamless integration with Laravel’s dependency injection, service container, and event systems.StartPlugin → Business Plugins → ParserPlugin) allows for easy extension (e.g., adding custom payment gateways like PayPal, Stripe) without modifying core logic. This aligns well with Laravel’s modularity and service provider patterns.Tenant abstraction, which can be leveraged in Laravel using middleware or service container bindings (e.g., Pay::tenant('tenant_id')).pay.success, pay.failure), allowing for observability, analytics, or custom workflows (e.g., triggering order fulfillment).laravel-pay extension (linked in the README) provides Laravel-specific features like:
Pay::alipay() → PayFacade::alipay()).config/pay.php..env → config/pay.php), aligning with Laravel’s 12-factor principles.CertManager), but misconfiguration (e.g., incorrect paths or permissions) can break payments.storage/app/certs) and cache (Cache::remember) to store/refresh certificates.Pay::wechat()->callback() with Pay::MODE_SERVICE for service accounts).queue:failed monitoring and dead-letter queues.trade_status vs. WeChat’s trade_state).validatePaymentStatus($provider, $data)).tenant_id column in payments table).Pay::tenant('tenant_id')->config()).TenantMiddleware binding tenant to request).signed routes for notify URLs.trustedProxies middleware).Pay::wechat()->verifyWebhookSign()).Log::channel('payments') + queue:failed jobs.PaymentException class extending Laravel’s Exception.Mockery for unit tests.Pay::MODE_SANDBOX) for integration tests.Pay facade/service to the container with tenant-aware configurations.config/pay.php using Laravel’s publishes in a service provider.PaymentProcessed, PaymentFailed) to integrate with Laravel’s event system.VerifyPaymentCallback middleware to validate webhook signatures (e.g., for /alipay/notify).pay.alipay.notify) for callback URLs to avoid hardcoding.payments table with fields like provider, out_trade_no, status, tenant_id, and metadata (JSON).Model with Payment model for CRUD and status transitions.ProcessPaymentJob and HandleWebhookJob for async operations (e.g., refunds, notifications).yansongda/pay and yansongda/laravel-pay.config/pay.php for primary providers (e.g., Alipay, WeChat).PayServiceProvider to bind Pay facade and publish configs.Payment model and migration./alipay/notify, /wechat/callback, etc.PaymentListener to handle events (e.g., update Payment model on success).Pay config to support tenant-specific settings.TenantMiddleware to bind tenant to request context.Payment model and service logic.laravel/framework:^9.0 in Docker).openssl, curl, and dom (for XML parsing in Alipay/UnionPay).payments table.config/caching to avoid runtime config reloads.app_secret_cert) in .env or Laravel Vault.scheduler:run) to refresh WeChat certificates via CertManager::reloadWechatPublicCerts().Log::warning).logger.enable: true in config and route logs to Laravel’s single or daily channels.logs/payments.log and queue:failed jobs.How can I help you explore Laravel packages today?