定制 tourze/wechat-pay-score-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tourze/wechat-pay-score-bundle

最新稳定版本:0.1.0

Composer 安装命令:

composer require tourze/wechat-pay-score-bundle

包简介

微信支付-支付分服务接入套件

README 文档

README

Packagist Version License Total Downloads PHP Version Build Status Code Coverage

English | 中文

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

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 entity
  • PostPayment - Post-payment information entity
  • PostDiscount - Discount information entity

Enums

  • ScoreOrderState - Order state enumeration

Services

  • AttributeControllerLoader - Attribute controller loader
  • CallbackController - Callback processing controller

Events

  • ScoreOrderCallbackEvent - Pay Score order callback event
  • ScoreOrderListener - 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

License

MIT License. See LICENSE file for details.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-14