j3k0 / cordova-plugin-purchase

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

Phonegap 3.0 compatibility? Project status? #1

Closed damrbaby closed 10 years ago

damrbaby commented 10 years ago

Hello!

Just curious about this project status given the warning in the readme:

WARNING: I'M CURRENLTY REWRITING PART OF THIS PLUGING. IT'S NOT YET USABLE!

Now that cordova 3.0 is out it's unclear whether this will work or not, or whether it is still in active development.

j3k0 commented 10 years ago

Hello!

Yes, I'm just done working on a project using it. It's on the store and it works, so the plugin is certainly safe to use.

I didn't try on Cordova 3.0 yet however, I use PhoneGap 2.7.0.

mlegenhausen commented 10 years ago

It seems PhoneGap 3.0 ios project has ARC enabled as default. When compiling this code it is not working.

jkirkell commented 10 years ago

I am using the plugin with Cordova 3.0x and it works for the most part. The main issue is that the config.xml needs to be updated to change the plugin tag to be a feature tag.

guiix-code commented 10 years ago

I second the issue of ARC problems. There are several uses of the release function, e.g. [numberFormatter release];, that are not permitted.

damrbaby commented 10 years ago

FYI you can get around ARC restrictions by following these instructions for InAppPurchase.m and SKProduct+LocalizedPrice.m

Also for PhoneGap >= 3.0 this plugin can be installed with a single command:

cordova plugin add git://github.com/j3k0/PhoneGap-InAppPurchase-iOS.git
areoburn commented 10 years ago

I setup the plugin through the cordova plugin command on Phonegap 3.0

I made sure the xml file has the feature tags and everything is in the right places.

I have been trying to get the plugin to work but for some reason storekit isn't being recognized from the beginning. I am running it inside the device ready function.

Can someone please look into this? I've been bashing my head on this for hours and couldn't get it to work.

jkirkell commented 10 years ago

take a look at https://github.com/jkirkell/cordova-inapp-sample which is just the steps to follow for setting up using InApp purchasing plugins. The code is for reference only and should not be run since I excluded the binaries.

areoburn commented 10 years ago

jkirkell thank you very much for the fast reply! I checked my project and everything is setup perfectly. I am sorry I miss worded my problem. I found the exact problem.

When I do: storekit.load(['inapp1', 'inapp2'], function (products, invalidIds) {});

The callback function does not run.

InAppPurchase[objc]: Getting products data InAppPurchase[objc]: Set has 2 elements InAppPurchase[objc]: - inapp1 InAppPurchase[objc]: - inapp2 InAppPurchase[objc]: start

That's about all I receive. I tried setting alerts and a variety of other tests inside the callback, but nothing seems to work.

It would be of great help if someone can help figure this out because I noticed many people were experiencing this problem on the guide page as well.

guiix-code commented 10 years ago

If you know a little Objective-C, when you compile and come up with errors, you can go through the list and click on each to highlight the problem lines, then you can comment out (add "//" to the beginning of the line) any line that just has release on it. There's one line that has some other initialisation too, where you would just remove the "release" part, and not the rest.

jkirkell commented 10 years ago

@areoburn I now see what you are seeing, but only when I compile and push to IOS7 in the simulator. IOS6.1 still works fine. I am looking at it and will report back later today.

jkirkell commented 10 years ago

The super quick answer is that the code works fine when using the simulator for IOS6.1 only. IOS7 and IOS7 64bit both are croaking with the storekit initialization. I will keep working on it.

damrbaby commented 10 years ago

I thought you can't test storekit in the simulator? I wouldn't expect it to work in the simulator at all.

jkirkell commented 10 years ago

For anyone looking, Apple is not letting the simulator to run in-app purchases per their notes https://developer.apple.com/library/ios/releasenotes/DeveloperTools/RN-Xcode/index.html.

StoreKit (In-App purchases) will not work in the Simulator. 13962338

I have tested the current code on a device running IOS7 (iPhone5) and sandbox in-app purchasing works.

areoburn commented 10 years ago

Thank you jkirkell! I finally can continue working on my app!

Has anyone experienced this problem with the callback function?

var IAP_loaded = false; // Global Scope var IAP_onReady = function(){ storekit.load(IAP_list, function (products, invalidIds) { console.log('IAP LOADING...'); IAP_products = products; IAP_loaded = true; console.log("1] -- IAP Loaded: "+IAP_loaded); // Outputs true }); console.log("2] -- IAP Loaded: "+IAP_loaded); // Outputs false IAP_loaded = true; console.log("3] -- IAP Loaded: "+IAP_loaded); // Outputs true };

console.log("4] -- IAP Loaded: "+IAP_loaded); // Outputs false

For some my global variables aren't staying modified outside the function itself... I created a completely separate function and changed a global variable and it works fine. This just mind baffles me. Any thoughts?

areoburn commented 10 years ago

