/// <summary> /// Buffer the event of a purchase using real currency, where a single item /// (that isn't an in-app currency) was purchased. /// The receipt provided will be validated against the Windows Store. /// </summary> /// <remarks> /// See the REST API documentation for the "iap" event. /// Note that this method is currently only supported for the Windows Store, /// and a valid receipt needs to be provided for verification. /// </remarks> /// <param name="receipt"> /// The receipt sent back from the Windows Store upon successful purchase - this receipt will be verified by Swrve /// </param> /// <param name="rewards"> /// SwrveIAPRewards object containing any in-app currency and/or additional items /// included in this purchase that need to be recorded. /// This parameter is optional. /// </param> public void IapWindows(IapReceipt receipt, IapRewards rewards) { if (config.AppStore != SwrveAppStore.Windows) { throw new Exception("This function can only be called to validate IAP events from Windows Store"); } else { string encodedReceipt = (receipt != null) ? receipt.GetBase64EncodedReceipt() : null; if (receipt != null && string.IsNullOrEmpty(encodedReceipt)) { SwrveLog.LogError("IAP event not sent: receipt cannot be empty for Windows Store verification"); return; } // Windows Store IAP is always of quantity 1 Dictionary <string, object> json = new Dictionary <string, object>(); json.Add("app_store", config.AppStore); if (!string.IsNullOrEmpty(GetAppVersion())) { json.Add("app_version", GetAppVersion()); } json.Add("receipt", encodedReceipt); AppendEventToBuffer("iap", json); if (config.AutoDownloadCampaignsAndResources) { // Send events automatically and check for changes CheckForCampaignsAndResourcesUpdates(false); } } }
void InAppCurrencyPurchase() { // Nofity of an in-app purchase with a some currency reward IapRewards rewards = new IapRewards(@"gold", 200); swrveComponent.SDK.Iap(1, @"productId", 0.99, @"USD", rewards); }
void RealIap() { IapRewards rewards = new IapRewards(@"gold", 100); rewards.AddCurrency(@"keys", 5); rewards.AddItem(@"sword", 1); #if UNITY_IPHONE // IAP validation happens on our servers. Provide if possible the receipt from Apple. IapReceipt receipt = RawReceipt.FromString("receipt-from-apple"); swrveComponent.SDK.IapApple(1, @"productId", 4.99, @"EUR", rewards, receipt); #elif UNITY_ANDROID // IAP validation happens on our servers. Provide if possible the purchase data from Google. string purchaseData = "purchase-data-from-google-play"; string dataSignature = "data-signature-from-google-play"; swrveComponent.SDK.IapGooglePlay(@"productId", 4.99, @"EUR", rewards, purchaseData, dataSignature); #endif }
/// <summary> /// Buffer the event of a purchase using real currency, where a single item /// (that isn't an in-app currency) was purchased. /// The receipt provided will be validated against the iTunes Store. /// </summary> /// <remarks> /// See the REST API documentation for the "iap" event. /// Note that this method is currently only supported for the Apple App Store, /// and a valid receipt needs to be provided for verification. /// </remarks> /// <param name="quantity"> /// Quantity purchased. /// </param> /// <param name="productId"> /// Unique product identifier for the item bought. This should match the Swrve resource name. /// </param> /// <param name="productPrice"> /// Price of the product purchased in real money. Note that this is the price /// per product, not the total price of the transaction (when quantity > 1). /// </param> /// <param name="currency"> /// Real world currency used for this transaction. This must be an ISO currency code. /// </param> /// <param name="receipt"> /// The receipt sent back from the iTunes Store upon successful purchase - this receipt will be verified by Swrve. /// Use either Base64EncodedReceipt or RawReceipt depending on what is offered by your plugin. /// </param> /// <param name="transactionId"> /// The transaction id identifying the purchase iOS7+ (see SKPaymentTransaction::transactionIdentifier). /// </param> public void IapApple(int quantity, string productId, double productPrice, string currency, IapReceipt receipt, string transactionId) { IapRewards no_rewards = new IapRewards(); IapApple(quantity, productId, productPrice, currency, no_rewards, receipt, transactionId); }
/// <summary> /// Buffer the event of a purchase using real currency, where any in-app /// currencies were purchased, or where multiple items were purchased as part of a bundle. /// The receipt provided will be validated against the iTunes Store. /// </summary> /// <remarks> /// See the REST API documentation for the "iap" event. /// Note that this method is currently only supported for the Apple App Store, /// and a valid receipt needs to be provided for verification. /// </remarks> /// <param name="quantity"> /// Quantity purchased. /// </param> /// <param name="productId"> /// Unique product identifier for the item bought. This should match the Swrve resource name. /// </param> /// <param name="productPrice"> /// Price of the product purchased in real money. Note that this is the price /// per product, not the total price of the transaction (when quantity > 1). /// </param> /// <param name="currency"> /// Real world currency used for this transaction. This must be an ISO currency code. /// </param> /// <param name="rewards"> /// SwrveIAPRewards object containing any in-app currency and/or additional items /// included in this purchase that need to be recorded. /// This parameter is optional. /// </param> /// <param name="receipt"> /// The receipt sent back from the iTunes Store upon successful purchase - this receipt will be verified by Swrve. /// Use either Base64EncodedReceipt or RawReceipt depending on what is offered by your plugin. /// </param> /// <param name="transactionId"> /// The transaction id identifying the purchase iOS7+ (see SKPaymentTransaction::transactionIdentifier). /// </param> public void IapApple(int quantity, string productId, double productPrice, string currency, IapRewards rewards, IapReceipt receipt, string transactionId) { if (config.AppStore != "apple") { throw new Exception("This function can only be called to validate IAP events from Apple"); } else { string encodedReceipt = null; if (receipt != null) { encodedReceipt = receipt.GetBase64EncodedReceipt(); } if (String.IsNullOrEmpty(encodedReceipt)) { SwrveLog.LogError("IAP event not sent: receipt cannot be empty for Apple Store verification"); return; } _Iap(quantity, productId, productPrice, currency, rewards, encodedReceipt, string.Empty, transactionId, config.AppStore); } }
/// <summary> /// Buffer the event of a purchase using real currency, where any in-app /// currencies were purchased, or where multiple items were purchased as part of a bundle. /// The receipt provided will be validated against the iTunes Store. /// </summary> /// <remarks> /// See the REST API documentation for the "iap" event. /// Note that this method is currently only supported for the Apple App Store, /// and a valid receipt needs to be provided for verification. /// </remarks> /// <param name="quantity"> /// Quantity purchased. /// </param> /// <param name="productId"> /// Unique product identifier for the item bought. This should match the Swrve resource name. /// </param> /// <param name="productPrice"> /// Price of the product purchased in real money. Note that this is the price /// per product, not the total price of the transaction (when quantity > 1). /// </param> /// <param name="currency"> /// Real world currency used for this transaction. This must be an ISO currency code. /// </param> /// <param name="rewards"> /// SwrveIAPRewards object containing any in-app currency and/or additional items /// included in this purchase that need to be recorded. /// This parameter is optional. /// </param> /// <param name="receipt"> /// The receipt sent back from the iTunes Store upon successful purchase - this receipt will be verified by Swrve. /// Use either Base64EncodedReceipt or RawReceipt depending on what is offered by your plugin. /// </param> public void IapApple(int quantity, string productId, double productPrice, string currency, IapRewards rewards, IapReceipt receipt) { IapApple(quantity, productId, productPrice, currency, rewards, receipt, string.Empty); }
public override void Iap(int quantity, string productId, double productPrice, string currency, IapRewards rewards) { }
void Update() { if (UIEnabled) { if (buttonPressed [(int)Buttons.SendEvent]) { // Trigger a custom event swrveComponent.SDK.NamedEvent(@"button pressed", new Dictionary <string, string> () { { "foo", "bar" } }); } if (buttonPressed [(int)Buttons.SendUserAttributes]) { // Update a user property swrveComponent.SDK.UserUpdate(new Dictionary <string, string> () { { "health", "100" }, { "gold", "20" } }); } if (buttonPressed [(int)Buttons.PurchaseItem]) { // Notify of an item purchase swrveComponent.SDK.Purchase(@"someItem", @"gold", 20, 1); } if (buttonPressed [(int)Buttons.InAppItemPurchase]) { // Notify of an in-app purchase swrveComponent.SDK.Iap(1, @"productId", 1.99, @"USD"); } if (buttonPressed [(int)Buttons.InAppCurrencyPurchase]) { // Nofity of an in-app purchase with a some currency reward IapRewards rewards = new IapRewards(@"gold", 200); swrveComponent.SDK.Iap(1, @"productId", 0.99, @"USD", rewards); } if (buttonPressed [(int)Buttons.RealIap]) { IapRewards rewards = new IapRewards(@"gold", 100); rewards.AddCurrency(@"keys", 5); rewards.AddItem(@"sword", 1); #if UNITY_IPHONE // IAP validation happens on our servers. Provide if possible the receipt from Apple. IapReceipt receipt = RawReceipt.FromString("receipt-from-apple"); swrveComponent.SDK.IapApple(1, @"productId", 4.99, @"EUR", rewards, receipt); #elif UNITY_ANDROID // IAP validation happens on our servers. Provide if possible the purchase data from Google. string purchaseData = "purchase-data-from-google-play"; string dataSignature = "data-signature-from-google-play"; swrveComponent.SDK.IapGooglePlay(@"productId", 4.99, @"EUR", rewards, purchaseData, dataSignature); #endif } if (buttonPressed [(int)Buttons.CurrencyGiven]) { // Notify of currency given swrveComponent.SDK.CurrencyGiven(@"gold", 20); } if (buttonPressed [(int)Buttons.UserResources]) { // Obtain the latest value of the resource item01.attribute or its default value int attributeValue = swrveComponent.SDK.ResourceManager.GetResourceAttribute <int> ("item01", "attribute", 99); UnityEngine.Debug.Log("User resource attribute: " + attributeValue); } if (buttonPressed [(int)Buttons.SendToSwrve]) { // Send the queued events in the buffer to Swrve swrveComponent.SDK.SendQueuedEvents(); } if (buttonPressed [(int)Buttons.TriggerMessage]) { // Trigger an in-app message. You will need to setup the campaign // in the In-App message section in the dashboard. swrveComponent.SDK.NamedEvent("campaign_trigger"); } if (buttonPressed [(int)Buttons.SaveToDisk]) { // Flush the queued events to disk swrveComponent.SDK.FlushToDisk(); } } base.ClearButtons(); }
/// <summary> /// Buffer the event of a purchase using real currency, where a single item /// (that isn't an in-app currency) was purchased. /// The receipt provided will be validated against the Google Play Store. /// </summary> /// <remarks> /// See the REST API documentation for the "iap" event. /// Note that this method is currently only supported for the Google Play Store, /// and a valid receipt and signature need to be provided for verification. /// </remarks> /// <param name="productId"> /// Unique product identifier for the item bought. This should match the Swrve resource name. /// </param> /// <param name="productPrice"> /// Price of the product purchased in real money. Note that this is the price /// per product, not the total price of the transaction (when quantity > 1). /// </param> /// <param name="currency"> /// Real world currency used for this transaction. This must be an ISO currency code. /// </param> /// <param name="purchaseData"> /// The receipt sent back from the Google Play Store upon successful purchase - this receipt will be verified by Swrve /// </param> /// <param name="dataSignature"> /// The receipt signature sent back from the Google Play Store upon successful purchase /// </param> public void IapGooglePlay(string productId, double productPrice, string currency, string purchaseData, string dataSignature) { IapRewards no_rewards = new IapRewards(); IapGooglePlay(productId, productPrice, currency, no_rewards, purchaseData, dataSignature); }
/// <summary> /// Buffer the event of a purchase using real currency, where any in-app /// currencies were purchased, or where multiple items were purchased as part of a bundle. /// The receipt provided will be validated against the Google Play Store. /// </summary> /// <remarks> /// See the REST API documentation for the "iap" event. /// Note that this method is currently only supported for the Google Play Store, /// and a valid receipt and signature need to be provided for verification. /// </remarks> /// <param name="productId"> /// Unique product identifier for the item bought. This should match the Swrve resource name. /// </param> /// <param name="productPrice"> /// Price of the product purchased in real money. Note that this is the price /// per product, not the total price of the transaction (when quantity > 1). /// </param> /// <param name="currency"> /// Real world currency used for this transaction. This must be an ISO currency code. /// </param> /// <param name="rewards"> /// SwrveIAPRewards object containing any in-app currency and/or additional items /// included in this purchase that need to be recorded. /// This parameter is optional. /// </param> /// <param name="purchaseData"> /// The receipt sent back from the Google Play Store upon successful purchase - this receipt will be verified by Swrve /// </param> /// <param name="dataSignature"> /// The receipt signature sent back from the Google Play Store upon successful purchase /// </param> public void IapGooglePlay(string productId, double productPrice, string currency, IapRewards rewards, string purchaseData, string dataSignature) { if (config.AppStore != "google") { throw new Exception("This function can only be called to validate IAP events from Google"); } else { if (String.IsNullOrEmpty(purchaseData)) { SwrveLog.LogError("IAP event not sent: purchase data cannot be empty for Google Play Store verification"); return; } if (String.IsNullOrEmpty(dataSignature)) { SwrveLog.LogError("IAP event not sent: data signature cannot be empty for Google Play Store verification"); return; } // Google IAP is always of quantity 1 _Iap(1, productId, productPrice, currency, rewards, purchaseData, dataSignature, string.Empty, config.AppStore); } }
public void LogSwrveGoogleIAPAction(string productId, double localCost, string localCurrency, string receipt, string receiptSignature, IapRewards rewards) { if (rewards == null) { SwrveComponent.Instance.SDK.IapGooglePlay(productId, localCost, localCurrency, receipt, receiptSignature); } else { SwrveComponent.Instance.SDK.IapGooglePlay(productId, localCost, localCurrency, rewards, receipt, receiptSignature); } }
/// <summary> /// Buffer the event of a purchase using real currency, where a single item /// (that isn't an in-app currency) was purchased. /// The receipt provided will be validated against the Windows Store. /// </summary> /// <remarks> /// See the REST API documentation for the "iap" event. /// Note that this method is currently only supported for the Windows Store, /// and a valid receipt needs to be provided for verification. /// </remarks> /// <param name="receipt"> /// The receipt sent back from the Windows Store upon successful purchase - this receipt will be verified by Swrve /// </param> public void IapWindows(IapReceipt receipt) { IapRewards no_rewards = new IapRewards(); IapWindows(receipt, no_rewards); }