In the dual risk model, we consider the optimal dividend and capital injection problem, which involves a random time horizon and a ruin penalty. Both fixed and proportional costs from the transactions of capital injection are considered. The objective is to maximize the total value of the expected discounted dividends, and the penalized discounted both capital injections and ruin penalty during the horizon, which is described by the minimum of the time of ruin and an exponential random variable. The explicit solutions for optimal strategy and value function are obtained, when the income jumps follow a hyper-exponential distribution.Besides, some numerical examples are presented to illustrate our results.