Search code examples
iosin-app-purchasetitaniumappceleratorappcelerator-titanium

How to get expiration date of auto renewable-subscription


I searched a lot for solutions / at least answers for my problem or misunderstanding. There's a lot of documentation about implementing IAP native for iOS within Objective-C - that's also helpful until a specific level, but related to the implementation with TiStorekit (Appcelerator Titanium) I'm completely blocked at the moment.

Basically it's simple. I'm trying to provide some premium packages in shape of auto renewable subscriptions to the user. These products are defined in iTunesConnect and I'm able to request the product with informations about title and description. I want to understand how the process within a Titanium (TiStorekit) implementation can work out with concrete examples (that's something completely missing in the documentation). It's well explained what kind of functions and listeners you need and we're you're landing after a product is purchased for example, but never where the data of the products are and how the structure of the data is looking like.

That's bringing the whole topic for me to a kind of blackbox development & also testing works like that. From an app perspective I only wanted to know, how I can get the information when the subscription (the user bought maybe seconds ago) is expiring. Where can I find this information and how can I access this?

In all the documentations I read about the fields seems to be there and available, but I'm not able to read any expiration-date at all. From a conceptual point of view I don't have a server side validation of the receipts. I want to store the receipt of the user on the server and when he's logging in, I would load the receipt (if marked as "premium" customer) and verify against apple. If it's still valid than everything is fine and I know that it's either renewed or still within the valid duration.

I tried now everything I found within all this documentation and other articles, the only thing I achieved was to parse the receipt coming form Storekit when you restore purchases or purchasing something. The receipt contains a signature and "purchase-info", but I cannot read a single helpful attribute from that.

First of all to bring the question on a point:

Where and how (!) can I access f.e. expiration date for auto renewable subscriptions, based on a TiStorekit (Appcelerator) implementation?

Hoping for rescue, weblion


Solution

  • To get the receipt use

    Storekit.addEventListener('transactionState', function (evt) 
    
    case Storekit.TRANSACTION_STATE_PURCHASED:
    
    // Receive the receipt and decode it
    ///**********************************************
      var receiptB64String = Ti.Utils.base64encode(evt.receipt).text; 
    

    Then send it to your web server,and using a php script verify the receipt through the Apple Server.

    and you get a Json response as below:

    Valid Json
    

    { "receipt": { "original_purchase_date_pst": "2016-10-15 07:24:27 America/Los_Angeles", "unique_identifier": "2716364e7fe61118b5fbfa12eaf3a7506a5e1c32", "original_transaction_id": "1000000242683498", "expires_date": "1476826579000", "transaction_id": "1000000243499464", "quantity": "1", "product_id": "6MONTHS", "item_id": "1164542704", "bid": "com.xxxxxxx.xxxxxxx", "unique_vendor_identifier": "xxxxxx-xxx-xxxxxxxxxx", "web_order_line_item_id": "1000000033471963", "bvrs": "1.0", "expires_date_formatted": "2016-10-18 21:36:19 Etc/GMT", "purchase_date": "2016-10-18 21:06:19 Etc/GMT", "purchase_date_ms": "1476824779000", "expires_date_formatted_pst": "2016-10-18 14:36:19 America/Los_Angeles", "purchase_date_pst": "2016-10-18 14:06:19 America/Los_Angeles", "original_purchase_date": "2016-10-15 14:24:27 Etc/GMT", "original_purchase_date_ms": "1476541467000" }, "latest_expired_receipt_info": { "original_purchase_date_pst": "2016-10-15 07:24:27 America/Los_Angeles", "unique_identifier": "2716364e7fe61118b5fbfa12eaf3a7506a5e1c32", "original_transaction_id": "1000000242683498", "expires_date": "1476826579000", "transaction_id": "1000000243499464", "quantity": "1", "product_id": "6MONTHS", "item_id": "1164542704", "bid": "com.xxxxxx.xxxxxxx", "unique_vendor_identifier": "xxxxxxxx-9CB8-xxxx-B1F4-xxxxxxxxxxx", "web_order_line_item_id": "1000000033471963", "bvrs": "1.0", "expires_date_formatted": "2016-10-18 21:36:19 Etc/GMT", "purchase_date": "2016-10-18 21:06:19 Etc/GMT", "purchase_date_ms": "1476824779000", "expires_date_formatted_pst": "2016-10-18 14:36:19 America/Los_Angeles", "purchase_date_pst": "2016-10-18 14:06:19 America/Los_Angeles", "original_purchase_date": "2016-10-15 14:24:27 Etc/GMT", "original_purchase_date_ms": "1476541467000" }, "status": 21006 }

    Status 21006 means this receipt has expired. Save the information to a database in the app or on a server.