Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
93 lines
3.9 KiB
TypeScript
93 lines
3.9 KiB
TypeScript
import { apiGet, apiPost } from "@/app/lib/clientApi";
|
|
import type {
|
|
PosCounterProduct,
|
|
PosTender,
|
|
CounterPlaceSalePayload,
|
|
PosPlaceSaleResult,
|
|
PosWalletBalanceView,
|
|
CounterWalletPreviewPayload,
|
|
CounterWalletSalePayload,
|
|
PosWalletSaleResult,
|
|
MemberCheckoutPreviewResult,
|
|
CounterSplitSalePayload,
|
|
SplitSaleResult,
|
|
SplitSettlementStatus,
|
|
PosQuotePayload,
|
|
} from "@/app/lib/types";
|
|
|
|
// Client-side wrapper for the /pos/counter page (add-branch-counter-sale). Calls only the
|
|
// portal's own /api/counter/* route handlers — never solvway-mobile-api directly. Ids stay as
|
|
// strings end-to-end (repo convention snowflake-ids-json-string). The mutation goes through
|
|
// apiPost so a Next.js GET prefetch can never trigger a sale (CLAUDE.md GET-prefetch rule).
|
|
|
|
/** List the MEMBER-tier products sellable at the operator's branch counter. Pure read. */
|
|
export function listCounterProducts(): Promise<PosCounterProduct[]> {
|
|
return apiGet<PosCounterProduct[]>("/api/counter/products");
|
|
}
|
|
|
|
/** List the POS-enabled, active tenders for the operator's branch. Pure read. */
|
|
export function listCounterTenders(): Promise<PosTender[]> {
|
|
return apiGet<PosTender[]>("/api/counter/payment-methods");
|
|
}
|
|
|
|
/** Place a recorded-tender branch counter sale. Mutation path — POST. */
|
|
export function placeCounterSale(payload: CounterPlaceSalePayload): Promise<PosPlaceSaleResult> {
|
|
return apiPost<PosPlaceSaleResult>("/api/counter/sale", payload);
|
|
}
|
|
|
|
// --- Member-wallet tender (add-branch-counter-wallet-tender) ---
|
|
// The PIN (candidatePin) is held only for the duration of the placeCounterWalletSale call and is
|
|
// never stored, logged, or persisted client-side.
|
|
|
|
/** Read member wallet balances + PIN status for the counter wallet tender UI. Pure read — GET. */
|
|
export function readCounterMemberWallet(memberCode: string): Promise<PosWalletBalanceView> {
|
|
return apiGet<PosWalletBalanceView>(
|
|
`/api/counter/wallet/${encodeURIComponent(memberCode)}`,
|
|
);
|
|
}
|
|
|
|
/** Preview the settlement split before placing a counter wallet sale. Mutation path — POST. */
|
|
export function previewCounterWallet(
|
|
payload: CounterWalletPreviewPayload,
|
|
): Promise<MemberCheckoutPreviewResult> {
|
|
return apiPost<MemberCheckoutPreviewResult>("/api/counter/wallet/preview", payload);
|
|
}
|
|
|
|
/** Price the Branch Counter cart net of promotions. Nothing is paid or written — POST so a prefetch never fires it. */
|
|
export function quoteCounterSale(payload: PosQuotePayload): Promise<MemberCheckoutPreviewResult> {
|
|
return apiPost<MemberCheckoutPreviewResult>("/api/counter/quote", payload);
|
|
}
|
|
|
|
/**
|
|
* Place a branch-counter member-wallet sale authorized by the member's PIN.
|
|
* The candidatePin value must be discarded immediately after this call returns.
|
|
*/
|
|
export function placeCounterWalletSale(
|
|
payload: CounterWalletSalePayload,
|
|
): Promise<PosWalletSaleResult> {
|
|
return apiPost<PosWalletSaleResult>("/api/counter/wallet/sale", payload);
|
|
}
|
|
|
|
// --- Split-tender (wallet + cash + gateway) sale + poll/cancel (split-payment gateway) ---
|
|
// The candidatePin (present only when a wallet amount is above 0) is held only for the duration of the
|
|
// placeCounterSplitSale call and is never stored, logged, or persisted client-side.
|
|
|
|
/** Place a branch-counter split-tender sale. Mutation path — POST. */
|
|
export function placeCounterSplitSale(
|
|
payload: CounterSplitSalePayload,
|
|
): Promise<SplitSaleResult> {
|
|
return apiPost<SplitSaleResult>("/api/counter/split/sale", payload);
|
|
}
|
|
|
|
/** Poll a split gateway sale's settlement state. Pure read — GET, prefetch-safe. */
|
|
export function pollCounterSplitStatus(uuid: string): Promise<SplitSettlementStatus> {
|
|
return apiGet<SplitSettlementStatus>(
|
|
`/api/counter/split/status/${encodeURIComponent(uuid)}`,
|
|
);
|
|
}
|
|
|
|
/** Cancel a still-pending split gateway sale (releases reserved stock). Mutation path — POST. */
|
|
export function cancelCounterSplit(uuid: string): Promise<boolean> {
|
|
return apiPost<boolean>(`/api/counter/split/cancel/${encodeURIComponent(uuid)}`);
|
|
}
|