如何查看订阅是否已取消? [英] How to check if a subscription has been cancelled?

查看:165
本文介绍了如何查看订阅是否已取消?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已要求我自己的应用每月订阅退款.苹果给了我退款.但是我的订阅仍然有效,可以使用高级功能.

I have requested a refund on my own app’s monthly subscription. Apple gave me the refund. But my subscription is still active and I can use the premium features.

我的应用每次使用收据时都会检查收据的有效性,这证明收据的有效期限一直有效.

My app is checking the validity of the receipt every time I use it, this proves that the receipt's expiry date has remained valid.

这就是我检查的方式.尽管它是在服务器上的Python中编写的,但我希望代码足够清晰,任何人都可以理解:

This is how I check for it. Although it is in Python on my server, I hope the code is clear enough for anyone to understand:

def verify_receipt(receipt):
    r = requests.post(config.APPLE_STORE_URL, json=Subscription.produce_receipt_with_credentials(receipt))
    now = datetime.utcnow()
    if 'latest_receipt_info' in r.json():
        for item in r.json()['latest_receipt_info']:
            dt, tz = item['expires_date'].rsplit(maxsplit=1)
            expires_date = datetime.strptime(dt, '%Y-%m-%d %H:%M:%S').replace(tzinfo=pytz.timezone(tz))
            expires_date = expires_date.astimezone(pytz.utc)
            expires_date = expires_date.replace(tzinfo=None)
            if expires_date > now:
                return True, expires_date, r.json()['latest_receipt'], item
    else:
        current_app.logger.info('latest_receipt_info not found: %s', r.json())
    return False, None, None, None

基本上,我正在检查每个收据的"expires_date"的"latest_receipt_info"集合中.如果将来至少要设置其中之一,则保费支票有效.

Essentially I'm checking within the collection of ‘latest_receipt_info’ for each receipt's ‘expires_date’. If at least one of them is set in the future, then the premium check is valid.

但就我而言,即使Apple已退还该订阅,他们仍将其保持激活状态,直到下一次续订.

But in my case even though that Apple has refunded the subscription, they left it active until the next renewal.

那么定期检查收据又有什么意义呢?要是我们无法赶上提前取消?

So what is the point of checking the receipt regularly then? If we can't catch early cancellation?

现有用户只将有效期保存在UserDefaults中,并在有效期到期时本地检查,然后然后检查下一张收据的有效性,是否会更高效,更快捷?

Wouldn’t be more efficient and faster for the existing users to just save the expiry date in UserDefaults and check locally when the expiry date has expired and then check for the validity of the next receipt?

SWIFT:

UserDefaults.standard.set(expiryDate,forKey:Constants.expiryDate)

更新:

那么根据我收到的答案,我想在最新收据中这些字段旁边是 cancellation_reason cancellation_date 吗?

So based on the answer I have received, I suppose the cancellation_reason and cancellation_date will be next to these fields in the latest receipt?

"latest_receipt_info": [
    {
      "quantity": "1",
      "product_id": "com.x.sub.weekly",
      "transaction_id": "100000053x",
      "original_transaction_id": "100000053x",
      "purchase_date": "2019-06-03 19:52:05 Etc/GMT",
      "purchase_date_ms": "1559591525000",
      "purchase_date_pst": "2019-06-03 12:52:05 America/Los_Angeles",
      "original_purchase_date": "2019-06-03 19:52:06 Etc/GMT",
      "original_purchase_date_ms": "1559591526000",
      "original_purchase_date_pst": "2019-06-03 12:52:06 America/Los_Angeles",
      "expires_date": "2019-06-03 19:55:05 Etc/GMT",
      "expires_date_ms": "1559591705000",
      "expires_date_pst": "2019-06-03 12:55:05 America/Los_Angeles",
      "web_order_line_item_id": "10000000x",
      "is_trial_period": "false",
      "is_in_intro_offer_period": "false"
      "cancellation_reason": "0", 
      "cancellation_date" "2019-06-03 21:55:05 Etc/GMT"
    },

我希望有一种方法可以模仿这一点.如何基于

I wished there was a way to emulate this. How can I code against this based on the docs and go to production without being really able to test it?

推荐答案

要退款,您需要检查 cancellation_reason 字段,该字段将表明客户支持已退款给用户.还有一个 cancellation_date (取消日期)将指示取消发生的时间.

For refunds you need to check the cancellation_reason field which will indicate that customer support refunded the user. There will also be a cancellation_date that will indicate when the cancellation occurred.

如果该字段存在,那么您的保费支票应该无效:

If that field is present then your premium check should be invalid:

对已取消的收据进行处理,就像从未进行过购买一样制成.

Treat a canceled receipt the same as if no purchase had ever been made.

这篇关于如何查看订阅是否已取消?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