Check if the user has a valid auto-renewing subscription with the Parse iOS SDK

I am trying to implement an auto-renewable subscription application. Users must pay for access to all the features of my application. I already use Parse as a backend for my application. It provides some API methods for inAppPurchases, but nothing is said about the auto-renewable type. The only thing I found was two years ago, the blog says that check verification was implemented only for downloadable purchases.

I tried to use what it is called “Easy Buy” in the docs and it works great, but I can’t figure out how I can check if my user has already bought a subscription or not.

Does anyone know if there is a way to do this using the Parse API or should it be implemented differently?

+6
source share
1 answer

As already mentioned, validation validation is only built into the Parse SDK for downloadable content, but it’s quite simple to create a cloud-based code function that sends a request to the application in the iTunes Store for verification. Here are the Apple docs for server-side validation : Checking checks using the App Store

Here's what the main function looks like:

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'); } }); }); 

For more information on interpreting a JSON receipt, see Receive Fields . It's pretty simple for iOS 7+, but automatically updating subscription receipts for iOS 6 and earlier is tedious.

+4
source

Source: https://habr.com/ru/post/978460/


All Articles