跳到主要内容

inAppPurchase

Mac App Store 中的应用内购买。

进程:主进程

事件

inAppPurchase 模块发出以下事件

事件:'transactions-updated'

返回值

  • event 事件
  • transactions Transaction[] - Transaction 对象的数组。

当一个或多个交易被更新时发出。

方法

inAppPurchase 模块具有以下方法

inAppPurchase.purchaseProduct(productID[, opts])

  • productID 字符串
  • opts Integer | Object (可选)- 如果指定为整数,则定义数量。
    • quantity Integer (可选)- 用户想要购买的商品数量。
    • username string (可选)- 将交易与您服务上的用户账户(applicationUsername)关联的字符串。

返回 Promise<boolean> - 如果产品有效并已添加到支付队列,则返回 true

您应该尽快监听 transactions-updated 事件,并且肯定要在调用 purchaseProduct 之前进行监听。

inAppPurchase.getProducts(productIDs)

  • productIDs string[] - 要获取的产品的标识符。

返回 Promise<Product[]> - 解析为 Product 对象的数组。

检索产品描述。

inAppPurchase.canMakePayments()

返回 boolean - 用户是否可以进行支付。

inAppPurchase.restoreCompletedTransactions()

恢复已完成的交易。此方法可以用于在其他设备上安装购买项,或者恢复用户删除并重新安装的应用程序的购买项。

支付队列为每个先前完成的可恢复交易提供一个新的交易。每个交易都包含原始交易的副本。

inAppPurchase.getReceiptURL()

返回 string - 收据的路径。

inAppPurchase.finishAllTransactions()

完成所有待处理的交易。

inAppPurchase.finishTransactionByDate(date)

  • date string - 要完成的交易的 ISO 格式日期。

完成与该日期相对应的待处理交易。