Monetization iap

From nlelouche/Unity-SkillForge · View interactive version

Monetization iap is an AI agent skill from the GitHub repository nlelouche/Unity-SkillForge. Setup for In-App Purchases (IAP) using Unity Purchasing. Handles product catalogs, receipt validation, and store initialization.

How to use this skill

Skill file

Monetization & IAP

Overview

Standardized In-App Purchasing (IAP) implemenation using Unity Purchasing package. Supports Consumable (Coins), Non-Consumable (Remove Ads), and Subscription products.

When to Use

Product Types

| Type | Description | Example |

|------|-------------|---------|

| Consumable | Can be bought repeatedly | 100 Gems, Health Potion |

| Non-Consumable | Bought once, permanent | Remove Ads, Level Pack |

| Subscription | Recurring billing | VIP Pass (Monthly) |

Architecture

┌─────────────────────────────────────────────────────────────┐
│                       IAP FLOW                              │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  UI BUTTON              IAP MANAGER (Unity)                 │
│  ┌──────────────┐      ┌─────────────────────────┐          │
│  │ OnClick()    │─────▶│ InitiatePurchase(ID)    │          │
│  └──────────────┘      └────────────┬────────────┘          │
│                                     │                       │
│                                     ▼                       │
│                        ┌─────────────────────────┐          │
│                        │ APP STORE / PLAY STORE  │          │
│                        │ (Process Payment)       │          │
│                        └────────────┬────────────┘          │
│                                     │                       │
│                                     ▼                       │
│  GAME LOGIC            ┌─────────────────────────┐          │
│  ┌──────────────┐      │ ProcessPurchase (Cb)    │          │
│  │ Grant Reward │◀─────│ Validate Receipt        │          │
│  └──────────────┘      └─────────────────────────┘          │
│                                                             │
└─────────────────────────────────────────────────────────────┘

Best Practices

Few-Shot Examples

Example 1: IAP Manager Init

User: "Setup IAP with coin packs."

Agent:

public void InitializePurchasing()
{
    var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    
    // Add Products
    builder.AddProduct("com.game.coins_100", ProductType.Consumable);
    builder.AddProduct("com.game.remove_ads", ProductType.NonConsumable);
    
    UnityPurchasing.Initialize(this, builder);
}

Example 2: Process Purchase

User: "Handle successful purchase."

Agent:

public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
    var product = args.purchasedProduct;
    
    if (product.definition.id == "com.game.coins_100")
    {
        CurrencyManager.AddCoins(100);
    }
    else if (product.definition.id == "com.game.remove_ads")
    {
        AdsManager.DisableAds();
    }
    
    return PurchaseProcessingResult.Complete;
}

Example 3: Restore Transactions

User: "Add restore button for iOS."

Agent:

public void RestorePurchases()
{
    if (Application.platform == RuntimePlatform.IPhonePlayer || 
        Application.platform == RuntimePlatform.OSXPlayer)
    {
        var apple = _extensionProvider.GetExtension<IAppleExtensions>();
        apple.RestoreTransactions(result => {
            Debug.Log($"Restore result: {result}");
        });
    }
}

TDD Contract

⚠️ Legacy Skill — Refactor Pending

Este skill NO tiene tests automatizados aún. El siguiente boilerplate es un punto de partida.

// Escribe estos tests ANTES de implementar:

// Test 1: should [expected behavior] when [condition]
[Test]
public void MonetizationIap_Should{ExpectedBehavior}_When{Condition}()
{{
    // Arrange
    // TODO: Setup test fixtures
    
    // Act
    // TODO: Execute system under test
    
    // Assert
    Assert.Fail("Not implemented — write test first");
}}

// Test 2: should handle [edge case]
[Test]
public void MonetizationIap_ShouldHandle{EdgeCase}()
{{
    // Arrange
    // TODO: Setup edge case scenario
    
    // Act
    // TODO: Execute
    
    // Assert
    Assert.Fail("Not implemented");
}}

// Test 3: should throw when [invalid input]
[Test]
public void MonetizationIap_ShouldThrow_When{InvalidInput}()
{{
    // Arrange
    var invalidInput = default;
    
    // Act & Assert
    Assert.Throws<Exception>(() => {{ /* execute */ }});
}}

Pasos para completar el TDD:

  1. Descomenta los tests above
  2. Implementa la funcionalidad mínima para que compile
  3. Ejecuta los tests — deben fallar (RED)
  4. Implementa la funcionalidad real
  5. Verifica que los tests pasen (GREEN)
  6. Refactorea manteniendo los tests verdes

Nota: Este skill fue marcado como tdd_first: false durante la auditoría v2.0.1. La sección TDD fue agregada automáticamente pero requiere customización manual para reflejar el comportamiento real del skill.

Related Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.