質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

0回答

2584閲覧

Unity IAPでGooglePlayのリストアボタンを設置したいが、PurchaseEventArgsが正常に取得されない。

ishizaku

総合スコア4

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2020/10/26 03:28

問題定義

CodelessIAPにてIGooglePlayStoreExtensions.RestoreTransactionsでリストア処理を行ったところ、複数リストア対象があったとしてもPurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)に1つしか送られてこない。
こちらの原因と、全リストア対象が送られてくるようにしたい。

試したこと

・複数の非消費型を購入した状態で端末テスト。
・hasReceiptでリストア判定が適正なことを確認。
・IGooglePlayStoreExtensions.RestoreTransactionsを実行したところ、1つしかPurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)を通らない。
・複数の購入済み非消費型のうち、1つをGooglePlay購入時の自動リストア処理でリストアを行った。
・その後再度IGooglePlayStoreExtensions.RestoreTransactionsを実行したところ、PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)を全てのリストア対象が通過した。

詳細

Android版で「購入を復元」ボタンを設けることになり、リストア処理を実装することになりました。
Unity IAPではGooglePlayのリストア処理は実装されていないので、自作することとなり、IAPButton.csのリストア処理にIGooglePlayStoreExtensionsを設けてGooglePlay用のリストア処理を実装してみました。
しかし、上記の問題が発生しうまく実装ができません。ご存知の方いらっしゃいましたら是非解決策をご教授頂きたいです。
※IAPButton.csのみGooglePlayリストア用に一部追記しております。
※CodelessIAPStoreListener.csは変更ありません。

IAPButton.cs (自作部分はコメントで記載)

C#

