You should never try to guess what address to send bitcoins to. If you guess wrong, then the bitcoins are permanently lost.
You should never look at inputs to try to figure out where bitcoins should be sent "back" to, since the original sender might not have control of that address.
Instead you should ALWAYS ask your users where they want their bitcoins sent. You should allow them to enter a bitcoin address, and then send the bitcoins to the entered address.
(There's no such thing as a "sending address". Attempting to guess at a "return address" by looking at the previous outputs that were used to supply value for the inputs of a transaction is a good way to cause frustration, lose money, and create confusion.)