The court may in its discretion require either a written undertaking with sufficient surety approved by the court or may require that cash be posted to secure compliance by the respondent with the order for support for such period. Such undertaking shall be for a definite period, not to exceed three years, and the required amount of the principal of such undertaking shall not exceed the total payments for support required for three years and shall be so stated in the order for support. After hearing and for good cause shown, the court may extend an undertaking requirement by requiring a new undertaking similar to the original undertaking. The respondent may deposit cash with the clerk, or when the court so orders, with the support collection unit designated by the appropriate social services district, when the order for support directs payments to such unit. When such cash has been deposited with the support collection unit and the respondent fails to make any payment, when due, within such period, payment shall be made by the support collection unit to the petitioner out of such cash. When cash is posted as security, as herein provided, the person or persons so posting such cash shall at the expiration of the period for which such security shall have been ordered be entitled to the return of such cash less any amount which shall have been paid therefrom to the petitioner by reason of any default or defaults in payments on the part of the respondent. The form of the undertaking and the form and manner of justification of the surety shall conform to the rules of court.