Featured

iPhone Phonegap plugin for In app Auto Renewable Subscription

March 27, 2013 by Sarath DR in Featured, Iphone Apps with 2 Comments

As a beginner Xcode developer I have faced some difficulties to implement the in App auto renewable subscription from the scratch. There are lots of articles on web about iPhone in app purchase. I grabbed all the ideas to implement this plugin and it is rather simple if you follow the below steps.

Step 1: Make sure that all you have provided all the information on iTunes before you start.

  • Provide all the payment information Go to your iTunes dashboard click Contracts, Tax, and Banking

Screen Shot 2013 03 26 at 18.17.55 iPhone Phonegap plugin for In app Auto Renewable Subscription

  • Set up all payment and tax information to work the app properly. This is an necessary step. Finally your payment section will be as follows.

Screen Shot 2013 03 26 at 18.20.33 iPhone Phonegap plugin for In app Auto Renewable Subscription

Step 2: Configure you Auto Renewable Subscription on iTunes.

  • You should provide all the details of the app, including screen shots and other details.
  • Make sure that your app status in now waiting to upload binary
  • Then click on Manage in app purchase link on your app details page

Screen Shot 2013 03 26 at 18.27.48 iPhone Phonegap plugin for In app Auto Renewable Subscription

  • Click Create New then you will see 5  options. Select Auto Renewable Subscription

Screen Shot 2013 03 26 at 18.30.24 iPhone Phonegap plugin for In app Auto Renewable Subscription

  • Provide necessary information for your products and select your duration. The most important part is the product id. You have to give unique name for your product. For example com.sarathdr.monthlysubscription

Screen Shot 2013 03 26 at 18.32.28 iPhone Phonegap plugin for In app Auto Renewable Subscription
Screen Shot 2013 03 26 at 18.32.17 iPhone Phonegap plugin for In app Auto Renewable Subscription

  • Generate a shared secret. This Step is specifically for auto renewable subscription. This shared key will be used to validate the receipt after user subscription.

Screen Shot 2013 03 26 at 18.34.56 iPhone Phonegap plugin for In app Auto Renewable Subscription

Step 3: Overall ideas for Auto renewable subscription.

  • The plugin use the StoreKit library  for implementing the in app subscription.
  • The store kit create a queue for all payment requests (transactions) and process it one by one.
  • It is an asynchronous process so our subscription class is a receiver for the events triggered by the Store kit library.
  • After processing each transaction it will call the receiver function with the transaction details.
  • The transaction details contains an encrypted receipt data which should be verified either from your server or from the app to provide the subscription service to the user if the receipt is valid.
  • It is better to store receipt data either on your app or server side to verify it later to check the expiry of the subscription.
  • You have to verify the receipt as a json request against the iTunes. Which is explained in another blog post. Also you can use the verify receipt tool. Please find the following links for more details.

    iPhone In App purchase receipt verification – Sandbox
    In App purchase receipt verification Sandbox

  • If the transaction is successful the plugin returns base64 encoded receipt data to the success javascript callback function.

Step 4: Download the below  files add that to your plugin
github button e1355486394525 iPhone Phonegap plugin for In app Auto Renewable SubscriptionGit Project Link Download
Plugin branch 1.0 ( iPhone Phonegap plugin for In app Auto Renewable Subscription )

Screen Shot 2013 03 27 at 11.21.28 iPhone Phonegap plugin for In app Auto Renewable Subscription

Step 5: Add the below configuration to the Cordova.plist file.

Screen Shot 2013 03 27 at 11.23.38 iPhone Phonegap plugin for In app Auto Renewable Subscription

Step 6: You can use the below javascript to call the plugin function to subscribe

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 cordova.exec( function(result) {
 
 
                   // Success Function.                         
                   console.log( result ); 
 
                   // you can write the code here to verify the receipt 
 
                   // Please call the function on Step 7 if the receipt is verified. 
 
 
                }, function(err) {
 
                   // Failure function
                   alert(err);
                   return;
 
                }, "SubscriptionManager", "subscribe", ["com.sarathdr.monthlysubscription"]);

Step 7: After you verify the receipt please call the below function. It is not necessary depends on your programming logic.

1
2
3
cordova.exec(function(result){
                         return true;                          
                     }, function(err) {return;}, "SubscriptionManager", "updateSubscriptionNotifyStatus", [""]);

Step 8: Please consider the below points when you test an auto renewable subscription.

When testing auto-renewable in-app purchase subscriptions in the sandbox environment, the duration times will be compressed to allow for more streamlined testing. Additionally, a sandbox subscription will only auto-renew a maximum of 6 times. After the subscription has auto-renewed 6 times, it will no longer renew in the sandbox. The compressed duration times are as follows:

Screen Shot 2013 03 27 at 12.02.29 iPhone Phonegap plugin for In app Auto Renewable Subscription

References:

  1. Apple Developer
  2. http://www.raywenderlich.com/2797/introduction-to-in-app-purchases
  3. http://www.imthi.com/blog/programming/iphone-sdk-base64-encode-decode.php

Tagged , , ,

Share this to

Related Posts

2 Comments

  1. vijayaAug 22, 2013 at 10:07 amReply

    The steps you have given are very clear,to implement auto renewable subscriptions but the main thing is plugin ,can you please make steps ho to write the plugin class & corresponding html files to auto renewable subscriptions it would be very helpful for phonegap beginers

    • adminAug 23, 2013 at 5:01 pmReplyAuthor

      I will do this week end running out of time.. :)

Leave a reply

Your email address will not be published. Required fields are marked *

*

About
View Sarath D R's profile on LinkedIn

I am a technology consultant and an entrepreneur focused on the following technologies Java,Spring, Android, Angular, Asterisk, Symfony, Cake , Code-Igniter, Jquery , XAMPP, XHTML, AJAX, MySql, Seo, Web Design, Wordpress, iPhone development.

Today’s Tips
  • Generate Codova.jar file from Phonegap project using ant
  • Google map javascript client  to find the geographic co-ordinates  from  Address or post code
  • Update Android main UI from Webview – Phonegap Plugin
  • Jplayer is not working  with HTC One Android 4.3 version browser
  • Regular expression to validate mobile phone numbers starting with + ( plus ) – php
  • Simple pagination script for PHP
  • Useful adb ( Android Debug Bridge ) commands
  • Change the javascript files url to absolute url – Symfony 1.4
  • Set Http authentication header from Client – PHP / CURL

This site uses cookies from Google to deliver its services, to personalise ads and to analyse traffic. Information about your use of this site is shared with Google. By using this site, you agree to its use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.This site also uses cookies from Google to deliver its services, to personalise ads and to analyse traffic. Information about your use of this site is shared with Google. By using this site, you agree to its use of cookies.

Close