tikhop / TPInAppReceipt

Reading and Validating In App Purchase Receipt Locally.
MIT License
636 stars 95 forks source link

Two active renewable IAP at a time #49

Closed chnbr closed 4 years ago

chnbr commented 4 years ago

Platform

Environment

Version

latest

Hi,

I am using the following code to process subcriptions.

      for productid in SubscriptionService.productIDs {
        if let subs = receipt.activeAutoRenewableSubscriptionPurchases(ofProductIdentifier: productid, forDate: Date()) {
          if let expDate = subs.subscriptionExpirationDate {
            print(Date(),#function, "IAP: \(productid) active until \(expDate)")
          }
        } else {
          print(Date(),#function, "IAP: \(productid) inactive")
        }
      }

I have 4 subscriptions (A,B,C,D) which are put into (ASC) levels (1,2,3,4) respectively. All are in the same subscription group.

I did test purchase all the IAPs in the order D-C-B-A, i.e. from level 4 to level 1.

According to Apple there should be only ONE active subscription at a time in a group. However in Sandbox I experience this:

2020-05-28 07:10:11 +0000 requestDidFinish(_:) IAP: receipt request successful, now restoring completed transactions
2020-05-28 07:10:11 +0000 processReceipt() IAP: Found 27 purchases
2020-05-28 07:10:11 +0000 processReceipt() IAP: A_yearly_universal active until 2020-05-28 07:28:00 +0000
2020-05-28 07:10:11 +0000 processReceipt() IAP: B_yearly active until 2020-05-28 07:27:09 +0000
2020-05-28 07:10:11 +0000 processReceipt() IAP: C_monthly_universal inactive
2020-05-28 07:10:11 +0000 processReceipt() IAP: D_monthly inactive

How can A and B be active at the same time, since all my subscriptions are in the same subscriptions group ? Is this an issue with ASC or with TPInAppReceip ?

Thanks Christian

tikhop commented 4 years ago

Interesting... might be only a sandbox issue. Could you please share your local receipt and I will take a look. You can send me email or upload it somewhere. Thanks, P

tikhop commented 4 years ago

@chnbr here is my email: tikhop at gmail.com

chnbr commented 4 years ago

Hi,

Waht is the easiest way to store it to file ? I only handle it in memory normally…

Regards Christian

Am 28.05.2020 um 10:28 schrieb Pavel Tikhoneko notifications@github.com:

Interesting... might be only a sandbox issue. Could you please share your local receipt and I will take a look. You can send me email or upload it somewhere. Thanks, P

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

-- Dr. Christian Neubauer Phone: +49 911 3774877 Händelstr. 2 Fax: +49 911 5805990 D-90491 Nürnberg Mobil: +49 179 5906913

tikhop commented 4 years ago

You can print a base64 string, copy and past it into a text file.

let base64Receipt = receipt.base64

Best, P

tikhop commented 4 years ago

Hi @chnbr,

I just tried to reproduce the issue and got two active subscriptions where the first didn't have cancelation date.

The only way to know whether a subscription has been expired or canceled is to check these two properties of the InAppPurchase:

subscriptionExpirationDateString cancellationDateString

Based on Apple Documentation cancellationDateString is not available in sandbox.

https://developer.apple.com/documentation/appstorereceipts/cancellation_date_ms

I can implement an extra method for retrieving the last purchased subscription which is still active.

Best, P

chnbr commented 4 years ago

Hi,

Thanks for investigating this. Sorry that I didn’t respond yet. I yesterday went on holiday with my wife and mit time is limited regarding programming….

Is the cancelation issue handled correctly in production ? If itÄs only a problem in sandbox I don’t see any need for changes. If this could occur in production I think it should be fixed. (Just my 2 cents…)

I think I donÄt need to send you a receipt anymore, since our replicated the issue already ?

Thanks and regards Christian

Am 30.05.2020 um 01:22 schrieb Pavel Tikhoneko notifications@github.com:

Hi @chnbr,

I just tried to reproduce the issue and got two active subscriptions where the first didn't have cancelation date.

The only way to know whether a subscription has been expired or canceled is to check these two properties of the InAppPurchase:

subscriptionExpirationDateString cancellationDateString

Based on Apple Documentation cancellationDateString is not available in sandbox.

https://developer.apple.com/documentation/appstorereceipts/cancellation_date_ms

I can implement an extra method for retrieving the last purchased subscription which is still active.

Best, P

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

-- Dr. Christian Neubauer Phone: +49 911 3774877 Händelstr. 2 Fax: +49 911 5805990 D-90491 Nürnberg Mobil: +49 179 5906913

tikhop commented 4 years ago

Hi @chnbr,

I’ve double checked that it does work if cancellation date value is presented in the purchase payload. I assume that it should work in production as well based on Apple docs.

Yeah, I don’t need your receipt anymore since I was able to reproduced the same behavior. Thanks anyways.

P