Add optional WHMCS admin credentials to environment configuration

- Introduced WHMCS_ADMIN_USERNAME and WHMCS_ADMIN_PASSWORD_MD5 for elevated admin actions.
- Updated env.validation.ts and portal-backend.env.sample to reflect new optional fields.
- Enhanced order fulfillment service to set order status to "Pending Review" and include error diagnostics in updates to Salesforce.
This commit is contained in:
T. Narantuya 2025-09-06 13:57:14 +09:00
parent ae56477714
commit 57c8fb0cab
3 changed files with 22 additions and 10 deletions

View File

@ -35,6 +35,11 @@ export const envSchema = z.object({
WHMCS_API_SECRET: z.string().optional(), WHMCS_API_SECRET: z.string().optional(),
WHMCS_API_ACCESS_KEY: z.string().optional(), WHMCS_API_ACCESS_KEY: z.string().optional(),
WHMCS_WEBHOOK_SECRET: z.string().optional(), WHMCS_WEBHOOK_SECRET: z.string().optional(),
// Optional elevated admin credentials for privileged WHMCS actions (eg. AcceptOrder)
WHMCS_ADMIN_USERNAME: z.string().optional(),
// Expect MD5 hash of the admin password (preferred). Alias supported for compatibility.
WHMCS_ADMIN_PASSWORD_MD5: z.string().optional(),
WHMCS_ADMIN_PASSWORD_HASH: z.string().optional(),
// Salesforce Configuration // Salesforce Configuration
SF_LOGIN_URL: z.string().url().optional(), SF_LOGIN_URL: z.string().url().optional(),

View File

@ -306,18 +306,20 @@ export class OrderFulfillmentOrchestrator {
// Try to update Salesforce with failure status // Try to update Salesforce with failure status
try { try {
await this.salesforceService.updateOrder({ const updates: Record<string, unknown> = {
Id: context.sfOrderId, Id: context.sfOrderId,
// Set overall Order.Status to Pending Review for manual attention
Status: "Pending Review",
[fields.order.activationStatus]: "Failed", [fields.order.activationStatus]: "Failed",
// Optional diagnostics fields if present in org };
...(fields.order.lastErrorCode && { updates[fields.order.lastErrorCode as string] = (
[fields.order.lastErrorCode]: this.orderFulfillmentErrorService.getShortCode(error) || String(errorCode)
this.orderFulfillmentErrorService.getShortCode(error) || String(errorCode), )
}), .toString()
...(fields.order.lastErrorMessage && { .substring(0, 60);
[fields.order.lastErrorMessage]: userMessage?.substring(0, 255), updates[fields.order.lastErrorMessage as string] = userMessage?.substring(0, 255);
}),
}); await this.salesforceService.updateOrder(updates as { Id: string; [key: string]: unknown });
this.logger.log("Salesforce updated with failure status", { this.logger.log("Salesforce updated with failure status", {
sfOrderId: context.sfOrderId, sfOrderId: context.sfOrderId,

View File

@ -26,6 +26,11 @@ TRUST_PROXY=true
WHMCS_BASE_URL=https://accounts.asolutions.co.jp WHMCS_BASE_URL=https://accounts.asolutions.co.jp
WHMCS_API_IDENTIFIER= WHMCS_API_IDENTIFIER=
WHMCS_API_SECRET= WHMCS_API_SECRET=
# Optional elevated admin credentials for privileged actions (eg. AcceptOrder)
# Provide the admin username and MD5 hash of the admin password.
# When set, the backend will use these ONLY for the AcceptOrder action.
WHMCS_ADMIN_USERNAME=
WHMCS_ADMIN_PASSWORD_MD5=
# Salesforce Credentials # Salesforce Credentials
SF_LOGIN_URL=https://asolutions.my.salesforce.com SF_LOGIN_URL=https://asolutions.my.salesforce.com