fix(cbe): update response code from 3 to 2 for business failures in CBE integration

This commit is contained in:
Marshal
2026-08-06 17:50:27 +00:00
parent 3a2f1a46d6
commit 533de3cc93
8 changed files with 98 additions and 19 deletions

View File

@@ -122,15 +122,18 @@ describe("CBE Unified Bill (payment service as biller)", () => {
End_To_End_Txn_Id: txnId("q404"),
Bill_Id: "000000000000",
});
// Business failures are HTTP 200 + Response_Code "3" — CBE treats a non-200
// Business failures are HTTP 200 + Response_Code "2" — CBE treats a non-200
// as a channel fault and retries.
expect(res.status).toBe(200);
expect(res.body.Response_Code).toBe("3");
expect(res.body.Response_Code).toBe("2");
});
let settleBody: Record<string, string>;
let settledTxnRef: string;
it("settles the freight invoice when CBE reports the debit", async () => {
const invoice = await currentInvoice(invoiceId);
const res = await cbe(token, "/cbe/payment", {
settleBody = {
Destination_Api_Name: API_NAME,
End_To_End_Txn_Id: txnId("p1"),
Cbe_Txn_Ref: `CBE${Date.now()}`,
@@ -140,9 +143,11 @@ describe("CBE Unified Bill (payment service as biller)", () => {
Currency: "ETB",
Full_Name: "IT Payer",
Phone_No: "+251911000001",
});
};
const res = await cbe(token, "/cbe/payment", settleBody);
expect(res.status).toBe(200);
expect(res.body.Response_Code).toBe("0");
settledTxnRef = res.body.Destination_Txn_Ref;
const paid = await poll<{ status: string }>(
"invoice PAID via CBE bill",
@@ -154,6 +159,24 @@ describe("CBE Unified Bill (payment service as biller)", () => {
expect(paid.status).toBe("PAID");
});
it("replays the stored success when CBE retries the same attempt verbatim", async () => {
const res = await cbe(token, "/cbe/payment", settleBody);
expect(res.status).toBe(200);
expect(res.body.Response_Code).toBe("0");
// The stored body, not a re-settlement — same order id as the first answer.
expect(res.body.Destination_Txn_Ref).toBe(settledTxnRef);
});
it("rejects a settled End_To_End_Txn_Id reused with a different amount", async () => {
const res = await cbe(token, "/cbe/payment", {
...settleBody,
Amount: "1.00",
});
expect(res.status).toBe(200);
expect(res.body.Response_Code).toBe("2");
expect(res.body.Response_Description).toContain("already used by a different payment");
});
it("rejects a second debit on the same bill", async () => {
const res = await cbe(token, "/cbe/payment", {
Destination_Api_Name: API_NAME,
@@ -165,7 +188,7 @@ describe("CBE Unified Bill (payment service as biller)", () => {
Currency: "ETB",
});
expect(res.status).toBe(200);
expect(res.body.Response_Code).toBe("3");
expect(res.body.Response_Code).toBe("2");
});
it("reports an already-paid bill on a later query", async () => {
@@ -175,6 +198,6 @@ describe("CBE Unified Bill (payment service as biller)", () => {
Bill_Id: billId,
});
expect(res.status).toBe(200);
expect(res.body.Response_Code).toBe("3");
expect(res.body.Response_Code).toBe("2");
});
});