chrismaddern/validate-in-app-purchase-iphone-ios-receipts — pull request #3 by letharion (2013-10-02 10:59:29+00:00)
Title: Move all print statements outside of the validateReceipt function to make it more re-usable.

In order to allow the validateReceipt function to be used in a wide variety of situations, I think it would be preferable if it didn't have hard coded print statements in it.

In this PR I've tried to move all the print statements out to the sample code at the bottom, which is primarily the choice of environment. That is now printed with the sample code at the bottom, and instead of passing in the $isSandbox variable, I now pass in the endpoint directly. We could still set the $endpoint inside validateReceipt if you want, but I like it better this way, as it makes it easy to add/change the urls in the future. For example, apple might add a "https://beta.itunes.apple.com/verifyReceipt" for testing new versions of their API, or I might run a local test service that pretends to be itunes.

Second, I now stick the error code into the exception instead of printing it. Now sure if that's optimal, but it looks nicer to me, as we can now easily use that exception to react in different ways to different status codes.