barsa 230a61c520 refactor: enhance account status handling and error messaging in auth guards
- Introduced a new `AccountStatusResult` interface to standardize account status detection across systems.
- Updated the `VerificationWorkflowService` to merge handoff data with discovered account status.
- Enhanced error handling in `GlobalAuthGuard` and `LocalAuthGuard` to include structured error codes for better clarity in unauthorized responses.
- Refined WHMCS and Salesforce integration schemas to ensure consistent data validation and coercion.
2026-03-02 18:00:41 +09:00

68 lines
2.1 KiB
TypeScript

/**
* WHMCS Payments Provider - Mapper
*/
import type { PaymentMethod, PaymentGateway } from "../../contract.js";
import { paymentMethodSchema, paymentGatewaySchema } from "../../schema.js";
import { whmcsPaymentMethodRawSchema, whmcsPaymentGatewayRawSchema } from "./raw.types.js";
const PAYMENT_TYPE_MAP: Record<string, PaymentMethod["type"]> = {
creditcard: "CreditCard",
bankaccount: "BankAccount",
remotecard: "RemoteCreditCard",
remotebankaccount: "RemoteBankAccount",
manual: "Manual",
remoteccreditcard: "RemoteCreditCard",
};
function mapPaymentMethodType(type: string): PaymentMethod["type"] {
const normalized = type.trim().toLowerCase();
return PAYMENT_TYPE_MAP[normalized] ?? "Manual";
}
const GATEWAY_TYPE_MAP: Record<string, PaymentGateway["type"]> = {
merchant: "merchant",
thirdparty: "thirdparty",
tokenization: "tokenization",
manual: "manual",
};
function mapGatewayType(type: string): PaymentGateway["type"] {
const normalized = type.trim().toLowerCase();
return GATEWAY_TYPE_MAP[normalized] ?? "manual";
}
export function transformWhmcsPaymentMethod(raw: unknown): PaymentMethod {
const whmcs = whmcsPaymentMethodRawSchema.parse(raw);
const paymentMethod: PaymentMethod = {
id: whmcs.id,
type: mapPaymentMethodType(whmcs.payment_type || whmcs.type || "manual"),
description: whmcs.description,
gatewayName: whmcs.gateway_name || whmcs.gateway,
cardLastFour: whmcs.card_last_four,
expiryDate: whmcs.expiry_date,
cardType: whmcs.card_type,
bankName: whmcs.bank_name,
remoteToken: whmcs.remote_token,
lastUpdated: whmcs.last_updated,
isDefault: whmcs.is_default ?? false,
};
return paymentMethodSchema.parse(paymentMethod);
}
export function transformWhmcsPaymentGateway(raw: unknown): PaymentGateway {
const whmcs = whmcsPaymentGatewayRawSchema.parse(raw);
const gateway: PaymentGateway = {
name: whmcs.name,
displayName: whmcs.display_name || whmcs.name,
type: mapGatewayType(whmcs.type),
isActive: whmcs.visible ?? false,
configuration: whmcs.configuration,
};
return paymentGatewaySchema.parse(gateway);
}