Search Unity

[Solved]Still fighting with Receipt Validation (iOS)

Discussion in 'Unity IAP' started by baumerj, Feb 4, 2017.

Thread Status:
Not open for further replies.
  1. baumerj

    baumerj

    Joined:
    Jun 21, 2016
    Posts:
    9
    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<IAppleConfiguration>().appReceipt;

    But again, the receipt is always null.

    Has anyone gotten this working?
     
  2. baumerj

    baumerj

    Joined:
    Jun 21, 2016
    Posts:
    9
    Figured this out based on some newer threads. Validating the apple receipt will look something like this...
    Code (CSharp):
    1. public void ReceiptCheck() {
    2.     ConfigurationBuilder builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    3.     IAppleConfiguration appleConfig = builder.Configure<IAppleConfiguration>();
    4.  
    5.     if (!string.IsNullOrEmpty (appleConfig.appReceipt)) {
    6.         Debug.Log (appleConfig.appReceipt);
    7.         try {
    8.             var receiptData = System.Convert.FromBase64String (appleConfig.appReceipt);
    9.             AppleReceipt receipt = new AppleValidator (AppleTangle.Data ()).Validate (receiptData);
    10.             Debug.Log("Apple receipt " + receipt);
    11.             foreach (AppleInAppPurchaseReceipt productReceipt in receipt.inAppPurchaseReceipts) {
    12.                 Debug.Log ("Product ID: " + productReceipt.productID);
    13.                 Debug.Log ("Purchase Date: " + productReceipt.purchaseDate);
    14.             }
    15.         } catch (Exception e) {
    16.             Debug.Log("Exception on converting receipt:  " + e.ToString());
    17.         }
    18.  
    19.     } else {
    20.         Debug.Log ("Apple receipt is null");
    21.     }
    22. }
     
    ap-unity likes this.
Thread Status:
Not open for further replies.