Never mind, I figured out storekit is being run as async and I came across a solution. Thanks again for the help

areoburn commented 10 years ago

Hey have any of you experienced the Error message "Cannot connect to itunes" after a successful purchase restore? I seem to keep getting this error, but the purchase is going through.

Not sure if this is a sandbox environment error or not

jkirkell commented 10 years ago

Running in the simulator using a sandbox user on IOS6 or 6.1, I would see strange issues like

When I installed on a device and used the sandbox user, all that went away.

Hope that helps

tiendq commented 10 years ago

For short, both methods work well:

  1. Add -fno-objc-arc flag to files as instructed here: https://github.com/jkirkell/cordova-inapp-sample
  2. Comment code as @doomsy pointed out. I prefer this way, error message is clear, isn't it?

Thanks,

guiix-code commented 10 years ago

The error messages are clear, though I ran into one app crash during my usage. I'm not sure if it was related specifically to what I commented out, but I ended up switching to the "Add -fno-objc-arc flag" option to keep things simple.

wootwoot1234 commented 10 years ago

@jkirkell and @areoburn did you guys ever figure out a fix for the storekit.load(['inapp1', 'inapp2'], function (products, invalidIds) {}); callback? It connects to apple's servers and prints the information in the console but never calls the callback. BTW, I'm running these tests on an iPhone 5 with iOS 7.

jkirkell commented 10 years ago

Apple disabled running storekit through the IOS Simulator. When you install on the device and login using the test accounts, everything works fine.

What I ended up doing in my code was to add a flag to add the product as a "fake" purchase so my app can be tested still in the simulator.

Hope that helps. Jeff

On Thu, Oct 3, 2013 at 10:46 AM, wootwoot1234 notifications@github.comwrote:

@jkirkell https://github.com/jkirkell and @areoburnhttps://github.com/areoburndid you guys ever figure out a fix for the storekit.load(['inapp1', 'inapp2'], function (products, invalidIds) {}); callback? It connects to apple's servers and prints the information in the console but never calls the callback. BTW, I'm running these tests on an iPhone 5 with iOS 7.

— Reply to this email directly or view it on GitHubhttps://github.com/j3k0/PhoneGap-InAppPurchase-iOS/issues/1#issuecomment-25626419 .

wootwoot1234 commented 10 years ago

Hey Jeff. Thanks for the quick response. Good point. I always forget to login to my test account. I logged in and still the load callback isn't being called. I thought it might be a timing issue with the init function so I pulled the load function out of the ready callback and put it in a 'setTimeout()' which delayed the call by 1 second but that didn't help. Here's the console output:

Finished load of: file:///var/mobile/Applications/...app/www/index.html
 InAppPurchase[js]: setup ok
 InAppPurchase[js]: load [...]
InAppPurchase[objc]: Getting products data
InAppPurchase[objc]: Set has 13 elements
InAppPurchase[objc]: - ...
InAppPurchase[objc]: start
THREAD WARNING: ['InAppPurchase'] took '38.044922' ms. Plugin should use a background thread.
InAppPurchase[objc]: productsRequest: didReceiveResponse:
InAppPurchase[objc]: Has 13 validProducts
InAppPurchase[objc]: - ...
InAppPurchase[objc]: productsRequest: didReceiveResponse: sendPluginResult: (...)

Thanks for the help. I really like how you cleaned up this plugin. The log outputs are really helpful.

wootwoot1234 commented 10 years ago

Here's my code (after removing the setTimeout()). Maybe I'm doing something wrong.

window.storekit.init({
    purchase: function (transactionId, productId, transactionReceipt) {
        console.log('purchased: ' + productId);
    },
    restore: function (transactionId, productId, transactionReceipt) {
        console.log('restored: ' + productId);
    },
    restoreCompleted: function () {
        console.log('restoreCompleted');
    },
    restoreFailed: function (errCode) {
        console.log('Error Code: ' + errCode);
    },
    error: function (errno, errtext) {
        console.log('failed: ' + errtext);
    },
    ready: function () {
        var productIds = ["..."];
        window.storekit.load(productIds, function(validProducts, invalidProductIds) {
            console.log("load callback");
            $.each(validProducts, function (i, val) {
                console.log("id: " + val.id + " title: " + val.title + " val: " + val.description + " price: " + val.price);
            });
            if(invalidProductIds.length) {
                console.log("Invalid Product IDs: " + JSON.stringify(invalidProductIds));
            }
        });
    }
});
wootwoot1234 commented 10 years ago

Hey Jeff.

Never mind my last couple of comments. You're correct, it's working. I just stripped my code down to nothing but the in app purchase and the load callback fired so there's something wrong somewhere else.

Thanks again for this plugin.

Oh, one last thing. The readme.md file talks about some functions that no longer exist. If you want I'm happy to clean it up.

j3k0 commented 10 years ago

Hi wootwoot, Of course feel free to clean the doc :) Any help to maintain this plugin is appreciated!