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.