1 package epayment.processor; 2 3 import epayment.framework.IGatewayAdapter; 4 import epayment.framework.IPaymentCommand; 5 import epayment.framework.IPaymentResponse; 6 import epayment.framework.PaymentException; 7 8 20 21 public class PaymentProcessor { 22 23 private IGatewayAdapter _adapter; 24 private static PaymentProcessor _processor; 25 26 30 public PaymentProcessor() { 31 32 try { 33 34 PaymentProcessorConfigurator configurator = 35 new PaymentProcessorConfigurator(); 36 configurator.configure(this); 37 38 } catch(Exception e) { 39 System.err.println("Payment processor configuration error: " + 40 e.getMessage()); 41 } 43 } 44 45 51 public PaymentProcessor(IGatewayAdapter adapter) { 52 setGatewayAdapter(adapter); 53 } 54 55 60 public static PaymentProcessor getProcessor() { 61 if (_processor == null) { 62 _processor = new PaymentProcessor(); 63 } 64 return _processor; 65 } 66 67 72 protected void setGatewayAdapter(IGatewayAdapter adapter) { 73 _adapter = adapter; 74 } 75 76 85 public IPaymentResponse process(IPaymentCommand command) 86 throws PaymentException { 87 88 return command.execute(_adapter); 89 } 90 } 91 | Popular Tags |