For agentic workers: REQUIRED SUB-SKILL: Use
executing-plansfor inline implementation orsubagent-driven-developmentonly when the user explicitly requests subagents. Execute tasks.md task-by-task; steps use checkbox syntax for tracking, and every production behavior must follow Red → Green → Refactor.
Goal: 从零实现测试环境 POST /pay/omg/create 和 POST /pay/omg/notify,按门店独立凭证创建官方 AIO 表单,并以凭证快照可信、幂等地同步最终付款结果。
Architecture: ruoyi-system/com.ruoyi.system.omgpay 负责新尝试表、订单锁、状态 CAS、凭证快照和 ipn_log 独立事务;ruoyi-admin/com.ruoyi.app.omgpay 负责 token 创建/查询/退款边界、外部表单、官方检查码、回调/查询校验、事务编排与日志。创建流程保存实际密钥快照;回调和可信查询结果共同进入同一不可逆支付状态机;退款在测试阶段由独立 Service 失败关闭,不读取或写入支付事实,也不连接正式网关。旧 pos_store_omg 凭证查询保持不变,其余旧 OMG 支付代码不得被新流程引用。
Tech Stack: Java 21、Spring Boot 3、MyBatis/MyBatis-Plus、MySQL、JUnit 5、Mockito、SLF4J/Logback、Maven Surefire。
specs/016-omg-payment 复制行为。com.ruoyi.app.omgpay、com.ruoyi.system.omgpay 及对应资源/测试目录。ruoyi-admin -> ruoyi-system;ruoyi-system 禁止导入 com.ruoyi.app.*。pos_store_omg 中已启用的 MerchantID / HashKey / HashIV;不修改可信凭证存储与管理代码。POST /pay/omg/create;Controller 使用 @RequestHeader String token、显式 @RequestBody DTO,禁止 Map 入参和 Bean Validation。orderId 与受控 paymentMethod;金额、门店、网关、ReturnURL、说明、OMG 原始支付参数和签名全部由服务端产生。paymentMethod 仅允许 CREDIT/APPLE_PAY:分别映射为 ChoosePayment=Credit + UnionPay=2 与 ChoosePayment=ApplePay。禁止 ChoosePayment=ALL 和 IgnorePayment;所有实际发送的非 CheckMacValue 字段全部参加检查码计算。CheckMacValue 排除。https://payment-stage.funpoint.com.tw/Cashier/AioCheckOut/V5,不得配置正式环境回退。ddId 最多一条 CREATED;存在时返回 PAYMENT_ATTEMPT_EXISTS,不重放旧表单、不生成新 MerchantTradeNo。updatesql/sql.md,绝不连接数据库执行。MessageUtils.message(...);新增 key 同步 default、zh_CN、zh_TW、en_US、vi 五个 properties 文件。HTTP token + {orderId}
-> OmgPaymentController resolves user
-> OmgPaymentCreateService @Transactional
-> SELECT pos_order by dd_id FOR UPDATE
-> validate owner/single-store/state/payStatus/payType/amount
-> SELECT active pos_order_omg_attempt
-> read trusted enabled store credential
-> generate 20-char MerchantTradeNo
-> build all AIO fields
-> sign every actual non-CheckMacValue field
-> INSERT CREATED attempt
-> transaction commits
-> log safe success context
-> AjaxResult.success({status,gatewayUrl,formFields})
second request waits on the same pos_order row lock
-> first transaction commits
-> second request sees active_dd_id
-> PAYMENT_ATTEMPT_EXISTS
-> no generator call, no form replay, no second insert
Business failures throw OmgPaymentBusinessException carrying OmgPaymentErrorCode and an i18n key. Controller logs the stable code and safe context, then returns AjaxResult.error(localizedMessage, new OmgPaymentErrorResponse(code.name())). Unexpected exceptions are logged with the throwable and mapped to PAYMENT_CREATION_FAILED; internal message, SQL and stack are never returned.
raw application/x-www-form-urlencoded request
-> explicit OmgNotifyRequest boundary preserves raw body + all fields + empty values + IP
-> OmgIpnAuditService REQUIRES_NEW inserts ipn_log(type=omg)
-> OmgPaymentNotifyService @Transactional
-> SELECT attempt BY MerchantTradeNo FOR UPDATE
-> sign every actual field except CheckMacValue with snapshot HashKey/HashIV
-> verify MerchantID and TradeAmt against attempt snapshot
-> RtnCode=1: CREATED/FAILED -> PAID, supersede other CREATED, pos_order.pay_status -> 1
-> RtnCode!=1: CREATED/FAILED -> FAILED, order remains unpaid
-> verified/idempotent result: text/plain 1|OK
-> untrusted/transaction failure: text/plain 0|ERROR
Language/Version: Java 21
Primary Dependencies: Spring Boot 3.3.5、MyBatis/MyBatis-Plus、Hutool、SLF4J、JUnit 5/Mockito
Storage: MySQL InnoDB;新增 pos_order_omg_attempt,复用 pos_order 与 pos_store_omg
Testing: Maven Surefire;纯单元测试 + Mapper/DDL 合约测试 + 手动 stage/并发验收
Target Platform: Windows 开发,Spring Boot 服务部署,多实例安全由数据库锁/唯一键保证
Project Type: 多模块后端 web service
Performance Goals: 创建流程无网关 HTTP;正常路径固定次数 DB 访问,目标 <1 秒
Constraints: stage-only、整数 TWD、MerchantTradeNo ≤20 ASCII 英数字、无旧表依赖、无敏感日志
Scale/Scope: 用户自己的单门店餐饮订单;一个创建端点、一张新尝试表
Branch/Date/Spec: test | 2026-08-13 | spec.md
.specify/memory/constitution.md 仍是占位模板,因此以根目录 AGENTS.md 与已批准规格为门禁:
updatesql/sql.md。FOR UPDATE。pos_store_omg 可信能力,旧支付/退款表运行时引用清零。结论:无须复杂性豁免。
specs/020-omg-payment-rebuild/
├── spec.md
├── plan.md
├── research.md
├── data-model.md
├── quickstart.md
├── tasks.md
└── contracts/
└── api.md
ruoyi-system/src/main/java/com/ruoyi/system/omgpay/
├── domain/
│ ├── OmgPaymentAttempt.java
│ └── OmgPaymentOrderSnapshot.java
├── mapper/
│ └── OmgPaymentAttemptMapper.java
└── service/
├── IOmgPaymentAttemptService.java
└── impl/
└── OmgPaymentAttemptServiceImpl.java
ruoyi-system/src/main/resources/mapper/omgpay/
└── OmgPaymentAttemptMapper.xml
ruoyi-system/src/test/java/com/ruoyi/system/omgpay/
├── mapper/OmgPaymentAttemptMapperContractTest.java
└── service/OmgPaymentAttemptServiceTest.java
ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/
├── OmgPaymentController.java
├── OmgPaymentCreateService.java
├── OmgPaymentCreateOutcome.java
├── OmgPaymentProperties.java
├── OmgPaymentTokenUserResolver.java
├── OmgPaymentForm.java
├── OmgPaymentFormFactory.java
├── OmgCheckMacSigner.java
├── OmgMerchantTradeNoGenerator.java
├── OmgPaymentBusinessException.java
├── OmgPaymentErrorCode.java
└── dto/
├── OmgCreatePaymentRequest.java
├── OmgCreatePaymentResponse.java
└── OmgPaymentErrorResponse.java
ruoyi-admin/src/test/java/com/ruoyi/app/omgpay/
├── OmgCheckMacSignerTest.java
├── OmgMerchantTradeNoGeneratorTest.java
├── OmgPaymentFormFactoryTest.java
├── OmgPaymentCreateServiceTest.java
├── OmgPaymentControllerTest.java
└── OmgLegacyRetirementTest.java
ruoyi-admin/src/main/resources/application.yml
ruoyi-admin/src/main/resources/i18n/messages.properties
ruoyi-admin/src/main/resources/i18n/messages_zh_CN.properties
ruoyi-admin/src/main/resources/i18n/messages_zh_TW.properties
ruoyi-admin/src/main/resources/i18n/messages_en_US.properties
ruoyi-admin/src/main/resources/i18n/messages_vi.properties
ruoyi-admin/src/main/java/com/ruoyi/app/order/UserOrderController.java
ruoyi-admin/src/main/java/com/ruoyi/app/order/PosOrderShOprateController.java
ruoyi-admin/src/main/java/com/ruoyi/app/order/PosOrderController.java
ruoyi-admin/src/main/java/com/ruoyi/app/order/OrderLifecycleService.java
ruoyi-admin/src/test/java/com/ruoyi/app/order/OrderLifecycleServiceTest.java
updatesql/sql.md
UserOrderController.java、OrderLifecycleService.java 和 OrderLifecycleServiceTest.java 当前已有用户未提交改动;只删除明确的旧 OMG 调用/依赖,并在最终 diff 中确认其余变化完整保留。
After old-table retirement, OrderLifecycleService constructors become:
public OrderLifecycleService(IPosOrderService posOrderService,
OrderService billingService,
OrderLogHelper orderLogHelper,
IUserWalletService userWalletService,
IPointsTransactionService pointsTransactionService) {
this(posOrderService, billingService, orderLogHelper, userWalletService,
pointsTransactionService, null, null);
}
@Autowired
public OrderLifecycleService(IPosOrderService posOrderService,
OrderService billingService,
OrderLogHelper orderLogHelper,
IUserWalletService userWalletService,
IPointsTransactionService pointsTransactionService,
IPosOrderLinePaymentService linePaymentService,
IPosOrderLineRefundService lineRefundService) { ... }
All updated tests use one of these signatures; no OMG payment/refund Service argument remains.
ruoyi-admin/src/main/java/com/ruoyi/app/pay/OmgPayController.java
ruoyi-admin/src/main/java/com/ruoyi/app/pay/dto/OmgCallbackRequest.java
ruoyi-admin/src/main/java/com/ruoyi/app/pay/dto/OmgOrderRequest.java
ruoyi-admin/src/main/java/com/ruoyi/app/pay/dto/OmgRefundOutcome.java
ruoyi-admin/src/main/java/com/ruoyi/app/task/OmgReconcileTask.java
ruoyi-admin/src/main/java/com/ruoyi/app/utils/omg/OmgQueryThrottle.java
ruoyi-admin/src/test/java/com/ruoyi/app/pay/OmgPayControllerTest.java
ruoyi-system/src/main/java/com/ruoyi/system/domain/PosOrderOmgPayment.java
ruoyi-system/src/main/java/com/ruoyi/system/domain/PosOrderOmgRefund.java
ruoyi-system/src/main/java/com/ruoyi/system/mapper/PosOrderOmgPaymentMapper.java
ruoyi-system/src/main/java/com/ruoyi/system/mapper/PosOrderOmgRefundMapper.java
ruoyi-system/src/main/java/com/ruoyi/system/service/IPosOrderOmgPaymentService.java
ruoyi-system/src/main/java/com/ruoyi/system/service/IPosOrderOmgRefundService.java
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PosOrderOmgPaymentServiceImpl.java
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PosOrderOmgRefundServiceImpl.java
ruoyi-system/src/main/resources/mapper/chanting/PosOrderOmgPaymentMapper.xml
ruoyi-system/src/main/resources/mapper/chanting/PosOrderOmgRefundMapper.xml
ruoyi-system/src/test/java/com/ruoyi/system/service/impl/PosOrderOmgPaymentServiceImplTest.java
ruoyi-system/src/test/java/com/ruoyi/system/service/impl/PosOrderOmgRefundServiceImplTest.java
保留 com.ruoyi.app.utils.omg.OmgPay/OmgPayConfig/OmgCheckMacValue,因为现有可信门店凭证管理 Controller 仍使用它们做录入时验证;新 omgpay 包通过测试保证对这些旧类零引用。
public interface OmgPaymentAttemptMapper {
OmgPaymentOrderSnapshot selectOrderForUpdate(@Param("ddId") String ddId);
OmgPaymentAttempt selectActiveByDdId(@Param("ddId") String ddId);
OmgPaymentAttempt selectByMerchantTradeNo(@Param("merchantTradeNo") String merchantTradeNo);
int insertCreated(OmgPaymentAttempt attempt);
}
public interface IOmgPaymentAttemptService {
OmgPaymentOrderSnapshot lockOrder(String ddId);
OmgPaymentAttempt getActiveByDdId(String ddId);
OmgPaymentAttempt getByMerchantTradeNo(String merchantTradeNo);
OmgPaymentAttempt createCreated(String ddId, String merchantTradeNo,
Long storeId, String merchantId, Integer amount);
}
@Component
public final class OmgCheckMacSigner {
public String sign(Map<String, String> fields, String hashKey, String hashIv);
}
@Component
public final class OmgMerchantTradeNoGenerator {
public String generate(); // "OMG" + 17 uppercase alphanumeric characters
}
@Component
public final class OmgPaymentFormFactory {
public static final String STAGE_GATEWAY_URL =
"https://payment-stage.funpoint.com.tw/Cashier/AioCheckOut/V5";
public OmgPaymentForm create(String orderId, Integer amount,
String merchantId, String hashKey, String hashIv,
String merchantTradeNo);
}
public record OmgPaymentForm(String gatewayUrl, Map<String, String> fields) {}
The form factory creates a new ordered map containing exactly these fields before signature:
fields.put("MerchantID", merchantId);
fields.put("MerchantTradeNo", merchantTradeNo);
fields.put("MerchantTradeDate", taipeiNow);
fields.put("PaymentType", "aio");
fields.put("TotalAmount", String.valueOf(amount));
fields.put("TradeDesc", "Foodie order " + safeOrderId);
fields.put("ItemName", "Order " + safeOrderId);
fields.put("ReturnURL", properties.requireSafeReturnUrl());
fields.put("OrderResultURL", properties.requireSafeOrderResultUrl());
fields.put("ChoosePayment", "ALL");
fields.put("IgnorePayment", "ATM#CVS#BarcodeATM");
fields.put("EncryptType", "1");
fields.put("InvoiceMark", "N");
fields.put("NeedExtraPaidInfo", "Y");
fields.put("CheckMacValue", signer.sign(fields, hashKey, hashIv));
@Transactional(rollbackFor = Exception.class)
public OmgPaymentCreateOutcome create(Long userId, String orderId);
public record OmgPaymentCreateOutcome(
OmgCreatePaymentResponse response,
Long attemptId,
String orderId,
Long userId,
Long storeId,
Integer amount,
String maskedMerchantTradeNo) {}
@Anonymous
@Auth
@PostMapping("/create")
public AjaxResult create(@RequestHeader String token,
@RequestBody(required = false) OmgCreatePaymentRequest request);
Do not add @RepeatSubmit: repeated clicks must reach the transactional duplicate check and return the stable PAYMENT_ATTEMPT_EXISTS result rather than a generic throttle response. This endpoint performs no external HTTP and is bounded by authentication, ownership validation and fixed DB work.
Files:
ruoyi-system/src/main/java/com/ruoyi/system/omgpay/domain/OmgPaymentAttempt.javaruoyi-system/src/main/java/com/ruoyi/system/omgpay/domain/OmgPaymentOrderSnapshot.javaruoyi-system/src/main/java/com/ruoyi/system/omgpay/mapper/OmgPaymentAttemptMapper.javaruoyi-system/src/main/java/com/ruoyi/system/omgpay/service/IOmgPaymentAttemptService.javaruoyi-system/src/main/java/com/ruoyi/system/omgpay/service/impl/OmgPaymentAttemptServiceImpl.javaruoyi-system/src/main/resources/mapper/omgpay/OmgPaymentAttemptMapper.xmlruoyi-system/src/test/java/com/ruoyi/system/omgpay/mapper/OmgPaymentAttemptMapperContractTest.javaruoyi-system/src/test/java/com/ruoyi/system/omgpay/service/OmgPaymentAttemptServiceTest.javaupdatesql/sql.mdInterfaces:
pos_order and no old OMG payment/refund table.Produces: the persistence interfaces listed under Component Interfaces.
[ ] Step 1: Write failing service validation tests
@Test
void createCreatedRejectsInvalidSnapshotsBeforeInsert() {
assertThrows(ServiceException.class,
() -> service.createCreated("DD-1", "OMG123", 10L, "M1", 0));
verifyNoInteractions(mapper);
}
@Test
void createCreatedInsertsOnlyCreatedFacts() {
when(mapper.insertCreated(any())).thenAnswer(invocation -> {
OmgPaymentAttempt row = invocation.getArgument(0);
row.setId(7L);
return 1;
});
OmgPaymentAttempt row = service.createCreated("DD-1", "OMG123", 10L, "M1", 100);
assertEquals(0, row.getAttemptStatus());
assertEquals(7L, row.getId());
assertNull(row.getActiveDdId()); // generated by DB, never inserted by Java
}
[ ] Step 2: Write failing Mapper/DDL contract tests
Load the XML and updatesql/sql.md as UTF-8 strings and assert:
assertTrue(xml.contains("FROM pos_order"));
assertTrue(xml.contains("FOR UPDATE"));
assertTrue(xml.contains("FROM pos_order_omg_attempt"));
assertFalse(xml.contains("pos_order_omg_payment"));
assertFalse(xml.contains("pos_order_omg_refund"));
assertTrue(sql.contains("UNIQUE KEY uk_omg_attempt_trade_no"));
assertTrue(sql.contains("UNIQUE KEY uk_omg_attempt_active_dd"));
assertTrue(sql.contains("IF(attempt_status = 0, dd_id, NULL)"));
[ ] Step 3: Run tests and observe RED
$env:JAVA_HOME='C:\Users\qmj\.jdks\graalvm-jdk-21.0.7'
$env:Path="$env:JAVA_HOME\bin;$env:Path"
mvn -pl ruoyi-system -am -Dtest='OmgPaymentAttemptServiceTest,OmgPaymentAttemptMapperContractTest' -Dsurefire.failIfNoSpecifiedTests=false test
Expected: compilation fails because new types/resources do not exist.
data-model.mdAppend the dated fenced SQL block. Do not run it. Keep dd_id utf8mb4 to match pos_order; keep gateway identifiers ascii_bin.
The XML must use parameter binding and explicit columns:
<select id="selectOrderForUpdate"
resultType="com.ruoyi.system.omgpay.domain.OmgPaymentOrderSnapshot">
SELECT id, dd_id AS ddId, parent_dd_id AS parentDdId, md_id AS storeId,
user_id AS userId, amount, state, pay_status AS payStatus, pay_type AS payType
FROM pos_order WHERE dd_id = #{ddId} LIMIT 1 FOR UPDATE
</select>
<insert id="insertCreated" useGeneratedKeys="true" keyProperty="id">
INSERT INTO pos_order_omg_attempt
(dd_id, merchant_trade_no, store_id, merchant_id, amount,
attempt_status, create_time, update_time)
VALUES
(#{ddId}, #{merchantTradeNo}, #{storeId}, #{merchantId}, #{amount},
#{attemptStatus}, #{createTime}, #{updateTime})
</insert>
Comment why FOR UPDATE serializes endpoint calls before MerchantTradeNo generation and why active_dd_id is omitted from INSERT.
Run the command from Step 3. Expected: both tests PASS.
[ ] Step 7: Commit only Task 1 files
git add -- ruoyi-system/src/main/java/com/ruoyi/system/omgpay ruoyi-system/src/main/resources/mapper/omgpay ruoyi-system/src/test/java/com/ruoyi/system/omgpay updatesql/sql.md
git commit -m "feat: add OMG payment attempt persistence"
Files:
ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgCheckMacSigner.javaruoyi-admin/src/test/java/com/ruoyi/app/omgpay/OmgCheckMacSignerTest.javaInterfaces:
Map<String,String> plus HashKey/HashIV.Produces: String sign(Map<String,String>, String, String).
[ ] Step 1: Write official-vector failing test
Use the exact official appendix parameters and public sample key/IV, then assert:
assertEquals("AA5842FDA7E55ACEB7118D6353E9822CA6D6FF09A0D1FC129A879DD5CAF93266",
signer.sign(fields, "5294y06JbISpM5x9", "v77hoKGq4kWxNNIS"));
[ ] Step 2: Write completeness and validation failing tests
assertNotEquals(signer.sign(fields, key, iv),
signer.sign(withExtraField(fields, "NeedExtraPaidInfo", "Y"), key, iv));
assertNotEquals(signer.sign(fields, key, iv),
signer.sign(withExtraField(fields, "EmptyExtra", ""), key, iv));
assertThrows(IllegalArgumentException.class,
() -> signer.sign(Map.of("CheckMacValue", "caller-value"), key, iv));
Also prove input map is unchanged and output matches [0-9A-F]{64}.
[ ] Step 3: Run RED
mvn -pl ruoyi-admin -am -Dtest='OmgCheckMacSignerTest' -Dsurefire.failIfNoSpecifiedTests=false test
Expected: new signer class missing.
[ ] Step 4: Implement the minimal signer
public String sign(Map<String, String> fields, String hashKey, String hashIv) {
requireSecrets(hashKey, hashIv);
TreeMap<String, String> sorted = validatedCopy(fields);
String query = sorted.entrySet().stream()
.map(e -> e.getKey() + "=" + e.getValue())
.collect(Collectors.joining("&"));
String raw = "HashKey=" + hashKey + "&" + query + "&HashIV=" + hashIv;
String encoded = dotNetUrlEncode(raw).toLowerCase(Locale.ROOT);
return HexFormat.of().withUpperCase().formatHex(sha256(encoded));
}
validatedCopy retains empty strings and rejects only null keys/values and CheckMacValue. Add a focused comment explaining the official .NET URL conversion; do not log raw or encoded strings.
Use these exact conversion operations after URLEncoder.encode(raw, UTF_8) and before lowercasing:
return encoded.replace("%2D", "-")
.replace("%5F", "_")
.replace("%2E", ".")
.replace("%21", "!")
.replace("%2A", "*")
.replace("%28", "(")
.replace("%29", ")");
Although Java already leaves some of these characters unchanged, retaining the complete official table in one method makes the protocol rule auditable.
Run Step 3. Expected: all signer tests PASS with official vector.
[ ] Step 6: Commit
git add -- ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgCheckMacSigner.java ruoyi-admin/src/test/java/com/ruoyi/app/omgpay/OmgCheckMacSignerTest.java
git commit -m "feat: implement official OMG check code signer"
Files:
ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentProperties.javaruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentForm.javaruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentFormFactory.javaruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgMerchantTradeNoGenerator.javaruoyi-admin/src/test/java/com/ruoyi/app/omgpay/OmgPaymentFormFactoryTest.javaruoyi-admin/src/test/java/com/ruoyi/app/omgpay/OmgMerchantTradeNoGeneratorTest.javaruoyi-admin/src/main/resources/application.ymlInterfaces:
Produces: exact stage URL and immutable ordered form field map.
[ ] Step 1: Write failing generator tests
Generate 1,000 values and assert each is unique in the sample, length 20, starts OMG, and matches [A-Z0-9]{20}.
With a fixed Clock at 2026-08-13T07:30:23Z, assert Taipei date 2026/08/13 15:30:23, exact gateway, exact 16-key set, fixed field values and that the signer receives exactly the 15 non-check-code fields.
Also assert invalid ReturnURL cases are rejected: HTTP, wrong path, query, fragment, user-info and relative URL.
Use order IDs containing <script>, #, | and non-ASCII characters to prove TradeDesc/ItemName contain no HTML or OMG item separator, use only the sanitized ASCII reference, and remain within the official length limits.
[ ] Step 3: Run RED
mvn -pl ruoyi-admin -am -Dtest='OmgMerchantTradeNoGeneratorTest,OmgPaymentFormFactoryTest' -Dsurefire.failIfNoSpecifiedTests=false test
[ ] Step 4: Implement properties, generator and form factory
OmgPaymentProperties is @Component @ConfigurationProperties(prefix="omgpay") with only returnUrl. requireSafeReturnUrl() parses URI and enforces the exact safety rules.
OmgMerchantTradeNoGenerator uses SecureRandom and alphabet 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ:
StringBuilder value = new StringBuilder("OMG");
while (value.length() < 20) {
value.append(ALPHABET.charAt(random.nextInt(ALPHABET.length())));
}
return value.toString();
OmgPaymentFormFactory uses a defensive unmodifiable copy for response fields and does not expose secrets.
The order reference used in TradeDesc and ItemName is derived only after a real order row is found. It keeps ASCII letters and digits, drops all other characters, falls back to ORDER when empty, and is truncated to 64 characters. Therefore neither field contains HTML or OMG item separators; ItemName remains below its 120 ASCII-character display limit.
Use constructor injection without a global Clock bean:
public OmgPaymentFormFactory(OmgPaymentProperties properties, OmgCheckMacSigner signer) {
this(properties, signer, Clock.systemUTC());
}
OmgPaymentFormFactory(OmgPaymentProperties properties,
OmgCheckMacSigner signer,
Clock clock) {
this.properties = properties;
this.signer = signer;
this.clock = clock;
}
Tests in the same package use the second constructor with Clock.fixed(...).
Append:
omgpay:
return-url: https://foodieapi.waimai-paotui.com/pay/omg/notify
Do not read omg.base-url, omg.order-result-url or omg.payment-info-url from the new package.
Run Step 3, then:
git add -- ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentProperties.java ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentForm.java ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentFormFactory.java ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgMerchantTradeNoGenerator.java ruoyi-admin/src/test/java/com/ruoyi/app/omgpay/OmgPaymentFormFactoryTest.java ruoyi-admin/src/test/java/com/ruoyi/app/omgpay/OmgMerchantTradeNoGeneratorTest.java ruoyi-admin/src/main/resources/application.yml
git commit -m "feat: build stage-only OMG checkout forms"
Files:
ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentErrorCode.javaruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentBusinessException.javaruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentCreateOutcome.javaruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentCreateService.javaruoyi-admin/src/main/java/com/ruoyi/app/omgpay/dto/OmgCreatePaymentResponse.javaruoyi-admin/src/test/java/com/ruoyi/app/omgpay/OmgPaymentCreateServiceTest.javaInterfaces:
IOmgPaymentAttemptService, trusted IPosStoreOmgService, form factory and generator.Produces: OmgPaymentCreateOutcome create(Long userId, String orderId).
[ ] Step 1: Write failing validation tests
One parameterized test matrix covers null order, other owner, parentDdId != ddId, null store, state 3/4, payStatus nonzero, payType other than "2", nonpositive amount and missing credential. Assert exact OmgPaymentErrorCode, no insert and no form generation.
[ ] Step 2: Write failing duplicate tests
when(attempts.lockOrder("DD-1")).thenReturn(payableOrder());
when(attempts.getActiveByDdId("DD-1")).thenReturn(existingAttempt());
OmgPaymentBusinessException error = assertThrows(
OmgPaymentBusinessException.class,
() -> service.create(5L, "DD-1"));
assertEquals(PAYMENT_ATTEMPT_EXISTS, error.getCode());
verifyNoInteractions(generator, formFactory, credentialService);
[ ] Step 3: Write failing success and collision tests
Success asserts call order: lock → active lookup → credential → generator → form → insert. Outcome contains response plus safe metadata; response contains no attempt ID or secrets.
For DuplicateKeyException, test:
PAYMENT_ATTEMPT_EXISTS and no retry;unclassified/third collision → PAYMENT_CREATION_FAILED.
[ ] Step 4: Run RED
mvn -pl ruoyi-admin -am -Dtest='OmgPaymentCreateServiceTest' -Dsurefire.failIfNoSpecifiedTests=false test
[ ] Step 5: Implement the transactional service
@Transactional(rollbackFor = Exception.class)
public OmgPaymentCreateOutcome create(Long userId, String orderId) {
OmgPaymentOrderSnapshot order = attempts.lockOrder(orderId);
validateOrder(userId, orderId, order);
if (attempts.getActiveByDdId(orderId) != null) {
throw business(PAYMENT_ATTEMPT_EXISTS);
}
PosStoreOmg credential = credentials.getEnabledCredential(order.getStoreId());
validateCredential(credential);
return createWithBoundedTradeNumberRetries(order, credential);
}
Validate before using any field. Keep the exact active check before generator invocation. Catch only DuplicateKeyException; never catch and downgrade arbitrary runtime exceptions inside the transaction.
Define the enum mapping explicitly:
AUTH_REQUIRED("omg.pay.auth.required"),
ORDER_REQUIRED("omg.pay.order.required"),
ORDER_NOT_AVAILABLE("omg.pay.order.not.available"),
MULTI_STORE_ORDER_NOT_SUPPORTED("omg.pay.multi.store.unsupported"),
ORDER_STATE_NOT_PAYABLE("omg.pay.order.state.not.payable"),
ORDER_ALREADY_PAID("omg.pay.order.already.paid"),
ORDER_AMOUNT_INVALID("omg.pay.order.amount.invalid"),
PAYMENT_TYPE_INVALID("omg.pay.payment.type.invalid"),
STORE_CREDENTIAL_UNAVAILABLE("omg.pay.credential.unavailable"),
PAYMENT_ATTEMPT_EXISTS("omg.pay.attempt.exists"),
PAYMENT_CONFIGURATION_INVALID("omg.pay.configuration.invalid"),
PAYMENT_CREATION_FAILED("omg.pay.creation.failed");
OmgPaymentBusinessException carries the enum and optional safe storeId. Failures after a real order is locked populate storeId; pre-order failures leave it null. Convert invalid ReturnURL/form configuration to PAYMENT_CONFIGURATION_INVALID without exposing its raw exception message.
Validate merchantId against [A-Za-z0-9]{1,10} and require nonblank HashKey/HashIV before form creation. After order and credential validation, emit one safe INFO event:
log.info("OMG payment validation passed orderId={}, userId={}, storeId={}",
order.getDdId(), userId, order.getStoreId());
Do not log the credential object or any individual secret. The Controller's success log runs only after this transactional method returns through the Spring proxy, so that event represents a committed attempt rather than an uncommitted insert.
Mask the trade number for logs as the first five characters, ***, and the final four characters. Values shorter than ten characters become ***; the full value remains only in the authorized success form.
[ ] Step 6: Run GREEN and check package isolation
mvn -pl ruoyi-admin -am -Dtest='OmgPaymentCreateServiceTest' -Dsurefire.failIfNoSpecifiedTests=false test
rg -n "com\.ruoyi\.app\.pay\.OmgPayController|com\.ruoyi\.app\.utils\.omg|IPosOrderOmgPaymentService|IPosOrderOmgRefundService" ruoyi-admin/src/main/java/com/ruoyi/app/omgpay ruoyi-system/src/main/java/com/ruoyi/system/omgpay
Expected: tests PASS; rg produces no matches.
[ ] Step 7: Commit
git add -- ruoyi-admin/src/main/java/com/ruoyi/app/omgpay ruoyi-admin/src/test/java/com/ruoyi/app/omgpay/OmgPaymentCreateServiceTest.java
git commit -m "feat: orchestrate safe OMG payment creation"
Files:
ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentTokenUserResolver.javaruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentController.javaruoyi-admin/src/main/java/com/ruoyi/app/omgpay/dto/OmgCreatePaymentRequest.javaruoyi-admin/src/main/java/com/ruoyi/app/omgpay/dto/OmgPaymentErrorResponse.javaruoyi-admin/src/test/java/com/ruoyi/app/omgpay/OmgPaymentControllerTest.javaruoyi-admin/src/main/resources/i18n/messages*.properties filesInterfaces:
JwtUtil/@Auth.Produces: public POST /pay/omg/create.
[ ] Step 1: Write failing Controller contract tests
Reflection assertions:
assertEquals("/pay/omg", controllerMapping);
assertEquals("/create", postMapping);
assertTrue(hasRequestHeaderNamedToken);
assertTrue(hasExplicitRequestBody);
assertEquals(Set.of("orderId"), declaredDtoProperties);
assertFalse(usesMapRequestParameter);
Behavior assertions cover missing body/orderId, resolver failure, each business exception, success, and unexpected exception. Confirm error data.status and success data shape.
Attach a Logback ListAppender and assert:
concatenated messages do not contain token, test HashKey/HashIV, 64-character CheckMacValue or full form field dump.
[ ] Step 3: Run RED
mvn -pl ruoyi-admin -am -Dtest='OmgPaymentControllerTest' -Dsurefire.failIfNoSpecifiedTests=false test
[ ] Step 4: Add i18n keys in all five bundles
Add keys matching every OmgPaymentErrorCode.messageKey. Use these exact key sets and translations:
# messages.properties and messages_zh_CN.properties
omg.pay.auth.required=请先登录
omg.pay.order.required=订单号不能为空
omg.pay.order.not.available=订单不存在或无权操作
omg.pay.multi.store.unsupported=多门店订单暂不支持 OMG 支付
omg.pay.order.state.not.payable=当前订单状态不可支付
omg.pay.order.already.paid=订单已支付或支付状态不可用
omg.pay.order.amount.invalid=订单金额异常
omg.pay.payment.type.invalid=订单支付方式不是 OMG
omg.pay.credential.unavailable=该门店暂未启用 OMG 支付
omg.pay.attempt.exists=该订单已有待处理的支付尝试
omg.pay.configuration.invalid=OMG 支付配置无效
omg.pay.creation.failed=OMG 支付创建失败,请稍后重试
# messages_zh_TW.properties
omg.pay.auth.required=請先登入
omg.pay.order.required=訂單號不能為空
omg.pay.order.not.available=訂單不存在或無權操作
omg.pay.multi.store.unsupported=多門店訂單暫不支援 OMG 支付
omg.pay.order.state.not.payable=目前訂單狀態不可支付
omg.pay.order.already.paid=訂單已付款或付款狀態不可用
omg.pay.order.amount.invalid=訂單金額異常
omg.pay.payment.type.invalid=訂單付款方式不是 OMG
omg.pay.credential.unavailable=此門店尚未啟用 OMG 支付
omg.pay.attempt.exists=此訂單已有待處理的支付嘗試
omg.pay.configuration.invalid=OMG 支付設定無效
omg.pay.creation.failed=OMG 支付建立失敗,請稍後再試
# messages_en_US.properties
omg.pay.auth.required=Please sign in first
omg.pay.order.required=The order number is required
omg.pay.order.not.available=The order does not exist or is not available to this user
omg.pay.multi.store.unsupported=OMG Pay does not support multi-store orders yet
omg.pay.order.state.not.payable=The current order state cannot be paid
omg.pay.order.already.paid=The order is already paid or its payment state is unavailable
omg.pay.order.amount.invalid=The order amount is invalid
omg.pay.payment.type.invalid=The order payment method is not OMG Pay
omg.pay.credential.unavailable=OMG Pay is not enabled for this store
omg.pay.attempt.exists=This order already has a pending payment attempt
omg.pay.configuration.invalid=The OMG Pay configuration is invalid
omg.pay.creation.failed=The OMG Pay checkout could not be created; please try again later
# messages_vi.properties
omg.pay.auth.required=Vui lòng đăng nhập trước
omg.pay.order.required=Vui lòng nhập mã đơn hàng
omg.pay.order.not.available=Đơn hàng không tồn tại hoặc người dùng không có quyền truy cập
omg.pay.multi.store.unsupported=OMG Pay chưa hỗ trợ đơn hàng từ nhiều cửa hàng
omg.pay.order.state.not.payable=Trạng thái đơn hàng hiện tại không thể thanh toán
omg.pay.order.already.paid=Đơn hàng đã được thanh toán hoặc trạng thái thanh toán không khả dụng
omg.pay.order.amount.invalid=Số tiền đơn hàng không hợp lệ
omg.pay.payment.type.invalid=Phương thức thanh toán của đơn hàng không phải OMG Pay
omg.pay.credential.unavailable=Cửa hàng này chưa bật OMG Pay
omg.pay.attempt.exists=Đơn hàng này đã có một lần thanh toán đang chờ xử lý
omg.pay.configuration.invalid=Cấu hình OMG Pay không hợp lệ
omg.pay.creation.failed=Không thể tạo trang thanh toán OMG Pay; vui lòng thử lại sau
Keep identical key sets across default/zh_CN/zh_TW/en_US/vi and localized values in each file.
The Controller does not log request/response objects:
try {
Long userId = tokenUserResolver.requireUserId(token);
log.info("OMG payment create started orderId={}, userId={}", orderId, userId);
OmgPaymentCreateOutcome outcome = createService.create(userId, orderId);
log.info("OMG payment create succeeded orderId={}, userId={}, storeId={}, "
+ "attemptId={}, amount={}, status=CREATED, merchantTradeNo={}",
outcome.orderId(), outcome.userId(), outcome.storeId(),
outcome.attemptId(), outcome.amount(), outcome.maskedMerchantTradeNo());
return AjaxResult.success(outcome.response());
} catch (OmgPaymentBusinessException error) {
log.warn("OMG payment create rejected orderId={}, userId={}, storeId={}, code={}",
safeOrderId, safeUserId, error.getStoreId(), error.getCode());
return AjaxResult.error(MessageUtils.message(error.getMessageKey()),
new OmgPaymentErrorResponse(error.getCode().name()));
} catch (Exception error) {
log.error("OMG payment create failed orderId={}, userId={}", safeOrderId, safeUserId, error);
return AjaxResult.error(MessageUtils.message("omg.pay.creation.failed"),
new OmgPaymentErrorResponse("PAYMENT_CREATION_FAILED"));
}
The project @Auth remains the first invalid-token gate. Resolver defense never logs token and maps missing/invalid user ID to AUTH_REQUIRED when reached.
Before logging, sanitize the untrusted request order ID to at most 64 characters, retaining only ASCII letters, digits, - and _; use "<empty>" when nothing remains. This prevents newline/control-character log injection and unbounded log entries. Add a test with "DD-1\r\nforged=true" and assert no CR/LF appears in any captured log message.
Run Step 3. Then compare all omg.pay.* keys across the five bundles; expected identical key lists.
[ ] Step 7: Commit
git add -- ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentTokenUserResolver.java ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentController.java ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/dto/OmgCreatePaymentRequest.java ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/dto/OmgPaymentErrorResponse.java ruoyi-admin/src/test/java/com/ruoyi/app/omgpay/OmgPaymentControllerTest.java ruoyi-admin/src/main/resources/i18n
git commit -m "feat: expose logged OMG payment creation endpoint"
Files:
ruoyi-admin/src/test/java/com/ruoyi/app/omgpay/OmgLegacyRetirementTest.javaUserOrderController.java, PosOrderShOprateController.java, PosOrderController.java, OrderLifecycleService.java, OrderLifecycleServiceTest.javaInterfaces:
OmgPaymentController; keeps OrderLifecycleService.PAY_TYPE_OMG="2" only for channel progression gate.Produces: one /pay/omg/create mapping and zero old callback/query/refund/table runtime references.
[ ] Step 1: Capture existing dirty diffs before editing
git diff -- ruoyi-admin/src/main/java/com/ruoyi/app/order/UserOrderController.java ruoyi-admin/src/main/java/com/ruoyi/app/order/OrderLifecycleService.java ruoyi-admin/src/test/java/com/ruoyi/app/order/OrderLifecycleServiceTest.java ruoyi-admin/src/main/java/com/ruoyi/app/pay/OmgPayController.java ruoyi-admin/src/test/java/com/ruoyi/app/pay/OmgPayControllerTest.java
Record that unrelated LINE/status changes remain visible after this task. Do not use checkout/reset.
[ ] Step 2: Write failing retirement test
assertThrows(ClassNotFoundException.class,
() -> Class.forName("com.ruoyi.app.pay.OmgPayController"));
assertThrows(ClassNotFoundException.class,
() -> Class.forName("com.ruoyi.app.task.OmgReconcileTask"));
assertThrows(ClassNotFoundException.class,
() -> Class.forName("com.ruoyi.system.domain.PosOrderOmgPayment"));
assertNotNull(OmgPaymentController.class.getAnnotation(RestController.class));
Also inspect OmgPaymentController#create annotations and assert the only exposed method under /pay/omg is /create; no notify, query, paymentInfo, return or refund handler exists in the new class.
[ ] Step 3: Run RED
mvn -pl ruoyi-admin -am -Dtest='OmgLegacyRetirementTest' -Dsurefire.failIfNoSpecifiedTests=false test
Expected: old classes still load.
Delete only the explicit retired file list. Preserve PosStoreOmg* and old OmgPay/OmgPayConfig/OmgCheckMacValue used by credential management.
[ ] Step 5: Remove reachable old calls surgically
UserOrderController.cancelOrder: delete only the old OMG refund block after cancellation; leave other cancellation and LINE behavior intact.
PosOrderShOprateController.cancelOrder: delete only the old OMG refund block.
PosOrderController: remove old Controller/DTO injection, the three OMG reconcile/refund/manual-confirm endpoints, and the now-unused refundData helper.
OrderLifecycleService: remove old table imports, constructor dependencies, validateOmgReconcile, validateOmgRefund, finalizeOmgRefund, finalizeSystemOmgRefund, old buildContext table queries and manual-refund helpers. Keep PAY_TYPE_OMG="2" and the unpaid-online-order progression gate.
OrderLifecycleServiceTest: remove only old payment/refund service mocks and tests; update constructors while preserving LINE Pay and current order lifecycle tests.
application.yml: under legacy omg, retain only base-url required by trusted PosStoreOmgController credential verification; remove old return-url, order-result-url, payment-info-url, client-redirect-url, create and reconcile configuration. Keep the new omgpay.return-url added in Task 3.
[ ] Step 6: Run GREEN and prove zero runtime references
mvn -pl ruoyi-admin -am -Dtest='OmgLegacyRetirementTest,OrderLifecycleServiceTest' -Dsurefire.failIfNoSpecifiedTests=false test
rg -n --glob '*.java' --glob '*.xml' "OmgPayController|OmgReconcileTask|IPosOrderOmgPaymentService|IPosOrderOmgRefundService|PosOrderOmgPayment|PosOrderOmgRefund|pos_order_omg_payment|pos_order_omg_refund" ruoyi-admin/src/main ruoyi-system/src/main
Expected: tests PASS; rg returns no matches. Historical SQL and old specs are excluded deliberately.
Review git diff for the three initially dirty files and verify unrelated hunks remain. Then stage only task files and commit:
git add -- ruoyi-admin/src/main/java/com/ruoyi/app/pay/OmgPayController.java ruoyi-admin/src/main/java/com/ruoyi/app/pay/dto/OmgCallbackRequest.java ruoyi-admin/src/main/java/com/ruoyi/app/pay/dto/OmgOrderRequest.java ruoyi-admin/src/main/java/com/ruoyi/app/pay/dto/OmgRefundOutcome.java ruoyi-admin/src/main/java/com/ruoyi/app/task/OmgReconcileTask.java ruoyi-admin/src/main/java/com/ruoyi/app/utils/omg/OmgQueryThrottle.java ruoyi-admin/src/test/java/com/ruoyi/app/pay/OmgPayControllerTest.java ruoyi-admin/src/test/java/com/ruoyi/app/omgpay/OmgLegacyRetirementTest.java ruoyi-system/src/main/java/com/ruoyi/system/domain/PosOrderOmgPayment.java ruoyi-system/src/main/java/com/ruoyi/system/domain/PosOrderOmgRefund.java ruoyi-system/src/main/java/com/ruoyi/system/mapper/PosOrderOmgPaymentMapper.java ruoyi-system/src/main/java/com/ruoyi/system/mapper/PosOrderOmgRefundMapper.java ruoyi-system/src/main/java/com/ruoyi/system/service/IPosOrderOmgPaymentService.java ruoyi-system/src/main/java/com/ruoyi/system/service/IPosOrderOmgRefundService.java ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PosOrderOmgPaymentServiceImpl.java ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PosOrderOmgRefundServiceImpl.java ruoyi-system/src/main/resources/mapper/chanting/PosOrderOmgPaymentMapper.xml ruoyi-system/src/main/resources/mapper/chanting/PosOrderOmgRefundMapper.xml ruoyi-system/src/test/java/com/ruoyi/system/service/impl/PosOrderOmgPaymentServiceImplTest.java ruoyi-system/src/test/java/com/ruoyi/system/service/impl/PosOrderOmgRefundServiceImplTest.java ruoyi-admin/src/main/resources/application.yml
git add -p -- ruoyi-admin/src/main/java/com/ruoyi/app/order/UserOrderController.java ruoyi-admin/src/main/java/com/ruoyi/app/order/PosOrderShOprateController.java ruoyi-admin/src/main/java/com/ruoyi/app/order/PosOrderController.java ruoyi-admin/src/main/java/com/ruoyi/app/order/OrderLifecycleService.java ruoyi-admin/src/test/java/com/ruoyi/app/order/OrderLifecycleServiceTest.java
git commit -m "refactor: retire legacy OMG payment runtime"
For git add -p, accept only old OMG retirement hunks and reject pre-existing LINE/order-status hunks. Before commit, use git diff --cached --name-only and git diff --cached; never include unrelated pre-staged content.
Files:
Interfaces: complete feature acceptance.
[ ] Step 1: Run all new and affected tests
$env:JAVA_HOME='C:\Users\qmj\.jdks\graalvm-jdk-21.0.7'
$env:Path="$env:JAVA_HOME\bin;$env:Path"
mvn -pl ruoyi-system -am -Dtest='OmgPaymentAttemptServiceTest,OmgPaymentAttemptMapperContractTest' -Dsurefire.failIfNoSpecifiedTests=false test
mvn -pl ruoyi-admin -am -Dtest='OmgCheckMacSignerTest,OmgMerchantTradeNoGeneratorTest,OmgPaymentFormFactoryTest,OmgPaymentCreateServiceTest,OmgPaymentControllerTest,OmgLegacyRetirementTest,OrderLifecycleServiceTest,LinePayCancellationRaceTest' -Dsurefire.failIfNoSpecifiedTests=false test
Expected: exit code 0.
[ ] Step 2: Build admin and dependencies
mvn -pl ruoyi-admin -am -DskipTests package
Expected: BUILD SUCCESS on JDK 21.
[ ] Step 3: Run static safety checks
rg -n "payment\.funpoint\.com\.tw|PlatformID|PaymentInfoURL|ClientRedirectURL|ClientBackURL" ruoyi-admin/src/main/java/com/ruoyi/app/omgpay
rg -n "OrderResultURL|ChoosePayment|IgnorePayment|UnionPay" ruoyi-admin/src/main/java/com/ruoyi/app/omgpay
rg -n "com\.ruoyi\.app\.pay\.OmgPayController|com\.ruoyi\.app\.utils\.omg|pos_order_omg_payment|pos_order_omg_refund" ruoyi-admin/src/main/java/com/ruoyi/app/omgpay ruoyi-system/src/main/java/com/ruoyi/system/omgpay
rg -n "HashKey|HashIV|CheckMacValue|formFields|token" ruoyi-admin/src/main/java/com/ruoyi/app/omgpay
Interpret results manually: stage URL、OrderResultURL、ChoosePayment=ALL 与 IgnorePayment=ATM#CVS#BarcodeATM 是预期结果;production URL、UnionPay、其他禁用字段、旧 import 和敏感值日志不是预期结果。
Review each new public type and non-obvious signer/transaction/unique-key branch. Confirm necessary “why” comments exist and trivial assignment comments do not. Inspect every log.* argument and verify no object serialization or sensitive values.
[ ] Step 5: Check diff, encoding and line endings
git diff --check
git status --short
git diff --stat
git diff --name-only
Compare against the pre-task dirty file list. No unrelated file may be staged or rewritten; no whole-file line-ending churn.
Follow quickstart.md: first creation, current-page form POST, repeated request, two-request concurrency, negative cases and log review. Do not treat payment/callback as acceptance.
If verification required small fixes, rerun Steps 1–5 and commit only those fixes:
git commit -m "test: verify OMG payment creation rebuild"
Do not create an empty commit.
pos_store_omg and credential management remain unchanged./pay/omg/notify is the only notify route; old query/paymentInfo/return/refund routes and scheduled task remain absent.ipn_log; full callback logging contains no database HashKey/HashIV.pos_order.pay_status; no order/delivery/push/refund side effects.| Spec requirements | Implemented/verified by |
|---|---|
| FR-001–FR-003 | Tasks 1, 4 and package-isolation scans |
| FR-004–FR-005 | Task 5 Controller reflection/DTO tests |
| FR-006–FR-007 | Task 4 validation matrix and server-side amount assertions |
| FR-008–FR-009 | Task 3 stage constant and trade-number tests |
| FR-010–FR-011 | Tasks 1 and 4 row lock, active unique key and duplicate tests |
| FR-012–FR-016 | Task 3 exact field-set, text, timezone and ReturnURL tests |
| FR-017–FR-019 | Task 2 create vector; T052/T056 callback actual-field, empty and unknown-field tests |
| FR-020–FR-021 | Tasks 3 and 5 response contract; quickstart.md client POST acceptance |
| FR-022 | Task 1 creation DDL plus T048–T051 credential snapshot extension |
| FR-023–FR-024 | Task 5 create log/error tests; T054/T058/T059 full callback/IPN logs |
| FR-025–FR-027 | Task 6 class absence, route absence and main-source zero-match scans |
| FR-028 | Task 1 SQL-only DDL registration |
| FR-029 | Tasks 3, 6 and T060 stage-only/new callback gates |
| FR-030–FR-031 | Tasks 5 and 7 comment/log reviews and automated log assertions |
| FR-032–FR-035 | T052–T057 DTO boundary, IPN transaction, snapshot signature and invariant validation |
| FR-036–FR-041 | T049/T056–T059 success-priority state machine, order-only payment update and gateway facts |
| FR-042–FR-044 | T071–T076 test-stage refund boundary, i18n and safe logging |
| FR-045–FR-050 | T082–T087 verified retry orchestration, exact-attempt replacement, App contract and regression tests |
| FR-051–FR-055 | T093–T098 sparse query response validation, fail-closed identity checks and retry recovery |
| FR-056–FR-060 | T099–T103 current WebView return listener, exact URL handoff and compatibility verification |
Self-review result: all 60 functional requirements have an implementation task and a verification point; no placeholders remain; interface names and signatures are consistent across tasks.
| Risk | Control |
|---|---|
| Duplicate payable entries | FOR UPDATE on order before generator + UNIQUE(active_dd_id) |
| MerchantTradeNo collision | UNIQUE(merchant_trade_no) + bounded three-attempt regeneration |
| Old table deletion breaks active paths | remove Controller/task/admin/cancel/lifecycle references; main-source zero-match scan |
| Credential rotation breaks callback | immutable HashKey/HashIV snapshot on each attempt |
| Credentials leak | response whitelist; full callback logs only request data, never DB secrets |
| Signature omits new fields | signer accepts full actual map; completeness mutation tests |
| Production accidentally enabled | gateway constant is exact stage URL; no production property |
| Old callback handles new notification | old Controller deleted; single new route mapping test |
| Duplicate/late notifications corrupt state | attempt row lock + success-priority conditional updates |
| IPN failure loses payment | REQUIRES_NEW audit is best effort and never gates notify processing |
| User dirty work overwritten | pre-edit diff capture, surgical patching, staged-file audit |
No constitution violations. The separate form factory, signer, generator and persistence service each hold one security-sensitive responsibility and are directly unit testable; none is a generic multi-provider abstraction.
orderId,验证订单归属。CREATED;已付款订单选择首条 PAID,客户端不能指定交易号。QueryTradeInfo/V5 请求。TradeStatus=1/10200095 进入与回调相同的订单/尝试锁和不可逆状态机;0 保持只读。ipn_log;日志只记录必要的脱敏定位信息。POST /pay/omg/refund 使用 token 和只有 orderId 的显式 DTO。CreditDetail/DoAction 地址、HTTP Gateway、退款表或订单/支付更新。PAYMENT_REFUND_UNAVAILABLE_IN_TEST_ENVIRONMENT 及五语言提示;异常统一为 PAYMENT_REFUND_FAILED。com.ruoyi.app.utils.omg 下的 OmgPay、OmgPayConfig、OmgCheckMacValue 及对应测试;rebuild 运行代码只使用 com.ruoyi.app.omgpay 和 com.ruoyi.system.omgpay。pos_store_omg Entity、Mapper、Service 和管理接口。原 Controller 的凭证联网探测迁入 OmgStoreCredentialVerifier,复用新的 OmgCheckMacSigner、OmgQueryResponseParser 与 stage-only OmgPaymentQueryGateway。omg.base-url 配置;stage 查询地址继续由 rebuild 网关固定控制,不接受客户端或旧配置覆盖。updatesql/sql.md 追加按依赖顺序删除 pos_order_omg_refund、pos_order_omg_payment 的 SQL,不在实现会话中执行;保留 pos_store_omg、pos_order_omg_attempt 和 ipn_log。specs/016-omg-payment 与历史建表 SQL 作为审计记录,但它们不再定义当前实现。/pay/omg/create;退出支付页后不保存、不恢复原 WebView,也不重放旧表单。/pay/omg/retry。retry 先通过可信 /query 链路向 OMG 核实旧交易;客户端只能重新选择受控 paymentMethod,不能指定交易号或 OMG 原始支付参数。PAID 直接拒绝新建;FAILED 在旧尝试已释放后正常创建;UNPAID 仅允许 paymentType 为空的尝试被替换;其他状态 fail closed。UNPAID 替换在独立写事务中锁订单并再次验证订单,要求活动尝试交易号与 query 结果精确一致,然后以 id + CREATED 条件更新为 SUPERSEDED 并插入新尝试。PAYMENT_RETRY_NOT_AVAILABLE。MerchantTradeNo 的新表单。无需数据库结构变更,现有 attempt_status=3 与生成列唯一键已覆盖该流程。Goal: 保持 App 直接进入 OMG 官方支付方式选择页,通过服务端隐藏 ATM、CVS 和 BarcodeATM,同时由 OMG 商户侧关闭 AFTEE,最终保留信用卡与 Apple Pay。
Architecture: 不修改 POST /pay/omg/create、POST /pay/omg/retry 的请求或响应结构。两条路径继续复用 OmgPaymentFormFactory#create(...);工厂固定发送 ChoosePayment=ALL 与 IgnorePayment=ATM#CVS#BarcodeATM,不发送 UnionPay,并把实际过滤字段纳入 CheckMacValue。不通过前端 CSS、DOM 注入或未公开参数修改 OMG 第三方页面。
Tech Stack: Java 21、Spring Boot、JUnit 5、Mockito、Maven、OMG AIO stage。
Files:
ruoyi-admin/src/test/java/com/ruoyi/app/omgpay/OmgPaymentFormFactoryTest.javaruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentFormFactory.javaInterfaces:
OmgPaymentFormFactory#create(String orderId, Integer amount, String merchantId, String hashKey, String hashIv, String merchantTradeNo)Produces: 原接口不变;OmgPaymentForm.fields() 返回包含 ChoosePayment=ALL、IgnorePayment=ATM#CVS#BarcodeATM 且不含 UnionPay 的不可变字段集合。
[x] 将测试改为 buildsSignedFormThatUsesOmgPageForCreditAndApplePay:字段集合移除 UnionPay、加入 IgnorePayment;断言 ChoosePayment=ALL、IgnorePayment=ATM#CVS#BarcodeATM、无 UnionPay;签名入参仍为 14 个非 CheckMacValue 字段。
[ ] 按项目 OMG 延后验证约束,等待统一验证阶段使用 JDK 21 运行 OmgPaymentFormFactoryTest,确认旧 ChoosePayment=Credit 实现会使新断言失败。
[x] 修改 OmgPaymentFormFactory,改为以下固定字段:
fields.put("ChoosePayment", "ALL");
fields.put("IgnorePayment", "ATM#CVS#BarcodeATM");
[ ] 在统一验证阶段再次运行 OmgPaymentFormFactoryTest,确认字段集合、值和签名入参全部通过。
Files:
specs/020-omg-payment-rebuild/omg-app-integration.mdspecs/020-omg-payment-rebuild/tasks.mdInterfaces:
{status, gatewayUrl, formFields} 响应。Produces: App 仍直接 POST 全部 formFields,不增加支付渠道参数、二级选择页面或原生 Apple Pay SDK。
[x] 更新规格、契约、快速验收和 App 文档中的示例表单及字段说明:ChoosePayment=ALL、IgnorePayment=ATM#CVS#BarcodeATM,删除 UnionPay;注明 AFTEE 必须由 OMG 商户侧关闭,Apple Pay 取决于门店开通状态和设备环境。
[ ] 在统一验证阶段使用 JDK 21 运行全部 OMG 定向测试:
$env:JAVA_HOME='C:\Users\qmj\.jdks\graalvm-jdk-21.0.7'
$env:PATH="$env:JAVA_HOME\bin;$env:PATH"
mvn -pl ruoyi-admin -am "-Dtest=com.ruoyi.app.omgpay.*Test,com.ruoyi.system.omgpay.*Test" "-Dsurefire.failIfNoSpecifiedTests=false" test
[ ] 在统一验证阶段运行模块构建:
mvn -pl ruoyi-admin -am -DskipTests package
[x] 静态检查源码中只存在预期渠道参数,git diff --check 无错误;暂存范围在提交前单独核对,不包含 .claude/homunculus/*。
[ ] 部署到 OMG stage 后人工确认信用卡可用、Apple Pay 在适用环境可用、ATM/CVS/BarcodeATM 不显示,并确认 OMG 商户侧已关闭 AFTEE。
[ ] 使用中文提交信息提交并推送当前分支:修复:恢复 OMG 官方支付方式选择页。
本节取代“2026-08-17 OMG 官方支付方式选择页实施计划”作为当前渠道实现依据。旧节保留用于说明已提交实现的历史背景,不再定义目标行为。
Goal: 测试环境没有商户后台渠道开关时,仍严格保证用户只能发起信用卡或 Apple Pay,不显示超商快付与 AFTEE。
Architecture: App 在进入 OMG 前显示“信用卡”和“Apple Pay”两个选项,并向 create/retry 传递稳定枚举 paymentMethod。后端只接受 CREDIT/APPLE_PAY,分别生成 ChoosePayment=Credit + UnionPay=2 或 ChoosePayment=ApplePay 的签名表单,不再使用 ALL 或 IgnorePayment。客户端不得传递 ChoosePayment、UnionPay 等 OMG 原始参数。支付尝试表、回调、查询、结果页和测试环境退款边界保持不变,无数据库变更。
OmgCreatePaymentRequest 与 OmgRetryPaymentRequest 只增加 paymentMethod;Controller 先校验白名单,再把领域枚举传给 Service。CREDIT:发送并签名 ChoosePayment=Credit、UnionPay=2,直接进入信用卡流程并隐藏银联。APPLE_PAY:发送并签名 ChoosePayment=ApplePay,不发送 UnionPay 或 IgnorePayment。PAYMENT_METHOD_INVALID;校验失败不得创建、替换或更新支付尝试。paymentMethod。retry 可以重新选择渠道,但仍先执行现有可信查询和替换规则。formFields,不接入原生 Apple Pay SDK,不通过 CSS 或 DOM 修改 OMG 页面。本计划的可执行批次只覆盖当前 foodie_server 仓库。已在 E:\QtwCode 查找用户端源码;候选仓库 CTE/cte_share 与 CTE/food-pdy 都没有规格指定的 pages/OrderList/buy/omgCheckout.vue,也没有当前 OMG create/retry 对接代码,因此不得猜测其中任一仓库就是生产 App。App 修改必须在用户确认实际仓库后单独形成精确计划。
服务端批次不修改 Entity、Mapper、数据库表或 updatesql/sql.md。文件职责如下:
ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentMethod.java:定义 App 白名单枚举、严格解析规则与 OMG 单渠道映射。ruoyi-admin/src/test/java/com/ruoyi/app/omgpay/OmgPaymentMethodTest.java:锁定大小写、空白和未知值拒绝规则。ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/dto/OmgCreatePaymentRequest.java:只增加 paymentMethod 字段及访问器。ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/dto/OmgRetryPaymentRequest.java:只增加 paymentMethod 字段及访问器。ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentErrorCode.java:增加稳定错误 PAYMENT_METHOD_INVALID。ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentController.java:token 验证后解析白名单枚举,并传递给 create/retry Service。ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentCreateService.java:让首次创建和精确替换都携带已验证枚举。ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentRetryService.java:在查询或写入前拒绝空枚举,并把重新选择的渠道传给新表单。ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentFormFactory.java:按枚举生成互斥的信用卡或 Apple Pay 字段并签名。ruoyi-admin/src/test/java/com/ruoyi/app/omgpay/OmgPaymentFormFactoryTest.java、OmgPaymentControllerTest.java、OmgPaymentRetryControllerTest.java、OmgPaymentCreateServiceTest.java、OmgPaymentRetryServiceTest.java:覆盖 DTO 契约、无副作用拒绝、参数贯穿和签名字段集合。ruoyi-admin/src/main/resources/i18n/messages.properties、messages_zh_CN.properties、messages_zh_TW.properties、messages_en_US.properties、messages_vi.properties:提供同一错误 key 的五套文案。specs/020-omg-payment-rebuild/tasks.md:实现提交后只更新 T105/T106,统一验证和 App 任务保持未完成。Interfaces:
{orderId, paymentMethod},其中 paymentMethod 只能是精确字符串 CREDIT 或 APPLE_PAY。OmgPaymentMethod.require(String);OmgPaymentCreateService#create(Long, String, OmgPaymentMethod);OmgPaymentCreateService#replaceActiveForRetry(Long, String, String, OmgPaymentMethod);OmgPaymentRetryService#retry(Long, String, OmgPaymentMethod);OmgPaymentFormFactory#create(String, Integer, String, String, String, String, OmgPaymentMethod)。Security invariant: 客户端不能提交 ChoosePayment、UnionPay、IgnorePayment 或其他 OMG 原始字段;非法 paymentMethod 在 query、订单锁、尝试创建或替换前失败。
[ ] Step 1: 先写枚举、表单和 Controller 失败测试源码,但按 OMG 延后验证规则暂不运行
OmgPaymentMethodTest 必须包含以下精确断言:
assertEquals(OmgPaymentMethod.CREDIT, OmgPaymentMethod.require("CREDIT"));
assertEquals(OmgPaymentMethod.APPLE_PAY, OmgPaymentMethod.require("APPLE_PAY"));
for (String invalid : new String[]{"", "credit", "Credit", "ALL", " CREDIT "}) {
OmgPaymentBusinessException error = assertThrows(
OmgPaymentBusinessException.class,
() -> OmgPaymentMethod.require(invalid));
assertEquals(OmgPaymentErrorCode.PAYMENT_METHOD_INVALID, error.getCode());
}
assertEquals(OmgPaymentErrorCode.PAYMENT_METHOD_INVALID,
assertThrows(OmgPaymentBusinessException.class,
() -> OmgPaymentMethod.require(null)).getCode());
OmgPaymentFormFactoryTest 将旧的 ALL + IgnorePayment 用例拆成两个用例:
OmgPaymentForm credit = factory.create("DD-1", 100, "1000031", "KEY", "IV",
"OMG12345678901234567", OmgPaymentMethod.CREDIT);
assertEquals("Credit", credit.fields().get("ChoosePayment"));
assertEquals("2", credit.fields().get("UnionPay"));
assertFalse(credit.fields().containsKey("IgnorePayment"));
OmgPaymentForm applePay = factory.create("DD-1", 100, "1000031", "KEY", "IV",
"OMG12345678901234567", OmgPaymentMethod.APPLE_PAY);
assertEquals("ApplePay", applePay.fields().get("ChoosePayment"));
assertFalse(applePay.fields().containsKey("UnionPay"));
assertFalse(applePay.fields().containsKey("IgnorePayment"));
同时捕获 signer 入参:信用卡签名前字段数为 14,包含 ChoosePayment=Credit、UnionPay=2;Apple Pay 签名前字段数为 13,包含 ChoosePayment=ApplePay 且不含 UnionPay/IgnorePayment/CheckMacValue。
Controller 测试把 DTO 字段集合断言改为:
assertEquals(Set.of("orderId", "paymentMethod"),
Arrays.stream(OmgCreatePaymentRequest.class.getDeclaredFields())
.map(Field::getName).collect(Collectors.toSet()));
create/retry 成功用例分别设置 CREDIT、APPLE_PAY 并验证 Service 收到领域枚举;缺失、ALL、Credit 和带空白值返回 PAYMENT_METHOD_INVALID,且 verifyNoInteractions(createService/retryService)。
将现有 create Service 测试调用统一增加 OmgPaymentMethod.CREDIT,并验证工厂参数:
verify(formFactory).create(eq("DD-1"), eq(100), eq("1000031"), eq("KEY"), eq("IV"),
anyString(), eq(OmgPaymentMethod.CREDIT));
新增 null 防御用例,要求在任何依赖交互前失败:
OmgPaymentBusinessException error = assertThrows(OmgPaymentBusinessException.class,
() -> service.create(5L, "DD-1", null));
assertEquals(PAYMENT_METHOD_INVALID, error.getCode());
verifyNoInteractions(attempts, credentials, generator, formFactory);
retry Service 的 FAILED 与可替换 UNPAID 用例分别验证:
verify(createService).create(5L, "DD-1", OmgPaymentMethod.APPLE_PAY);
verify(createService).replaceActiveForRetry(5L, "DD-1", "OMGOLD",
OmgPaymentMethod.CREDIT);
retry 的 null 防御必须在 queryService.query(...) 前返回 PAYMENT_METHOD_INVALID,并断言 verifyNoInteractions(queryService, createService)。原有 PAID/UNKNOWN/paymentType 非空/并发变化 断言保持不变,只补充枚举参数。
OmgPaymentMethod.java 使用以下完整领域边界:
package com.ruoyi.app.omgpay;
/** Maps the App payment-method allowlist to one OMG hosted payment channel. */
public enum OmgPaymentMethod {
CREDIT("Credit", true),
APPLE_PAY("ApplePay", false);
private final String choosePayment;
private final boolean unionPayDisabled;
OmgPaymentMethod(String choosePayment, boolean unionPayDisabled) {
this.choosePayment = choosePayment;
this.unionPayDisabled = unionPayDisabled;
}
public String getChoosePayment() {
return choosePayment;
}
public boolean isUnionPayDisabled() {
return unionPayDisabled;
}
public static OmgPaymentMethod require(String value) {
try {
return value == null ? invalid() : valueOf(value);
} catch (IllegalArgumentException error) {
return invalid();
}
}
private static OmgPaymentMethod invalid() {
throw new OmgPaymentBusinessException(OmgPaymentErrorCode.PAYMENT_METHOD_INVALID);
}
}
两个请求 DTO 都只增加:
private String paymentMethod;
public String getPaymentMethod() {
return paymentMethod;
}
public void setPaymentMethod(String paymentMethod) {
this.paymentMethod = paymentMethod;
}
错误枚举增加 PAYMENT_METHOD_INVALID("omg.pay.payment.method.invalid")。五个 properties 文件使用同一 key:
# messages.properties / messages_zh_CN.properties
omg.pay.payment.method.invalid=请选择信用卡或 Apple Pay
# messages_zh_TW.properties
omg.pay.payment.method.invalid=請選擇信用卡或 Apple Pay
# messages_en_US.properties
omg.pay.payment.method.invalid=Please select Credit Card or Apple Pay
# messages_vi.properties
omg.pay.payment.method.invalid=Vui lòng chọn Thẻ tín dụng hoặc Apple Pay
Controller 在 token 解析成功后执行白名单解析,再调用 Service:
String paymentMethodValue = request == null ? null : request.getPaymentMethod();
safeUserId = tokenUserResolver.requireUserId(token);
OmgPaymentMethod paymentMethod = OmgPaymentMethod.require(paymentMethodValue);
OmgPaymentCreateOutcome outcome = createService.create(safeUserId, orderId, paymentMethod);
retry 同样调用 retryService.retry(safeUserId, orderId, paymentMethod)。不得把原始 paymentMethodValue 写入日志或传入表单工厂。
create Service 在 create(...) 和 replaceActiveForRetry(...) 的第一条业务判断调用统一的 requirePaymentMethod(paymentMethod),然后把枚举传入 createWithBoundedTradeNumberRetries(...):
private static void requirePaymentMethod(OmgPaymentMethod paymentMethod) {
if (paymentMethod == null) {
throw business(PAYMENT_METHOD_INVALID);
}
}
retry Service 在调用 query 前执行同样的 null 判断并抛出 new OmgPaymentBusinessException(PAYMENT_METHOD_INVALID),再在 FAILED、可替换 UNPAID 两条路径传递原枚举。
表单工厂签名追加 OmgPaymentMethod paymentMethod,删除旧固定字段并改为:
fields.put("ChoosePayment", paymentMethod.getChoosePayment());
if (paymentMethod.isUnionPayDisabled()) {
fields.put("UnionPay", "2");
}
IgnorePayment 和 ChoosePayment=ALL 不得出现在生产代码。签名器继续接收表单实际字段的不可变副本,现有字段安全清洗、URL 校验和响应不可变性保持不变。
[ ] Step 5: 做一次统一静态审查,不运行 Maven、编译或测试
rg -n 'ChoosePayment|IgnorePayment|UnionPay|paymentMethod|PAYMENT_METHOD_INVALID' `
ruoyi-admin/src/main/java/com/ruoyi/app/omgpay `
ruoyi-admin/src/test/java/com/ruoyi/app/omgpay `
ruoyi-admin/src/main/resources/i18n
rg -n 'omg.pay.payment.method.invalid' `
ruoyi-admin/src/main/resources/i18n/messages.properties `
ruoyi-admin/src/main/resources/i18n/messages_zh_CN.properties `
ruoyi-admin/src/main/resources/i18n/messages_zh_TW.properties `
ruoyi-admin/src/main/resources/i18n/messages_en_US.properties `
ruoyi-admin/src/main/resources/i18n/messages_vi.properties
git diff --check
人工确认:生产代码没有 ChoosePayment=ALL 或 IgnorePayment;只有信用卡分支包含 UnionPay=2;客户端原始字符串只在 Controller 白名单解析边界出现;日志、错误响应和测试失败信息不包含 token、HashKey、HashIV、CheckMacValue 或完整表单;无 Entity、Mapper、SQL 或数据库文件变化。
仅在生产代码、测试源码、五语言 i18n 和文档静态审查完成后,把 T105/T106 标记为完成;T107/T108/T109 保持未完成。使用 PowerShell 数组暂存本批次明确文件,运行 git diff --cached --name-only 和 git diff --cached --check,确认不包含 .claude/homunculus/* 或其他用户脏文件,然后提交:
git commit -m "实现 OMG 信用卡与 Apple Pay 双入口"
提交后状态只能报告为“已提交”,不能报告“已验证”。
Interfaces:
Produces: 定向测试、完整 OMG 回归、模块构建和 stage 双渠道人工证据。
[ ] Step 1: 使用 JDK 21 运行渠道定向测试
$env:JAVA_HOME='C:\Users\qmj\.jdks\graalvm-jdk-21.0.7'
$env:PATH="$env:JAVA_HOME\bin;$env:PATH"
mvn -pl ruoyi-admin -am "-Dtest=com.ruoyi.app.omgpay.OmgPaymentMethodTest,com.ruoyi.app.omgpay.OmgPaymentFormFactoryTest,com.ruoyi.app.omgpay.OmgPaymentControllerTest,com.ruoyi.app.omgpay.OmgPaymentRetryControllerTest,com.ruoyi.app.omgpay.OmgPaymentCreateServiceTest,com.ruoyi.app.omgpay.OmgPaymentRetryServiceTest" "-Dsurefire.failIfNoSpecifiedTests=false" test
Expected: Maven 退出码 0,六个指定测试类全部通过;信用卡签名前 14 个字段,Apple Pay 签名前 13 个字段。
[ ] Step 2: 运行 OMG 回归与模块构建
mvn -pl ruoyi-admin -am "-Dtest=com.ruoyi.app.omgpay.*Test,com.ruoyi.system.omgpay.*Test" "-Dsurefire.failIfNoSpecifiedTests=false" test
mvn -pl ruoyi-admin -am -DskipTests package
Expected: 两条命令退出码均为 0,构建输出 BUILD SUCCESS。
按 quickstart.md 分别发送 paymentMethod=CREDIT 与 paymentMethod=APPLE_PAY。确认信用卡表单只含 ChoosePayment=Credit + UnionPay=2,Apple Pay 表单只含 ChoosePayment=ApplePay;两个页面均不出现超商快付、AFTEE 或其他渠道选择。Apple Pay 若因门店未开通或设备不支持而失败,记录为外部环境限制,不把信用卡成功当作 Apple Pay 验收证据。
只有上述自动化、构建和人工证据全部检查后,才能把功能状态报告为“已验证”。若 App 仍未接入,服务端最多报告为“已验证”,完整用户功能仍不得宣称完成。
Goal: 修复用户连续点击支付时,retry 查询到已签名但省略非核心字段的 OMG 响应而错误返回 PAYMENT_QUERY_FAILED。
Architecture: 保持 /pay/omg/query 与 /pay/omg/retry 接口不变。查询服务对所有实际字段验签,并将核心身份字段与结算字段分层校验:任何状态都必须核对商户号、交易号、金额、状态和签名;只有 PAID 必须具备完整结算字段,UNPAID/10200095/10200047 可省略非核心字段。OMG stage 对从未提交的表单返回签名有效的 TradeStatus=10200047 与 TradeAmt=0,该组合按“网关不存在交易”同步失败并进入既有 retry 新建表单流程;其他状态继续要求金额与本地尝试一致。
Tech Stack: Java 21、Spring Boot、JUnit 5、Mockito、Maven、OMG AIO stage。
Files:
ruoyi-admin/src/test/java/com/ruoyi/app/omgpay/OmgPaymentQueryServiceTest.javaInterfaces:
OmgPaymentQueryService#query(Long userId, String orderId)。Produces: 对已签名的稀疏 TradeStatus=0/10200095 响应分别返回 UNPAID/FAILED;对 stage 实际返回的 TradeStatus=10200047 + TradeAmt=0 返回 FAILED;缺少核心字段、签名错误、10200047 金额非零或已付款结算字段缺失时仍返回 PAYMENT_QUERY_FAILED。
[x] 先增加稀疏未付款/失败响应测试,并运行 OmgPaymentQueryServiceTest 观察旧实现因固定 17 字段校验而失败。
[x] 增加缺少核心金额、已付款缺少结算字段的 fail-closed 回归断言。
[x] 增加 stage 实际 10200047 + TradeAmt=0 响应与非零金额篡改的回归断言,并观察现有金额校验导致前者失败。
Files:
ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentQueryService.javaspecs/020-omg-payment-rebuild/spec.mdspecs/020-omg-payment-rebuild/tasks.mdInterfaces:
OmgQueryResponseParser#parse(String) 返回的完整实际字段集合。Produces: 核心字段校验、完整实际字段验签、按 TradeStatus 校验结算字段,以及仅包含字段名称的安全诊断日志。
[x] 将固定字段存在性校验改为核心字段校验;验签仍覆盖解析得到的全部实际字段。
[x] 仅对 TradeStatus=1 强制要求支付交易号、支付方式、付款时间、建单时间和通路费;失败状态允许这些字段不存在。
[x] 仅在签名和身份验证通过且 TradeStatus=10200047 + TradeAmt=0 时同步旧尝试失败,使 retry 复用既有 FAILED -> create 流程。
[x] 使用 JDK 21 运行查询定向测试、全部 OMG 回归与 ruoyi-admin 模块构建。
[x] 执行 git diff --check、最终差异和暂存范围检查,不包含 .claude/homunculus/*。
Goal: 让 OMG 专用页面 pages/OrderList/buy/omgCheckout 在 iOS 中可靠识别后端结果页已经加载,并把控制权交给 App 逻辑层;后端保留现有结果 HTML、“返回 App”按钮和 Scheme 兜底。
Architecture: omgCheckout 的 renderjs 继续只负责提交 OMG HTML Form。普通 <script> 在 App-Plus iOS 环境获取当前页面 this.$scope.$getAppWebview(),监听原生 loaded 并通过 getURL() 精确识别 /pay/omg/result;识别后只触发一次前端业务处理入口。该页面没有 <web-view> 子组件,因此不得读取 children()[0]。
Tech Stack: uni-app App-vue(Vue2)、renderjs、HTML5+ WebviewObject、iOS WKWebView、Java 21/Spring Boot 后端兼容回归。
pages/OrderList/buy/omgCheckout.vue;该仓库不在当前后端工作区,本计划不假设或修改其请求封装。payChannel 参数。WebviewObject,不得使用 children()[0]。https://foodieapi.waimai-paotui.com/pay/omg/result 及其 query/hash 形式。OMG_RETURNED 信号,不代表支付成功;查询、轮询、提示和最终路由由前端业务实现。/pay/omg/result 继续返回现有 HTML;本阶段不删除提示内容、“返回 App”按钮、Bridge 诊断或 App Scheme。CheckMacValue。用户端 App 仓库(当前工作区外)
└── pages/OrderList/buy/omgCheckout.vue # 绑定当前页面 WebView、识别结果 URL、清理监听
当前后端仓库
├── ruoyi-admin/src/test/java/com/ruoyi/app/omgpay/
│ └── OmgPaymentClientReturnServiceTest.java # 现有结果 HTML/按钮/Scheme 兼容回归
└── specs/020-omg-payment-rebuild/
├── omg-ios-webview-return-fix.md # 已批准交接设计
├── plan.md # 本实施计划
└── tasks.md # T099-T103 执行清单
Files:
pages/OrderList/buy/omgCheckout.vueInterfaces:
this.$scope.$getAppWebview(): WebviewObject、WebviewObject#addEventListener('loaded', handler)、WebviewObject#getURL(): string。Produces: 同一次结果页加载最多调用一次前端业务入口 handleOmgReturnDetected({ orderId, currentUrl });该入口的支付查询和路由实现由前端负责。
[ ] Step 1: 先验证当前页面结构与失败基线
在 iPhone 真机或 iOS 模拟环境记录当前页面 WebView URL 变化,确认 Form 提交后当前 WebviewObject 依次加载 OMG 收银台和 /pay/omg/result,并确认页面没有可供监听的 <web-view> 子组件。预期旧版本最终停留在后端结果页,控制台没有 [OMG-APP] result_page_detected。
<script> 增加固定结果地址与状态在组件外声明:
const OMG_RESULT_URL =
'https://foodieapi.waimai-paotui.com/pay/omg/result'
在 data() 中增加 omgReturnHandled: false。不得把完整 OMG 表单或返回 URL 保存到响应式数据。
将以下行为合并进页面现有生命周期,不覆盖原有 onReady/onUnload:
onReady() {
// #ifdef APP-PLUS
if (uni.getSystemInfoSync().platform === 'ios') {
this.bindOmgReturnListener()
}
// #endif
},
onUnload() {
this.clearOmgReturnListener()
}
bindOmgReturnListener() 必须使用当前页面对象:
const pageWebView = this.$scope.$getAppWebview()
保存 pageWebView 和具名 loaded handler,绑定后立即调用一次 URL 检查。不得调用 pageWebView.children()。
URL 判断必须等价于:
const isResultPage =
currentUrl === OMG_RESULT_URL ||
currentUrl.indexOf(OMG_RESULT_URL + '?') === 0 ||
currentUrl.indexOf(OMG_RESULT_URL + '#') === 0
非结果地址直接返回;结果地址且 omgReturnHandled === false 时先把它设为 true,再记录脱敏日志并调用:
this.handleOmgReturnDetected({
orderId: this.orderId,
currentUrl
})
handleOmgReturnDetected 是本交接单元提供给前端业务的唯一入口。该入口不得仅凭 URL 直接声明支付成功;查询和最终路由由前端在用户端仓库中完成。
clearOmgReturnListener() 使用保存的同一个 handler 调用 removeEventListener('loaded', handler),然后清空引用。模拟两次相同 loaded 时,handleOmgReturnDetected 调用次数必须为 1;页面卸载后调用次数必须保持不变。
[ ] Step 6: 使用中文提交用户端改动
git add -- 'pages/OrderList/buy/omgCheckout.vue'
git commit -m '修复:接管 OMG iOS WebView 返回信号'
Files:
ruoyi-admin/src/main/java/com/ruoyi/app/omgpay/OmgPaymentReturnPageRenderer.javaruoyi-admin/src/test/java/com/ruoyi/app/omgpay/OmgPaymentClientReturnServiceTest.javaspecs/020-omg-payment-rebuild/omg-ios-webview-return-fix.mdInterfaces:
POST /pay/omg/result 返回的现有 text/html 页面。Produces: 保持 HTTP 200、繁体提示、“返回 App”按钮、App Scheme 和无敏感信息的现有兼容页面;iOS 主流程不依赖这些兜底成功。
[ ] Step 1: 运行现有后端结果页定向测试
$env:JAVA_HOME='C:\Users\qmj\.jdks\graalvm-jdk-21.0.7'
$env:Path="$env:JAVA_HOME\bin;$env:Path"
mvn -pl ruoyi-admin -am "-Dtest=OmgPaymentClientReturnServiceTest" "-Dsurefire.failIfNoSpecifiedTests=false" test
预期退出码为 0;verifiedPaymentResultReturnsNoStoreHtmlThatOnlyNavigatesToApp 和 verifiedPaymentResultUsesUniAppBridgeBeforeKeepingSchemeFallback 继续通过。除非测试暴露与已批准规格直接冲突,不修改返回页生产代码。
完成一笔 OMG stage 支付,确认日志顺序至少包含:
[OMG-APP] webview_loaded {"isOmgResultPage":true}
[OMG-APP] result_page_detected {"orderRef":"***7389"}
同一次返回不得出现第二次 result_page_detected。即使结果页仍输出旧 Bridge/Scheme 失败日志,也不得阻止 App 逻辑层收到该信号。
在 OMG 收银台中间页、取消页和其他 URL 上确认不触发 result_page_detected;使用 Android 和外部浏览器确认现有结果页提示、按钮与 Scheme 仍保留。
后端仓库不应出现 OmgPaymentReturnPageRenderer.java 生产差异;用户端提交只包含 omgCheckout.vue 及该仓库确有的对应测试。不得混入 .claude/homunculus/*。
| 设计要求 | 实施/验证位置 |
|---|---|
| 监听当前页面而非子 WebView | Task 1 Steps 1、3 |
| 精确识别固定结果 URL | Task 1 Step 4 |
| 只触发一次并在卸载时清理 | Task 1 Step 5 |
| 结果页到达不等于支付成功 | Task 1 Step 4、Task 2 Step 2 |
| 保留现有 HTML、按钮与 Scheme | Task 2 Steps 1、3 |
| iOS 主流程不依赖旧 Bridge/Scheme | Task 2 Step 2 |
| Android/外部浏览器不受影响 | Task 2 Step 3 |
自检结论:交接设计的每项要求都有明确实施或验收点;前端查询、轮询、提示和最终路由明确属于交接入口的消费方,不在本计划中虚构实现。