3

I want to use in-app-purchase on my RoboVM app on iOS. As far as I understand is that I need to access Apples StoreKit framework for that. I found the following solutions:

  • robovm-ios-bindings (labeled as deprecatred in favor of robopods)
  • robopods (..where I can not find StoreKid bindings)
  • gdx-pay (..is a cross platform solution that I do not need)

I wonder what's the best way for me. I tried gdx-pay first but I do not need a cross platform solution. robovm-ios-bindings seems to be focusing just on the functionality I need. But since it is marked as deprecated I have doubt. robopods would be great since it's referenced by the RoboVM site but I can not find StoreKid bindings there.

I am trying to find a documentation/tutorial of how to use one of the technologies. E.g

  • how to implement it
  • how to test the purchases on a simulator without using real money
  • good/bad practices, documentation links etc.
Luca Hofmann
  • 1,442
  • 2
  • 14
  • 26
  • I recommend using Gdx-Pay , cross-platform or not. It will still work with only iOS implementation. – Benni Jan 11 '16 at 19:08

1 Answers1

1

Gdx-Pay is the easiest way to go. This contains all the information you need to implement it.

Testing can't be done with real money. You can set up a test environment in order to test purchases, described here: Testing IAP

A rule from Apple that must be followed is to have an "Restore" button for purchases. Your users must explicitly request to restore their purchases, on a button for example.

Here's an example of how I've set up Gdx-Pay:

if(PurchaseSystem.hasManager()){
        config = new PurchaseManagerConfig();
        config.addOffer(new Offer().setType(OfferType.ENTITLEMENT).setIdentifier(item1String));

        //Stores
        config.addStoreParam(PurchaseManagerConfig.STORE_NAME_ANDROID_GOOGLE, base64EncodedKey);
        config.addStoreParam(PurchaseManagerConfig.STORE_NAME_IOS_APPLE, base64EncodedKey); // <-- CHANGE KEY

        PurchaseSystem.install(new PurchaseObserver() {
            @Override
            public void handleInstall() {
                message(" - purchase manager installed: " + PurchaseSystem.storeName() + ".\n");
                // restore purchases
                message(" - do a restore to check inventory\n");

                //Execute this on a button instead!
                PurchaseSystem.purchaseRestore();
            }

            @Override
            public void handleInstallError(Throwable e) {
                message(" - error installing purchase manager: " + e + "\n");

                // throw error
                throw new GdxRuntimeException(e);
            }

            @Override
            public void handleRestore(Transaction[] transactions) {
                // keep note of our purchases
                message(" - totally " + transactions.length + " purchased products\n");
                for (int i = 0; i < transactions.length; i++) {
                    if(transactions[i].getIdentifier().equals(stone1)) {
                        preferences.putBoolean("item1_purchased", true);
                    }
                }

            }

            @Override
            public void handleRestoreError(Throwable e) {
                message(" - error during purchase manager restore: " + e + "\n");

                // throw error
                throw new GdxRuntimeException(e);
            }

            @Override
            public void handlePurchase(Transaction transaction) {
                message(" - purchased: " + transaction.getIdentifier() + "\n");

                // dispose the purchase system
                Gdx.app.postRunnable(new Runnable() {
                    @Override
                    public void run () {
                        message(" - disposing the purchase manager.\n");
                        PurchaseSystem.dispose();
                        message("Testing InApp System: COMPLETED\n");
                    }
                });
            }

            @Override
            public void handlePurchaseError(Throwable e) {
                message(" - error purchasing: " + e + "\n");
                // throw error
                throw new GdxRuntimeException(e);
            }

            @Override
            public void handlePurchaseCanceled() {
                message(" - purchase cancelled.\n");

                // dispose the purchase system
                Gdx.app.postRunnable(new Runnable() {
                    @Override
                    public void run () {
                        message(" - user canceled! - disposing the purchase manager.\n");
                        PurchaseSystem.dispose();
                        message("Testing InApp System: COMPLETED\n");
                    }
                });
            }
        },config);

    } else {
        //Toast an error
    }

Then you can just call

PurchaseSystem.purchase("itemID");

to make a purchase.

Benni
  • 969
  • 1
  • 19
  • 29