Search Unity

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,822
    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,822