Пример #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);
        }