/******************************************************************************* Copyright © 2015-2022 PICO Technology Co., Ltd.All rights reserved. NOTICE:All information contained herein is, and remains the property of PICO Technology Co., Ltd. The intellectual and technical concepts contained herein are proprietary to PICO Technology Co., Ltd. and may be covered by patents, patents in process, and are protected by trade secret or copyright law. Dissemination of this information or reproduction of this material is strictly forbidden unless prior written permission is obtained from PICO Technology Co., Ltd. *******************************************************************************/ using System; using Pico.Platform.Models; using UnityEngine; namespace Pico.Platform { /** * \ingroup Platform * * You can diversify user experience and grow your revenue by selling * products such as cosmetics, props, and coins/diamonds within your * app. The PICO Unity Integration SDK provides In-App Purchase (IAP) * service which enables users to purchase products within your app. * The IAP service packages a series of payments systems such as Alipay, * bank card, and Paypal, thereby providing you with a one-stop * multi-payment-method solution. */ public static class IAPService { /// /// Records the order fulfillment result for a consumable. /// @note Users are unable to repurchase the same comsumable until the previous order is fulfilled. /// /// The SKU of the add-on to fulfill. public static Task ConsumePurchase(string sku) { if (!CoreService.Initialized) { Debug.LogError(CoreService.NotInitializedError); return null; } return new Task(CLIB.ppf_IAP_ConsumePurchase(sku)); } /// Gets a list of purchasable add-ons in the current app. /// The SKUs of the add-ons to retrieve. If this parameter is empty, all purchasable add-ons will be returned. /// A list of purchasable add-ons with their information, including the description, price, SKU, and more. public static Task GetProductsBySKU(string[] skus) { if (!CoreService.Initialized) { Debug.LogError(CoreService.NotInitializedError); return null; } if (skus == null) { skus = Array.Empty(); } return new Task(CLIB.ppf_IAP_GetProductsBySKU(skus)); } /// Gets a list of purchased add-ons for a user, including durables and unfilfilled consumables. /// A list of the user's purchased add-ons. public static Task GetViewerPurchases() { if (!CoreService.Initialized) { Debug.LogError(CoreService.NotInitializedError); return null; } return new Task(CLIB.ppf_IAP_GetViewerPurchases()); } /// @deprecated LaunchCheckoutFlow(string sku,string price,string currency) can be replaced by \ref LaunchCheckoutFlow2(Product product) /// /// Launches the checkout flow for a user to make a payment. /// \note This method doesn't support subscription add-ons, you need to /// use \ref LaunchCheckoutFlow2 instead. /// /// The SKU of the product the user wants to purchase. /// The price for the product. /// The currency of the payment. /// Returns the purchased product if the user successfully pays the money. /// Otherwise the purchase will be null. You can get the failure reason from the returned error code and error message. [Obsolete("Please use LaunchCheckoutFlow2(Product product)", false)] public static Task LaunchCheckoutFlow(string sku, string price, string currency) { if (!CoreService.Initialized) { Debug.LogError(CoreService.NotInitializedError); return null; } return new Task(CLIB.ppf_IAP_LaunchCheckoutFlow(sku, price, currency)); } /// /// Launches the checkout flow for a user to make a payment. /// /// The add-on's information which can be acquired by \ref GetProductsBySKU. /// /// Returns the purchased add-on if the user successfully makes the payment. /// Otherwise the purchase will be null. You can get the failure reason from the returned error code and error message. /// public static Task LaunchCheckoutFlow2(Product product) { if (!CoreService.Initialized) { Debug.LogError(CoreService.NotInitializedError); return null; } return new Task(CLIB.ppf_IAP_LaunchCheckoutFlowV2(product.SKU, product.Price, product.Currency, product.OuterId)); } /// /// Launches the checkout flow for a user to make a payment. /// /// The add-on's information which can be acquired by \ref GetProductsBySKU. /// /// The comment for the order. If the user successfully purchases this add-on, /// The order's comment can be accessed in \ref Purchase. The length of this field cannot exceed 1024 bytes in UTF-8 encoding. /// /// Returns the purchased add-on if the user successfully makes the payment. /// Otherwise the purchase will be null. You can get the failure reason from the returned error code and error message. /// public static Task LaunchCheckoutFlow3(Product product, string orderComment) { if (!CoreService.Initialized) { Debug.LogError(CoreService.NotInitializedError); return null; } return new Task(CLIB.ppf_IAP_LaunchCheckoutFlowV3(product.SKU, product.Price, product.Currency, product.OuterId, orderComment)); } /// /// Gets the subscription status of a subscription add-on. /// /// The SKU of the add-on. /// /// The subscription status of the add-on. If the user is not entitled to access the add-on, the result will be an empty struct. /// public static Task GetSubscriptionStatus(string sku) { if (!CoreService.Initialized) { Debug.LogError(CoreService.NotInitializedError); return null; } return new Task(CLIB.ppf_IAP_GetSubscriptionStatus(sku)); } /// /// Gets the next page of purchasable add-ons. /// /// The current page of purchasable add-ons. /// The next page of purchasable add-ons. public static Task GetNextProductListPage(ProductList list) { if (!CoreService.Initialized) { Debug.LogError(CoreService.NotInitializedError); return null; } if (!list.HasNextPage) { Debug.LogWarning("Pico.Platform.GetNextProductListPage: List has no next page"); return null; } return new Task( CLIB.ppf_IAP_GetNextProductArrayPage(list.NextPageParam) ); } /// /// Gets the next page of purchased add-ons. /// /// The current page of purchased add-ons. /// The next page of purchased add-ons. public static Task GetNextPurchaseListPage(PurchaseList list) { if (!CoreService.Initialized) { Debug.LogError(CoreService.NotInitializedError); return null; } if (!list.HasNextPage) { Debug.LogWarning("Pico.Platform.GetNextPurchaseListPage: List has no next page"); return null; } return new Task(CLIB.ppf_IAP_GetNextPurchaseArrayPage(list.NextPageParam)); } } }