If money has been deposited instead of bail, and the defendant, at any time before the forfeiture thereof, surrenders himself or herself to the officer to whom the commitment was directed, in the manner provided in Sections 1300 and 1301, the court shall order a return of the deposit to the defendant or to the person or persons found by the court to have deposited said money on behalf of the defendant, upon the production of the certificate of the officer showing the surrender, and upon a notice of five days to the district attorney, with a copy of the certificate.