Skip to content

Add overseas WeChat Pay support with GlobalTradeTypeEnum and new API methods #3653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 24, 2025

This PR adds comprehensive support for overseas WeChat Pay (境外微信支付) to address the limitations mentioned in the issue where new overseas merchant accounts can only use the new global API endpoints.

Problem

The existing createOrderV3 method only supports domestic WeChat Pay endpoints and is missing required parameters for overseas payments:

  • Missing trade_type parameter
  • Missing merchant_category_code parameter
  • Uses domestic endpoints (/v3/pay/transactions/*) instead of global endpoints
  • Cannot specify overseas base URL (https://apihk.mch.weixin.qq.com)

Solution

Added new classes and methods specifically for overseas WeChat Pay while maintaining full backward compatibility:

New Classes

  1. GlobalTradeTypeEnum - Enum for overseas payment types with global endpoints:

    APP("/global/v3/transactions/app")
    JSAPI("/global/v3/transactions/jsapi") 
    NATIVE("/global/v3/transactions/native")
    H5("/global/v3/transactions/h5")
  2. WxPayUnifiedOrderV3GlobalRequest - Extended request class with overseas-specific fields:

    @SerializedName(value = "trade_type")
    private String tradeType;
    
    @SerializedName(value = "merchant_category_code") 
    private String merchantCategoryCode;

New API Methods

  • createOrderV3Global(GlobalTradeTypeEnum, WxPayUnifiedOrderV3GlobalRequest) - High-level method for overseas orders
  • unifiedOrderV3Global(GlobalTradeTypeEnum, WxPayUnifiedOrderV3GlobalRequest) - Low-level API call using overseas base URL

Usage Example

// Create overseas payment request
WxPayUnifiedOrderV3GlobalRequest request = new WxPayUnifiedOrderV3GlobalRequest();
request.setOutTradeNo(RandomUtils.getRandomStr());
request.setDescription("境外商品购买");

// Set required overseas parameters
request.setTradeType("JSAPI");
request.setMerchantCategoryCode("5812"); // Required for overseas merchants

// Set amount and payer
WxPayUnifiedOrderV3GlobalRequest.Amount amount = new WxPayUnifiedOrderV3GlobalRequest.Amount();
amount.setTotal(100);
request.setAmount(amount);

WxPayUnifiedOrderV3GlobalRequest.Payer payer = new WxPayUnifiedOrderV3GlobalRequest.Payer();
payer.setOpenid("user_openid");
request.setPayer(payer);

// Call overseas payment API
WxPayUnifiedOrderV3Result.JsapiResult result = payService.createOrderV3Global(
    GlobalTradeTypeEnum.JSAPI, request
);

Key Features

  • Backward Compatible - No changes to existing domestic payment functionality
  • Complete Coverage - Supports all payment types (JSAPI, APP, NATIVE, H5)
  • Automatic URL Handling - Uses https://apihk.mch.weixin.qq.com for overseas payments
  • Proper Parameter Support - Includes trade_type and merchant_category_code
  • Consistent API Design - Follows existing patterns and conventions
  • Comprehensive Examples - Includes usage examples and documentation

Testing

  • Added unit tests verifying new request class functionality
  • Created comprehensive usage examples for all payment types
  • Verified compilation and backward compatibility

Fixes #3618.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] 境外微信支付 Add overseas WeChat Pay support with GlobalTradeTypeEnum and new API methods Jul 24, 2025
@Copilot Copilot AI requested a review from binarywang July 24, 2025 08:04
Copilot finished work on behalf of binarywang July 24, 2025 08:04
Sign up for free to 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