User reports a payment failure when attempting to top up credits in the frontend.
Error Logs:
index-Th5hJOs5.js:338 [CreateCrossmintOrder Error] 创建订单失败
index-Th5hJOs5.js:338 [PaymentOrchestrator] Failed to create order: 创建订单失败
index-Th5hJOs5.js:338 [Payment Error] 支付服务暂时不可用: 创建订单失败
Analysis:
- The error
支付服务暂时不可用maps toCROSSMINT_ERRORinerrorCodes.ts. - The root cause message is
创建订单失败(Failed to create order). - The error originates in
PaymentOrchestratorduring thecreatePaymentSessionflow. - The likely source is
CrossmintService.initializeCheckoutthrowing an error or a backend API call failing.
The NEXT_PUBLIC_CROSSMINT_CLIENT_API_KEY environment variable is missing or invalid in the frontend environment. The CrossmintService checks for this key and throws an error if missing. The error message might be localized to "创建订单失败" in the user's specific build/environment.
The PaymentOrchestrator or CrossmintService might be attempting to create a backend order (e.g., via PaymentApiService) before initializing Crossmint. If the backend returns a 500 error or a specific error message "创建订单失败", this would propagate to the UI.
The Crossmint SDK (@crossmint/client-sdk-react-ui) might be failing to initialize due to network restrictions, invalid lineItems (e.g., invalid price format), or unsupported browser environment.
- Verify Configuration: Check if
NEXT_PUBLIC_CROSSMINT_CLIENT_API_KEYis set in.envor Vercel config. - Inspect Backend Logs: Check
api/ornofx-backendlogs for any 500 errors corresponding to the timestamp. - Enhance Frontend Logging: Add detailed error logging in
PaymentOrchestrator.tsto capture the full stack trace and original error object, not just the message.
- Improve Error Handling: Modify
PaymentOrchestrator.tsto log the full error object. - Validate Configuration: Update
CrossmintService.tsto strictly validate configuration and throw specific, English-language error codes (e.g.,MISSING_API_KEY) that can be mapped to user-friendly messages. - Check Backend: If a backend endpoint exists for order creation, ensure it returns structured error codes.
- Step 1: Modified
web/src/features/payment/services/PaymentOrchestrator.tsto log detailed error info. - Step 2: Modified
web/src/features/payment/services/CrossmintService.tsto ensure clear API key validation and better error messages.