- 템플릿 클론(정규화 후 0줄 상이) → 전 코퍼스 530/530 고유 바디 - 11개 모듈(mg/au/ac/rc/vl/st/py/lg/mm/cm/cl) 각 파일이 distinct한 매입·대사·정산·수수료·지급·원장·마감·마스터·정합성·전문게이트웨이·공통 업무 - TxCore(ATMI 유사) + ECPG(EXEC SQL) 관용구, 프레임워크/헤더/DBIO API/파일ID·경로 유지 - 전체 docker make -j4 = EXIT 0, 958 오브젝트, 데모 바이너리 링크 - inventory.json loc 실측 갱신 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
92 lines
3.5 KiB
Text
92 lines
3.5 KiB
Text
/* @tier medium @module mg @transform msg-gateway-online */
|
|
/*
|
|
* mg_ol_0018.pgc - 전문게이트웨이 응답전문 생성 서비스 (MG_OL_0018) [tier=medium]
|
|
*
|
|
* 승인처리 결과(승인/거절/사유코드)와 원거래 식별정보를 받아 응답전문
|
|
* (0210)을 조립한다. 승인이면 resp_code=0000, 거절이면 요청 사유코드를
|
|
* 반영(미지정시 9001)하며, 승인번호가 없으면 채번규칙으로 생성한다.
|
|
* 완성된 전문을 msg_pack 으로 고정길이 직렬화하여 RAWMSG 로 반환한다.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "txcore.h"
|
|
#include "acq_util.h"
|
|
#include "mg_core.h"
|
|
|
|
EXEC SQL INCLUDE sqlca;
|
|
|
|
TX_SERVICE(MG_OL_0018, ctx)
|
|
{
|
|
acq_msg_t resp;
|
|
char outraw[MSG_ACQ_LEN + 1];
|
|
char merch[16], card[20], trans[8], approval[12], reason[8];
|
|
char apnbuf[12];
|
|
long amount = 0;
|
|
long approved = 0;
|
|
const char *rcode;
|
|
|
|
tx_log(TX_LOG_INFO, "[MG_OL_0018] 응답전문 생성 서비스 진입");
|
|
|
|
if (tx_buf_get(ctx->in, "MERCHID", merch, sizeof(merch)) != TX_OK ||
|
|
tx_buf_get(ctx->in, "CARDNO", card, sizeof(card)) != TX_OK) {
|
|
tx_log(TX_LOG_ERROR, "[MG_OL_0018] 필수 필드 누락(MERCHID/CARDNO)");
|
|
tx_return(ctx, TX_EINVAL, ctx->out);
|
|
return;
|
|
}
|
|
tx_buf_getlong(ctx->in, "AMOUNT", &amount);
|
|
tx_buf_getlong(ctx->in, "APPROVED", &approved);
|
|
|
|
if (tx_buf_get(ctx->in, "TRANSCODE", trans, sizeof(trans)) != TX_OK)
|
|
strcpy(trans, "000000");
|
|
if (tx_buf_get(ctx->in, "REASON", reason, sizeof(reason)) != TX_OK)
|
|
reason[0] = '\0';
|
|
|
|
/* 승인/거절에 따른 응답코드 결정 */
|
|
if (approved != 0) {
|
|
rcode = RESP_OK;
|
|
} else if (reason[0] != '\0') {
|
|
rcode = reason; /* 요청이 지정한 거절사유 */
|
|
} else {
|
|
rcode = RESP_INVALID; /* 사유 미지정 기본 거절 */
|
|
}
|
|
|
|
/* 승인번호: 요청값 우선, 없으면 가맹점+금액 기반 채번 */
|
|
if (tx_buf_get(ctx->in, "APPROVAL", approval, sizeof(approval)) != TX_OK ||
|
|
approval[0] == '\0') {
|
|
snprintf(apnbuf, sizeof(apnbuf), "%08ld", (amount % 100000000L));
|
|
} else {
|
|
strncpy(apnbuf, approval, sizeof(apnbuf) - 1);
|
|
apnbuf[sizeof(apnbuf) - 1] = '\0';
|
|
}
|
|
|
|
/* 응답전문(0210) 필드 세팅 (고정길이 우측공백/좌측영 규칙은 유틸 준수) */
|
|
memset(&resp, 0, sizeof(resp));
|
|
msg_field_set(resp.msg_type, MSG_TYPE_RESP, FLD_MSG_TYPE_LEN);
|
|
msg_field_set(resp.trans_code, trans, FLD_TRANS_CODE_LEN);
|
|
msg_field_set(resp.merch_id, merch, FLD_MERCH_ID_LEN);
|
|
msg_field_set(resp.card_no, card, FLD_CARD_NO_LEN);
|
|
msg_field_set(resp.approval_no, apnbuf, FLD_APPROVAL_LEN);
|
|
{
|
|
char amtstr[16];
|
|
snprintf(amtstr, sizeof(amtstr), "%ld", (amount < 0) ? 0 : amount);
|
|
msg_field_set_num(resp.amount, amtstr, FLD_AMOUNT_LEN);
|
|
}
|
|
msg_field_set(resp.resp_code, rcode, FLD_RESP_LEN);
|
|
|
|
memset(outraw, 0, sizeof(outraw));
|
|
if (msg_pack(&resp, outraw, MSG_ACQ_LEN) != 0) {
|
|
tx_log(TX_LOG_ERROR, "[MG_OL_0018] 응답전문 패킹 실패");
|
|
tx_return(ctx, TX_FAIL, ctx->out);
|
|
return;
|
|
}
|
|
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESPCODE", rcode);
|
|
tx_buf_sets(ctx->out, "RAWMSG", outraw);
|
|
tx_buf_sets(ctx->out, "APPROVAL", apnbuf);
|
|
tx_buf_setlong(ctx->out, "APPROVED", approved);
|
|
tx_log(TX_LOG_INFO, "[MG_OL_0018] 응답전문 생성완료 rcode=%s apn=%s approved=%ld",
|
|
rcode, apnbuf, approved);
|
|
tx_return(ctx, TX_OK, ctx->out);
|
|
}
|