private async Task <IHttpActionResult> OwnerProductSuspend(Guid accountProductId, bool suspend, string source = null) { return(await OwnerProductExecuteAsync(async delegate(Guid accountId, ViewOwnerProduct product) { var subscription = suspend ? await UpclickClient.SubscriptionSuspend(product.SpId, source) : await UpclickClient.SubscriptionResume(product.SpId); if (object.Equals(subscription, null)) { return BadRequest(); } DateTime?nextRebillDate = null; if (string.Equals(subscription.Status, "Active")) { nextRebillDate = subscription.NextRebillDate; } var pair = new AccountProductPair(accountId, product.AccountProductId); await _authProduct.ProductNextRebillDateSetAsync(pair, nextRebillDate); product = await _authProduct.OwnerProductDetailsGetAsync(pair); await NotificationManager.ProductSuspend(accountId, product, nextRebillDate); return Ok(ProductConvertor.OwnerAccountProductConvertor(product)); }, accountProductId)); }
public async Task <IHttpActionResult> PaymentInformation() { try { var creditCards = await UpclickClient.SubscriptionsPaymentInstruments(User.Identity.Name); if (!object.Equals(creditCards, null)) { foreach (var creditCard in creditCards) { string token = UpclickClient.Token("paymentinstrument.edit"); Uri uri = new Uri(string.Format("https://billing.upclick.com/{0}/PaymentInstrument/Edit", token)); var query = HttpUtility.ParseQueryString(string.Empty); query.Add("id", HttpUtility.UrlDecode(creditCard.PayTokenID)); var uriBuilder = new UriBuilder(uri); uriBuilder.Query = query.ToString(); creditCard.EditUrl = uriBuilder.Uri.ToString(); } } return(Ok(creditCards)); } catch (Exception exc) { return(Request.HttpExceptionResult(exc)); } }
private async Task <IHttpActionResult> OwnerProductSuspend(Guid accountId, Guid accountProductId, bool suspend) { return(await CurrentAccountExecuteAsync(async delegate(Account account) { var product = await _authProduct.OwnerProductGetAsync(new AccountProductPair(accountId, accountProductId)); if (object.Equals(product, null) || product.IsDisabled) { return ProductNotFound(); } if (!product.IsRenewal || IsLocalSubscription(product.SpId)) { return ErrorContent(string.Empty, "This product can't be suspend or resumed."); } DateTime?nextRebillDate = null; var subscriptionDetails = await UpclickClient.SubscriptionDetails(product.SpId); if (object.Equals(subscriptionDetails, null)) { return ErrorContent(string.Empty, "Product is not exists in Customer info(Upclick)."); } var subscription = suspend ? await UpclickClient.SubscriptionSuspend(product.SpId) : await UpclickClient.SubscriptionResume(product.SpId); if (suspend && string.Equals(subscription.Status, "Active")) { return ErrorContent(string.Empty, "Product can't be suspend. Product is still active in Customer info(Upclick)."); } if (!suspend && !string.Equals(subscription.Status, "Active")) { return ErrorContent(string.Empty, "Product can't be resumed. Product is not active in Customer info(Upclick)."); } if (string.Equals(subscription.Status, "Active")) { nextRebillDate = subscription.NextRebillDate; } var pair = new AccountProductPair(accountId, product.AccountProductId); await _authProduct.ProductNextRebillDateSetAsync(pair, nextRebillDate); var log = string.Format("Product({0}, {1}) has been {2} successfully.", product.ProductName, product.AccountProductId, nextRebillDate.HasValue ? "resumed" : "suspended"); await LogInsertAsync(log, LogActionTypeEnum.AccountProductDeactivate, accountId); product = await _authProduct.OwnerProductDetailsGetAsync(pair); return Ok(ProductConvertor.OwnerAccountProductConvertor(product)); }, accountId)); }
public async Task <IHttpActionResult> OwnerProductDeactivate(Guid accountId, Guid accountProductId) { try { var product = await _authProduct.OwnerProductGetAsync(new AccountProductPair(accountId, accountProductId)); if (object.Equals(product, null)) { return(ProductNotFound()); } var ownerAccount = await _auth.AccountGetAsync(accountId); if (!object.Equals(ownerAccount, null) && !product.IsFree && !product.IsTrial && !product.IsDisabled) { if (!IsLocalSubscription(product.SpId) && !string.IsNullOrEmpty(product.SpId)) { var subscription = await UpclickClient.SubscriptionDetails(product.SpId); if (object.Equals(subscription, null) || object.Equals(subscription.Status, null)) { return(ErrorContent("Unknown subscription", "Upclick error. Unknown subscription.")); } if (string.Equals(subscription.Status.Name, "Active")) { subscription = await UpclickClient.SubscriptionCancel(product.SpId); //cuz Upclick has bug in API Thread.Sleep(TimeSpan.FromSeconds(3)); subscription = await UpclickClient.SubscriptionDetails(product.SpId); if (string.Equals(subscription.Status.Name, "Active")) { return(ErrorContent("Subscription is active", "Upclick error. Subscription is active.")); } } } await _authProduct.ProductDeactivateAsync(new AccountProductPair(accountId, product.AccountProductId)); var log = string.Format("Product({0}, {1}) has been deactivated successfully. Customer's email is {2}.", product.ProductName, product.AccountProductId, ownerAccount.Email); await LogInsertAsync(log, LogActionTypeEnum.AccountProductDeactivate, ownerAccount.Id); } return(Ok()); } catch (Exception exc) { return(ErrorContent(exc)); } }
public async Task <IHttpActionResult> OwnerProductNextRebillDate(Guid accountId, Guid accountProductId, [FromUri] DateTime nextRebillDate) { return(await CurrentAccountExecuteAsync(async delegate(Account account) { var product = await _authProduct.OwnerProductGetAsync(new AccountProductPair(accountId, accountProductId)); if (object.Equals(product, null) || product.IsDisabled || !product.IsRenewal) { return ProductNotFound(); } if (!product.IsRenewal || IsLocalSubscription(product.SpId)) { return ErrorContent(string.Empty, "You can't change next rebill date for this product."); } var subscription = await UpclickClient.SubscriptionDetails(product.SpId); if (object.Equals(subscription, null)) { return ErrorContent(string.Empty, "Product is not exists in Customer info(Upclick)."); } subscription = await UpclickClient.SubscriptionUpdate(product.SpId, nextRebillDate); DateTime?newNextRebillDate = null; if (string.Equals(subscription.Status.Name, "Active") && !object.Equals(subscription.NextCycleBill, null)) { newNextRebillDate = subscription.NextCycleBill.Date; } var pair = new AccountProductPair(accountId, product.AccountProductId); if (newNextRebillDate.HasValue) { await _authProduct.ProductNextRebillDateSetAsync(pair, newNextRebillDate); var log = string.Format("Next rebill date has been changed successfully. Product({0}, {1}).", product.ProductName, product.AccountProductId); await LogInsertAsync(log, LogActionTypeEnum.AccountProductNextRebillDateEdit, accountId); } product = await _authProduct.OwnerProductDetailsGetAsync(pair); return Ok(ProductConvertor.OwnerAccountProductConvertor(product)); }, accountId)); }