CiviCRM membership component
This functionality already exists in CiviCRM; however, by default it isn't exposed to the UI.  Look in the database at civicrm_membership_log.

The main difference between what you're describing and what exists is that the contribution isn't tied directly to the civicrm_membership_log record.  Instead of an extension, you may want to extend civicrm_membership_payment to include a foreign key to the appropriate civicrm_membership_log entry.  

Alternatively, you can most likely write an extension to correlate contributions and membership periods in the log by date for display in the UI.