I've been working on my first project for an iPhone app that uses in-app purchasing capabilities. In the process I encountered and fell through quite a few pitfalls. This is my attempt to document my ordeal, and help those who are experiencing the same issues.
When trying to test with the sandboxed App Store I got errors like : "Cannot connect to iTunes Store", or "Invalid Product Id". Getting things working in that environment is quite tricky, and you need to follow exactly the steps that Apple expects. So in other words, RTFM. The problem is that you need to have the right manual. I had followed the instructions from a book, which turned out to be incomplete, out-of-date and in some cases flat out wrong. Your best bet is to read the latest docs coming straight from Apple, as this is their technology and is subject to change.
I found a fine doc that helped me tremendously at http://developer.apple.com/library/ios/#technotes/tn2009/tn2259.html. You may also check out the dev forums at http://devforums.apple.com, for any current issues with the sandbox, or good advice.
Turns out that the root cause of my issues was the fact that:
1. I didn't have all contracts and banking/tax details set up in my iTunes Connect account
2. I was using a provisioning profile tied to a wildcard app id, which is not supported for in-app purchase
I wish Apple's tools were able to catch such errors, or the error messages at run time were more explicitly pointing to the real issue.
Getting iTunes Connect find my bank was tricky too. They're trying to look up banks based on transit number. It turns out that's not what's commonly referred to as transit numbers in Canada (usually 5 digits). No, to that you need to prepend the bank number (3 digits in my case). Your best bet is to search for the bank name and location, just make sure to use the full name instead of the commonly used abbreviations made up of initials.