Пример #1
0
        public static bool Cancel(string paymentGuidString)
        {
            Guid paymentGuid = Guid.Empty;

            if (!Guid.TryParse(paymentGuidString, out paymentGuid))
            {
                return(false);
            }

            Payment payment = Payment.CreateManager().Load(paymentGuid, GuidType.Internal);

            if (payment == null)
            {
                return(false);
            }

            ServiceLookupMethodMap slmm = ServiceLookupMethodMap.CreateManager(2).Load(payment.ServiceOffer.Service, payment.PaymentRequest.Customer.Country, LookupMethod.Wap);

            string referenceId = payment.ExternalPaymentGuid.Value.ToString();
            string username    = slmm.PaymentConfiguration.PaymentCredentials.Username;
            string password    = slmm.PaymentConfiguration.PaymentCredentials.Password;
            CancelSubscriptionRequest request = new CancelSubscriptionRequest(RequestMode.Synchronous, referenceId, username, password, payment.ExternalPaymentGuid.Value, SubscriptionCancellationMode.Interactive, null);
            SubscriptionClient        client  = new SubscriptionClient();

            client.AttachLogWriter(new CashflowLog(payment.ServiceOffer.Service));
            CancelSubscriptionResponse response = client.CancelSubscription(request);

            if (response == null || response.Status == null || response.Status.Code != MessageStatusCode.Success)
            {
                // TODO: logging error
                return(false);
            }
            // TODO: logging subscription canceled
            return(true);
        }
Пример #2
0
        public ActionResult CancelSubscription()
        {
            CancelSubscriptionResponse response = _subscriptionsService.CancelSubscription(Customer.CustomerId);

            if (response.IsStatusActive)
            {
                return(RedirectToAction("index", "subscriptions")
                       .AndAlert(AlertType.Danger, "Error.", "The subscription wasn't cancelled."));
            }

            return(RedirectToAction("index").AndAlert(AlertType.Warning, "Cancelled.", "The subscription was cancelled successfully."));
        }
Пример #3
0
        public CancelSubscriptionResponse CancelSubscription(Guid customerId)
        {
            var response = new CancelSubscriptionResponse();

            var customer = _customerRepository.Get(customerId);

            if (customer.Plan != null)
            {
                var status = StripeFactory.GetStripeService().CloseCustomerPlan(customer.PaymentCustomerId);

                if (status.ToLower() == "active")
                {
                    response.IsStatusActive = true;
                    return(response);
                }
                customer.RemovePlan();
                _customerRepository.Update(customer);

                _unitOfWork.Commit();
            }
            return(response);
        }