Android 使用flatter确认购买

Android 使用flatter确认购买,android,flutter,in-app-purchase,Android,Flutter,In App Purchase,Flatter的in_app_purchase插件已更新至0.3.0版,将Google Play库迁移至2.0.3版。 根据Google Play Library v2,如果是测试订单,所有购买必须在3天或5分钟内确认,否则将自动取消。 在In_app_purchase的最新提交中,一个名为Acknowledge purchase的方法被添加到BillingClient类中。 但是,当前记录在案的进行应用内购买的方式是通过InAppPurchaseConnection.instance,它不提供

Flatter的in_app_purchase插件已更新至0.3.0版,将Google Play库迁移至2.0.3版。 根据Google Play Library v2,如果是测试订单,所有购买必须在3天或5分钟内确认,否则将自动取消。 在In_app_purchase的最新提交中,一个名为Acknowledge purchase的方法被添加到BillingClient类中。 但是,当前记录在案的进行应用内购买的方式是通过InAppPurchaseConnection.instance,它不提供任何确认购买的方法

in_app_purchase的一般实现如下所示:

//倾听新购买 final Stream purchaseUpdates=InAppPurchaseConnection.instance.purchaseUpdatedStream; StreamSubscription\u subscription=purchaseUpdates.listenpurchases{ _handlePurchaseUpdatespurchases; }; //产品详情 ProductDetailsResponse\u ProductDetailsResponse=wait InApp-PurchaseConnection.instance.queryProductDetailsthis.ProductId.toSet; //过去的购买 QueryPurchaseDetailsResponse\u purchaseDetailsResponse=apppurchaseconnection.instance.queryPastPurchases等待; //进行不可消费的购买 PurchaseParam param=PurchaseParam productDetails:productDetails, applicationUserName:null, 沙盒测试:沙盒测试 ; InAppPurchaseConnection.instance.buyNonConsumablepurchaseParam:param;
一旦购买并验证,产品即交付。但是,我们如何在倾听新购买的同时确认新购买,如果在获取过去购买的列表时未确认旧购买,如何确认旧购买?

我也在寻找解决方案,看起来在发行说明中有描述。

例如,在获取过去购买的物品时:

//在顶级级别,即应用程序包装器 InApp PurchaseConnection.enablePendingPurchases; //在课堂内处理购买 final InAppPurchaseConnection _connection=InAppPurchaseConnection.instance; //示例使用 最终QueryPurchaseDetailsResponse purchaseResponse=await\u connection.queryPastPurchases; 如果purchaseResponse.error!=空的{ //处理错误 }否则{ //清除本地存储 等待未来 purchaseResponse.pastPurchases,purchaseDetails异步{ 如果等待(u verifyPurchasepurchaseDetails){ 等待//将购买插入本地商店; 最终挂起=Platform.isIOS ?采购详情。待完成采购 :!purchaseDetails.billingClientPurchase.isAcknowledged; 如果待决{ 等待连接。完成采购采购详细信息; } } } ; } 以前,step_connection.competitepurchase仅用于iOS,现在Android也需要它

purchaseDetails.pendingCompletePurchase如果购买需要在iOS和Android上完成,则为true

purchaseDetails.billingClientPurchase.isAcknowledged添加了Android附加检查,以确保在需要时执行completePurchase

0.3.0

计费客户端包装的其他更新: 更新PurchaseWrapper:添加developerPayload、purchaseState和isAcknowledged字段

InAppPurchaseConnection的更新: [中断更改]:InAppPurchaseConnection.completePurchase现在返回的是未来,而不是未来。API中还添加了一个新的可选参数{String developerPayload}。在Android上,该API不再抛出异常,而是确认购买。如果在Android上3天内未完成购买,用户将获得退款

[Breaking Change]:InAppPurchaseConnection.consumePurchase现在返回的是未来,而不是未来。API中还添加了一个新的可选参数{String developerPayload}。 PurchaseDetails类中添加了一个新的布尔字段pendingCompletePurchase。它可以用作是否在购买时调用InAppPurchaseConnection.completePurchase的指示器

