Sorry for the long post but hopefully the code will help. This is my first in-app purchase attempt. I'm testing just android for now. I have one test user for a free version of the app in Alpha release. I've apparently successfully purchased one each of the 3 products according to my google play account, but each purchase showed the "purchase fail" error. Additional purchase attempts gives no response in the app.
I then checked if there were any unconsumed products. That code only gives an error of "Failure checking the received data when validating the inapp purchase"
I thought I followed the help examples accurately but I can't see what's wrong.
Thanks, Bill
App Start up:
arrIdentifier is array of strings
arrIdentifier = ["student1", "student5", "student10"]
garrProducts is array of inAppProduct
gMyProduct is inAppProduct
gnStudentPurchaseQty is int
IF inAppListProductInfo(arrIdentifier, ListProductInfo) = False AND NOT InTestMode() THEN
Error("Unable to access in-app Products: " + ErrorInfo)
END
PROCEDURE ListProductInfo(bSuccess is boolean, arrProducts is array of inAppProduct)
IF NOT bSuccess THEN
Error("Error: " + ErrorInfo())
RETURN
END
garrProducts <= arrProducts
***********************************************
List Products Window, Looper Init:
LooperDeleteAll(LOOP_ProductInfo)
FOR i = 1 _TO_ garrProducts..Occurrence
LooperAddLine(LOOP_ProductInfo, garrProducts.Caption, i, garrProducts.Price)
END
***********************************************
List Products Window, Select row:
nIdx is int = LOOP_ProductInfo
gMyProduct = garrProducts[nIdx]
SWITCH gMyProduct.Identifier
CASE "student1"
gnStudentPurchaseQty = 1
CASE "student5"
gnStudentPurchaseQty = 5
CASE "student10"
gnStudentPurchaseQty = 10
OTHER CASE
Info("Unknown Product")
END
inAppPurchaseProduct(gMyProduct, PurchaseProduct)
PROCEDURE PurchaseProduct(bSuccess is boolean, PurchasedProduct is inAppProduct, PurchaseID)
IF NOT bSuccess THEN
Info("purchase fail " + PurchasedProduct.Identifier + "--" + ErrorInfo(errFullDetails))
RETURN
ELSE
IF InAndroidMode() THEN
// Consume the product (optional)
IF inAppConsumeProduct(PurchasedProduct, PurchaseID, ConsumeProduct) <> True THEN
Info("consume fail " + PurchasedProduct.Identifier + "--" + ErrorInfo(errFullDetails))
END
END
IF IniOSMode() THEN
// Activate the product in the application
ConsumeProduct(bSuccess)
END
END
PROCEDURE ConsumeProduct(bSuccess is boolean)
IF NOT bSuccess THEN
ToastDisplay(ErrorInfo())
ELSE
HReadFirst(Settings)
Settings.MaxStudents += gnStudentPurchaseQty
HSave(Settings)
END
***********************************************
Unconsumed Purchases Window:
inAppListPurchase(ListUnusedPurchases, inAppOrderId)
PROCEDURE ListUnusedPurchases(bSuccess is boolean, sPurchaseList is string)
LooperDeleteAll(LOOP_ProductInfo)
IF NOT bSuccess THEN
Info("list unused: " + ErrorInfo(errFullDetails))
ELSE
// Browses the purchases performed
FOR EACH STRING sPurchaseInfo OF sPurchaseList SEPARATED BY CR
// Retrieves the identifier of the product
sProductID is string = ExtractString(sPurchaseInfo, 1, TAB)
// Retrieves the identifier of the purchase
sPurchaseID is string = ExtractString(sPurchaseInfo, 2, TAB)
// Consumes the product if necessary
LooperAddLine(LOOP_ProductInfo, sProductID, sPurchaseID)
END
END
I then checked if there were any unconsumed products. That code only gives an error of "Failure checking the received data when validating the inapp purchase"
I thought I followed the help examples accurately but I can't see what's wrong.
Thanks, Bill
App Start up:
arrIdentifier is array of strings
arrIdentifier = ["student1", "student5", "student10"]
garrProducts is array of inAppProduct
gMyProduct is inAppProduct
gnStudentPurchaseQty is int
IF inAppListProductInfo(arrIdentifier, ListProductInfo) = False AND NOT InTestMode() THEN
Error("Unable to access in-app Products: " + ErrorInfo)
END
PROCEDURE ListProductInfo(bSuccess is boolean, arrProducts is array of inAppProduct)
IF NOT bSuccess THEN
Error("Error: " + ErrorInfo())
RETURN
END
garrProducts <= arrProducts
***********************************************
List Products Window, Looper Init:
LooperDeleteAll(LOOP_ProductInfo)
FOR i = 1 _TO_ garrProducts..Occurrence
LooperAddLine(LOOP_ProductInfo, garrProducts.Caption, i, garrProducts.Price)
END
***********************************************
List Products Window, Select row:
nIdx is int = LOOP_ProductInfo
gMyProduct = garrProducts[nIdx]
SWITCH gMyProduct.Identifier
CASE "student1"
gnStudentPurchaseQty = 1
CASE "student5"
gnStudentPurchaseQty = 5
CASE "student10"
gnStudentPurchaseQty = 10
OTHER CASE
Info("Unknown Product")
END
inAppPurchaseProduct(gMyProduct, PurchaseProduct)
PROCEDURE PurchaseProduct(bSuccess is boolean, PurchasedProduct is inAppProduct, PurchaseID)
IF NOT bSuccess THEN
Info("purchase fail " + PurchasedProduct.Identifier + "--" + ErrorInfo(errFullDetails))
RETURN
ELSE
IF InAndroidMode() THEN
// Consume the product (optional)
IF inAppConsumeProduct(PurchasedProduct, PurchaseID, ConsumeProduct) <> True THEN
Info("consume fail " + PurchasedProduct.Identifier + "--" + ErrorInfo(errFullDetails))
END
END
IF IniOSMode() THEN
// Activate the product in the application
ConsumeProduct(bSuccess)
END
END
PROCEDURE ConsumeProduct(bSuccess is boolean)
IF NOT bSuccess THEN
ToastDisplay(ErrorInfo())
ELSE
HReadFirst(Settings)
Settings.MaxStudents += gnStudentPurchaseQty
HSave(Settings)
END
***********************************************
Unconsumed Purchases Window:
inAppListPurchase(ListUnusedPurchases, inAppOrderId)
PROCEDURE ListUnusedPurchases(bSuccess is boolean, sPurchaseList is string)
LooperDeleteAll(LOOP_ProductInfo)
IF NOT bSuccess THEN
Info("list unused: " + ErrorInfo(errFullDetails))
ELSE
// Browses the purchases performed
FOR EACH STRING sPurchaseInfo OF sPurchaseList SEPARATED BY CR
// Retrieves the identifier of the product
sProductID is string = ExtractString(sPurchaseInfo, 1, TAB)
// Retrieves the identifier of the purchase
sPurchaseID is string = ExtractString(sPurchaseInfo, 2, TAB)
// Consumes the product if necessary
LooperAddLine(LOOP_ProductInfo, sProductID, sPurchaseID)
END
END