1 Reply Latest reply on Feb 11, 2017 1:17 PM by kerrishotts

    In app purchase

    amirs77182119 Level 1

      Hello ,

      I have some problem in integrating in app purchase in our project.

      My code is:

       

      var prod_id = $('#plan').attr('sku_id');

                    var plan = $('#plan').attr('sku_alias'); 

                   

                   

                    //SweetAlert.swal(prod_id+plan);

                    store.verbosity = store.DEBUG;

       

                    // Inform the store of your products

                    store.register({

                                     id:    'com.wrctechnologies.itrackapps.'+prod_id,

                                     alias: plan,

                                     type:   store.NON_RENEWING_SUBSCRIPTION

                                   });

                   

      //              store.register({

      //                               id:    'com.telerik.demoproduct.nonconsumable1',

      //                               alias: 'Full version',

      //                               type:   store.NON_CONSUMABLE

      //                             });

      //             

      //              store.register({

      //                               id:    'com.telerik.demoproduct.subscription1',

      //                               alias: 'subscription1',

      //                               type:  store.PAID_SUBSCRIPTION

      //                             });

       

                    // When any product gets updated, refresh the HTML

                    store.when("product").updated(function (p) {

                      var container = document.getElementById('productContainer');

                      var elId = p.id.split(".")[3];

                      var el = document.getElementById(elId);

                      if (!el) {

                        container.innerHTML += '<div id="'+elId+'"></div>';

                        el = document.getElementById(elId);

                      }

                     

                      if (!p.loaded) {

                        //el.innerHTML += '<h3>...</h3>';

                        SweetAlert.swal("Problem...");

                      } else if (!p.valid) {

                        //el.innerHTML += '<h3>' + p.alias + ' Invalid</h3>';

                        SweetAlert.swal("Invalid");

                      } else if (p.valid) {

                       // var html = "<h3>" + p.title + "</h3>" + "<p>" + p.description + "</p>";

                        if (p.canPurchase) {

                            store.order(p.id);

                          //html += "<button class='button' onclick='store.order(\"" + p.id + "\")'>Buy for " + p.price + "</button>";

                        }

                        //el.innerHTML = html;

      //                  el.innerHTML = JSON.stringify(p);

                      }

                    });

       

                    // handle subscription events

                    store.when("subscription1").approved(function(p) {

                                               SweetAlert.swal("verify subscription");

                                               p.verify();

                                             });

       

                    store.when("subscription1").verified(function(p) {

                                                           SweetAlert.swal("subscription verified");

                                                           p.finish();

                                                         });

       

                    store.when("subscription1").unverified(function(p) {

                                                             SweetAlert.swal("subscription unverified");

                                                           });

       

                    store.when("subscription1").updated(function(p) {

                                                          if (p.owned) {

                                                            console.log('You have a subscription');

                                                            //document.getElementById('subscriber-info').innerHTML = 'You are a lucky subscriber!';

                                                          } else {

                                                            console.log('You don\'t have a subscription');

                                                            //document.getElementById('subscriber-info').innerHTML = 'You are not subscribed';

                                                          }

                                                        });

                   

       

                    // When purchase of 100 coins is approved, show an alert

                    store.when(plan).approved(function (order) {

                        //alert(JSON.stringify(order));

                                                       

                                                        order.finish();

                                                       

                                $.ajax({

              url:BASE_URL+'registration.php',

              type: 'POST',

              data:{

                  type:type,

                  fname:fname,

                  lname:lname,

                  email:email,

                  mobile:mob,

                  password:password,

                  no_of_person:person,

                  no_of_days:days,

                  plan:plan

                 

              },

              mimeType:"multipart/form-data",

              //contentType: false,

              cache: false,

              //processData:false,

             success: function(data, textStatus, jqXHR)

              {

                 

                  localStorage.setItem("username",email);

                  localStorage.setItem("password",password);

              //console.log(data);

                 

      var obj= $.parseJSON(data);           

            //var obj= JSON.stringify(data);

                if(obj.code=="100"){

            //SweetAlert.swal("Registration successful");

            localStorage.setItem("userid",obj.user_id);

                localStorage.setItem("type",obj.user_type);

                $scope.family_code=obj.family_code;

                var d = new Date();

                var n = d.getTime();

                $.ajax({

                      url:BASE_URL+'payment_api.php',

                      data:{user_id:obj.user_id,txnid:'ITL'+n,payment_amount:$('#buyNowBtn').attr('log_price'), plan_id:prod_id,type:'p'},

                      type:'post',

                      success:function(resp){

                         SweetAlert.swal("Plan paid successfully!");                                      

                      }

                      });

              window.location.href="#/parent_dashboard";

                }else{

                 SweetAlert.swal(obj.msg);  

                }

              },

              error: function(jqXHR, textStatus, errorThrown)

              {

                  SweetAlert.swal('Registration failed');

              }         

          }); 

                                                        //window.location.href="";

                                                      });

                    store.when(plan).updated(function (product) {

                                                         //SweetAlert.swal("Done!");

                                                       });   

                    store.when(plan).cancelled(function (product) {

                                                         SweetAlert.swal("Selected Plan cancelled!");

                                                       });

                                                      // Deal with errors

                    store.error(function(error) {

                                  SweetAlert.swal('ERROR ' + error.code + ': ' + error.message);

                                });

       

                    // When purchase of the full version is approved, show an alert and finish the transaction.

                    store.when("Full version").approved(function (order) {

                                                          SweetAlert.swal('You just unlocked the FULL VERSION!');

                                                          order.finish();

                                                        });

       

                    // The play button can only be accessed when the user owns the full version.

                   

       

                    // When the store is ready all products are loaded and in their "final" state.

                    // Note that the "ready" function will be called immediately if the store is already ready.

                    // When the store is ready, activate the "refresh" button;

                    store.ready(function() {

                                  console.log("The store is ready");

                                });

       

                    // Refresh the store.

                    // This will contact the server to check all registered products validity and ownership status.

                    // It's fine to do this only at application startup, as it could be pretty expensive.

                    store.refresh();

       

       

       

      I want to use NON_RENEWING_SUBSCRIPTION product as type.But it didn't purchase any products,always shows an error message.

       

       

      Please guide me through out the process of in app purchase having NON_RENEWING_SUBSCRIPTION type  with the help of phonegap build source code.

       

      Thanks in advance

      Amir