public UnityProductDefinion(UnityEngine.Purchasing.ProductDefinition definition) { _definition = definition; if (!_definition.IsNull() && !definition.payout.IsNull()) { _payout = new UnityPayoutDefinition(_definition.payout); } if (!_definition.payouts.IsNull()) { var payouts = default(List <IPayoutDefinition>); foreach (var payout in _definition.payouts) { if (payout.IsNull()) { return; } if (payouts.IsNull()) { payouts = new List <IPayoutDefinition>(); } payouts.Add(new UnityPayoutDefinition(payout)); } _payouts = payouts; } }
public override void FinishTransaction(UnityEngine.Purchasing.ProductDefinition product, string transactionId) { // Product definitions may be null if a store tells Unity IAP about an unknown product; // Unity IAP will not have a corresponding definition but will still finish the transaction. var def = product == null ? null : JSONSerializer.SerializeProductDef(product); store.FinishTransaction(def, transactionId); }
public override void Purchase(UnityEngine.Purchasing.ProductDefinition product, string developerPayload) { if (!string.IsNullOrEmpty(developerPayload)) { Dictionary <string, object> dic = null; // try and get dev payload dictionary from the the developerPayload string, this may fail if the // developer payload is not a json string, so we catch the exception silently. try { dic = (Dictionary <string, object>)MiniJSON.Json.Deserialize(developerPayload); } catch { } if ((dic != null) && (dic.ContainsKey("iapPromo")) && (dic.TryGetValue("productId", out var prodId))) { m_Logger.Log("UnityIAP: Promo Purchase(" + prodId + ")"); promoPayload = dic; // Add more fields to promoPayload // promoPayload.Add("type", "iap.purchase"); promoPayload.Add("iap_service", true); var thisProduct = unity.products.WithID(prodId as string); if (thisProduct != null) { promoPayload.Add("amount", thisProduct.metadata.localizedPrice); promoPayload.Add("currency", thisProduct.metadata.isoCurrencyCode); } // For promotions we want to delete the promo JSON // before sending upstream to stores developerPayload = "iapPromo"; } } store.Purchase(JSONSerializer.SerializeProductDef(product), developerPayload); }
public override void Purchase(UnityEngine.Purchasing.ProductDefinition product, string developerPayload) { m_Store.Purchase(JSONSerializer.SerializeProductDef(product), developerPayload); }