I need it to return a payment to one of the sending addresses.
No!
No, no, no.
Just no.
In Bitcoin, there's no such thing as a "sending address". DO NOT try to guess at a return address from the inputs of a transaction. Doing so WILL eventually result in lost bitcoins and angry users. If you want to send bitcoins to someone, ASK THEM TO PROVIDE a receiving address, then use the address they give you.
There are just SO MANY ways that guessing a user's address from inputs will result in you using an incorrect address.