Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac App Store consumable receipts have empty in_app hash on server side validation

I verify the receipt of in-app-purchases (so called consumables) for the Mac App Store on the server side. The response from Apple's servers usually looks like this:

    { 
      "status"=>0, 
      "environment"=>"Production", 
      "receipt" => 
        { 
          "receipt_type" => "Production", 
          "adam_id"=>410628904, 
          "bundle_id" => "com.company.product", 
          "application_version"=>"1.0.0", 
          "download_id"=>002141541230420, 
          "request_date"=>"2013-10-22 07:53:11 Etc/GMT", 
          "request_date_ms"=>"1382428391914", 
          "request_date_pst"=>"2013-10-22 00:53:11 America/Los_Angeles", 
          "original_purchase_date"=>"2011-08-22 06:05:47 Etc/GMT", 
          "original_purchase_date_ms"=>"1313993147000", 
          "original_purchase_date_pst"=>"2011-08-21 23:05:47 America/Los_Angeles", 
          "original_application_version"=>"1.0.0", 
          "in_app"=> [
            {
              "quantity"=>"1", 
              "product_id"=>"com.company.product.mac_consumable", 
              "transaction_id"=>"9123912391231", 
              "original_transaction_id"=>"51881235936908", 
              "purchase_date"=>"2013-10-22 07:52:06 Etc/GMT", 
              "purchase_date_ms"=>"1382428326000", 
              "purchase_date_pst"=>"2013-10-22 00:52:06 America/Los_Angeles", 
              "original_purchase_date"=>"2013-10-22 07:52:06 Etc/GMT", 
              "original_purchase_date_ms"=>"1382428326000", 
              "original_purchase_date_pst"=>"2013-10-22 00:52:06 America/Los_Angeles", 
              "bundle_id"=>"com.company.product"
              }
         ]
      }
    }

But sometimes we get back information without the in_app hash set:

    { 
      "status"=>0, 
      "environment"=>"Production", 
      "receipt" => 
        { 
          "receipt_type" => "Production", 
          "adam_id"=>312621904, 
          "bundle_id" => "com.company.product", 
          "application_version"=>"1.0.0", 
          "download_id"=>002141541230420, 
          "request_date"=>"2013-10-22 07:53:11 Etc/GMT", 
          "request_date_ms"=>"1382428391914", 
          "request_date_pst"=>"2013-10-22 00:53:11 America/Los_Angeles", 
          "original_purchase_date"=>"2011-08-22 06:05:47 Etc/GMT", 
          "original_purchase_date_ms"=>"1313993147000", 
          "original_purchase_date_pst"=>"2011-08-21 23:05:47 America/Los_Angeles", 
          "original_application_version"=>"1.0.0", 
          "in_app"=> []
      }
    }

Does this mean the receipts are invalid? Should the in_app field always be populated? Or should those receipts be considered valid as well and why is the in_app information empty then?

like image 342
user2906965 Avatar asked Oct 22 '13 12:10

user2906965


1 Answers

Does this mean the receipts are invalid?

No, the status value is 0, which according to the docs means that the receipt is valid. It just doesn't contain any in-app purchase “sub-receipts”.

Should the in_app field always be populated?

No, it's possible for a receipt to not contain any in-app purchases.


So apparently your problem is that for some reason the receipt your app is sending to your backend doesn't contain information for an in-app purchase, even though you expect it to.

When an in-app purchase transaction enters the "purchased" state, the receipt should be up to date on the client device — you should ensure that you don't try to send the receipt onto your server before this happens.

One other thing to consider trying is SKReceiptRefreshRequest (only available since 10.9, though) — in some edge conditions the receipt might not be up to date, and you'd need to wait for it to update before sending the receipt redemption request to your backend.

like image 83
hasseg Avatar answered Oct 01 '22 19:10

hasseg