From 2cc9d66aa1ae6db81685f1ff5219c029da6d29f9 Mon Sep 17 00:00:00 2001 From: huyufei Date: Thu, 9 May 2024 20:35:47 +0800 Subject: [PATCH] + add new iap API method for subscraption. --- Runtime/Code/SDK/GuruSDK.Ads.cs | 6 +-- Runtime/Code/SDK/GuruSDK.IAP.cs | 92 ++++++++++++++++++++++++++++++++- Runtime/Code/SDK/GuruSDK.cs | 8 ++- Tests/Test_IAP.cs | 13 +++-- package.json | 2 +- 5 files changed, 111 insertions(+), 10 deletions(-) diff --git a/Runtime/Code/SDK/GuruSDK.Ads.cs b/Runtime/Code/SDK/GuruSDK.Ads.cs index 4ba5d1f..0eac1a5 100644 --- a/Runtime/Code/SDK/GuruSDK.Ads.cs +++ b/Runtime/Code/SDK/GuruSDK.Ads.cs @@ -233,12 +233,12 @@ namespace Guru private void CheckPermission() { float delay = 1; - Debug.Log($"---- Check PushPermission ---"); + UnityEngine.Debug.Log($"---- Check PushPermission ---"); #if UNITY_ANDROID // 如果已经请求过权限的话, 则不做动作 if (UnityEngine.Android.Permission.HasUserAuthorizedPermission(PERMISSION_POST_NOTIFICATION)) { - Debug.Log($"--- PushPermission has passed ---"); + UnityEngine.Debug.Log($"--- PushPermission has passed ---"); return; } #endif @@ -251,7 +251,7 @@ namespace Guru private void RequestNotification() { #if UNITY_ANDROID - Debug.Log("--- Target 33 Request Notification ---"); + UnityEngine.Debug.Log("--- Target 33 Request Notification ---"); // Android直接申请授权 if (!UnityEngine.Android.Permission.HasUserAuthorizedPermission(PERMISSION_POST_NOTIFICATION)) { diff --git a/Runtime/Code/SDK/GuruSDK.IAP.cs b/Runtime/Code/SDK/GuruSDK.IAP.cs index a192e52..845f3a6 100644 --- a/Runtime/Code/SDK/GuruSDK.IAP.cs +++ b/Runtime/Code/SDK/GuruSDK.IAP.cs @@ -23,7 +23,7 @@ namespace Guru /// /// 初始化IAP 功能 /// - public static void InitIAP(byte[] googleKey, byte[] appleRootCerts) + public static void InitIAP(string userId, byte[] googleKey, byte[] appleRootCerts) { GuruIAP.Instance.OnInitResult += OnIAPInitResult; GuruIAP.Instance.OnRestored += OnRestored; @@ -34,7 +34,7 @@ namespace Guru Callbacks.IAP._onIAPInitStart?.Invoke(); // 初始化之前进行调用 - GuruIAP.Instance.InitWithKeys(googleKey, appleRootCerts, IsDebugMode); + GuruIAP.Instance.InitWithKeys(userId, googleKey, appleRootCerts, IsDebugMode); } /// @@ -244,6 +244,94 @@ namespace Guru } #endregion + + #region Subscriptions + + /// + /// 订阅是否被取消 + /// + /// + /// + public static bool IsSubscriptionCancelled(string productName) + { + return GuruIAP.Instance.IsSubscriptionCancelled(productName); + } + /// + /// 订阅是否可用 + /// + /// + /// + public static bool IsSubscriptionAvailable(string productName) + { + return GuruIAP.Instance.IsSubscriptionAvailable(productName); + } + + /// + /// 订阅是否过期 + /// + /// + /// + public static bool IsSubscriptionExpired(string productName) + { + return GuruIAP.Instance.IsSubscriptionExpired(productName); + } + + public static bool IsSubscriptionFreeTrail(string productName) + { + return GuruIAP.Instance.IsSubscriptionFreeTrail(productName); + } + + public static bool IsSubscriptionAutoRenewing(string productName) + { + return GuruIAP.Instance.IsSubscriptionAutoRenewing(productName); + } + + public static bool IsSubscriptionIntroductoryPricePeriod(string productName) + { + return GuruIAP.Instance.IsSubscriptionIntroductoryPricePeriod(productName); + } + + public DateTime GetSubscriptionExpireDate(string productName) + { + return GuruIAP.Instance.GetSubscriptionExpireDate(productName); + } + + + public DateTime GetSubscriptionPurchaseDate(string productName) + { + return GuruIAP.Instance.GetSubscriptionPurchaseDate(productName); + } + + + public DateTime GetSubscriptionCancelDate(string productName) + { + return GuruIAP.Instance.GetSubscriptionCancelDate(productName); + } + + + public TimeSpan GetSubscriptionRemainingTime(string productName) + { + return GuruIAP.Instance.GetSubscriptionRemainingTime(productName); + } + + public TimeSpan GetSubscriptionIntroductoryPricePeriod(string productName) + { + return GuruIAP.Instance.GetSubscriptionIntroductoryPricePeriod(productName); + } + + + public TimeSpan GetSubscriptionFreeTrialPeriod(string productName) + { + return GuruIAP.Instance.GetSubscriptionFreeTrialPeriod(productName); + } + + public string GetSubscriptionInfoJsonString(string productName) + { + return GuruIAP.Instance.GetSubscriptionInfoJsonString(productName); + } + + + #endregion } } \ No newline at end of file diff --git a/Runtime/Code/SDK/GuruSDK.cs b/Runtime/Code/SDK/GuruSDK.cs index 9e3a025..f3ee024 100644 --- a/Runtime/Code/SDK/GuruSDK.cs +++ b/Runtime/Code/SDK/GuruSDK.cs @@ -334,7 +334,13 @@ namespace Guru Try(() => { LogI($"#4.3 --- Start IAP ---"); - InitIAP(_initConfig.GoogleKeys, _initConfig.AppleRootCerts); // 初始化IAP + if (_initConfig.GoogleKeys == null || _initConfig.AppleRootCerts == null) + { + LogException("[IAP] GoogleKeys is null when using IAPService! Integration failed. App will Exit"); + } + + + InitIAP(UID, _initConfig.GoogleKeys, _initConfig.AppleRootCerts); // 初始化IAP }, ex => { UnityEngine.Debug.LogError($"--- ERROR on useIAP: {ex.Message}"); diff --git a/Tests/Test_IAP.cs b/Tests/Test_IAP.cs index 2c7f504..aa04d2b 100644 --- a/Tests/Test_IAP.cs +++ b/Tests/Test_IAP.cs @@ -2,13 +2,13 @@ -using UnityEngine; namespace Guru.Debug.Tests { - using Debug; using UnityEditor; using NUnit.Framework; + using UnityEngine; + using System; public class Test_IAP { @@ -18,9 +18,16 @@ namespace Guru.Debug.Tests { var model = IAPModel.Load(); int level = 1; + int orderType = 0; for (int i = 0; i < 5; i++) { - model.AddAppleOrder(new AppleOrderData(0, $"i.iap.test.icon_{i}", "receipt_{i}", level)); + model.AddAppleOrder(new AppleOrderData(orderType, + $"i.iap.test.icon_{i}", + $"receipt_{i}", + $"order_id_{i}", + DateTime.Now.ToString("g"), + level)); + level++; } diff --git a/package.json b/package.json index 60e011c..fea39b6 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "description": "Guru SDK for unity project", "unity": "2020.3", "author":{ - "name": "Guru Games" + "name": "Guru Game" }, "license": "MIT", "category": "Game,Tool,Development",