WxJava
WxJava copied to clipboard
Fix validation logic in WxMaIntracityServiceImpl.balanceQuery for PayMode handling
The validation logic in WxMaIntracityServiceImpl.balanceQuery was incorrectly blocking valid API calls when wxStoreId is null and payMode is APP or COMPONENT.
Problem
The original condition was inverted:
if (wxStoreId == null && (payMode != null && payMode != PayMode.STORE)) {
throw new IllegalArgumentException("payMode是PAY_MODE_STORE或null时,必须传递wxStoreId");
}
This caused the method to throw an exception when:
wxStoreIdis null ANDpayModeisAPPorCOMPONENT
But according to the API documentation and comments in BasicWxMaStoreChargeRefundRequest.java, wxStoreId should only be required when payMode is STORE or null (which defaults to STORE).
Issue Example
Before this fix, the following valid call would incorrectly throw an exception:
// This should work but threw IllegalArgumentException
intracityService.balanceQuery(null, "service123", PayMode.APP);
Users had to work around this by passing a dummy wxStoreId value.
Solution
Fixed the validation condition to correctly require wxStoreId only when payMode is STORE or null:
if (wxStoreId == null && (payMode == null || payMode == PayMode.STORE)) {
throw new IllegalArgumentException("payMode是PAY_MODE_STORE或null时,必须传递wxStoreId");
}
Behavior After Fix
- ✅
balanceQuery(null, serviceId, null)→ Throws exception (requires wxStoreId for default STORE mode) - ✅
balanceQuery(null, serviceId, PayMode.STORE)→ Throws exception (requires wxStoreId for STORE mode) - ✅
balanceQuery(null, serviceId, PayMode.APP)→ Passes validation (doesn't require wxStoreId) - ✅
balanceQuery(null, serviceId, PayMode.COMPONENT)→ Passes validation (doesn't require wxStoreId) - ✅
balanceQuery("store123", serviceId, any)→ Passes validation (wxStoreId provided)
No breaking changes - existing code that works will continue to work, and previously broken valid usage patterns now work correctly.
Fixes #3704.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.