contract PaymentMasterFactory {

	// payment master logic contract address
	address public masterLogicAddress ;
	address public handlerLogicAddress;

	// Events triggered for listeners
	event MasterCreated(address indexed _addr);

	/** Deploy the payment handler logic contract */
	constructor() public {
		deployLogic();
	}

	/**
	 * Called by the constructor this function deploys impl contracts
	 */
	function deployLogic() internal {
		// Deploy the new master contract
		PaymentMaster createdMaster = new PaymentMaster();
		masterLogicAddress = address(createdMaster);

		// Deploy the new handler contract
		PaymentHandler createdHandler = new PaymentHandler();
		handlerLogicAddress = address(createdHandler);

		// initialize the deployed contracts - not needed but just in case
		createdHandler.initialize(createdMaster);
		createdMaster.initialize(msg.sender, address(handlerLogicAddress));
	}

	/**
	Called to create a new payment master and emit an event
	 */
	function deployNewMaster(address owner) public {
		// Deploy the new Proxy contract with the handler logic address
		Proxy createdProxy = new Proxy(masterLogicAddress);

		// instantiate a PaymentMaster contract at the created Proxy address
		PaymentMaster proxyMaster = PaymentMaster(address(createdProxy));

		// Initialize with the owner address and logic impl address
		proxyMaster.initialize(owner, address(handlerLogicAddress));

		// Emit the event that a new master was deployed
		emit MasterCreated(address(proxyMaster));
	}
}
/**
 Deploys new instances of the Payment Master
 */
function deployNewMaster(address owner) public {
	// Deploy the new Proxy contract with the handler logic address
	Proxy createdProxy = new Proxy(masterLogicAddress);

	// instantiate a PaymentMaster contract at the created Proxy address
	PaymentMaster proxyMaster = PaymentMaster(address(createdProxy));

	// Initialize with the owner address and logic impl address
	proxyMaster.initialize(owner, address(handlerLogicAddress));

	// Emit the event that a new master was deployed
	emit MasterCreated(address(proxyMaster));
}

/**
 	Called to create a new payment master and emit an event
 	 */