Troubleshoot Customer Creation During Payment
Use these failure scenarios and log messages to investigate a payment paused in PENDING_FOR_CUSTOMER_CREATION or failed during customer lookup or creation.
Common Failure Scenariosβ
| Scenario | Observed State | Recovery |
|---|---|---|
| Customer service unavailable (network timeout) | handleError() branch 2: errorGroup=INTERNAL_ERROR, httpStatus=504 GATEWAY_TIMEOUT; transaction transitions to FAILED via handlePostProcessingCommandFailure(); not publishable (504 β PUBLISHABLE_FAILED_HTTP_STATUSES); INTERNAL_ERROR β BUSINESS_RULE_VIOLATION_ERROR_GROUPS; GET returns 200 (FAILED) | Caller retries POST /v2/payments |
| Customer service returns 422 (e.g. invalid metadata key) | Post-processing wraps as UNPROCESSABLE_ENTITY/422; transaction β FAILED; event published | Caller polls GET /v2/payments β receives 422 with customer-service error detail |
| Customer service returns 4xx that is not 404 on USER_INITIATED | Same as above β preserved as 422 via PaymentException branch | Caller polls GET, discovers failure |
| Customer creation event never arrives | Transaction stays in PENDING_FOR_CUSTOMER_CREATION indefinitely | Operational alert on stale PENDING_FOR_CUSTOMER_CREATION rows; manual requeue or support escalation |
| Customer event arrives but attempt creation fails | Transaction transitions to FAILED, event published | Caller investigates via PAYMENT_UPDATED webhook |
| Duplicate customer event delivered (at-least-once delivery) | TransactionAttemptOrchestrator idempotency check returns empty Flux | No duplicate payments created |
Missing customer object (MERCHANT_INITIATED) | TransactionCommandException with no ErrorResponse β wrapped as UNPROCESSABLE_ENTITY/422; transaction β FAILED | Caller polls GET, discovers validation error |
Null customerId (USER_INITIATED) | Same as above β UNPROCESSABLE_ENTITY/422 via polling | Caller polls GET, discovers validation error |
Logging Referenceβ
Key log messages to trace this flow in Splunk / Application Insights:
| Message | Level | Location |
|---|---|---|
"Guest payment β skipping customer lookup for transaction: {merchantTransactionId}" | INFO | CustomerCheckCommand |
"Customer not found for USER_INITIATED_PAYMENT transaction: {} β transitioning to PENDING_FOR_CUSTOMER_CREATION" | INFO | CustomerCheckCommand |
"Failed to publish PENDING_FOR_CUSTOMER_CREATION event for transaction: {} β {}" | WARN | CustomerCheckCommand |
"Resuming V2 transaction {} after customer creation" | INFO | CustomerConsumer |
"Customer creation failed for transaction: {} β transitioning to FAILED" | WARN | CustomerConsumer |
"Re-triggered TransactionAttempt with {} result(s) for transaction: {}" | INFO | CustomerConsumer |
"Attempt creation failed for transaction: {} β transitioning to FAILED" | ERROR | CustomerConsumer |
"Unable to process V2 transaction on customer creation" | ERROR | CustomerConsumer |
Search query example (Splunk):
index=wallet_payment "PENDING_FOR_CUSTOMER_CREATION" OR "customer creation"
| eval flow=if(searchmatch("Resuming V2"), "resumed", if(searchmatch("FAILED"), "failed", "parked"))
| stats count by flow, merchantTransactionId
Prior to this fix, CustomerCheckCommand.isPreProcessingCommand() returned true, causing any customer-service error (e.g. invalid metadata key, 422 from customer service) to be returned synchronously as an HTTP 422. The contract requires these failures to be asynchronous. This was fixed by moving the command to post-processing (isPreProcessingCommand() = false) and adding correct PaymentException handling in handleError().
CC-12883 β Root Cause & Resolutionβ
Ticket: CC-12883
Symptom: POST /v2/payments returned 422 Unprocessable Entity synchronously when the customer object contained an invalid metadata key (e.g. a key not recognised by the customer service).
Expected: 202 Accepted always; failure surfaced via GET /v2/payments polling.
Root Causesβ
Three defects combined to produce the bug:
| # | Defect | Impact |
|---|---|---|
| 1 | isPreProcessingCommand() returned true | Customer check ran synchronously β any error became a synchronous HTTP response |
| 2 | No PaymentException branch in handleError() | Customer-service errors (delivered as PaymentException(ErrorResponse)) fell into the generic fallback, producing TransactionCommandException with no ErrorResponse β shouldPublishFailedEvent() returned false β failure invisible via polling |
| 3 | PaymentException(ErrorResponse) constructor sets no string message | throwable.getMessage() returns null β "Customer validation failed: null" in error messages without Optional guard |
Fixes Appliedβ
| File | Change |
|---|---|
CustomerCheckCommand.isPreProcessingCommand() | true β false |
CustomerCheckCommand.handleError() | Added PaymentException branch (branch 3) preserving downstream ErrorResponse with null-safe message extraction |
CustomerCheckCommand.handleError() | Added TransactionCommandException (null ErrorResponse) branch (branch 4) wrapping pre-validation failures as UNPROCESSABLE_ENTITY/422 |
End-to-End After Fixβ
POST /v2/payments (invalid metadata)
β 202 Accepted (transaction saved as INITIATED)
β async on boundedElastic
CustomerCheckCommand.execute()
β customer service returns 422
β handleError() β PaymentException branch β TransactionCommandException(errorResponse={422, UNPROCESSABLE_ENTITY})
β handlePostProcessingCommandFailure()
β transaction.status = FAILED, error = {httpStatus=422, group=UNPROCESSABLE_ENTITY}
β publishFailedTransactionEvent() [422 β PUBLISHABLE_FAILED_HTTP_STATUSES]
GET /v2/payments β FAILED + isBusinessRuleViolation() β 422 with detail
Related Documentationβ
- Payment Lifecycle States
- Single Payment Flow
- Split-Tender Payment Flow
- Pay with Wallet β the standard V2 payment flow without new-customer creation
- Error Strategy
- V2 Payment Request Lifecycle
- Commons Library
- Error Codes
- Customer Creation During Payment
- Customer Creation During Payment β Reference