I'm with @JeffSchwenk you probably need an intermediate program to process the data from the 3rd party vendor. I've never had much luck getting the data provider to send anything other than data they capture from the original transaction (who, date, amt paid, and check number). Sometimes they can provide the distribution but not every customer provides a check stub with the payment distribution. If the payment comes in via ACH, there won't be any distribution info.
As such, we generally have to do the calculation of the payment application via a logic routine and that logic is rarely the same between two customers. If your lucky, it will be a FIFO process. However, late fee's, open adjustments, and partial payments always get to be a challenge.
On prepayments, are you using PO's? If so, your payment needs to go to a GL account rather than a prepaid invoice and the PO document needs to be updated.
Workflow automation is always fun. The workflow and decision tree definition is the critical starting point.