Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question Recording an IAP transaction from an external payment provider

Discussion in 'Unity Analytics' started by Meltdown, Nov 22, 2022.

  1. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,840
    I am using XSolla to handle the payments for my WebGL game.
    I am using the latest 4.2.0 Unity Analytics.

    In the Legacy Analytics, there was an easy way to log a transaction...
    Code (CSharp):
    1. public static Analytics.AnalyticsResult Transaction(string productId, Decimal amount, string currency);
    I am now trying to do something similar using the latest analytics with AnalyticsService.Instance.Transaction, but not sure if this is on the right track, or is there an easier way?

    In the case of the code below, I am trying to record a transaction for a player buying a pack of virtual currency.

    Code (CSharp):
    1. public void CreateVirtualCurrencyRealMoneyTransaction(string realCurrencyIsoCode, long realCurrencyAmount, string virtualCurrencyBundleType, string virtualCurrencyBundleId, string virtualCurrencyCode, long virtualCurrencyAmount)
    2.     {
    3.         AnalyticsService.Instance.Transaction(new TransactionParameters()
    4.         {
    5.             ProductsSpent = new Product()
    6.             {
    7.                 RealCurrency = new RealCurrency()
    8.                 {
    9.                     RealCurrencyAmount = realCurrencyAmount,
    10.                     RealCurrencyType = realCurrencyIsoCode
    11.                 }
    12.             },
    13.             ProductsReceived = new Product()
    14.             {
    15.                 VirtualCurrencies = new List<VirtualCurrency>()
    16.                 {
    17.                     new()
    18.                     {
    19.                         VirtualCurrencyName =  virtualCurrencyCode,
    20.                         VirtualCurrencyAmount = virtualCurrencyAmount
    21.                     }
    22.                 },
    23.                 Items = new List<Item>()
    24.                 {
    25.                     new()
    26.                     {
    27.                         ItemAmount = 1,
    28.                         ItemName = virtualCurrencyBundleId,
    29.                         ItemType = virtualCurrencyBundleType
    30.                     }
    31.                 }
    32.             }
    33.         });
    34.     }
     
  2. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,840