/// <summary> /// This will be called when a purchase completes. /// </summary> private void onPurchased(PurchaseEvent e) { Debug.Log("Purchase OK: " + e.PurchasedItem.Id); Debug.Log(string.Format("{0} has now been purchased {1} times.", e.PurchasedItem.name, Unibiller.GetPurchaseCount(e.PurchasedItem))); }
public PurchaseViewModel(PurchaseEvent purchaseEvent) { Id = purchaseEvent.Id; ProductId = purchaseEvent.ProductId; ClientId = purchaseEvent.ClientId; Date = purchaseEvent.EventDate; }
public void DeletePurchaseEvent() { int clientId = clientService.GetLastlyAddedClient()._id; int productId = productService.GetLastlyAddedProduct()._id; PurchaseEvent e = new PurchaseEvent() { ClientId = clientId, ProductId = productId, EventDate = DateTime.Now.ToLongDateString() }; purchaseService.AddPurchaseEvent(e); PurchaseEvent last = purchaseService.GetLastClientPurchaseOfProduct(clientId, productId); if (last != null) { Assert.IsTrue(purchaseService.DeletePurchaseEvent(last.Id)); foreach (var purchase in purchaseService.GetAllPurchases()) { Assert.AreNotEqual(purchase.Id, last.Id); } } }
public void FetchClientPurchases() { if (productService.GetAllProducts().Count > 0 && clientService.GetAllClients().Count > 0) { int clientId = clientService.GetLastlyAddedClient()._id; int productId = productService.GetLastlyAddedProduct()._id; PurchaseEvent e = new PurchaseEvent() { ClientId = clientId, ProductId = productId, EventDate = DateTime.Now.ToLongDateString() }; purchaseService.AddPurchaseEvent(e); foreach (var purchase in purchaseService.GetAllClientPurchases(clientId)) { Assert.AreEqual(purchase.ClientId, clientId); } PurchaseEvent last = purchaseService.GetMostRecentPurchase(); Assert.AreEqual(last.ClientId, clientId); Assert.AreEqual(last.ProductId, productId); } }
public void AddReturn() { int clientId = clientService.GetLastlyAddedClient()._id; List <PurchaseEvent> purchases = purchaseService.GetAllClientPurchases(clientId); if (purchases.Count > 0) { PurchaseEvent purchaseEvent = purchases[purchases.Count - 1]; ReturnEvent returnEvent = new ReturnEvent() { ClientId = purchaseEvent.ClientId, ProductId = purchaseEvent.ProductId, EventDate = DateTime.Now.ToLongDateString() }; Assert.IsTrue(returnService.AddReturnEvent(returnEvent)); foreach (var purchase in purchaseService.GetAllClientPurchases(clientId)) { Assert.AreNotEqual(purchase.Id, purchaseEvent.Id); } } }
public void GetMostRecentPurchaseEvent() { List <PurchaseEvent> evs = eventRepository.GetAllPurchaseEvents(); PurchaseEvent recent = eventRepository.GetMostRecentPurchase(); Assert.AreEqual(evs.Last().Id, recent.Id); }
private void onPurchased(PurchaseEvent e) { Debug.Log("Purchase OK: " + e.PurchasedItem.Id); Debug.Log ("Receipt: " + e.Receipt); Debug.Log(string.Format ("{0} has now been purchased {1} times.", e.PurchasedItem.name, Unibiller.GetPurchaseCount(e.PurchasedItem))); }
private void onSucceeded(PurchaseEvent e) { if (restoreInProgress) { // We don't send notifications of restorations. return; } onEvent(EventType.purchase_succeeded, e.PurchasedItem, e.Receipt); }
void purchaseSuccessful( PurchaseEvent e ) { if(e != null) { byte[] receipt = GetBytes(e.Receipt); FuseLog(e.PurchasedItem.description + " " + e.PurchasedItem.localizedPriceString); FuseSDK.RegisterUnibillPurchase(e.PurchasedItem.Id, receipt); } }
void purchaseSuccessful(PurchaseEvent e) { if (e != null) { byte[] receipt = GetBytes(e.Receipt); FuseLog(e.PurchasedItem.description + " " + e.PurchasedItem.localizedPriceString); FuseSDK.RegisterUnibillPurchase(e.PurchasedItem.Id, receipt); } }
public static void OnEvent(JAnalytics.Event e) { int type = e.getType(); switch (type) { case JAnalytics.Event.BrowseEventType: BrowseEvent browseEven = (BrowseEvent)e; string browseId = browseEven.getBrowseId(); string browseName = browseEven.getBrowseName(); string browseType = browseEven.getBrowseType(); long browseDuration = browseEven.getBrowseDuration(); OnBrowseEvent(browseId, browseName, browseType, browseDuration, browseEven.getExtraDic()); break; case JAnalytics.Event.CalculateEventType: CalculateEvent calculateEvent = (CalculateEvent)e; string eventId = calculateEvent.getEventId(); double eventValues = calculateEvent.getEventValued(); OnCalculateEvent(eventId, eventValues, calculateEvent.getExtraDic()); break; case JAnalytics.Event.CountEventType: CountEvent countEvent = (CountEvent)e; OnCountEvent(countEvent.getEventId(), countEvent.getExtraDic()); break; case JAnalytics.Event.LoginEventType: LoginEvent loginEvent = (LoginEvent)e; OnLoginEvent(loginEvent.getLoginMethod(), loginEvent.geLoginSuccess(), loginEvent.getExtraDic()); break; case JAnalytics.Event.PurchaseEventType: PurchaseEvent purchaseEvent = (PurchaseEvent)e; string purchaseGoodsid = purchaseEvent.getPurchaseGoodsid(); string purchaseGoodsName = purchaseEvent.getPurchaseGoodsName(); double purchasePrice = purchaseEvent.getPurchasePrice(); bool purchaseSuccess = purchaseEvent.getPurchaseSuccess(); int purchaseCurrencyUnity = purchaseEvent.getPurchaseCurrencyInt(); string purchaseGoodsType = purchaseEvent.getPurchaseGoodsType(); int purchaseGoodsCount = purchaseEvent.getPurchaseGoodsCount(); OnPurchaseEvent(purchaseGoodsid, purchaseGoodsName, purchasePrice, purchaseSuccess, purchaseCurrencyUnity, purchaseGoodsType, purchaseGoodsCount, purchaseEvent.getExtraDic()); break; case JAnalytics.Event.RegisterEventType: RegisterEvent registerEvent = (RegisterEvent)e; OnRegisterEvent(registerEvent.getRegisterMethod(), registerEvent.getRegisterSuccess(), registerEvent.getExtraDic()); break; } }
public bool AddPurchaseEvent(PurchaseEvent ev) { if (ev == null || InvalidEventData(ev)) { return(false); } purchaseRepository.AddPurchaseEvent(ev); return(true); }
private static void _onPurchaseComplete(PurchaseEvent e) { if (null != onPurchaseComplete) { onPurchaseComplete(e.PurchasedItem); } if (null != onPurchaseCompleteEvent) { onPurchaseCompleteEvent(e); } }
public void AddInvalidPurchase() { PurchaseEvent e = new PurchaseEvent() { ClientId = 0, ProductId = 0, EventDate = DateTime.Now.ToLongDateString() }; Assert.IsFalse(purchaseService.AddPurchaseEvent(e)); Assert.IsFalse(purchaseService.AddPurchaseEvent(null)); }
public void EventAdditionTest() { DataContext context = new DataContext(); DataRepository data = new DataRepository(context); Logic logic = new Logic(data); Data.PurchaseEvent new_event = new PurchaseEvent(1, new Data.Customer("Jon", "Smith", 1), DateTime.Now, new Product("milk"), new State(20, true), 4); data.Add_Event(new_event); Assert.AreEqual(1, new_event.Get_ID()); }
async Task Purchased(PurchaseEvent purchaseEvent) { IsBusy = false; if (purchaseEvent.Response.TransactionResult == TransactionResultTypes.Ok) { await MessageAsync("Success"); await Navigation.PopAsync(); } else { await ErrorTextAsync(purchaseEvent.Response.GetErrorMessage()); } }
public void SendPurchase(PurchaseEvent purchase) { var serializedString = JsonConvert.SerializeObject(purchase); var data = new EventData(Encoding.UTF8.GetBytes(serializedString)) { PartitionKey = purchase.ProductId.ToString() }; // Set user properties if needed data.Properties.Add("Type", "Telemetry_" + DateTime.UtcNow.ToLongTimeString()); _eventHubs.PurchaseClient.Send(data); }
public void ValidateReceiptAndReport(PurchaseEvent purchaseEvent) { PurchasableItem item = purchaseEvent.PurchasedItem; if (item != null) { try { if (item.localizedPriceString == null) { Debug.LogError("item.localizedPriceString is null"); } else { Debug.LogWarning(item.localizedPriceString); } string onlyNumbers = new System.String(item.localizedPriceString.Where(itemc => System.Char.IsDigit(itemc) || itemc == '.').ToArray()); string token = null; object jsonObject = Json.Deserialize(purchaseEvent.Receipt); if (jsonObject != null && jsonObject.GetType() == typeof(Dictionary <string, object>)) { Dictionary <string, object> jsonDict = jsonObject as Dictionary <string, object>; object innerJsonObject = null; if (jsonDict.TryGetValue("json", out innerJsonObject)) { if (innerJsonObject != null && innerJsonObject.GetType() == typeof(string)) { object innerJsonDecodedObject = Json.Deserialize(innerJsonObject as string); if (innerJsonDecodedObject != null && innerJsonDecodedObject.GetType() == typeof(Dictionary <string, object>)) { Dictionary <string, object> innerJsonDict = innerJsonDecodedObject as Dictionary <string, object>; object tokenObject = null; if (innerJsonDict.TryGetValue("purchaseToken", out tokenObject)) { if (tokenObject != null && tokenObject.GetType() == typeof(string)) { token = tokenObject as string; } } } } } } ValidateReceiptAndReport(token, onlyNumbers, item.isoCurrencySymbol, item.Id); } catch (System.Exception e) { Debug.LogException(e); } } }
public void LogPurchase(decimal itemPrice, string currency, bool purchaseSucceeded, string itemName, string itemType, string itemId, Dictionary <string, object> customAttributes = null) { var answersEvent = new PurchaseEvent(); answersEvent.PutItemPrice(new BigDecimal(itemPrice.ToString(CultureInfo.InvariantCulture))); answersEvent.PutSuccess(purchaseSucceeded); answersEvent.PutItemName(itemName); answersEvent.PutItemType(itemType); answersEvent.PutItemId(itemId); answersEvent.PutCustomAttributes(customAttributes); if (currency != string.Empty) { answersEvent.PutCurrency(Currency.GetInstance(currency)); } Bindings.AnswersKit.Answers.Instance.LogPurchase(answersEvent); }
public void BuyTest() { DataContext context = new DataContext(); DataRepository data = new DataRepository(context); Logic logic = new Logic(data); Data.Customer new_customer = new Data.Customer("Jon", "Smith", 1); data.Add_Product("milk", 5); data.Add_State(100, true); PurchaseEvent new_event = new PurchaseEvent(1, new_customer, DateTime.Now, new Product("milk"), new State(100, true), 2); data.Add_Event(new_event); Assert.AreEqual(50, logic.Buy("milk", 10, 5)); }
public void AddPurchaseEvent() { PurchaseEvent e = GetEvent(); int initialCount = eventRepository.GetAllPurchaseEvents().Count; eventRepository.AddPurchaseEvent(e); int actualCount = eventRepository.GetAllPurchaseEvents().Count; PurchaseEvent addedEvent = eventRepository.GetPurchaseEventById(e.Id); Assert.AreEqual(addedEvent.Id, e.Id); Assert.AreEqual(addedEvent.ClientId, e.ClientId); Assert.AreEqual(addedEvent.ProductId, e.ProductId); Assert.AreEqual(initialCount, actualCount - 1); }
public void AddPurchase() { if (productService.GetAllProducts().Count > 0 && clientService.GetAllClients().Count > 0) { int clientId = clientService.GetLastlyAddedClient()._id; int productId = productService.GetLastlyAddedProduct()._id; PurchaseEvent e = new PurchaseEvent() { ClientId = clientId, ProductId = productId, EventDate = DateTime.Now.ToLongDateString() }; Assert.IsTrue(purchaseService.AddPurchaseEvent(e)); } }
public bool AddReturnEvent(ReturnEvent ev) { if (ev == null || InvalidEventData(ev)) { return(false); } PurchaseEvent recentPurchase = GetClientRecentPurchaseOfSuchProduct(ev); if (recentPurchase == null) { return(false); } returnRepository.AddReturnEvent(ev); purchaseRepository.DeletePurchaseEvent(recentPurchase.Id); return(true); }
/// <summary> /// This will be called when a purchase completes. /// </summary> private void onPurchased(PurchaseEvent e) { Debug.Log("Purchase OK: " + e.PurchasedItem.Id); Debug.Log("Receipt: " + e.Receipt); Debug.Log(string.Format("{0} has now been purchased {1} times.", e.PurchasedItem.name, Unibiller.GetPurchaseCount(e.PurchasedItem))); try { #if UNITY_ANDROID var jsonNode = JSON.Parse(e.Receipt); jsonNode = JSON.Parse(jsonNode[0].Value); string purchaseState = jsonNode["purchaseState"].Value; string productId = jsonNode["productId"].Value; string purchaseToken = jsonNode["purchaseToken"].Value; if (purchaseState == "0") { if (OnResponseUniBill != null) { OnResponseUniBill.Invoke(productId, purchaseToken); OnResponseUniBill -= OnResponseUniBill; } } #elif UNITY_IOS if (OnResponseUniBill != null) { OnResponseUniBill.Invoke(e.PurchasedItem.Id, e.Receipt); OnResponseUniBill -= OnResponseUniBill; } #endif } catch { if (OnResponseUniBill != null) { OnResponseUniBill.Invoke("", ""); OnResponseUniBill -= OnResponseUniBill; } } }
public void PurchaseCopyTest() { repo = new DataRepository(new ContextFiller()); dataService = new DataService(repo); DateTimeOffset testDate = new DateTimeOffset(2019, 10, 19, 22, 0, 0, new TimeSpan(2, 0, 0)); bool PurchaseEventRised = false; dataService.PurchaseHappened += PurchaseEventMethod; void PurchaseEventMethod(object sender, EventArgs e) { if (PurchaseEventRised == true) { Assert.Fail("Event rised multiple times"); } else { PurchaseEventRised = true; } } Assert.AreEqual(false, repo.ContainsCopy(101)); dataService.PurchaseCopy(101, 1, CopyCondition.Mint, testDate, "TestDistrib"); PurchaseEvent purchaseEvent = (PurchaseEvent)repo.GetAllEvents().Last(); Assert.AreEqual(true, PurchaseEventRised); Assert.AreEqual(true, repo.ContainsCopy(101)); Assert.AreEqual(CopyCondition.Mint, repo.GetCopy(101).Condition); Assert.AreEqual(repo.GetBook(1), repo.GetCopy(101).Book); Assert.AreEqual("Wydra", repo.GetCopy(101).Book.Title); Assert.AreEqual("Jan Lasica", repo.GetCopy(101).Book.Author); Assert.AreEqual(101, purchaseEvent.Copy.CopyId); Assert.AreEqual(repo.GetCopy(101), purchaseEvent.Copy); Assert.AreEqual("TestDistrib", purchaseEvent.Distributor); Assert.AreEqual(testDate, purchaseEvent.EventDate); }
public ActionResult Buy(int id) { var customer = _customerRepository.GetCustomerByName(User.Identity.Name); var product = _productsRepository.GetProduct(id); var promotion = _promotionsRepository.GetPromotion(customer.CustomerId, product.Id); var purchaseEvent = new PurchaseEvent { CustomerId = customer.CustomerId, ProductId = id, Price = promotion != null ? promotion.NewPrice : product.Price, PurchaseTime = DateTime.Now, OrderId = Guid.NewGuid() }; _telemetryRepository.SendPurchase(purchaseEvent); Thread.Sleep(TimeSpan.FromSeconds(5)); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
void Awake() { DontDestroyOnLoad(this.gameObject); onInitializeSuccess = new UnityEvent(); onInitializeFailed = new UnityEvent(); onPurchaseSuccess = new PurchaseEvent(); onPurchaseFailed = new PurchaseEvent(); _builder = new AppcoinsConfigurationBuilder(); _appcoinsPurchasing = gameObject.AddComponent <AppcoinsPurchasing>(); _versionReporter = gameObject.AddComponent <BDSVersionReporter>(); if (_versionReporter == null) { //Debug.LogError("Failed initializing! Plugin prefab is missing BDS VersionReporter. Please use the unmodified version of the prefab."); Debug.LogError("Failed initializing! Plugin prefab is missing BDS VersionReporter. Please use the unmodified version of the prefab."); return; } }
private void onCancelled(PurchaseEvent e) { onEvent(EventType.purchase_cancelled, e.PurchasedItem, null); }
private bool InvalidEventData(PurchaseEvent ev) { return(PurchaseExists(ev.Id) || !ClientExists(ev.ClientId) || !ProductExists(ev.ProductId)); }
void OnPurchased(PurchaseEvent e) //购买成功 { GlobalVars.PurchaseSuc = true; }
void purchaseSuccessful(PurchaseEvent e) { if (e != null) { //The Recipt is a json with the contents we need to pass in, parse it here JSONObject jObj = new JSONObject(e.Receipt); JSONObject json = new JSONObject(jObj.GetField("json").ToString().Replace("\\\"", "\"").Trim('"')); JSONObject sig = jObj.GetField("signature"); string sigstr = sig.ToString(); FuseLog("json = " + json.Print(true)); FuseLog("sig = " + sigstr); int purchaseState = 0; string purchaseToken = ""; string productId = ""; string orderId = ""; double purchaseTime = 0; json.GetField(ref purchaseState, "purchaseState"); json.GetField(ref purchaseToken, "purchaseToken"); json.GetField(ref orderId, "orderId"); json.GetField(ref productId, "productId"); json.GetField(ref purchaseTime, "purchaseTime"); double price = 0; try { price = double.Parse(e.PurchasedItem.localizedPriceString, NumberStyles.Currency); } catch { var re = new System.Text.RegularExpressions.Regex(@"\D*(?<num>[\d\s\.,]+?)(?<dec>([\.,]\s*\d?\d?)?)\D*$"); var match = re.Match(e.PurchasedItem.localizedPriceString); if (match.Success) { string stripped = ""; try { var dec = System.Text.RegularExpressions.Regex.Replace(match.Groups["dec"].Value, @"\s", ""); stripped = System.Text.RegularExpressions.Regex.Replace(match.Groups["num"].Value, @"[^\d]", "") + dec; price = double.Parse(stripped, NumberStyles.Currency); //Just in case the culture info is broken and double.Parse can't parse the decimal part properly if (price % 1 == 0 && dec.Length > 1) { price /= 100; } } catch { Debug.LogError("Fuse Unibill Tracking: Error parsing " + e.PurchasedItem.localizedPriceString + " >> Unable to parse " + stripped); } } else { Debug.LogError("Fuse Unibill Tracking: Error parsing " + e.PurchasedItem.localizedPriceString + " >> String did not match regex"); } } FuseSDK.RegisterAndroidInAppPurchase((FuseMisc.IAPState)purchaseState, purchaseToken, productId, orderId, (long)purchaseTime, sigstr, price, null); } }
void purchaseSuccessful( PurchaseEvent e ) { if(e != null) { //The Recipt is a json with the contents we need to pass in, parse it here JSONObject jObj = new JSONObject(e.Receipt); JSONObject json = new JSONObject(jObj.GetField("json").ToString().Replace("\\\"","\"").Trim('"')); JSONObject sig = jObj.GetField("signature"); string sigstr = sig.ToString(); FuseLog("json = " + json.Print(true)); FuseLog("sig = " + sigstr); int purchaseState = 0; string purchaseToken = ""; string productId = ""; string orderId = ""; double purchaseTime = 0; json.GetField(ref purchaseState,"purchaseState"); json.GetField(ref purchaseToken,"purchaseToken"); json.GetField(ref orderId,"orderId"); json.GetField(ref productId,"productId"); json.GetField(ref purchaseTime,"purchaseTime"); double price = 0; try { price = double.Parse(e.PurchasedItem.localizedPriceString, NumberStyles.Currency); } catch { var re = new System.Text.RegularExpressions.Regex(@"\D*(?<num>[\d\s\.,]+?)(?<dec>([\.,]\s*\d?\d?)?)\D*$"); var match = re.Match(e.PurchasedItem.localizedPriceString); if(match.Success) { string stripped = ""; try { var dec = System.Text.RegularExpressions.Regex.Replace(match.Groups["dec"].Value, @"\s", ""); stripped = System.Text.RegularExpressions.Regex.Replace(match.Groups["num"].Value, @"[^\d]", "") + dec; price = double.Parse(stripped, NumberStyles.Currency); //Just in case the culture info is broken and double.Parse can't parse the decimal part properly if(price % 1 == 0 && dec.Length > 1) { price /= 100; } } catch { Debug.LogError("Fuse Unibill Tracking: Error parsing " + e.PurchasedItem.localizedPriceString + " >> Unable to parse " + stripped); } } else { Debug.LogError("Fuse Unibill Tracking: Error parsing " + e.PurchasedItem.localizedPriceString + " >> String did not match regex"); } } FuseSDK.RegisterAndroidInAppPurchase((FuseMisc.IAPState)purchaseState,purchaseToken, productId, orderId, (long)purchaseTime, sigstr, price , null); } }
private void onCancelled(PurchaseEvent e) { onEvent (EventType.purchase_cancelled, e.PurchasedItem, null); }
private static void _onPurchaseComplete(PurchaseEvent e) { if (null != onPurchaseComplete) { onPurchaseComplete (e.PurchasedItem); } if (null != onPurchaseCompleteEvent) { onPurchaseCompleteEvent (e); } }
private void onSucceeded(PurchaseEvent e) { if (restoreInProgress) { // We don't send notifications of restorations. return; } onEvent (EventType.purchase_succeeded, e.PurchasedItem, e.Receipt); }
public void GetPurchaseEventsByProductId() { PurchaseEvent ev = GetEvent(); Assert.IsTrue(eventRepository.GetPurchaseEventsByProductId(ev.ProductId).Count >= 1); }