[Solved]Still fighting with Receipt Validation (iOS)

I’ve tried several ways to validate receipts and can’t seem to get past it. My latest try is this:

public void ValidateReceipt() {
bool validPurchase = false;
Product[ ] products = m_StoreController.products.all;

try {
CrossPlatformValidator validator = new CrossPlatformValidator (null, AppleTangle.Data (), Application.bundleIdentifier);
for (int i = 0; i < products.Length; i++) {
if (products .receipt != null) { // <— This is always null
IPurchaseReceipt[ ] result = validator.Validate (products .receipt);
for (int j = 0; j < result.Length; j++) {
if (result [j].productID == kProductIDNonConsumable) {
Debug.Log(result [j].productID);
validPurchase = true;
}
}
} else {
Debug.Log("Null Value " + products*.transactionID);*
}
}
} catch (Exception ex) {
Debug.Log(ex.ToString ());
}
if (validPurchase) {
// SUCCESSFUL RECEIPT VALIDATION
} else {
// RECEIPT NOT VALID
}
}

The receipt is always null in this example. I’ve always played with…
var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance()); string receipt = builder.Configure().appReceipt;

But again, the receipt is always null.

Has anyone gotten this working?

Figured this out based on some newer threads. Validating the apple receipt will look something like this…

public void ReceiptCheck() {
    ConfigurationBuilder builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    IAppleConfiguration appleConfig = builder.Configure<IAppleConfiguration>();

    if (!string.IsNullOrEmpty (appleConfig.appReceipt)) {
        Debug.Log (appleConfig.appReceipt);
        try {
            var receiptData = System.Convert.FromBase64String (appleConfig.appReceipt);
            AppleReceipt receipt = new AppleValidator (AppleTangle.Data ()).Validate (receiptData);
            Debug.Log("Apple receipt " + receipt);
            foreach (AppleInAppPurchaseReceipt productReceipt in receipt.inAppPurchaseReceipts) {
                Debug.Log ("Product ID: " + productReceipt.productID);
                Debug.Log ("Purchase Date: " + productReceipt.purchaseDate);
            }
        } catch (Exception e) {
            Debug.Log("Exception on converting receipt:  " + e.ToString());
        }

    } else {
        Debug.Log ("Apple receipt is null");
    }
}
1 Like