Phase 3 Complete: Fiserv Commerce Hub Integration

โœ… What's Been Completed

1. Fiserv Adapter - app/services/payment_processors/fiserv_adapter.rb

2. Fiserv Helper - app/helpers/fiserv_helper.rb

3. API Payment Session Endpoint - app/controllers/app/api/payment_controller.rb

4. Updated Payment View - app/views/app/quotes/payment.html.erb

5. Updated Routes - config/routes.rb

6. Fiserv Initializer - config/initializers/fiserv.rb

7. Environment Configuration - .env.example


๐Ÿš€ How to Use

Testing with Fiserv (Sandbox)

  1. Add Fiserv credentials to .env:

    DEFAULT_PAYMENT_PROCESSOR=fiserv
    
    FISERV_API_KEY=bG5L6qhCDXXl3M53VbbKXATU1aOZSlXx
    FISERV_API_SECRET=pOyVKDgp1lxIrXASDM9g5q84SmtqjEet
    FISERV_MERCHANT_ID=500100005000
    FISERV_HOST_URL=https://connect-cert.fiservapis.com/ch
    FISERV_ENVIRONMENT=sandbox
    
  2. Run database migrations (if not already done):

    bin/rails db:migrate
    
  3. Restart your development server:

    bin/dev
    
  4. Test the payment flow:

Switching Back to Authorize.Net

Simply change the environment variable:

DEFAULT_PAYMENT_PROCESSOR=authorize_net

Then restart your server. No code changes needed!


๐Ÿ—๏ธ Architecture Overview

Payment Flow with Fiserv

Customer โ†’ Payment Page
           โ†“
        [Frontend JavaScript]
           โ†“ (Fetch payment session)
        POST /api/payment/session
           โ†“
        FiservHelper.create_payment_session
           โ†“ (Returns session_id + public_key)
        Initialize Hosted Fields (iframes)
           โ†“ (Customer enters card data)
        Validate fields
           โ†“ (Submit form with session_id)
        POST /order/:token/process_payment
           โ†“
        PaymentProcessorFactory.for_order
           โ†“
        FiservAdapter.process_payment_with_session
           โ†“
        1. Create customer profile
        2. Tokenize via Data Capture API
        3. Authorize payment
           โ†“
        Save PaymentProfile + PaymentTransaction
           โ†“
        Redirect to complete page

Payment Flow with Authorize.Net

Customer โ†’ Payment Page
           โ†“
        [Frontend JavaScript]
           โ†“ (Customer enters card data)
        Accept.js tokenizes card data
           โ†“ (Returns payment_nonce)
        POST /order/:token/process_payment
           โ†“
        PaymentProcessorFactory.for_order
           โ†“
        AuthorizeNetAdapter.process_payment_with_nonce
           โ†“
        1. Create customer profile
        2. Create payment token
        3. Authorize payment
           โ†“
        Save PaymentProfile + PaymentTransaction
           โ†“
        Redirect to complete page

๐Ÿ“Š Database Schema

Both processors use the same database tables with processor-agnostic fields:

PaymentProfile

PaymentTransaction


๐Ÿ” PCI Compliance Improvements

Before (Authorize.Net Accept.js)

After (Fiserv Hosted Fields)


๐Ÿงช Testing Checklist

Before switching to production:


๐Ÿšจ Important Notes

Environment Variables Required

For Fiserv (Production):

DEFAULT_PAYMENT_PROCESSOR=fiserv
FISERV_API_KEY=<production_api_key>
FISERV_API_SECRET=<production_api_secret>
FISERV_MERCHANT_ID=<production_merchant_id>
FISERV_HOST_URL=https://connect.fiservapis.com/ch
FISERV_ENVIRONMENT=production

For Authorize.Net (if keeping as backup):

AUTHORIZENET_API_LOGIN_ID=<your_api_login_id>
AUTHORIZENET_TRANSACTION_KEY=<your_transaction_key>
AUTHORIZENET_SIGNATURE_KEY=<your_signature_key>
AUTHORIZENET_PUBLIC_CLIENT_KEY=<your_public_client_key>

Per-Customer Processor Selection

The factory supports per-customer processor selection:

# In customer model (future enhancement):
customer.payment_processor = 'fiserv' # or 'authorize_net'

This allows gradual migration:

  1. Keep existing customers on Authorize.Net
  2. Route new customers to Fiserv
  3. Migrate customers one-by-one as needed

๐Ÿ“ Files Changed/Created

Created:

Modified:

Previously Created (Phase 1 & 2):


๐ŸŽฏ Next Steps

1. Test in Sandbox

2. Prepare for Production

3. Migration Strategy Options

Option A: Switch All at Once

Option B: Gradual Migration

Option C: New Customers Only


๐Ÿค Benefits Achieved

โœ… Processor Agnostic - Can switch processors with one environment variable โœ… Better PCI Compliance - SAQ-A vs SAQ A-EP โœ… Cost Savings - Free processing with Fiserv โœ… Backwards Compatible - Existing Authorize.Net data still works โœ… Future Proof - Easy to add more processors โœ… Per-Customer Selection - Can route customers to different processors โœ… Better Testing - Can mock processors in tests


๐Ÿ“ž Support

Fiserv Documentation:

Sandbox Credentials:

Questions?