Skip to content

Commit

Permalink
- add method subscription info
Browse files Browse the repository at this point in the history
  • Loading branch information
VirtueSky committed Dec 28, 2024
1 parent 4db1f14 commit 65c06c8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
5 changes: 5 additions & 0 deletions Editor/IapSettingsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ void GenerateProductImpl()
$"\n\t\tpublic static UnityEngine.Purchasing.Product GetProduct{CultureInfo.CurrentCulture.TextInfo.ToTitleCase(itemName)}() => IapManager.GetProduct(IapSettings.Instance.IapDataProducts[{i}]);";

str += $"\n\t\tpublic static float PriceConfig{CultureInfo.CurrentCulture.TextInfo.ToTitleCase(itemName)}() => IapSettings.Instance.IapDataProducts[{i}].price;";
if (iapDataProducts[i].iapProductType == IapProductType.Subscription)
{
str +=
$"\n\t\tpublic static UnityEngine.Purchasing.SubscriptionInfo GetSubscriptionInfo{CultureInfo.CurrentCulture.TextInfo.ToTitleCase(itemName)}() => IapManager.GetSubscriptionInfo(IapSettings.Instance.IapDataProducts[{i}]);";
}
str += "\n";
}

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

### Add the line below to `Packages/manifest.json`

for version `1.0.7`
for version `1.0.8`
```csharp
"com.wolf-org.in-app-purchasing":"https://github.com/unity-package/in-app-purchasing-unity.git#1.0.7",
"com.wolf-org.in-app-purchasing":"https://github.com/unity-package/in-app-purchasing-unity.git#1.0.8",
```
dependency `extensions-unity-1.0.5`
```csharp
Expand Down
27 changes: 18 additions & 9 deletions Runtime/IapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class IapManager : MonoBehaviour, IDetailedStoreListener

private IStoreController _controller;
private IExtensionProvider _extensionProvider;
private bool IsInitialized { get; set; }
public static bool IsInitialized { get; private set; }
private IapSettings iapSettings;

private void Awake()
Expand Down Expand Up @@ -65,7 +65,7 @@ void InitImpl()
builder.Configure<IGooglePlayConfiguration>();

UnityPurchasing.Initialize(this, builder);
IsInitialized = true;

}


Expand Down Expand Up @@ -179,13 +179,14 @@ public void OnInitialized(IStoreController controller, IExtensionProvider extens
_controller = controller;
_extensionProvider = extensions;

#if UNITY_ANDROID && !UNITY_EDITOR
foreach (var product in _controller.products.all)
{
if (product != null && !string.IsNullOrEmpty(product.transactionID))
_controller.ConfirmPendingPurchase(product);
}
#endif
// #if UNITY_ANDROID && !UNITY_EDITOR
// foreach (var product in _controller.products.all)
// {
// if (product != null && !string.IsNullOrEmpty(product.transactionID))
// _controller.ConfirmPendingPurchase(product);
// }
// #endif
IsInitialized = true;
}

public void OnPurchaseFailed(Product product, PurchaseFailureDescription failureDescription)
Expand Down Expand Up @@ -238,6 +239,12 @@ ProductType ConvertProductType(IapProductType iapProductType)
}

#region Internal API
private SubscriptionInfo InternalGetSubscriptionInfo(IapDataProduct product)
{
if (_controller == null || ConvertProductType(product.iapProductType) != ProductType.Subscription || !_controller.products.WithID(product.Id).hasReceipt) return null;
var subscriptionManager = new SubscriptionManager(InternalGetProduct(product), null);
return subscriptionManager.getSubscriptionInfo();
}

private IapDataProduct InternalPurchaseProduct(string id)
{
Expand Down Expand Up @@ -294,6 +301,8 @@ public static IapDataProduct PurchaseProduct(IapDataProduct product) =>

public static Product GetProduct(string id) => _instance.InternalGetProduct(id);
public static Product GetProduct(IapDataProduct product) => _instance.InternalGetProduct(product);
public static SubscriptionInfo GetSubscriptionInfo(IapDataProduct iapDataProduct) =>
_instance.InternalGetSubscriptionInfo(iapDataProduct);
#if UNITY_IOS
public static void RestorePurchase() => _instance.InternalRestorePurchase();
#endif
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.wolf-org.in-app-purchasing",
"displayName": "UnityCommon-IAP",
"description": "Support for unity in-app-purchasing",
"version": "1.0.7",
"version": "1.0.8",
"unity": "2021.3",
"category": "virtuesky",
"license": "MIT",
Expand Down

0 comments on commit 65c06c8

Please sign in to comment.