refactor : payment

This commit is contained in:
2026-01-03 18:34:39 +03:30
parent 0a1ef0f8f2
commit 5a0a5f883a
+24 -1
View File
@@ -92,7 +92,30 @@ class SepGateway implements IGateway {
verifyData,
{ headers: this.requestHeader }
);
return response.data;
const sepResponse = response.data;
// Normalize SEP response to match expected format
// SEP considers ResultCode = 0 and Success = true as successful
const isSuccess = sepResponse.ResultCode === 0 && sepResponse.Success === true;
// Validate amount if transaction details are available
let amountValid = true;
if (sepResponse.TransactionDetail && sepResponse.TransactionDetail.OrginalAmount) {
// According to SEP docs, OrginalAmount should match the expected amount
amountValid = sepResponse.TransactionDetail.OrginalAmount === data.amount;
if (!amountValid) {
this.logger.warn(`SEP amount mismatch: expected ${data.amount}, got ${sepResponse.TransactionDetail.OrginalAmount}`);
}
}
return {
code: (isSuccess && amountValid) ? 100 : sepResponse.ResultCode, // Use 100 for success to match expected format
message: sepResponse.ResultDescription,
ref_id: data.refNum, // SEP uses refNum as transaction identifier
success: isSuccess && amountValid,
raw_response: sepResponse // Keep original response for debugging
};
} catch (error) {
this.logger.error("error in SEP payment verification", error);
throw new InternalError(["error in SEP payment verification"]);