检查用户是否具有Parse iOS SDK的有效自动续订订阅 [英] Check if user has valid auto-renewable subscription with Parse iOS SDK

查看:243
本文介绍了检查用户是否具有Parse iOS SDK的有效自动续订订阅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用自动续订订阅来实现应用程序。用户应该付费访问我的应用程序的所有功能。我已经将Parse用作我的应用程序的后端。它为inAppPurchases提供了一些API方法,但没有任何关于自动更新类型的说法。我发现的唯一一件事是在博客中有两年的线程,据说收据验证只针对可下载的商品实施。

I'm trying to implement an application with auto-renewable subscription. Users should pay to access all functions of my application. I already use Parse as backend for my application. It provides some API methods for inAppPurchases but there is nothing said about auto-renewable type. The only thing I have found is some two years old threads in the blog it is said that receipt verification was implemented only for downloadable purchases.

我试过用它作为它在文档简单购买中调用,它工作正常但我无法弄清楚如何检查我的用户是否已经购买了订阅。

I have tried to use as it called in docs "Simple purchase" and it works fine but I can't figure out how can I check if my user already bought subscription or not.

有谁知道是有没有办法通过Parse API或者这应该以另一种方式实现?

Does anybody know is there way to do it via Parse API or This should implemented in another way?

推荐答案

如上所述,收据验证仅内置于用于可下载内容的Parse SDK,但创建一个将应用程序收据POST到iTunes Store进行验证的Cloud Code功能非常简单。以下是用于服务器端验证的Apple文档:验证收据App Store

As mentioned, receipt validation is only built into the Parse SDK for downloadable content, but it is fairly simple to to create a Cloud Code function that POSTs the app receipt to the iTunes Store for validation. Here are the Apple docs for server side validation: Validating Receipts with the App Store

这是基本功能的样子:

Parse.Cloud.define('validateReceipt', function (request, response) {
    var receiptAsBase64EncodedString = request.params.receiptData;
    var postData = {
        method: 'POST',
        url: 'http://buy.itunes.apple.com/verifyReceipt',
        body: { 'receipt-data': receiptAsBase64EncodedString,
                'password': SHARED_SECRET }
    }

    Parse.Cloud.httpRequest(postData).then(function (httpResponse) {
        // httpResponse is a Parse.Cloud.HTTPResponse
        var json = httpResponse.data; // Response body as a JavaScript object.
        var validationStatus = json.status; // App Store validation status code
        var receiptJSON = json.receipt; // Receipt data as a JSON object

        // TODO: You'll need to check the IAP receipts to retrieve the
        //       expiration date of the auto-renewing subscription, and
        //       determine if it is expired yet.
        var subscriptionIsActive = true;

       if (subscriptionIsActive) {
           return response.success('Subscription Active');
       }
       else {
           return response.error('Subscription Expired');
       }
    });
});

参见收据字段,了解有关解释收据JSON的详细信息。对于iOS 7+来说,这是相当直接的,但iOS 6及更早版本的自动续订订阅收据很乏味。

See Receipt Fields for details on interpreting the receipt JSON. It's fairly straight forward for iOS 7+, but auto-renewing subscription receipts for iOS 6 and earlier are tedious.

这篇关于检查用户是否具有Parse iOS SDK的有效自动续订订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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