Skip to content

Implement WeChat Pay V3 subscription billing functionality (预约扣费功能/连续包月功能) - #3688

Merged
binarywang merged 4 commits into
developfrom
copilot/fix-3593
Nov 15, 2025
Merged

Implement WeChat Pay V3 subscription billing functionality (预约扣费功能/连续包月功能)#3688
binarywang merged 4 commits into
developfrom
copilot/fix-3593

Conversation

CopilotAI commented Aug 31, 2025

Copy link
Copy Markdown
Contributor

This PR implements the WeChat Pay V3 subscription billing functionality (预约扣费功能/连续包月功能) as requested by the community. The subscription billing feature enables merchants to automatically charge users on a recurring basis for services like monthly subscriptions, with proper user authorization.

What's Added

Service Interface

  • SubscriptionBillingService - Main service interface providing subscription billing operations

Bean Classes

Complete request/response model classes following WeChat Pay V3 API specification:

  • SubscriptionScheduleRequest/Result - Schedule future billing
  • SubscriptionQueryResult - Query subscription status
  • SubscriptionCancelRequest/Result - Cancel subscriptions
  • SubscriptionInstantBillingRequest/Result - Execute immediate billing
  • SubscriptionTransactionQueryRequest/Result - Query billing history
  • SubscriptionAmount - Amount and currency information
  • BillingPlan - Billing plan configuration (monthly/weekly/daily/yearly)

Service Implementation

  • SubscriptionBillingServiceImpl - Complete implementation following existing V3 API patterns
  • Integrated into WxPayService interface and BaseWxPayServiceImpl
  • Proper error handling and exception management

Features Supported

  1. Schedule Subscription Billing - Create advance billing schedules for recurring payments
  2. Query Subscription Status - Check subscription details and current status
  3. Cancel Subscriptions - Cancel existing subscription schedules
  4. Instant Billing - Execute immediate charges (useful for makeup payments)
  5. Query Transaction Records - Retrieve billing history with pagination

Usage Example

// Get the subscription billing serviceSubscriptionBillingServiceservice = wxPayService.getSubscriptionBillingService();
// Create a monthly subscriptionSubscriptionScheduleRequestrequest = newSubscriptionScheduleRequest();
request.setOutTradeNo("monthly_vip_" + System.currentTimeMillis());
request.setOpenid("user_openid");
request.setDescription("VIP会员 - 连续包月");
request.setScheduleTime("2024-09-01T10:00:00+08:00");
// Set amountSubscriptionAmountamount = newSubscriptionAmount();
amount.setTotal(3000); // 30 RMB in centsamount.setCurrency("CNY");
request.setAmount(amount);
// Configure monthly billing planBillingPlanplan = newBillingPlan();
plan.setPlanType("MONTHLY");
plan.setPeriod(1);
plan.setTotalCount(12); // 12 monthsrequest.setBillingPlan(plan);
// Execute the subscriptionSubscriptionScheduleResultresult = service.scheduleSubscription(request);

Implementation Details

The implementation follows WeChat Pay V3 API documentation: https://pay.weixin.qq.com/doc/v3/merchant/4012161105

  • API Endpoints: All 5 core subscription billing endpoints are supported
  • Authentication: Uses existing V3 signature and certificate handling
  • Error Handling: Leverages existing WxPayException framework
  • Code Style: Passes all checkstyle validations and follows project patterns
  • Testing: Includes basic test structure (disabled by default due to credential requirements)
  • Documentation: Comprehensive usage guide with examples provided

Code Quality

✅ Builds successfully with existing codebase
✅ Passes all checkstyle validations
✅ Follows established architectural patterns
✅ Comprehensive JavaDoc documentation
✅ Proper exception handling

This implementation provides production-ready support for WeChat's subscription billing capabilities while maintaining full compatibility with the existing WxJava architecture.

Fixes#3593.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

CopilotAIand others added 2 commits August 31, 2025 15:03
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
…onality
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
CopilotAI changed the title [WIP] 功能询问-预约扣费功能Implement WeChat Pay V3 subscription billing functionality (预约扣费功能/连续包月功能)Aug 31, 2025
CopilotAI requested a review from binarywangAugust 31, 2025 15:05
@binarywangbinarywang added this to the 4.7.9 milestone Sep 24, 2025
@binarywang
binarywang marked this pull request as ready for review November 15, 2025 09:11
@binarywang
binarywang merged commit 092e992 into developNov 15, 2025
1 check was pending
@binarywang
binarywang deleted the copilot/fix-3593 branch November 15, 2025 09:16
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

功能询问-预约扣费功能

2 participants

@binarywang