j3k0 / cordova-plugin-purchase

In-App Purchase for Cordova on iOS, Android and Windows
https://purchase.cordova.fovea.cc
1.3k stars 537 forks source link

[iOS] Validation of auto renewable subscription #617

Closed PTechK closed 6 years ago

PTechK commented 7 years ago

First of all, I really appreciate your efforts and hard work in development of this plugin. I am able to make the purchase work for iOS devices.

I am sorry but I am not clear about the implementation of a method to validate subscription i.e. to find out if a product subscription has expired or not.

My question is here how do I know if purchase has expired and where do I get the error codes.

I am not clear about the mistake that I might be doing.

To validate a purchase in test flight env, I am doing the following:

function ValidatePurchase(productId)
{
var p= store.get(productId);
store.validator(p)
}

store.validator=function(product,callback)
{
   alert( 'in store.validator');
           var myData = {
              transactionReceipt: product.transaction.transactionReceipt,
              purchaseType: product.transaction.type
            };
alert(product.transaction.transactionReceipt);

            $.ajax({
              url: "https://sandbox.itunes.apple.com/verifyReceipt",
              data: myData,
              type: "POST",
              error: function(jqXHR, textStatus, errorThrown) {

                 alert('error');
              },
              success: function(data) {

                if (data.success) {

                    alert('success validator');

                } else {

                      alert('failure validator');

                }
              }

            }); //.ajax ends

}

Please guide what is wrong in this implementation or how it should be ideally implemented. Thanks for all your efforts again.

petarov commented 7 years ago

It depends on whether you'd like to use your own server for validation or not. Check out this great tutorial, but be advised that there is a lot to be done.

hariharanhs commented 6 years ago

@PTechK We had the same issue. Do you have a solution for this? @petarov We did validation locally using ajax method. We are receiving the status 21002 as the response from the validator. Can you please advice us how to proceed on this?

petarov commented 6 years ago

@hariharanhs I wouldn't verify a purchase only on the client side, because its prone to hacking. You will also be distributing the iTunes password with your app, which in the case with cordova apps, may easily be extracted.

The 21002 seems to come from a problem in the receipt-data field of the JSON payload you are sending to the iTunes servers. Check out the Apple docs for more info.

Dexus commented 6 years ago

See https://github.com/j3k0/cordova-plugin-purchase/issues/640

You need to use a Validation Service as backend, where you call against. And also to receive Apple Notifications.