/*
 * PAY_RETRY.pgc - py 모듈 서비스 PAY_RETRY (one service = one file).
 * 실패 지급 재시도: 실패/보류(J,H) 건만 요청(R)으로 되돌리고 retry_count 증가.
 * Moved verbatim from the former inline py_svr.pgc; runs on the caller's XA
 * branch (no EXEC SQL CONNECT). Advertised by py_svr at tpsvrinit.
 */
#include "PAY_RETRY.h"

void PAY_RETRY(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    EXEC SQL BEGIN DECLARE SECTION;
    long h_pay;
    EXEC SQL END DECLARE SECTION;
    h_pay = getl(b, T_ID1);
    EXEC SQL UPDATE py_payout SET status = 'R', retry_count = retry_count + 1, updated_at = now()
        WHERE payout_id = :h_pay AND status IN ('J', 'H');
    if (sqlca.sqlcode < 0) FAIL(b);
    if (sqlca.sqlcode == 100) { setl(b, T_RC, 1); FAIL(b); }
    setl(b, T_RC, 0);
    Bchg(b, T_STATUS, 0, "R", 0L);
    OK(b);
}
