Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

GooglePlayConfiguration.cs 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #nullable enable
  2. using System;
  3. using UnityEngine.Purchasing.Extension;
  4. using UnityEngine.Purchasing.Interfaces;
  5. namespace UnityEngine.Purchasing
  6. {
  7. /// <summary>
  8. /// Access Google Play store specific configurations.
  9. /// </summary>
  10. class GooglePlayConfiguration : IGooglePlayConfiguration, IGooglePlayConfigurationInternal
  11. {
  12. Action? m_InitializationConnectionLister;
  13. readonly IGooglePlayStoreService m_GooglePlayStoreService;
  14. Action<Product>? m_DeferredPurchaseAction;
  15. Action<Product>? m_DeferredProrationUpgradeDowngradeSubscriptionAction;
  16. Action<int>? m_QueryProductDetailsFailedListener;
  17. bool m_FetchPurchasesAtInitialize = true;
  18. bool m_FetchPurchasesExcludeDeferred = true;
  19. public GooglePlayConfiguration(IGooglePlayStoreService googlePlayStoreService)
  20. {
  21. m_GooglePlayStoreService = googlePlayStoreService;
  22. }
  23. /// <summary>
  24. /// Set an optional listener for failures when connecting to the base Google Play Billing service. This may be called
  25. /// after <typeparamref name="UnityPurchasing.Initialize"/> if a user does not have a Google account added to their
  26. /// Android device.
  27. /// </summary>
  28. /// <param name="action">Will be called when <typeparamref name="UnityPurchasing.Initialize"/>
  29. /// is interrupted by a disconnection from the Google Play Billing service.</param>
  30. public void SetServiceDisconnectAtInitializeListener(Action action)
  31. {
  32. m_InitializationConnectionLister = action;
  33. }
  34. /// <summary>
  35. /// Internal API, do not use.
  36. /// </summary>
  37. public void NotifyInitializationConnectionFailed()
  38. {
  39. m_InitializationConnectionLister?.Invoke();
  40. }
  41. public void SetQueryProductDetailsFailedListener(Action<int> action)
  42. {
  43. m_QueryProductDetailsFailedListener = action;
  44. }
  45. public void NotifyQueryProductDetailsFailed(int retryCount)
  46. {
  47. m_QueryProductDetailsFailedListener?.Invoke(retryCount);
  48. }
  49. /// <summary>
  50. /// Set listener for deferred purchasing events.
  51. /// Deferred purchasing is enabled by default and cannot be changed.
  52. /// </summary>
  53. /// <param name="action">Deferred purchasing successful events. Do not grant the item here. Instead, record the purchase and remind the user to complete the transaction in the Play Store. </param>
  54. public void SetDeferredPurchaseListener(Action<Product> action)
  55. {
  56. m_DeferredPurchaseAction = action;
  57. }
  58. public void NotifyDeferredProrationUpgradeDowngradeSubscription(IStoreCallback? storeCallback, string productId)
  59. {
  60. var product = storeCallback.FindProductById(productId);
  61. if (product != null)
  62. {
  63. m_DeferredProrationUpgradeDowngradeSubscriptionAction?.Invoke(product);
  64. }
  65. }
  66. public bool IsFetchPurchasesAtInitializeSkipped()
  67. {
  68. return !m_FetchPurchasesAtInitialize;
  69. }
  70. public bool DoesRetrievePurchasesExcludeDeferred()
  71. {
  72. return m_FetchPurchasesExcludeDeferred;
  73. }
  74. public void NotifyDeferredPurchase(IStoreCallback? storeCallback, IGooglePurchase? purchase, string? receipt, string? transactionId)
  75. {
  76. var product = storeCallback?.FindProductById(purchase?.sku);
  77. if (product != null)
  78. {
  79. ProductPurchaseUpdater.UpdateProductReceiptAndTransactionID(product, receipt, transactionId, GooglePlay.Name);
  80. m_DeferredPurchaseAction?.Invoke(product);
  81. }
  82. }
  83. /// <summary>
  84. /// Set listener for deferred subscription change events.
  85. /// Deferred subscription changes only take effect at the renewal cycle and no transaction is done immediately, therefore there is no receipt nor token.
  86. /// </summary>
  87. /// <param name="action">Deferred subscription change event. No payout is granted here. Instead, notify the user that the subscription change will take effect at the next renewal cycle. </param>
  88. public void SetDeferredProrationUpgradeDowngradeSubscriptionListener(Action<Product> action)
  89. {
  90. m_DeferredProrationUpgradeDowngradeSubscriptionAction = action;
  91. }
  92. /// <summary>
  93. /// Optional obfuscation string to detect irregular activities when making a purchase.
  94. /// For more information please visit <a href="https://developer.android.com/google/play/billing/security">https://developer.android.com/google/play/billing/security</a>
  95. /// </summary>
  96. /// <param name="accountId">The obfuscated account id</param>
  97. public void SetObfuscatedAccountId(string accountId)
  98. {
  99. m_GooglePlayStoreService.SetObfuscatedAccountId(accountId);
  100. }
  101. /// <summary>
  102. /// Optional obfuscation string to detect irregular activities when making a purchase
  103. /// For more information please visit <a href="https://developer.android.com/google/play/billing/security">https://developer.android.com/google/play/billing/security</a>
  104. /// </summary>
  105. /// <param name="profileId">The obfuscated profile id</param>
  106. public void SetObfuscatedProfileId(string? profileId)
  107. {
  108. m_GooglePlayStoreService.SetObfuscatedProfileId(profileId);
  109. }
  110. public void SetFetchPurchasesAtInitialize(bool enable)
  111. {
  112. m_FetchPurchasesAtInitialize = enable;
  113. }
  114. public void SetFetchPurchasesExcludeDeferred(bool exclude)
  115. {
  116. m_FetchPurchasesExcludeDeferred = exclude;
  117. }
  118. public void SetMaxConnectionAttempts(int maxConnectionAttempts)
  119. {
  120. m_GooglePlayStoreService.SetMaxConnectionAttempts(maxConnectionAttempts);
  121. }
  122. }
  123. }