文档

支持

In-App Purchasing

In-App Purchasing

SubscriptionInfo class reference

Reference the `SubscriptionInfo` class methods to retrieve subscription product information and status.
阅读时间3 分钟最后更新于 9 天前

Unity IAP provides detailed subscription product information through the
SubscriptionInfo
class.

SubscriptionInfo class methods

The
SubscriptionInfo
class is a container for a product’s subscription-related information.
The following methods are available in the
SubscriptionInfo
class:

Method

Description

public string GetProductId()
Returns a product’s store ID.
public DateTime GetPurchaseDate()
Returns the product’s purchase date.
For Apple, the purchase date is the date when the subscription was either purchased or renewed. For Google, the purchase date is the date when the subscription was originally purchased.
public Result IsSubscribed()
Indicates if a product is currently subscribed.
Non-renewable products in the Apple App Store return a
Result.Unsupported
value. Auto-renewable products in the Apple App Store and subscription products in the Google Play Store return a
Result.True
or
Result.False
value.
public Result IsExpired()
Indicates if the subscription has expired.
* Non-renewable products in the Apple App Store return a
Result.Unsupported
value.
* Auto-renewable products in the Apple App Store and subscription products in the Google Play Store return a
Result.True
or
Result.False
value.
public Result IsCancelled()
Indicates if the subscription has been cancelled.
A cancelled subscription means the product is currently subscribed, but will not renew on the next billing date.
For Apple, this is determined by the cancellation date.
For Google, this is determined by the auto-renew status.
Non-renewable products in the Apple App Store return a
Result.Unsupported
value.
public Result IsFreeTrial()
Indicates if the product is in a free trial.
Non-renewable products in the Apple App Store return a
Result.Unsupported
value. Auto-renewable products in the Apple App Store and subscription products in the Google Play Store return a
Result.True
or
Result.False
value.
public Result IsAutoRenewing()
Indicates if the subscription is auto-renewable.
For Apple, this is computed based on product type, cancellation status, and expiration status.
For Google, this returns the stored auto-renew flag.
Non-renewable products in the Apple App Store return a
Result.Unsupported
value.
public TimeSpan GetRemainingTime()
Returns a TimeSpan indicating the time remaining until the next billing date.
Non-renewable products in the Apple App Store return
TimeSpan.Zero
.
public Result IsIntroductoryPricePeriod()
Indicates if the subscription is in an introductory price period.
Non-renewable products in the Apple App Store return a
Result.Unsupported
value.
Auto-renewable products in the Apple App Store and subscription products in the Google Play Store return a
Result.True
or
Result.False
value.
public TimeSpan GetIntroductoryPricePeriod()
Returns a
TimeSpan
to indicate how much time remains for the introductory price period.
Subscription products with no introductory price period return
TimeSpan.Zero
. Products in the Apple App Store return
TimeSpan.Zero
if the application does not support iOS version 11.2+, macOS 10.13.2+, or tvOS 11.2+.
public long GetIntroductoryPricePeriodCycles()
Returns number of introductory price cycles.
Products in the Apple App Store return 0 if the application does not support iOS version 11.2+, macOS 10.13.2+, or tvOS 11.2+.
public string GetIntroductoryPrice()
Returns the introductory price string.
Products with no introductory price return a
"not available"
value. Apple App Store products with an introductory price return a value formatted as
“0.99USD”
. Google Play products with an introductory price return a value formatted as
“$0.99”
. Products in the Apple App Store return
“not available”
if the application does not support iOS version 11.2+, macOS 10.13.2+, or tvOS 11.2+.
public DateTime GetExpireDate()
Returns the date of the product's next auto-renew or expiration (for a cancelled auto-renewing subscription).
public DateTime GetCancelDate()
Returns the date when the subscription was cancelled.
Apple App Store: Returns the cancellation date from the receipt.
Google Play Store: Not supported - returns
DateTime.MinValue
. Use IsCancelled() to check cancellation status on Google Play.
public TimeSpan GetFreeTrialPeriod()
Returns the duration of the free trial period.
Google Play Store: Returns the configured free trial duration from the product details.
Apple App Store: Not supported - returns
TimeSpan.Zero
. Free trial status can be checked with
IsFreeTrial()
.
public TimeSpan GetSubscriptionPeriod()
Returns the duration of the subscription billing period.
Google Play Store: Returns the subscription period from the product details.
Apple App Store: Not supported - returns
TimeSpan.Zero
.
public string GetFreeTrialPeriodString()
Returns the free trial period as an ISO8601 duration string (e.g., "P1W" for one week).
However, this method only returns useful data for the Google Play Store.
For the Apple App Store, this returns
null
.
public string GetSkuDetails()
Returns the raw JSON SkuDetails from the Google Play API.
For the Apple App Store, this returns
null
.
public string GetSubscriptionInfoJsonString()
Returns a JSON string with the subscription data, including
productId
,
is_free_trial
,
is_introductory_price_period
, and
remaining_time_in_seconds
.
Used internally for subscription updates to the Google Play Store.