# Generic Gateway Architecture Demo # This script demonstrates the new generic gateway architecture that we've implemented. # Instead of having separate MPGS tables, we now use the existing pos_transaction tables # with generic gateway fields and JSON metadata for gateway-specific data. import DaProductApp.Repo import Ecto.Query alias DaProductApp.Acquirer.GenericProcessor alias DaProductApp.Acquirer.Schemas.{PosTempTransaction, PosTransaction} alias DaProductApp.Transactions # Demo configuration mpgs_config = %{ mpgs_config: %{ merchant_id: "TEST_MERCHANT", api_base_url: "https://ap-gateway.mastercard.com", api_version: "63" }, network_name: "MPGS_TEST" } # Sample transaction message sample_transaction = %{ field_41: "12345678", # Terminal ID mti: "0200", # Purchase request field_3: "000000", # Processing code (purchase) field_4: "1000", # Amount (10.00) currency_code: "840", # USD masked_pan: "411111****1111", amount: Decimal.new("10.00") } IO.puts """ === Generic Gateway Architecture Demo === šŸŽÆ Key Benefits: āœ… Works for ANY gateway (MPGS, VISA, AMEX, etc.) āœ… Clean existing schema - no gateway-specific fields āœ… Flexible JSON metadata for gateway-specific data āœ… Easy reporting across all gateways āœ… Future-proof architecture šŸ—ļø Database Changes Added: - gateway_type: "MPGS", "VISA", "AMEX", etc. - gateway_reference_id: Gateway's transaction ID - gateway_status: "PENDING", "SUCCESS", "FAILED" - processing_state: "CREATED", "PROCESSING", "COMPLETED" - settlement_date: Settlement date - settlement_status: "PENDING", "SETTLED" - metadata: JSON field with gateway-specific data šŸ“Š Current Tables: - pos_temp_transaction: Processing/pending transactions with gateway fields - pos_transaction: Final transactions with gateway fields - payment_methods: Reusable across all gateways (kept from Phase 4) šŸ”„ Usage Pattern: 1. GenericProcessor.process_transaction("MPGS", config, transaction_data) 2. Gateway-specific processor handles the transaction 3. Response stored with standardized metadata structure 4. GenericProcessor.finalize_transaction() moves to permanent storage šŸ“ˆ Reporting Examples: - Cross-gateway volume reports - Settlement reconciliation - Failed transaction analysis - Gateway performance comparison šŸš€ Next Steps: 1. Test MPGS integration with new architecture 2. Add VISA processor using same pattern 3. Implement settlement reporting 4. Add gateway-specific queries using JSON functions šŸ’” Example Metadata Structure (MPGS): { "gateway": { "type": "MPGS", "version": "63", "session": {"id": "SESSION_123", ...}, "response": {"authorization_code": "123456", ...}, "settlement": {"batch_id": "BATCH_20250103", ...} } } This architecture is clean, flexible, and scales to any number of gateways! šŸŽ‰ """ # Example of how to use the new architecture IO.puts "\n=== Example Usage ===" try do # This would process a transaction through MPGS using the generic architecture IO.puts "1. Process transaction: GenericProcessor.process_transaction(\"MPGS\", config, transaction)" IO.puts "2. Store with metadata: All gateway-specific data in JSON metadata field" IO.puts "3. Query examples: Transactions.list_transactions_by_gateway(\"MPGS\")" IO.puts "4. Settlement: Transactions.settlement_reconciliation(Date.utc_today())" IO.puts "\nāœ… Generic Gateway Architecture is ready for testing!" rescue e -> IO.puts "Note: #{Exception.message(e)}" end