[中断更改]:在AppPurchaseConnection中添加了enablePendingPurchases。在Android上初始化InAppPurchaseConnection时,应用程序必须调用此方法。有关更多信息,请参阅enablePendingPurchases


我也在寻找解决方案,看起来在发行说明中有描述。

例如,在获取过去购买的物品时:

//在顶级级别,即应用程序包装器 InApp PurchaseConnection.enablePendingPurchases; //在课堂内处理购买 final InAppPurchaseConnection _connection=InAppPurchaseConnection.instance; //示例使用 最终QueryPurchaseDetailsResponse purchaseResponse=await\u connection.queryPastPurchases; 如果purchaseResponse.error!=空的{ //处理错误 }否则{ //清除本地存储 等待未来 purchaseResponse.pastPurchases,purchaseDetails异步{ 如果等待(u VerifyPurchasePurchasePurchasePurchasePurchasePurchasePurchasePurchasePurchasePurchased) 蜗牛{ 等待//将购买插入本地商店; 最终挂起=Platform.isIOS ?采购详情。待完成采购 :!purchaseDetails.billingClientPurchase.isAcknowledged; 如果待决{ 等待连接。完成采购采购详细信息; } } } ; } 以前,step_connection.competitepurchase仅用于iOS,现在Android也需要它

purchaseDetails.pendingCompletePurchase如果购买需要在iOS和Android上完成,则为true

purchaseDetails.billingClientPurchase.isAcknowledged添加了Android附加检查,以确保在需要时执行completePurchase

0.3.0

计费客户端包装的其他更新: 更新PurchaseWrapper:添加developerPayload、purchaseState和isAcknowledged字段

InAppPurchaseConnection的更新: [中断更改]:InAppPurchaseConnection.completePurchase现在返回的是未来,而不是未来。API中还添加了一个新的可选参数{String developerPayload}。在Android上,该API不再抛出异常,而是确认购买。如果在Android上3天内未完成购买,用户将获得退款

[Breaking Change]:InAppPurchaseConnection.consumePurchase现在返回的是未来,而不是未来。API中还添加了一个新的可选参数{String developerPayload}。 PurchaseDetails类中添加了一个新的布尔字段pendingCompletePurchase。它可以用作是否在购买时调用InAppPurchaseConnection.completePurchase的指示器

[中断更改]:在AppPurchaseConnection中添加了enablePendingPurchases。在Android上初始化InAppPurchaseConnection时,应用程序必须调用此方法。有关更多信息,请参阅enablePendingPurchases


谢谢你的回答,这对我帮助很大。请将这些要点添加到您的答案中,以便更好地帮助他人。1.purchaseDetails.pendingCompletePurchase可能为false,即使对于尚未确认的购买也是如此。但是,如果purchaseDetails.pendingCompletePurchase为true,则必须调用_connection.completePurchasepurchaseDetails 2。要检查购买是否已确认,您必须使用purchaseDetails.billingClientPurchase.isAcknowledged.purchaseDetails.billingClientPurchase在iOS上为空,因为这就是为什么purchaseDetails.pendingCompletePurchase可以覆盖这两种平台的原因。如果不承认,事实上可能不是这样,但在这种情况下,购买状态不是购买的。谢谢你的回答,这对我帮助很大。请将这些要点添加到您的答案中,以便更好地帮助他人。1.purchaseDetails.pendingCompletePurchase可能为false,即使对于尚未确认的购买也是如此。但是,如果purchaseDetails.pendingCompletePurchase为true,则必须调用_connection.completePurchasepurchaseDetails 2。要检查购买是否已确认,您必须使用purchaseDetails.billingClientPurchase.isAcknowledged.purchaseDetails.billingClientPurchase在iOS上为空,因为这就是为什么purchaseDetails.pendingCompletePurchase可以覆盖这两种平台的原因。如果未确认,则事实上可能不真实,但在这种情况下,购买状态未被购买。