Whenever a child is committed by the court to the custody of other than that of his parents, or is given medical, psychological or psychiatric treatment under order of the court, and no provision is otherwise made by law for the support of such child or payment for such treatment, compensation for the care and treatment of such child, when approved by order of the court, shall be charged upon the territory. The court may, after giving the parent a reasonable opportunity to be heard, order that such parent shall pay in such manner as the court may direct, such sum, within his ability to pay, as will cover in whole or in part the support and treatment of such child. If such parent shall willfully fail or refuse to pay such sum, the court may proceed against him as for contempt.