Payment Lifecycle
Overviewβ
This document outlines the complete payment lifecycle in the Wallet Payment Service. It describes the various states a payment can transition through from initialization to completion, supporting both card and bank account payment methods.
Payment Methodsβ
The Wallet Payment Service supports the following payment methods:
- Card Payments: Credit and debit card transactions
- Bank Account Payments: ACH transfers
Payment Vendorsβ
The system integrates with multiple payment processing vendors:
- STRIPE
Payment Lifecycle Stagesβ
1. Payment Creationβ
The payment lifecycle begins with the creation of a payment through one of three entry points:
- Guest Payment: One-time payment without saving payment details
- User Payment: Payment with a logged-in user
- Merchant-Initiated Payment: Payment triggered by a merchant
Initial Statesβ
INITIATED: The payment has been created but processing has not yet startedPENDING: The payment request is being processed
2. Customer Creation/Validationβ
Before processing the payment, the system validates or creates customer records:
States During Customer Handlingβ
PENDING_FOR_CUSTOMER_CREATION: The payment is waiting for customer record creationFAILED: Customer creation failed, preventing payment from proceeding
3. Payment Method Processingβ
The system processes the payment method based on whether it's saved, new, or a guest payment:
States During Payment Method Handlingβ
PENDING_FOR_PAYMENT_METHOD_CREATION: Waiting for payment method to be created/validatedPAYMENT_METHOD_FAILED: Payment method validation failed but can be retriedPROCESSING: Payment is being processed with the vendorPROCESSING_DEDUP_CHECK: For pay-and-save flow, checking for duplicate payment methodsAUTH_REQUIRED: Additional authentication required from the customer
4. Payment Authorizationβ
For card payments, an authorization step may occur:
Authorization Statesβ
AUTHORIZED: Payment has been authorized but not yet capturedACCEPTED: Payment has been accepted by the system (specific to certain flows)
5. Payment Confirmation and Captureβ
After authorization, payments can be confirmed and funds captured:
Confirmation Statesβ
CONFIRMATION_INITIALIZED: Payment confirmation has been initiatedCAPTURE_INITIALIZED: Fund capture has been initiatedCANCEL_INITIALIZED: Payment cancellation has been initiatedCANCEL_FAILED: Payment cancellation attempt failed
6. Final Payment Statesβ
Payments ultimately reach one of these terminal states:
Terminal Statesβ
COMPLETED: Payment successfully processed and funds transferredFAILED: Payment processing failedCANCELED: Payment was canceled before completion
Payment Flow Typesβ
Standard Payment Flowβ
INITIATEDβPROCESSINGβCOMPLETED/FAILED
Authorization and Capture Flowβ
INITIATEDβPROCESSINGβAUTHORIZEDβCAPTURE_INITIALIZEDβCOMPLETED/FAILED
Customer Creation Flowβ
INITIATEDβPENDING_FOR_CUSTOMER_CREATIONβINITIATEDβ (standard flow continues)
Payment Method Creation Flowβ
INITIATEDβPENDING_FOR_PAYMENT_METHOD_CREATIONβINITIATEDβ (standard flow continues)
Pay and Save Flowβ
INITIATEDβPROCESSING_DEDUP_CHECKβPROCESSINGβCOMPLETED/FAILED
Payment Cancellation Flowβ
- Any state β
CANCEL_INITIALIZEDβCANCELED/CANCEL_FAILED
Error Handlingβ
The payment service handles various error conditions:
- Payment Method Errors: Issues with the payment instrument like expired cards, insufficient funds
- Customer Creation Errors: Problems creating or finding customer records
- Merchant Configuration Errors: Issues with merchant setup or allowed payment methods
- Vendor Errors: Issues from payment processing vendors
- Internal Errors: System errors within the payment service
Payment Retry Mechanismβ
The system allows for retry of failed payments:
- Tracks retry attempts via
retryCount - Applies maximum retry logic via
canRetry(maxRetry)check - Distinguishes between retryable failures (
PAYMENT_METHOD_FAILED) and permanent failures (FAILED)
Payment Lifecycle Diagramβ
This diagram summarizes the main payment state transitions, including customer and payment method creation, processing, authorization, capture, and cancellation flows.