Whenever any consular officer collects, or knowingly allows to be collected for any service, any other or greater fees than are allowed by law for such service, he shall, besides his liability to refund the same, be liable to pay to the person by whom or in whose behalf the same are paid, treble the amount of the unlawful charge so collected, as a penalty, to be recovered with costs, in any proper form of action, by such person for his own use. And in any such case the Secretary of the Treasury may retain, out of the compensation of such officer, the amount of such overcharge and of such penalty, and charge the same to such officer in account, and may thereupon refund such unlawful charge, and pay such penalty to the person entitled to the same if he shall think proper so to do.