tourze / wechat-pay-score-bundle
微信支付-支付分服务接入套件
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/wechat-pay-score-bundle
Requires
- ext-json: *
- doctrine/collections: ^2.3
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- doctrine/persistence: ^4.1
- easycorp/easyadmin-bundle: ^4
- knplabs/knp-menu: ^3.7
- monolog/monolog: ^3.1
- psr/http-message: ^1.1 || ^2.0
- psr/log: ^3|^2|^1
- symfony/config: ^7.3
- symfony/dependency-injection: ^7.3
- symfony/doctrine-bridge: ^7.3
- symfony/event-dispatcher: ^7.3
- symfony/event-dispatcher-contracts: ^3
- symfony/framework-bundle: ^7.3
- symfony/http-foundation: ^7.3
- symfony/http-kernel: ^7.3
- symfony/property-access: ^7.3
- symfony/routing: ^7.3
- symfony/yaml: ^7.3
- tourze/arrayable: 1.*
- tourze/bundle-dependency: 1.*
- tourze/doctrine-snowflake-bundle: 1.1.*
- tourze/doctrine-timestamp-bundle: 1.1.*
- tourze/doctrine-user-bundle: 1.0.*
- tourze/easy-admin-enum-field-bundle: 1.0.*
- tourze/easy-admin-menu-bundle: 1.0.*
- tourze/enum-extra: 1.0.*
- tourze/symfony-dependency-service-loader: 1.0.*
- tourze/symfony-routing-auto-loader-bundle: 1.0.*
- tourze/wechat-pay-bundle: 0.0.*
- wechatpay/wechatpay: ^1.4
- yiisoft/json: ^1.0
Requires (Dev)
- doctrine/data-fixtures: ^2.0
- doctrine/doctrine-fixtures-bundle: ^4.0
- fakerphp/faker: ^1.23
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
- tourze/phpunit-base: 1.*
- tourze/phpunit-doctrine-entity: 1.*
- tourze/phpunit-enum: 1.*
- tourze/phpunit-symfony-kernel-test: 1.0.*
- tourze/phpunit-symfony-unit-test: 1.*
- tourze/phpunit-symfony-web-test: 1.*
This package is auto-updated.
Last update: 2025-11-14 06:25:27 UTC
README
WeChat Pay Score Symfony Bundle for integrating WeChat Pay Score services, supporting create, query, complete, and cancel Pay Score orders.
Table of Contents
- Quick Start
- Features
- Core Components
- Configuration Examples
- API Reference
- Requirements
- Advanced Usage
- Testing
- Documentation
- License
Quick Start
Installation
composer require tourze/wechat-pay-score-bundle
1. Register Bundle
Add to config/bundles.php:
return [ // ... WechatPayScoreBundle\WechatPayScoreBundle::class => ['all' => true], ];
2. Database Configuration
Run migrations to create necessary tables:
php bin/console doctrine:migrations:diff php bin/console doctrine:migrations:migrate
3. Basic Usage
use WechatPayScoreBundle\Entity\ScoreOrder; use WechatPayScoreBundle\Enum\ScoreOrderState; // Create Pay Score order $scoreOrder = new ScoreOrder(); $scoreOrder->setOutTradeNo('20241201001') ->setAppId('your_app_id') ->setServiceId('your_service_id') ->setServiceIntroduction('Service description') ->setRiskFundName('Risk fund') ->setRiskFundAmount(10000) ->setNotifyUrl('https://example.com/notify') ->setStartTime('20241201120000') ->setState(ScoreOrderState::CREATED); $entityManager->persist($scoreOrder); $entityManager->flush();
Features
- 🎯 Pay Score Order Management - Support create, query, complete, and cancel Pay Score orders
- 📊 Order Status Tracking - Complete order status management (Created, Doing, Done, Revoked, Expired)
- 💰 Payment Handling - Support post-payment and discount information management
- 🔔 Callback Processing - Built-in callback controller for WeChat Pay Score notifications
- 📱 Mini Program Support - Support jumping to WeChat Mini Program for Pay Score operations
- 🔒 Security & Reliability - Integrated with WeChat Pay official SDK for secure transactions
Core Components
Entities
ScoreOrder- Pay Score order entityPostPayment- Post-payment information entityPostDiscount- Discount information entity
Enums
ScoreOrderState- Order state enumeration
Services
AttributeControllerLoader- Attribute controller loaderCallbackController- Callback processing controller
Events
ScoreOrderCallbackEvent- Pay Score order callback eventScoreOrderListener- Pay Score order event listener
Configuration Examples
Entity Relationship Configuration
// Add Pay Score order relationship in your user entity class User { #[ORM\OneToMany(mappedBy: 'user', targetEntity: ScoreOrder::class)] private Collection $scoreOrders; }
Event Listener Configuration
// Listen to Pay Score order status changes class ScoreOrderSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents(): array { return [ ScoreOrderCallbackEvent::class => 'onScoreOrderCallback', ]; } public function onScoreOrderCallback(ScoreOrderCallbackEvent $event): void { $scoreOrder = $event->getScoreOrder(); // Handle order status changes } }
API Reference
Order States
| State | Description |
|---|---|
CREATED |
Created |
DOING |
In Progress |
DONE |
Completed |
REVOKED |
Cancelled |
EXPIRED |
Expired |
Callback Interface
The system automatically registers callback route: /wechat-pay-score/callback
Requirements
- PHP 8.1+
- Symfony 6.4+
- Doctrine ORM 3.0+
- WeChat Pay Official SDK
Advanced Usage
Custom Event Listeners
use WechatPayScoreBundle\Event\ScoreOrderCallbackEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class CustomScoreOrderListener implements EventSubscriberInterface { public static function getSubscribedEvents(): array { return [ ScoreOrderCallbackEvent::class => 'onScoreOrderCallback', ]; } public function onScoreOrderCallback(ScoreOrderCallbackEvent $event): void { $scoreOrder = $event->getScoreOrder(); $callbackData = $event->getCallbackData(); // Custom business logic switch ($scoreOrder->getState()) { case ScoreOrderState::DONE: // Handle completed order break; case ScoreOrderState::REVOKED: // Handle cancelled order break; } } }
Order State Management
use WechatPayScoreBundle\Entity\ScoreOrder; use WechatPayScoreBundle\Enum\ScoreOrderState; // Complete an order $scoreOrder->setState(ScoreOrderState::DONE); $scoreOrder->setEndTime(date('YmdHis')); $scoreOrder->setTotalAmount(10000); $entityManager->flush(); // Cancel an order $scoreOrder->setCancelReason('User requested cancellation'); $entityManager->remove($scoreOrder); $entityManager->flush();
Post-Payment and Discount Configuration
use WechatPayScoreBundle\Entity\PostPayment; use WechatPayScoreBundle\Entity\PostDiscount; // Add post-payment information $postPayment = new PostPayment(); $postPayment->setName('Service Fee') ->setAmount(5000) ->setDescription('Basic service fee') ->setCount(1); $scoreOrder->addPostPayment($postPayment); // Add discount information $postDiscount = new PostDiscount(); $postDiscount->setName('New User Discount') ->setAmount(1000) ->setDescription('First-time user discount') ->setCount(1); $scoreOrder->addPostDiscount($postDiscount);
Testing
# Run tests ./vendor/bin/phpunit packages/wechat-pay-score-bundle/tests # Run code analysis php -d memory_limit=2G ./vendor/bin/phpstan analyse packages/wechat-pay-score-bundle
Documentation
- [WeChat Pay Score API Documentation] (https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter6_1_1.shtml)
- [WeChat Pay Score Business Introduction] (https://pay.weixin.qq.com/wiki/doc/apiv3/open/pay/chapter2_8.shtml)
- [Symfony Bundle Development Guide] (https://symfony.com/doc/current/bundles.html)
License
MIT License. See LICENSE file for details.