Unity 5.3.5p4 で Unity IAP を使い GooglePlay のアイテム課金(消費型)のテストをしていますが
・購入時に GooglePlay から受け取る情報内から orderId が無くなり、TransactionId も空で返ってきます
(SandboxのIDで購入成功時にはどちらも得られるんですが自前の商品のIDだとその情報が欠落します)
・テストアカウントで自前の商品を何度も購入できているので消費型としては機能しているように見えます
(消費型でなければ2回目の購入ができないらしいので)
・購入時に表示される GooglePlay の支払いましたパネル(Sandbox時)が出ず「ライブラリに追加しました」というパネルが表示されます
・Validate() を呼び出すとその中でクラッシュしてしまいます
検索しても原因や対策がわかりそうな情報がみつからず困っています。
似たような症状に遭遇した方や原因に見当がつく方がいましたら解決に向けて情報を頂けると助かります。
よろしくお願い致します。
---以下6/27追記(実際に使っている物から不要箇所削除しID類情報を変更するなど加工して掲載)---
c#
1#if UNITY_ANDROID || UNITY_IPHONE || UNITY_STANDALONE_OSX || UNITY_TVOS 2//#define RECEIPT_VALIDATION 3#endif 4 5using System; 6using System.Collections.Generic; 7using UnityEngine; 8using UnityEngine.Purchasing; 9#if RECEIPT_VALIDATION 10using UnityEngine.Purchasing.Security; 11#endif 12 13public class Unity5Purchase : MonoBehaviour, IStoreListener { 14 private static IStoreController m_StoreController; 15 private static IExtensionProvider m_StoreExtensionProvider; 16#if RECEIPT_VALIDATION 17 private CrossPlatformValidator validator; 18#endif 19 20 // GooglePlayライセンスコード. 21 const string API_KEY = "(ないしょ)"; 22 23 void Start() { 24 if (m_StoreController == null) { 25 InitializePurchasing(); 26 } 27 } 28 29 public void InitializePurchasing() { 30 if (IsInitialized()) { 31 return;// 初期化済み. 32 } 33 var module = StandardPurchasingModule.Instance(); 34 var builder = ConfigurationBuilder.Instance(module); 35 builder.Configure<IGooglePlayConfiguration>().SetPublicKey(API_KEY);// GooglePlayのライセンスキー登録. 36 // (以下のID等は実際に使っている物とは違います今回のための仮記載情報です) 37 builder.AddProduct("PRODUCT_ID1", ProductType.Consumable, new IDs { 38 { "test01", GooglePlay.Name }, 39 { "TEST01", AppleApPStore.Name }, 40 { "Test01", MacAppStore.Name }, 41 }); 42 builder.AddProduct("PRODUCT_ID2", ProductType.Consumable, new IDs { 43 { "test02", GooglePlay.Name }, 44 { "TEST02", AppleApPStore.Name }, 45 { "Test02", MacAppStore.Name }, 46 }); 47#if RECEIPT_VALIDATION 48 validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), Application.bundleIdentifier); 49#endif 50 UnityPurchasing.Initialize(this, builder); 51 } 52 53 private bool IsInitialized() { 54 return m_StoreController != null && m_StoreExtensionProvider != null; 55 } 56 57 // 購入ボタン押下時にここを呼び出す. 58 void BuyProductID(string productId) { 59 if (IsInitialized()) { 60 Product product = m_StoreController.products.WithID(productId); 61 if (product != null && product.availableToPurchase) { 62 m_StoreController.InitiatePurchase(product); 63 } 64 } 65 } 66 67 public void RestorePurchases() { 68 } 69 70 // 71 // --- IStoreListener 72 // 73 74 // 初期化成功時. 75 public void OnInitialized(IStoreController controller, IExtensionProvider extensions) { 76 m_StoreController = controller; 77 m_StoreExtensionProvider = extensions; 78 } 79 80 // 初期化失敗. 81 public void OnInitializeFailed(InitializationFailureReason error) { 82 } 83 84 [Serializable] 85 class unityReceipt { 86 public string Store; 87 public string TransactionID; 88 public string Payload; 89 public unityReceipt() { 90 this.Store = null; 91 this.TransactionID = null; 92 this.Payload = null; 93 } 94 } 95 96 [Serializable] 97 class googlePlayPayload { 98 public string json; 99 public string signature; 100 public googlePlayPayload() { 101 this.json = null; 102 this.signature = null; 103 } 104 } 105 [Serializable] 106 class googlePayloadJson { 107 public string orderId; 108 public string packageName; 109 public string productId; 110 public uint purchaseTime; 111 public uint purchaseState; 112 public string purchaseToken; 113 public googlePayloadJson() { 114 this.orderId = null; 115 this.packageName = null; 116 this.productId = null; 117 this.purchaseTime = 0; 118 this.purchaseState = 0; 119 this.purchaseToken = null; 120 } 121 } 122 123 private string getReceiptPayload(string strReceipt) { 124 unityReceipt u5r = JsonUtility.FromJson<unityReceipt>(strReceipt); 125 if (u5r != null) { 126 string receipt = null; 127 googlePlayPayload gpp = JsonUtility.FromJson<googlePlayPayload>(u5r.Payload); 128 if (gpp != null) { 129 receipt = gpp.json; 130 if (!string.IsNullOrEmpty(receipt)) { 131 googlePayloadJson googleJson = JsonUtility.FromJson<googlePayloadJson>(receipt); 132 if (googleJson != null) { 133 receipt = googleJson.orderId;// ←何故かSandboxでしか存在しない. 134 } else { 135 receipt = null; 136 } 137 } 138 } 139#if RECEIPT_VALIDATION 140 if (Application.platform == RuntimePlatform.Android) { 141 try { 142 var result = validator.Validate(strReceipt);// ←この中でクラッシュ. 143 foreach (IPurchaseReceipt productReceipt in result) { 144 GooglePlayReceipt google = productReceipt as GooglePlayReceipt; 145 if (null != google) { 146 147 } 148 } 149 } catch (IAPSecurityException) { 150 receipt = null;// 不正なレシートだったので不成立とする. 151 } 152 } 153#endif 154 return receipt;// OK 155 } 156 return null; 157 } 158 // 購入実行(成功). 159 public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args) { 160 bool given = false; 161 if (String.Equals(args.purchasedProduct.definition.id, "PRODUCT_ID1", StringComparison.Ordinal)) { 162 string receipt = getReceiptPayload(args.purchasedProduct.receipt, "test01"); 163 if (string.IsNullOrEmpty(receipt)) { 164 // 不正?想定外? 165 } else { 166 // (ここで付与) 167 given = true; 168 } 169 } else if (String.Equals(args.purchasedProduct.definition.id, "PRODUCT_ID2", StringComparison.Ordinal)) { 170 string receipt = getReceiptPayload(args.purchasedProduct.receipt, "test02"); 171 if (string.IsNullOrEmpty(receipt)) { 172 // 不正?想定外? 173 } else { 174 // (ここで付与) 175 given = true; 176 } 177 } 178 if (!given) { 179 // (付与失敗) 180 } 181 return PurchaseProcessingResult.Complete; 182 } 183 184 // 購入失敗. 185 public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason) { 186 // (付与失敗) 187 } 188} 189
あと、6/20までに何度か購入テストしていた時のレシートメールは日本語の件名で
「テスト:Google Play のご注文明細(ご注文:2016/06/??) - Goole Play ご購入ありがとうご(以下略)」
のようにきていましたが6/24以降に来ているレシートメールは全て英語の件名で
「Test: Your Google Play Order Receipt from Jun ??,2016 - Google Play Thank you. You've made a purchase (以下略)」
のように変わっていました。(メールの内容(本文)は日本語のレシートですが件名だけ英語に変わった状態)
回答3件
あなたの回答
tips
プレビュー