Skip to content

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

Merged
binarywang merged 4 commits into
developfrom
copilot/fix-3618
Oct 3, 2025
Merged

Add overseas WeChat Pay support with GlobalTradeTypeEnum and new API methods#3653
binarywang merged 4 commits into
developfrom
copilot/fix-3618

Conversation

CopilotAI commented Jul 24, 2025

Copy link
Copy Markdown
Contributor

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")
    privateStringtradeType;
    @SerializedName(value = "merchant_category_code") privateStringmerchantCategoryCode;

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 requestWxPayUnifiedOrderV3GlobalRequestrequest = newWxPayUnifiedOrderV3GlobalRequest();
request.setOutTradeNo(RandomUtils.getRandomStr());
request.setDescription("境外商品购买");
// Set required overseas parametersrequest.setTradeType("JSAPI");
request.setMerchantCategoryCode("5812"); // Required for overseas merchants// Set amount and payerWxPayUnifiedOrderV3GlobalRequest.Amountamount = newWxPayUnifiedOrderV3GlobalRequest.Amount();
amount.setTotal(100);
request.setAmount(amount);
WxPayUnifiedOrderV3GlobalRequest.Payerpayer = newWxPayUnifiedOrderV3GlobalRequest.Payer();
payer.setOpenid("user_openid");
request.setPayer(payer);
// Call overseas payment APIWxPayUnifiedOrderV3Result.JsapiResultresult = 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.

CopilotAIand others added 2 commits July 24, 2025 07:59
…fiedOrderV3GlobalRequest
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
…umentation
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
CopilotAI changed the title [WIP] 境外微信支付Add overseas WeChat Pay support with GlobalTradeTypeEnum and new API methodsJul 24, 2025
CopilotAI requested a review from binarywangJuly 24, 2025 08:04
@binarywangbinarywang added this to the 4.7.9 milestone Sep 24, 2025
@binarywang
binarywang marked this pull request as ready for review October 3, 2025 17:40
@binarywang
binarywang merged commit ca567ce into developOct 3, 2025
1 check failed
@binarywang
binarywang deleted the copilot/fix-3618 branch October 3, 2025 17:45
@mouhao

Copy link
Copy Markdown

GlobalTradeTypeEnum的链接地址有误,
应该是
https://apihk.mch.weixin.qq.com/v3/global/transactions/native

不是 /global/v3/transactions/native

而且应该是 https://apihk.mch.weixin.qq.com/v3/global/transactions/mweb
不是 /global/v3/transactions/h5

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.

境外微信支付

3 participants

@mouhao@binarywang