I'm testing in-app-purchase functionality and stuck in receipt validation step. My receipt validation is customized and based on number of checks I proceed on server-side(calling my server API) and one them is condition for transactionID uniqueness to confirm payment. So, using RMStore I'm getting receipt successfully and addPayment function return unique transaction to success block. After that I'm running verifyTransaction and call receiptURL inside success block. Unfortunately, it looks like I'm always get the same receipt using receiptURL and when I send it to my server it responds me with error that transactionID already exists in DB and transactionID is not unique. This error indicates that I send the same receipt even I do new payment. Please, note I use consumable product.
Can someone show me the right workflow for functions I provide below(?):
- [RMStore productRequest] - I call it right in init function.
- [RMStore addPayment] - It is start of consequence I need to understand.
- [[[RMStore defaultStore].transactionPersistor consumeProductOfIdentifier:pID] -- Do I need to call this function at all? Apple sends me unique transactinID each time I pay and calling this function has no influence.
- [[[RMStore] defaultStore].receiptVerificator verifyTransaction:transaction] -- Do I need to call transaction verification?
- [RMStore receiptURL] or [[NSBundle mainBundle] appStoreReceiptURL] -- are those ways to get receiptURL equal ? Both don't work as I expect.
- [NSData dataWithContentOfURL:receiptURL] - here is the main problem I'm experiencing. After different attempts with combination of functions I mentioned upper, this method always return the receipt with the same transactionID. This makes me think that there is a cash I need to refresh before run #5, #6 to get the last receipt, but it is not clear how to do that.
So, RMStore wiki looks good, but I always expect that library will give me a chance do not fully understand what is going on under the hood. Unfortunately for RMStore I have to investigate how Apple in app purchase API works. This can be resolved if a consequence of function calls will be provided, but I cannot find it anywhere(!)
Can someone review the list of functions I provided upper and help me with putting them in right order what let me fix my issue with getting the last receipt after the purchase I do?
I have two answers here to my questions:
The code:
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
, works fine(i.e. it return correct receipt body), but for some reason Apple can return TWO(or even array[]) payments where first transactionID can be the same as you previously got. As my server developer said this is unexpected behaviour. So, when I get receipt and send receipt to server it read only first transactionID which could be the same what you got previously.As result, server return FALSE as verification result(it looks like you try to pay twice). So, since it is not clear why Apple send me two or more transaction records in receipt, but as workaround I asked server side developer to check all transactions in receipt for any unique transactionID. More investigation is needed to understand Apple behaviour but it can take more time. I did not find the answer and go ahead for now.
What is related to RMStore workflow I realised that actually we have just two most important functions: addPayment and verifyTransaction. The addPayment function will call verifyTransaction implicitly. You should overload verifyTransaction and call serverAPI verification function inside. So, if verification is success you go to success block of addPayment and do what you need for successful payment. If not - do something else. My mistake was to call verifyTransaction inside addPayment successful block what means to call it twice.