1#if UNITY_PURCHASING || UNITY_UNIFIED_IAP 2using UnityEngine.Events; 3using UnityEngine.UI; 4using System.IO; 5using System.Collections.Generic; 6using TMPro; 7 8namespace UnityEngine.Purchasing 9{ 10 [RequireComponent(typeof(Button))] 11 [AddComponentMenu("Unity IAP/IAP Button")] 12 [HelpURL("https://docs.unity3d.com/Manual/UnityIAP.html")] 13 public class IAPButton : MonoBehaviour 14 { 15 public enum ButtonType 16 { 17 Purchase, 18 Restore 19 } 20 21 [System.Serializable] 22 public class OnPurchaseCompletedEvent : UnityEvent<Product> 23 { 24 }; 25 26 [System.Serializable] 27 public class OnPurchaseFailedEvent : UnityEvent<Product, PurchaseFailureReason> 28 { 29 }; 30 31 [HideInInspector] 32 public string productId; 33 34 [Tooltip("The type of this button, can be either a purchase or a restore button")] 35 public ButtonType buttonType = ButtonType.Purchase; 36 37 [Tooltip("Consume the product immediately after a successful purchase")] 38 public bool consumePurchase = true; 39 40 [Tooltip("Event fired after a successful purchase of this product")] 41 public OnPurchaseCompletedEvent onPurchaseComplete; 42 43 [Tooltip("Event fired after a failed purchase of this product")] 44 public OnPurchaseFailedEvent onPurchaseFailed; 45 46 [Tooltip("[Optional] Displays the localized title from the app store")] 47 public TextMeshProUGUI titleText; 48 49 [Tooltip("[Optional] Displays the localized description from the app store")] 50 public TextMeshProUGUI descriptionText; 51 52 [Tooltip("[Optional] Displays the localized price from the app store")] 53 public TextMeshProUGUI priceText; 54 55 void Start() 56 { 57 Button button = GetComponent<Button>(); 58 59 if (buttonType == ButtonType.Purchase) 60 { 61 if (button) 62 { 63 button.onClick.AddListener(PurchaseProduct); 64 } 65 66 if (string.IsNullOrEmpty(productId)) 67 { 68 Debug.LogError("IAPButton productId is empty"); 69 } 70 71 if (!CodelessIAPStoreListener.Instance.HasProductInCatalog(productId)) 72 { 73 Debug.LogWarning("The product catalog has no product with the ID \"" + productId + "\""); 74 } 75 } 76 else if (buttonType == ButtonType.Restore) 77 { 78 if (button) 79 { 80 button.onClick.AddListener(Restore); 81 } 82 } 83 } 84 85 //GameObject生成時に外部からproductIdを取得するため作成 86 public void Initialize(ProductCatalogItem productid) 87 { 88 productId = productid.id; 89 if (buttonType == ButtonType.Purchase) 90 { 91 CodelessIAPStoreListener.Instance.AddButton(this); 92 if (CodelessIAPStoreListener.initializationComplete) 93 { 94 //リストア対象か確認 95 Debug.Log("ReStore : " + CodelessIAPStoreListener.Instance.GetProduct(productId).hasReceipt); 96 UpdateText(); 97 } 98 } 99 } 100 101 //Initializeで初期化するためOnEnableは不必要に 102 void OnEnable() 103 { 104 /* 105 if (buttonType == ButtonType.Purchase) 106 { 107 CodelessIAPStoreListener.Instance.AddButton(this); 108 if (CodelessIAPStoreListener.initializationComplete) 109 { 110 UpdateText(); 111 } 112 } 113 */ 114 } 115 116 void OnDisable() 117 { 118 if (buttonType == ButtonType.Purchase) 119 { 120 CodelessIAPStoreListener.Instance.RemoveButton(this); 121 } 122 } 123 124 void PurchaseProduct() 125 { 126 if (buttonType == ButtonType.Purchase) 127 { 128 Debug.Log("IAPButton.PurchaseProduct() with product ID: " + productId); 129 130 CodelessIAPStoreListener.Instance.InitiatePurchase(productId); 131 } 132 } 133 134 void Restore() 135 { 136 if (buttonType == ButtonType.Restore) 137 { 138 if (Application.platform == RuntimePlatform.WSAPlayerX86 || 139 Application.platform == RuntimePlatform.WSAPlayerX64 || 140 Application.platform == RuntimePlatform.WSAPlayerARM) 141 { 142 CodelessIAPStoreListener.Instance.ExtensionProvider.GetExtension<IMicrosoftExtensions>() 143 .RestoreTransactions(); 144 } 145 else if (Application.platform == RuntimePlatform.IPhonePlayer || 146 Application.platform == RuntimePlatform.OSXPlayer || 147 Application.platform == RuntimePlatform.tvOS) 148 { 149 CodelessIAPStoreListener.Instance.ExtensionProvider.GetExtension<IAppleExtensions>() 150 .RestoreTransactions(OnTransactionsRestored); 151 } 152 else if (Application.platform == RuntimePlatform.Android && 153 StandardPurchasingModule.Instance().appStore == AppStore.SamsungApps) 154 { 155 CodelessIAPStoreListener.Instance.ExtensionProvider.GetExtension<ISamsungAppsExtensions>() 156 .RestoreTransactions(OnTransactionsRestored); 157 } 158 //GooglePlay用にリストア処理を作成 159 else if (Application.platform == RuntimePlatform.Android && 160 StandardPurchasingModule.Instance().appStore == AppStore.GooglePlay) 161 { 162 CodelessIAPStoreListener.Instance.ExtensionProvider.GetExtension<IGooglePlayStoreExtensions>() 163 .RestoreTransactions(OnTransactionsRestored); 164 } 165 else 166 { 167 Debug.LogWarning(Application.platform.ToString() + 168 " is not a supported platform for the Codeless IAP restore button"); 169 } 170 } 171 } 172 173 void OnTransactionsRestored(bool success) 174 { 175 Debug.Log("Transactions restored: " + success); 176 } 177 178 /** 179 * Invoked to process a purchase of the product associated with this button 180 */ 181 public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e) 182 { 183 Debug.Log(string.Format("IAPButton.ProcessPurchase(PurchaseEventArgs {0} - {1})", e, 184 e.purchasedProduct.definition.id)); 185 186 onPurchaseComplete.Invoke(e.purchasedProduct); 187 188 return (consumePurchase) ? PurchaseProcessingResult.Complete : PurchaseProcessingResult.Pending; 189 } 190 191 /** 192 * Invoked on a failed purchase of the product associated with this button 193 */ 194 public void OnPurchaseFailed(Product product, PurchaseFailureReason reason) 195 { 196 Debug.Log(string.Format("IAPButton.OnPurchaseFailed(Product {0}, PurchaseFailureReason {1})", product, 197 reason)); 198 199 onPurchaseFailed.Invoke(product, reason); 200 } 201 202 internal void UpdateText() 203 { 204 var product = CodelessIAPStoreListener.Instance.GetProduct(productId); 205 if (product != null) 206 { 207 if (titleText != null) 208 { 209 titleText.text = product.metadata.localizedTitle; 210 } 211 212 if (descriptionText != null) 213 { 214 descriptionText.text = product.metadata.localizedDescription; 215 } 216 217 if (priceText != null) 218 { 219 priceText.text = product.metadata.localizedPriceString; 220 } 221 } 222 } 223 } 224} 225#endif 226

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問