You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity IAP 4.1.3版本:订单退款后仍重复调用ProcessPurchase的问题咨询

Unity IAP 4.1.3: ProcessPurchase Triggered for Refunded Google Play Orders

Hey there, let's break down why you're stuck with this persistent issue and walk through actionable fixes:

Possible Root Causes

  • Local Cache Desync: Unity IAP stores pending order data locally on the device. When a refund is processed on Google Play, older versions like 4.1.3 don't automatically sync this status update to the local cache. So every time the game initializes, it picks up the stale order entry and tries to process it repeatedly.
  • Unconsumed Orders: If the order wasn't properly marked as consumed (via ConsumePurchase() or confirming a pending purchase) before the refund, Google Play might still report the order as "incomplete" to Unity IAP, triggering endless retry attempts.
  • Version-Specific Bug: Unity IAP 4.1.3 has known gaps in its Google Play Billing integration, especially around real-time sync of refund/cancellation statuses. Later versions addressed many of these sync inconsistencies.

Fixes to Implement

1. Validate Order Status Directly in ProcessPurchase

Modify your ProcessPurchase method to check the latest order state against Google Play's data before proceeding. Use the GooglePlayStorePurchaseExtension to fetch the purchase status:

public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
    var googleExtension = args.purchasedProduct.transactionReceipt.GetGooglePlayStorePurchaseExtension();
    
    // Check if the order has been refunded
    if (googleExtension.purchaseState == GooglePurchaseState.Refunded)
    {
        // Mark the order as completed to stop Unity IAP from retrying
        return PurchaseProcessingResult.Complete;
    }
    
    // Your existing valid purchase logic goes here
    return PurchaseProcessingResult.Pending; // Or Complete if no further processing is needed
}

This tells Unity IAP to abandon processing once it detects the refunded state.

2. Force Transaction Sync on Initialization

Call RestoreTransactions() during your IAP setup to trigger a sync with Google Play's server. This can refresh the local cache with up-to-date order statuses:

UnityPurchasing.Instance.RestoreTransactions((success) => {
    if (success)
    {
        Debug.Log("Successfully synced transaction statuses with Google Play");
    }
    else
    {
        Debug.LogError("Failed to sync transactions - check network or store setup");
    }
});

Note: Follow store policies by only triggering restore when the user logs in (to avoid unintended data access), but it’s a quick way to flush stale entries in this scenario.

3. Clear Local Unity IAP Cache (Temporary Quick Fix)

For immediate testing relief, manually clear the game's cache on the device. On Android, go to Settings > Apps > [Your Game] > Storage > Clear Cache. This removes stale order data, though it’s not a permanent code-based solution.

4. Upgrade Unity IAP to a Newer Version

The most reliable long-term fix is upgrading to a stable newer version (v5.x or later). These versions have improved sync logic with Google Play Billing, including better handling of refund and cancellation events that prevent stale order retries entirely.

5. Ensure Proper Order Consumption

Double-check that all valid purchases are marked as processed correctly. If you use PurchaseProcessingResult.Pending, make sure to call UnityPurchasing.Instance.ConfirmPendingPurchase(product) once processing is done—this keeps local and server states aligned, reducing the chance of stale entries.

内容的提问来源于stack exchange,提问作者Kino

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 21:13:13