I have set up a sandbox user and successfully subscribed them to a one-month auto-renewable subscription on my iPhone device. How can I detect whether or not the user's subscription has ended?
I have the following code:
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
It will eventually call this method and logic:
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
for (SKPaymentTransaction *transaction in queue.transactions) {
if (transaction.transactionState == SKPaymentTransactionStateRestored) {
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
[self setSubscriptionActive]; // <-- Probably not the right way to restore subscriptions?
return; // Return because we have successfully set the subscribed state of the app.
}
}
[self purchase:self.validProduct]; // No valid transactions, so ask them to purchase.
}
My problem is that given my current logic, its been two hours now and this test user always gets to the line of code, [self setSubscriptionActive];
, thus the only payment I've made under his test account always returns SKPaymentTransactionStateRestored
. I would expect it to expire by now according to the documentation from Table 3-1 (Subscription durations for testing)...so now I am wondering, am I doing something wrong, and/or does anyone know what the correct way is of validating whether or not this one-month/timely subscription has expired?
I even tried to JSON query the receipt on Apple's sandbox server, following their Receipt Validation articles. Look at this data carefully and see for yourself how broken this all is:
"original_purchase_date" = "2013-08-01 07:00:00 Etc/GMT";
"original_purchase_date_ms" = 1375340400000;
"original_purchase_date_pst" = "2013-08-01 00:00:00 America/Los_Angeles";
"receipt_creation_date" = "2016-08-18 01:05:09 Etc/GMT";
"receipt_creation_date_ms" = 1471482309000;
"receipt_creation_date_pst" = "2016-08-17 18:05:09 America/Los_Angeles";
"receipt_type" = ProductionSandbox;
"request_date" = "2016-08-18 01:05:09 Etc/GMT";
"request_date_ms" = 1471482309971;
"request_date_pst" = "2016-08-17 18:05:09 America/Los_Angeles";
There's two problems I see:
This is the first purchase, but yet it shows an
original_purchase_date
of2013-08-01 07:00:00 Etc/GMT
. I purchased it today. This time is nowhere near August 17th. This is very much incorrect.receipt_creation_date
is2016-08-18 01:05:09 Etc/GMT
.request_date
is2016-08-18 01:05:09 Etc/GMT
...I would have had to make the web request the split second I created the receipt. I am assuming sincerequest_date
(like much of this garbage API) isn't documented its the effective internet time so you can use it to compare (instead of the local time) the delta time between it and thereceipt_creation_date
. God this is such a nightmare...why would anyone let anyone make such a complicated, ridiculous back-end system like this? This is absolutely horrible. Its such a shame, because Apple's other API's have generally been good.