PHPackages                             tourze/wechat-pay-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. tourze/wechat-pay-bundle

ActiveSymfony-bundle[Payment Processing](/categories/payments)

tourze/wechat-pay-bundle
========================

微信支付集成包，提供统一支付接口和账单管理功能

0.1.0(4mo ago)03801MITPHPCI failing

Since May 9Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/wechat-pay-bundle)[ Packagist](https://packagist.org/packages/tourze/wechat-pay-bundle)[ RSS](/packages/tourze-wechat-pay-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (59)Versions (5)Used By (1)

WeChat Pay Bundle
=================

[](#wechat-pay-bundle)

[![Latest Version](https://camo.githubusercontent.com/1df795f8cffbc2dae63ca274916bfec1ab5efb922aac80ff120bcb43fe66224c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f7765636861742d7061792d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/wechat-pay-bundle)[![PHP Version](https://camo.githubusercontent.com/cc9cdea9aa96b40a822425e981b0a030e3371202973c7d57b74e8e99834f81dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c7565)](https://www.php.net/)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE)[![Test Status](https://camo.githubusercontent.com/df64f9246cc2e25fa8f3825d4a66c03e4f9eb93b0737e742597c3b5a10b55156/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d38342532307061737365642d627269676874677265656e)](https://github.com/tourze/wechat-pay-bundle)[![Code Coverage](https://camo.githubusercontent.com/08f9e2cc3cc2ac54c1a3318cd1fc74d87e564fe653e479f69ca8a42ee4821c98/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d39352532352d627269676874677265656e)](https://github.com/tourze/wechat-pay-bundle)[![Total Downloads](https://camo.githubusercontent.com/d444059a2a2cd0dd7c3a980d2ec0d5c1fb8ab30576183edcc6ae4c06d85e7820/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f7765636861742d7061792d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/wechat-pay-bundle)

[English](README.md) | [中文](README.zh-CN.md)

WeChat Pay integration for Symfony applications, providing payment order management, refund processing, and automated bill synchronization.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Configuration](#configuration)
- [Console Commands](#console-commands)
- [Entities](#entities)
- [Services](#services)
- [Usage Example](#usage-example)
- [Advanced Usage](#advanced-usage)
- [Development Guide](#development-guide)
- [Dependencies](#dependencies)
- [Contributing](#contributing)
- [License](#license)

Features
--------

[](#features)

- WeChat Pay order creation and management
- Refund order processing
- Automated bill downloading
- Order status synchronization
- Multi-merchant support
- Payment callback handling

Installation
------------

[](#installation)

```
composer require tourze/wechat-pay-bundle
```

Configuration
-------------

[](#configuration)

Register the bundle in your Symfony application:

```
// config/bundles.php
return [
    // ...
    WechatPayBundle\WechatPayBundle::class => ['all' => true],
];
```

Console Commands
----------------

[](#console-commands)

### Download Fund Flow Bill

[](#download-fund-flow-bill)

```
php bin/console wechat:pay:download-fund-flow-bill
```

Downloads WeChat Pay fund flow bills. Runs automatically at 10:00 and 11:00 daily, fetching the last 7 days of fund statements.

### Download Trade Bill

[](#download-trade-bill)

```
php bin/console wechat:pay:download-trade-bill
```

Downloads WeChat Pay trade bills. Runs automatically at 10:00 and 11:00 daily, fetching the last 7 days of transaction records.

### Check Order Expiration

[](#check-order-expiration)

```
php bin/console wechat:pay:check-order-expire
```

Checks and updates expired payment orders. Runs every minute to query orders that have expired but are still in INIT status.

### Check Refund Status

[](#check-refund-status)

```
php bin/console wechat:refund:check-order-status
```

Checks and updates refund order status. Runs every minute to query refunds in PROCESSING status and update their actual status.

Entities
--------

[](#entities)

- `PayOrder` - Payment order entity with order management
- `RefundOrder` - Refund order entity with goods detail support
- `RefundGoodsDetail` - Refund goods detail entity
- `Merchant` - Merchant configuration entity
- `TradeBill` - Trade bill record entity
- `FundFlowBill` - Fund flow bill record entity

Enums
-----

[](#enums)

- `PayOrderStatus` - Payment order status enumeration
- `AccountType` - WeChat Pay account type enumeration
- `BillType` - Bill type enumeration

Services
--------

[](#services)

- `UnifiedOrder` - Creates payment orders for various trade types
- `WechatAppPayService` - Handles APP payment order creation
- `WechatJsApiPayService` - Handles JSAPI payment order creation
- `WechatPayBuilder` - Builds WeChat Pay API clients
- `AttributeControllerLoader` - Loads controller attributes for routing

Usage Example
-------------

[](#usage-example)

```
// Create a payment order
$params = new AppOrderParams();
$params->setMchId('your_merchant_id');
$params->setAppId('your_app_id');
// ... set other parameters
$payOrder = $unifiedOrder->createAppOrder($params);

// Refund processing is handled automatically via RefundOrder entity
$refundOrder = new RefundOrder();
$refundOrder->setPayOrder($payOrder);
$refundOrder->setMoney($amount);
$refundOrder->setReason($reason);
$entityManager->persist($refundOrder);
$entityManager->flush(); // This triggers the refund via RefundOrderListener
```

Advanced Usage
--------------

[](#advanced-usage)

### Custom Payment Processing

[](#custom-payment-processing)

```
use WechatPayBundle\Service\UnifiedOrder;
use WechatPayBundle\Request\AppOrderParams;

class CustomPaymentService
{
    public function __construct(private UnifiedOrder $unifiedOrder) {}

    public function processCustomPayment(array $orderData): array
    {
        $params = new AppOrderParams();
        $params->setMchId($orderData['merchant_id']);
        $params->setAppId($orderData['app_id']);
        $params->setContractId($orderData['order_id']);
        $params->setDescription($orderData['description']);
        $params->setMoney($orderData['amount']);

        return $this->unifiedOrder->createAppOrder($params);
    }
}
```

### Handling Payment Callbacks

[](#handling-payment-callbacks)

```
use WechatPayBundle\Entity\PayOrder;
use WechatPayBundle\Enum\PayOrderStatus;

class PaymentCallbackHandler
{
    public function handleCallback(array $callbackData): void
    {
        $orderId = $callbackData['out_trade_no'];
        $payOrder = $this->findPayOrder($orderId);

        if ($callbackData['result_code'] === 'SUCCESS') {
            $payOrder->setStatus(PayOrderStatus::SUCCESS);
            $payOrder->setPayTime(new \DateTime());
        } else {
            $payOrder->setStatus(PayOrderStatus::FAIL);
        }

        $this->entityManager->flush();
    }
}
```

### Multi-Merchant Configuration

[](#multi-merchant-configuration)

```
use WechatPayBundle\Entity\Merchant;

class MerchantService
{
    public function configureMerchant(string $mchId, string $pemKey): Merchant
    {
        $merchant = new Merchant();
        $merchant->setMchId($mchId);
        $merchant->setPemKey($pemKey);
        $merchant->setIsActive(true);

        $this->entityManager->persist($merchant);
        $this->entityManager->flush();

        return $merchant;
    }
}
```

Development Guide
-----------------

[](#development-guide)

### Database Migrations

[](#database-migrations)

Use Doctrine migrations to manage database schema:

```
php bin/console doctrine:migrations:migrate
```

### Testing

[](#testing)

Run unit tests:

```
./vendor/bin/phpunit packages/wechat-pay-bundle/tests
```

### Events

[](#events)

This bundle provides the following events:

- `AppPayCallbackSuccessEvent` - Triggered after successful APP payment callback
- `JSAPIPayCallbackSuccessEvent` - Triggered after successful JSAPI payment callback
- `NativePayCallbackSuccessEvent` - Triggered after successful Native payment callback

### Entity Listeners

[](#entity-listeners)

- `PayOrderListener` - Handles payment order lifecycle events
- `RefundOrderListener` - Handles refund order lifecycle events

Dependencies
------------

[](#dependencies)

This bundle requires the following packages:

### Core Dependencies

[](#core-dependencies)

- `php: ^8.1`
- `symfony/framework-bundle: ^7.3`
- `doctrine/orm: ^3.0`
- `wechatpay/wechatpay: ^1.4`
- `nesbot/carbon: ^2.72 || ^3`
- `league/flysystem: ^3.10`
- `yiisoft/json: ^1.0`
- `yiisoft/arrays: ^3`

### Tourze Internal Dependencies

[](#tourze-internal-dependencies)

- `tourze/doctrine-snowflake-bundle: 0.1.*`
- `tourze/symfony-snowflake-bundle: 0.0.*`
- `tourze/http-client-bundle: 0.1.*`
- `tourze/symfony-cron-job-bundle: 0.1.*`
- `tourze/doctrine-timestamp-bundle: 0.0.*`
- `tourze/doctrine-track-bundle: 0.1.*`
- `tourze/enum-extra: 0.1.*`
- `tourze/file-storage-bundle: 0.0.*`
- `tourze/xml-helper: 0.0.*`

Contributing
------------

[](#contributing)

We welcome Pull Requests and Issues. Please ensure:

1. Follow PSR-12 coding standards
2. Add appropriate unit tests
3. Update relevant documentation

License
-------

[](#license)

This bundle is part of the Tourze monorepo project.

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance79

Regular maintenance activity

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~75 days

Total

4

Last Release

139d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-wechat-pay-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-wechat-pay-bundle/health.svg)](https://phpackages.com/packages/tourze-wechat-pay-bundle)
```

###  Alternatives

[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M151](/packages/sulu-sulu)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
