Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

[Solved] UnityIAP Subscription Purchase

Discussion in 'Unity IAP' started by siddharth3322, Feb 1, 2017.

Thread Status:
Not open for further replies.
  1. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    639
    Basically I want to setup UnityIAP for implementation of weekly or monthly subscription for apple store game. I completely read following article given by Unity:

    https://unity3d.com/learn/tutorials/topics/analytics/integrating-unity-iap-your-game?playlist=17123

    After this I become aware with actual implementation but i have following questions arise:
    1. how we can get information about subscription already purchased by this user?

    2. how we track time for auto renewable subscription purchase?
    Please give me some information about this.
     
  2. Kamil-Says

    Kamil-Says

    Joined:
    Jun 30, 2014
    Posts:
    154
    I'm not apple dev but this would look like this:

    Code (CSharp):
    1. public void CheckIfSubscriptionIsActive(){
    2.         ConfigurationBuilder builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    3.         // Get a reference to IAppleConfiguration during IAP initialization.
    4.         IAppleConfiguration appleConfig = builder.Configure<IAppleConfiguration>();
    5.         if (!string.IsNullOrEmpty (appleConfig.appReceipt)) {
    6.             Debug.Log (appleConfig.appReceipt);
    7. //            InstantiateDebugText (DebugInfoPanel, "APP Receipt Base64 " + appleConfig.appReceipt);
    8.             var receiptData = System.Convert.FromBase64String (appleConfig.appReceipt);
    9. //            InstantiateDebugText (DebugInfoPanel, "receipt Data "+ receiptData);
    10.             AppleReceipt receipt = new AppleValidator (AppleTangle.Data ()).Validate (receiptData);
    11.             InstantiateDebugText (DebugInfoPanel, "Apple receipt " + receipt);
    12.             foreach (AppleInAppPurchaseReceipt productReceipt in receipt.inAppPurchaseReceipts) {
    13.                 Debug.Log ("PRODUCTID: " + productReceipt.productID);
    14.                 Debug.Log ("PURCHASE DATE: " + productReceipt.purchaseDate);
    15.                 Debug.Log ("EXPIRATION DATE: " + productReceipt.subscriptionExpirationDate);
    16.                 Debug.Log ("CANCELDATE DATE: " + productReceipt.cancellationDate);
    17.                 InstantiateDebugText (DebugInfoPanel, "PRODUCTID: " + productReceipt.productID);
    18.                 InstantiateDebugText (DebugInfoPanel, "PURCHASE DATE: " + productReceipt.purchaseDate);
    19.                 InstantiateDebugText (DebugInfoPanel, "EXPIRATION DATE: " + productReceipt.subscriptionExpirationDate);
    20.                 InstantiateDebugText (DebugInfoPanel, "CANCELDATE DATE: " + productReceipt.cancellationDate);
    21.             }
    22.         }
     
    siddharth3322 likes this.
  3. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    639
    @Kamil-Says Thanks for your quick reply.
    I got your point regarding above code, you mentioned.

    One more question regarding this, for ex one user has purchased subscription for a week and now say, week is passed for him. Then how can I detect that for this user subscription is over? I can't take reference of current iPhone date and time because it may be possible, user will change that. so what is actual way for deciding expiration of subscription?
     
  4. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,236
    You have to implement server-side receipt verification that checks for the validity of the receipt remotely and returns the result back to the client.
     
    siddharth3322 likes this.
  5. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    639
    @Baroni Then what is difference between if you create consumable product or subscription product in Apple Store?
    If we have to manage subscription duration by ourself....

    Please give me reply for this, its really necessary for this.
     
  6. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,236
    @siddharth3322 consumable products do not get invalid at a certain point later, they are consumed immediately and accessible only once right after the purchase. Thus you don't need to check receipts for consumable products. Non-consumable products usually cannot expire either and are returned when the user restores his/her transactions on (another) device, so no need to check these as well.

    Subscriptions on the other hand expire at some point, days or weeks are their purchase. Also, they are returned when restoring transactions too, but despite listed in the receipt, they could have expired already. You definitely want to send the receipt to your server and Apple for checking against the initial purchase date, subscription duration and current date.
     
    siddharth3322 likes this.
  7. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    639
    @Baroni Thanks for your awesome reply.
    So we require to store expiration date and time zone within our server to deal with expiration.
    Am I correct in above sentence?
    Whether we require to do anything with Apple for subscription expiration checking?
     
  8. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,236
    In a php script on your server, you have access to the date methods which return the current time. For calculating whether a subscription is expired or not, you would check the initial purchase date or expired time of products inside the receipt. The client sends a base64 encoded receipt to your server, so first you have to send that to the Apple servers, get their (source) receipt response and calculate the expiration based on that.

    I might add that we do everything of the above points in our Simple IAP System asset already, if you go with the (optional) server-side receipt validation service on our website.
     
    siddharth3322 and ap-unity like this.
  9. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    639
    @Baroni if you have published subscription related plugin in Asset Store then let me give link for that.
    Because it will reduce my task. Thanks for all above replies and give your time :)
     
  10. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,236
    I don't want to post links here to prevent an advertising war, but if you're interested then please have a look at our Simple IAP System asset on the Asset Store. In the asset description, there's a link to the services page on our website as well.
     
    siddharth3322 likes this.
  11. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    639
    More question, After setting up, Unity IAP for apple store purchase. Where is actual money get stored?
    Who provide the payment gateway?
    Apple account will hold all earned money?

    Please reply me for following questions so I can move ahead and clear understand the actual system.
     
  12. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,090
    @siddharth3322

    Unity IAP is a pass-through API, so we don’t collect money from users or pay money to developers. That is all handled by the respective stores.
     
    siddharth3322 likes this.
  13. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    639
    @ap-unity and @Baroni thanks for giving me proper information upto now. I have read few more documents and started implementation within app.

    First of all clear documentation about Subscription setup is not exist and this is really required.
    At present I have completed implementation upto successful transaction of monthly subscription product.
    But now I want further explanation into this:
    1. In which case can we use local receipt verification? because mostly its a risky thing to depend on local receipt.
    2. Whether local receipt will automatically get updated when transaction happen for auto renewal subscription?
    3. If I was depend on local receipt content then at which time I require to refresh its content?
    4. How to update local receipt content?
    5. If I was sending base64 key to my custom server, so custom server require to call on which url? Give me some document link if exist.
    6. I require to send base64 key to my custom server -> custom sever will sent this key to apple server-> apple server provide reply in json format -> custom server reply back to me json format, Is this correct step I have mentioned for subscription verification process?
    7. At which place in code I require to check for expiration of subscription? I have used following script in coding: https://unity3d.com/learn/tutorials/topics/ads-analytics/integrating-unity-iap-your-game
    8. I have purchase auto renewable subscription but in sandbox environment its not auto renewing, each time I require to purchase it for testing purpose. Is this normal process?
    I want above doubts reply so I can move ahead in implementation.
     
    Last edited: May 25, 2017
  14. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,090
    @siddharth3322

    Sorry for the delayed response.

    This will be up to your preference. It is a trade off between security and convenience.

    No, Unity IAP will only get a transaction event when the purchase happens in the app. If a subscription auto-renews (or a user subscribes outside of your app) this may not be picked up in the purchasing system.

    From the Apple documentation:
    >With this API, the app can request a new receipt if the receipt is invalid or missing.
    https://developer.apple.com/documentation/storekit/skreceiptrefreshrequest

    When you make a purchase, the local receipt is updated by the app store. You do not manually update the receipt.

    You can find Apple's receipt Validation documentation here:
    https://developer.apple.com/library...html#//apple_ref/doc/uid/TP40010573-CH104-SW1

    Server verification is outside the scope of Unity IAP. You would have to confirm this with Apple's documentation.

    Unity IAP does not do any inventory management, so you would need to parse the receipt to check for a subscription. You could do this at app start to get the most current subscription information. More details here:
    https://forum.unity3d.com/threads/how-do-i-track-auto-renewing-subscriptions.476293/#post-3108170

    I didn't find a lot of documentation for that:
    https://stackoverflow.com/questions...-a-renewal-for-an-auto-renewable-subscription
    https://forums.developer.apple.com/thread/68594
     
    unityjingyao likes this.
Thread Status:
Not open for further replies.