public void RestoreProducts() { var purchases = this._serviceConnection.BillingHandler.GetPurchases(ItemType.Product); // Record what we restored foreach (var purchase in purchases) { var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); var purchaseTime = epoch.AddMilliseconds(purchase.PurchaseTime); var newPurchase = new InAppPurchase { OrderId = purchase.OrderId, ProductId = purchase.ProductId, PurchaseTime = purchaseTime }; App.ViewModel.Purchases.Add(newPurchase); } // Notifiy anyone who needs to know products were restored if (this.OnRestoreProducts != null) { this.OnRestoreProducts(); } }
public void FireOnPurchaseProduct(int response, InAppPurchase purchase, string purchaseData, string purchaseSignature) { if (this.OnPurchaseProduct != null) { this.OnPurchaseProduct(); } }
public static async Task BuyProduct(string productId) { InAppBillingPurchase purchase = await InAppPurchase.Buy(productId, true); string message = purchase == null ? LN.PurchaseFailed : LN.ThanksForYourSupport; await Shell.Current.CurrentPage.DisplayToastAsync(message); }
public virtual void PurchaseProduct(InAppPurchase purchase) { purchasingProduct = purchase; if (OnPurchaseSuccess != null) { OnPurchaseSuccess(GetPurchaseId(purchasingProduct)); } }
protected void OnInAppDisabled(InAppPurchase purchase) { if (OnPurchaseFail != null) { OnPurchaseFail(GetPurchaseId(purchase)); } ShowInAppDisabledWindow(); }
private async void DonateHigh_Clicked(object sender, EventArgs e) { if (await InAppPurchase.Buy(InAppProducts.DonateHigh, true) != null) { await DisplayAlert(LN.Purchase, LN.ThanksForYourSupport, LN.Ok); } else { await DisplayAlert(LN.Purchase, LN.PurchaseFailed, LN.Ok); } }
public void UpdatePayment(PaymentResponse paymentResponse) { var simsipProductId = this.FortumoToSimsipProductId(paymentResponse.ServiceId); var newPurchase = new InAppPurchase { OrderId = paymentResponse.PaymentCode, ProductId = simsipProductId, PurchaseTime = DateTime.Now }; App.ViewModel.Purchases.Add(newPurchase); }
public async Task <InAppPurchaseResult> Purchase(InAppPurchase Purchase) { RestRequest elm = CreateRequest <InAppPurchase>("Store/Purchase", Method.POST, Purchase); var body = elm.Parameters.Where(p => p.Type == ParameterType.RequestBody).FirstOrDefault(); string req = body.Value.ToString(); IRestResponse <InAppPurchaseResult> resp = await Client.ExecuteTaskAsync <InAppPurchaseResult>(elm); if (resp.StatusCode == HttpStatusCode.Unauthorized) { throw new UnauthorizedException(); } else if (resp.StatusCode != HttpStatusCode.OK) { throw new eDockAPIException(); } return(resp.Data); }
public static O_E_INSERT_IN_APP_BILLING_BY_GOOGLE Execute(I_E_INSERT_IN_APP_BILLING_BY_GOOGLE input, long userNo) { if (input == null || string.IsNullOrEmpty(input.ProductID)) { ErrorHandler.OccurException(RowCode.Invalid_InputValue); } // Check ProductID valid if (!InAppPurchase.TryGetInAppPurchase(input.ProductID, out var inAppProduct) || inAppProduct.StoreType != StoreType.GooglePlay) { ErrorHandler.OccurException(RowCode.Invalid_Product_Id); } // Check DB PoseGlobalDB.Procedures.P_INSERT_IN_APP_BILLING.Output db_output; using (var P_INSERT_IN_APP_BILLING = new PoseGlobalDB.Procedures.P_INSERT_IN_APP_BILLING()) { P_INSERT_IN_APP_BILLING.SetInput(new PoseGlobalDB.Procedures.P_INSERT_IN_APP_BILLING.Input { UserNo = userNo, ProductID = input.ProductID, PurchaseState = PosePurchaseStateType.Canceled.ToString(), StoreType = StoreType.GooglePlay.ToString(), CurrentTime = DateTime.UtcNow, }); db_output = P_INSERT_IN_APP_BILLING.OnQuery(); if (P_INSERT_IN_APP_BILLING.EntityStatus != null || db_output.Result != 0) { ErrorHandler.OccurException(RowCode.DB_Failed_Insert_Billing); } } return(new O_E_INSERT_IN_APP_BILLING_BY_GOOGLE { BillingPayload = db_output.TransNo.ToString(), }); }
protected override void OnCreate(Bundle bundle) { InitCrashlytics(); TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; Current = this; base.OnCreate(bundle); global::Xamarin.Forms.Forms.Init(this, bundle); var builder = new ContainerBuilder(); builder.RegisterInstance(new InternalStorage()) .As <IInternalStorage> (); builder.RegisterType <CodeStorageManager> ().InstancePerLifetimeScope(); builder.RegisterType <CodeManager> ().InstancePerLifetimeScope(); builder.RegisterType <RefreshManager> ().InstancePerLifetimeScope(); builder.RegisterInstance(new ResourceManager()) .As <IResourceManager> (); builder.RegisterInstance(new InAppPurchase()) .As <IInAppPurchase> (); builder.RegisterInstance(new TimerInstance()) .As <ITimerInstance> (); var container = builder.Build(); Vibrator = (Vibrator)GetSystemService(Context.VibratorService); ServiceLocator.SetLocatorProvider(() => new AutofacServiceLocator(container)); MobileAds.Initialize(ApplicationContext, "ca-app-pub-9132934287753769~2766954331"); _iInAppPurchase = ServiceLocator.Current.GetInstance <IInAppPurchase> () as InAppPurchase; LoadApplication(new App()); }
public override void PurchaseProduct(InAppPurchase purchase) { #if UNITY_EDITOR base.PurchaseProduct(purchase); #elif UNITY_IPHONE if (StoreKitBinding.canMakePayments()) { purchasingProduct = purchase; RequestProductList(); StoreKitManager.productPurchaseAwaitingConfirmationEvent += OnProductAwaitingVerification; StoreKitManager.purchaseFailedEvent += OnProductFailed; StoreKitManager.purchaseCancelledEvent += OnProductCanceled; Debug.Log("Purchasing product: " + productIds[(int)purchasingProduct]); StoreKitBinding.purchaseProduct(GetPurchaseId(purchase), 1); } else { OnInAppDisabled(purchase); } #endif }
public virtual string GetPurchaseId(InAppPurchase purchase) { return prefix + productIds[(int)purchase]; }
public override string GetPurchaseId(InAppPurchase purchase) { return prefix + productIds[(int)purchase] + productExtraIds[(int)purchase]; }
public override void PurchaseProduct(InAppPurchase purchase) { #if UNITY_EDITOR base.PurchaseProduct(purchase); #elif UNITY_ANDROID if (!billingSupported) { RequestProductList(); //try to check again OnInAppDisabled(purchase); } else { purchasingProduct = purchase; RequestProductList(); GoogleIABManager.purchaseCompleteAwaitingVerificationEvent += OnProductAwaitingVerificationAndroid; GoogleIABManager.purchaseSucceededEvent += OnVerificationSuccess; GoogleIABManager.purchaseFailedEvent += OnProductFailed; Debug.Log("Purchasing product: " + GetPurchaseId(purchase)); GoogleIAB.purchaseProduct(GetPurchaseId(purchase)); } #endif }
public void Initialize() { // A Licensing and In-App Billing public key is required before an app can communicate with // Google Play, however you DON'T want to store the key in plain text with the application. // The Unify command provides a simply way to obfuscate the key by breaking it into two or // or more parts, specifying the order to reassemlbe those parts and optionally providing // a set of key/value pairs to replace in the final string. string value = Security.Unify( new string[] { "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoCgVnYrLIlkOF4tZoX4bS8LJYtn2gzPQa68Csfgi33Q/v6AdB85rFsdZ0HMwdxkcN7mOkW2ktf19bD", "t+BT94sAxbry1qO9hD6QIDAQAB", "JI7qCFzXsCJ1/LV/hXSHAsiQOShE83sQnmk2FiwDi1yuj6SlA0uN8nO175o1rsTMmKE12CDCWH01eCaJSvwnpKI2xaJZ0wlPjRpnnup/6Flmsd7zTNa3Lw3fvK", "nzp5pSshUmQJhxQhXvVdXXGjQYsV6ai7SdQ4APvBT9abKMo7ZsnmC7wxohDFfk+3nHXOxZyYi9PKH6XpVTqgEfhzGi5/O7YivHT04/CphwCXUSYHMSZ/mLi60C" }, new int[] { 0, 3, 2, 1 }); // Create a new connection to the Google Play Service _serviceConnection = new InAppBillingServiceConnection(MainActivity.Instance, value); _serviceConnection.OnConnected += () => { this._serviceConnection.BillingHandler.OnProductPurchased += (int response, Purchase purchase, string purchaseData, string purchaseSignature) => { // Record what we purchased var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); var purchaseTime = epoch.AddMilliseconds(purchase.PurchaseTime); var newPurchase = new InAppPurchase { OrderId = purchase.OrderId, ProductId = purchase.ProductId, PurchaseTime = purchaseTime }; App.ViewModel.Purchases.Add(newPurchase); // Let anyone know who is interested that purchase has completed if (this.OnPurchaseProduct != null) { this.OnPurchaseProduct(); } }; this._serviceConnection.BillingHandler.QueryInventoryError += (int responseCode, Bundle skuDetails) => { if (this.OnQueryInventoryError != null) { this.OnQueryInventoryError(responseCode, null); } }; this._serviceConnection.BillingHandler.BuyProductError += (int responseCode, string sku) => { // Note, BillingResult.ItemAlreadyOwned, etc. can be used to determine error if (this.OnPurchaseProductError != null) { this.OnPurchaseProductError(responseCode, sku); } }; this._serviceConnection.BillingHandler.InAppBillingProcesingError += (string message) => { if (this.OnInAppBillingProcesingError != null) { this.OnInAppBillingProcesingError(message); } }; this._serviceConnection.BillingHandler.OnInvalidOwnedItemsBundleReturned += (Bundle ownedItems) => { if (this.OnInvalidOwnedItemsBundleReturned != null) { this.OnInvalidOwnedItemsBundleReturned(null); } }; this._serviceConnection.BillingHandler.OnProductPurchasedError += (int responseCode, string sku) => { if (this.OnPurchaseProductError != null) { this.OnPurchaseProductError(responseCode, sku); } }; this._serviceConnection.BillingHandler.OnPurchaseFailedValidation += (Purchase purchase, string purchaseData, string purchaseSignature) => { if (this.OnPurchaseFailedValidation != null) { this.OnPurchaseFailedValidation(null, purchaseData, purchaseSignature); } }; this._serviceConnection.BillingHandler.OnUserCanceled += () => { if (this.OnUserCanceled != null) { this.OnUserCanceled(); } }; this._connected = true; // Load inventory or available products // this.QueryInventory(); }; /* Uncomment these if you want to be notified for these events * _serviceConnection.OnDisconnected += () => * { * System.Diagnostics.Debug.WriteLine("Remove"); * }; * * _serviceConnection.OnInAppBillingError += (error, message) => * { * System.Diagnostics.Debug.WriteLine("Remove"); * }; */ // Are we connected to a network? ConnectivityManager connectivityManager = (ConnectivityManager)MainActivity.Instance.GetSystemService(MainActivity.ConnectivityService); NetworkInfo activeConnection = connectivityManager.ActiveNetworkInfo; if ((activeConnection != null) && activeConnection.IsConnected) { // Ok, carefully attempt to connect to the in-app service try { _serviceConnection.Connect(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception trying to connect to in app service: " + ex); } } }
public static async Task <(PoseBillingResult BillingResult, long Payload, string OrderId)> InAppProductProcess(InAppPurchase inAppPurchase, string appPackageName, string purchaseToken) { ProductPurchase poductPurchase = await _androidPublisher.Purchases.Products.Get(appPackageName, inAppPurchase.ProductId, purchaseToken).ExecuteAsync(); if (!long.TryParse(poductPurchase.DeveloperPayload, out long payLoad)) { return(null, 0, ""); } PoseBillingResult billingResult = new PoseBillingResult(); switch (poductPurchase.PurchaseState) { case 0: billingResult.PurchaseStateType = PosePurchaseStateType.Purchased; break; case 1: billingResult.PurchaseStateType = PosePurchaseStateType.Canceled; break; case 2: billingResult.PurchaseStateType = PosePurchaseStateType.Pending; break; } DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0); DateTime purchaseTime = origin.AddMilliseconds(poductPurchase.PurchaseTimeMillis ?? 0); billingResult.MemberRoleType = inAppPurchase.OfferRoleType; billingResult.RoleExpireTime = purchaseTime.AddDays(inAppPurchase.OfferPeriod); billingResult.ProductId = inAppPurchase.ProductId; return(billingResult, payLoad, poductPurchase.OrderId); }
public virtual string GetPurchaseId(InAppPurchase purchase) { return(prefix + productIds[(int)purchase]); }
public static async Task <O_E_CHECK_MEMBERSHIP_BY_GOOGLE> Execute(I_E_CHECK_MEMBERSHIP_BY_GOOGLE input, long userNo, int serviceRoleType) { PoseBillingResult billingResult = null; //////////////////////////////////////////////////// /// 프로모션 유저 만료 처리 /////////////////////////////////////////////////// if (serviceRoleType == (int)ServiceRoleType.Promotion) { billingResult = new PoseBillingResult() { MemberRoleType = MemberRoleType.Regular, RoleExpireTime = DateTime.UtcNow, }; // Update DB bool db_output_promo; using (var P_UPDATE_USER_ROLE = new PoseGlobalDB.Procedures.P_UPDATE_USER_ROLE()) { P_UPDATE_USER_ROLE.SetInput(new PoseGlobalDB.Procedures.P_UPDATE_USER_ROLE.Input { UserNo = userNo, LinkedTransNo = 0, RoleType = billingResult.MemberRoleType.ToString(), RoleExpireTime = billingResult.RoleExpireTime, CurrentTime = DateTime.UtcNow, }); db_output_promo = P_UPDATE_USER_ROLE.OnQuery(); if (P_UPDATE_USER_ROLE.EntityStatus != null || db_output_promo == false) { ErrorHandler.OccurException(RowCode.DB_User_Role_Update_Failed); } } // Refrash PoseToken billingResult.MemberRoleType.ToString().TryParseEnum(out ServiceRoleType promoServiceRoleType); billingResult.PoseToken = PoseCredentials.CreateToken(userNo, promoServiceRoleType); return(new O_E_CHECK_MEMBERSHIP_BY_GOOGLE { BillingResult = billingResult, }); } //////////////////////////////////////////////////// /// 결제 유저 멤버십 처리 /////////////////////////////////////////////////// // Check DB PoseGlobalDB.Procedures.P_SELECT_LINKED_BILLING.Output db_output; using (var P_SELECT_LINKED_BILLING = new PoseGlobalDB.Procedures.P_SELECT_LINKED_BILLING()) { P_SELECT_LINKED_BILLING.SetInput(userNo); db_output = P_SELECT_LINKED_BILLING.OnQuery(); if (P_SELECT_LINKED_BILLING.EntityStatus != null || db_output.Result != 0) { ErrorHandler.OccurException(RowCode.P_SELECT_LINKED_BILLING + db_output.Result); } } // Check ProductID valid if (!InAppPurchase.TryGetInAppPurchase(db_output.InAppBilling.product_id, out var inAppPurchase) || inAppPurchase.StoreType != StoreType.GooglePlay) { Log4Net.WriteLog($"Invalid Google ProudctId, UserNo: {userNo}, productId: {db_output.InAppBilling.product_id}", Log4Net.Level.ERROR); ErrorHandler.OccurException(RowCode.Invalid_Product_Id); } long linkedTransNo = 0; if (inAppPurchase.PurchaseType == InAppPurchaseType.InAppProduct) { linkedTransNo = db_output.UserRole.linked_trans_no; billingResult = new PoseBillingResult(); billingResult.MemberRoleType = inAppPurchase.OfferRoleType; billingResult.RoleExpireTime = db_output.UserRole.expire_time; billingResult.ProductId = db_output.InAppBilling.product_id; billingResult.PurchaseStateType = db_output.UserRole.expire_time > DateTime.UtcNow ? PosePurchaseStateType.Purchased : PosePurchaseStateType.Unknown; } else if (inAppPurchase.PurchaseType == InAppPurchaseType.Subscription) { var process_ret = await P_E_UPDATE_IN_APP_BILLING_BY_GOOGLE.SubscriptionProcess(inAppPurchase, input.AppPackageName, db_output.InAppBilling.purchase_token); billingResult = process_ret.BillingResult; linkedTransNo = process_ret.Payload; } // 회원등급 심사 if (billingResult.PurchaseStateType != PosePurchaseStateType.Purchased && billingResult.PurchaseStateType != PosePurchaseStateType.Grace) // 결제 유예기간.. { billingResult.MemberRoleType = MemberRoleType.Regular; linkedTransNo = 0; } // Update DB bool db_output2; using (var P_UPDATE_USER_ROLE = new PoseGlobalDB.Procedures.P_UPDATE_USER_ROLE()) { P_UPDATE_USER_ROLE.SetInput(new PoseGlobalDB.Procedures.P_UPDATE_USER_ROLE.Input { UserNo = userNo, LinkedTransNo = linkedTransNo, RoleType = billingResult.MemberRoleType.ToString(), RoleExpireTime = billingResult.RoleExpireTime, CurrentTime = DateTime.UtcNow, }); db_output2 = P_UPDATE_USER_ROLE.OnQuery(); if (P_UPDATE_USER_ROLE.EntityStatus != null || db_output2 == false) { ErrorHandler.OccurException(RowCode.DB_User_Role_Update_Failed); } } // Refrash PoseToken billingResult.MemberRoleType.ToString().TryParseEnum(out ServiceRoleType convertedServiceRoleType); billingResult.PoseToken = PoseCredentials.CreateToken(userNo, convertedServiceRoleType); return(new O_E_CHECK_MEMBERSHIP_BY_GOOGLE { BillingResult = billingResult, }); }
public static async Task <(PoseBillingResult BillingResult, long Payload, string OrderId)> SubscriptionProcess(InAppPurchase inAppPurchase, string appPackageName, string purchaseToken) { SubscriptionPurchase subscriptionPurchase = await _androidPublisher.Purchases.Subscriptions.Get(appPackageName, inAppPurchase.ProductId, purchaseToken).ExecuteAsync(); if (!long.TryParse(subscriptionPurchase.DeveloperPayload, out long payLoad)) { return(null, 0, ""); } DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0); DateTime expireTiem = origin.AddMilliseconds(subscriptionPurchase.ExpiryTimeMillis ?? 0); PoseBillingResult billingResult = new PoseBillingResult(); billingResult.PurchaseStateType = ParseSubscriptionPurchaseState(subscriptionPurchase); billingResult.MemberRoleType = inAppPurchase.OfferRoleType; billingResult.RoleExpireTime = expireTiem; billingResult.ProductId = inAppPurchase.ProductId; return(billingResult, payLoad, subscriptionPurchase.OrderId); }
public static async Task <O_E_UPDATE_IN_APP_BILLING_BY_GOOGLE> Execute(I_E_UPDATE_IN_APP_BILLING_BY_GOOGLE input, long userNo) { if (input == null || string.IsNullOrEmpty(input.ProductID) || string.IsNullOrEmpty(input.AppPackageName) || string.IsNullOrEmpty(input.PurchaseToken)) { ErrorHandler.OccurException(RowCode.Invalid_InputValue); } // Check ProductID valid if (!InAppPurchase.TryGetInAppPurchase(input.ProductID, out var inAppPurchase) || inAppPurchase.StoreType != StoreType.GooglePlay) { Log4Net.WriteLog($"Invalid Google ProudctId, UserNo: {userNo}, productId: {input.ProductID}", Log4Net.Level.ERROR); ErrorHandler.OccurException(RowCode.Invalid_Product_Id); } PoseBillingResult billingResult = null; long trasNo = 0; string orderId = string.Empty; switch (inAppPurchase.PurchaseType) { case InAppPurchaseType.InAppProduct: // 소비성 상품 { var process_ret = await InAppProductProcess(inAppPurchase, input.AppPackageName, input.PurchaseToken); billingResult = process_ret.BillingResult; trasNo = process_ret.Payload; orderId = process_ret.OrderId; } break; case InAppPurchaseType.Subscription: // 구독 상품 { var process_ret = await SubscriptionProcess(inAppPurchase, input.AppPackageName, input.PurchaseToken); billingResult = process_ret.BillingResult; trasNo = process_ret.Payload; orderId = process_ret.OrderId; } break; } // 유효하지않은 PurchaseToken if (billingResult == null) { Log4Net.WriteLog($"Google PurchaseToken is Invalid, UserNo: {userNo}, productId: {input.ProductID}, purchaseToken: {input.PurchaseToken}", Log4Net.Level.ERROR); ErrorHandler.OccurException(RowCode.Invalid_Google_Receipt); } if (billingResult.PurchaseStateType == PosePurchaseStateType.Purchased) { // DB Process PoseGlobalDB.Procedures.P_UPDATE_IN_APP_BILLING.Output db_output; using (var P_UPDATE_IN_APP_BILLING = new PoseGlobalDB.Procedures.P_UPDATE_IN_APP_BILLING()) { P_UPDATE_IN_APP_BILLING.SetInput(new PoseGlobalDB.Procedures.P_UPDATE_IN_APP_BILLING.Input { UserNo = userNo, TransNo = trasNo, PurchaseState = PosePurchaseStateType.Purchased.ToString(), PurchaseToken = input.PurchaseToken, OrderId = orderId, RoleType = billingResult.MemberRoleType.ToString(), RoleExpireTime = billingResult.RoleExpireTime, CurrentTime = DateTime.UtcNow, }); db_output = P_UPDATE_IN_APP_BILLING.OnQuery(); if (P_UPDATE_IN_APP_BILLING.EntityStatus != null || db_output.Result != 0) { ErrorHandler.OccurException(RowCode.P_UPDATE_IN_APP_BILLING + db_output.Result); } } // Refrash PoseToken billingResult.MemberRoleType.ToString().TryParseEnum(out ServiceRoleType serviceRoleType); billingResult.PoseToken = PoseCredentials.CreateToken(userNo, serviceRoleType); } return(new O_E_UPDATE_IN_APP_BILLING_BY_GOOGLE { BillingResult = billingResult, }); }
public override string GetPurchaseId(InAppPurchase purchase) { return(prefix + productIds[(int)purchase] + productExtraIds[(int)purchase]); }
public void Initialize() { // A Licensing and In-App Billing public key is required before an app can communicate with // Google Play, however you DON'T want to store the key in plain text with the application. // The Unify command provides a simply way to obfuscate the key by breaking it into two or // or more parts, specifying the order to reassemlbe those parts and optionally providing // a set of key/value pairs to replace in the final string. string value = Security.Unify( new string[] { "Insert part 0", "Insert part 3", "Insert part 2", "Insert part 1" }, new int[] { 0, 3, 2, 1 }); // Create a new connection to the Google Play Service _serviceConnection = new InAppBillingServiceConnection(MainActivity.Instance, value); _serviceConnection.OnConnected += () => { this._serviceConnection.BillingHandler.OnProductPurchased += (int response, Purchase purchase, string purchaseData, string purchaseSignature) => { // Record what we purchased var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); var purchaseTime = epoch.AddMilliseconds(purchase.PurchaseTime); var newPurchase = new InAppPurchase { OrderId = purchase.OrderId, ProductId = purchase.ProductId, PurchaseTime = purchaseTime }; App.ViewModel.Purchases.Add(newPurchase); // Let anyone know who is interested that purchase has completed if (this.OnPurchaseProduct != null) { this.OnPurchaseProduct(); } }; this._serviceConnection.BillingHandler.QueryInventoryError += (int responseCode, Bundle skuDetails) => { if (this.OnQueryInventoryError != null) { this.OnQueryInventoryError(responseCode, null); } }; this._serviceConnection.BillingHandler.BuyProductError += (int responseCode, string sku) => { // Note, BillingResult.ItemAlreadyOwned, etc. can be used to determine error if (this.OnPurchaseProductError != null) { this.OnPurchaseProductError(responseCode, sku); } }; this._serviceConnection.BillingHandler.InAppBillingProcesingError += (string message) => { if (this.OnInAppBillingProcesingError != null) { this.OnInAppBillingProcesingError(message); } }; this._serviceConnection.BillingHandler.OnInvalidOwnedItemsBundleReturned += (Bundle ownedItems) => { if (this.OnInvalidOwnedItemsBundleReturned != null) { this.OnInvalidOwnedItemsBundleReturned(null); } }; this._serviceConnection.BillingHandler.OnProductPurchasedError += (int responseCode, string sku) => { if (this.OnPurchaseProductError != null) { this.OnPurchaseProductError(responseCode, sku); } }; this._serviceConnection.BillingHandler.OnPurchaseFailedValidation += (Purchase purchase, string purchaseData, string purchaseSignature) => { if (this.OnPurchaseFailedValidation != null) { this.OnPurchaseFailedValidation(null, purchaseData, purchaseSignature); } }; this._serviceConnection.BillingHandler.OnUserCanceled += () => { if (this.OnUserCanceled != null) { this.OnUserCanceled(); } }; this._connected = true; // Load inventory or available products this.QueryInventory(); }; /* Uncomment these if you want to be notified for these events * _serviceConnection.OnDisconnected += () => * { * System.Diagnostics.Debug.WriteLine("Remove"); * }; * * _serviceConnection.OnInAppBillingError += (error, message) => * { * System.Diagnostics.Debug.WriteLine("Remove"); * }; */ // Are we connected to a network? ConnectivityManager connectivityManager = (ConnectivityManager)MainActivity.Instance.GetSystemService(MainActivity.ConnectivityService); NetworkInfo activeConnection = connectivityManager.ActiveNetworkInfo; if ((activeConnection != null) && activeConnection.IsConnected) { // Ok, carefully attempt to connect to the in-app service try { _serviceConnection.Connect(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception trying to connect to in app service: " + ex); } } }