Example of adding multi-record custom fields to a contact via API
To clarify this scenario: you must be talking about muti-record contact custom data and not contribution custom data (which only supports single-records currently).

I recommend you use hook_civicrm_postProcess to insert code to store the data on form submission. This code inside your implementation of the hook should use the CustomValue API to save the data. You'll find documentation and examples of how to use it in the API explorer.