示例#1
0
        public ANetApiResponse TestGetSubscription()
        {
            var response    = (ARBCreateSubscriptionResponse)CreateSubscription.Run(apiLoginId, transactionKey, GetMonth());
            var getResponse = GetSubscription.Run(apiLoginId, transactionKey, response.subscriptionId);

            CancelSubscription.Run(apiLoginId, transactionKey, response.subscriptionId);
            return(getResponse);
        }
示例#2
0
        public ActionResult Cancel()
        {
            CancelSubscription cxl = new CancelSubscription();
            CreditRefund       cr  = new CreditRefund();

            cr.refund();
            //cxl.cancelSub();
            return(View());
        }
示例#3
0
        public ANetApiResponse TestCreateSubscriptionFromCustomerProfile()
        {
            var profileResponse        = (createCustomerProfileResponse)CreateCustomerProfile.Run(apiLoginId, transactionKey, GetEmail());
            var paymentProfileResponse = (createCustomerPaymentProfileResponse)CreateCustomerPaymentProfile.Run(apiLoginId, transactionKey, profileResponse.customerProfileId);
            var shippingResponse       = (createCustomerShippingAddressResponse)CreateCustomerShippingAddress.Run(apiLoginId, transactionKey, profileResponse.customerProfileId);

            var response = (ARBCreateSubscriptionResponse)CreateSubscriptionFromCustomerProfile.Run(apiLoginId, transactionKey, GetMonth(),
                                                                                                    profileResponse.customerProfileId, paymentProfileResponse.customerPaymentProfileId,
                                                                                                    shippingResponse.customerAddressId);

            CancelSubscription.Run(apiLoginId, transactionKey, response.subscriptionId);
            DeleteCustomerProfile.Run(apiLoginId, transactionKey, profileResponse.customerProfileId);
            return(response);
        }
示例#4
0
        public void Should_handle_cancelation_from_handler()
        {
            Event1 eventFromSubscription = null;

            CancelSubscription cancelEvent = null;

            cancelEvent = eventBus.Subscribe <Event1>(@event =>
            {
                cancelEvent();
                eventFromSubscription = @event;
            });

            var publishedEvent1 = new Event1
            {
                Text = "Hello World"
            };

            eventBus.Publish(publishedEvent1);

            eventFromSubscription.ShouldNotBeNull();
        }
示例#5
0
        /// <summary>
        /// 订阅(注册),等同于 Click += Method
        /// </summary>
        /// <typeparam name="TEvent"></typeparam>
        /// <param name="eventHandler"></param>
        /// <returns></returns>
        public CancelSubscription Subscribe <TEvent>(Action <TEvent> eventHandler)
        {
            CancelSubscription cancelSubscription = null;

            this._subscriptions.AddOrUpdate(typeof(TEvent),
                                            t =>
            {
                var l = new List <object> {
                    eventHandler
                };
                cancelSubscription = () => l.Remove(eventHandler);
                return(l);
            },
                                            (t, l) =>
            {
                l.Add(eventHandler);
                cancelSubscription = () => l.Remove(eventHandler);
                return(l);
            }
                                            );

            return(cancelSubscription);
        }
示例#6
0
        public ActionResult CancelSubscription(CancelSubscription model)
        {
            // If the user has not provided a reason for cancellation, then don't do anything
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            WebSite.Models.User currentUser = Authentication.GetCurrentUser();

            // Email the admins and let them know the reason
            this.EmailAdminsAboutCancellation(model.Reason, currentUser);

            // Cancel the subscription at Authorize.NET
            ISubscriptionGateway gateway = GetSubscriptionGateway();

            // TODO: Assert the return value
            gateway.CancelSubscription(currentUser.Subscription.AuthorizeNETSubscriptionId);

            // Determine the user's last day based on how much they have paid so far
            DateTime subscriptionExpiryDate = DateTime.UtcNow;
            DateTime cancellationDate       = DateTime.UtcNow;
            DateTime activationDate         = currentUser.Subscription.ActivationDate;
            int      moduloAmount           = 1;

            ViewBag.SubscriptionFrequency = currentUser.Subscription.SubscriptionType.SubscriptionFrequency.Name.ToLower();

            if (currentUser.Subscription.SubscriptionType.SubscriptionFrequency.Name == PredefinedSubscriptionFrequencies.Monthly)
            {
                moduloAmount = 30;
            }
            else if (currentUser.Subscription.SubscriptionType.SubscriptionFrequency.Name == PredefinedSubscriptionFrequencies.Quarterly)
            {
                moduloAmount = 365 / 4;
            }
            else if (currentUser.Subscription.SubscriptionType.SubscriptionFrequency.Name == PredefinedSubscriptionFrequencies.Yearly)
            {
                moduloAmount = 365;
            }
            else
            {
                // TODO: Log Error
            }

            subscriptionExpiryDate = cancellationDate.AddDays(moduloAmount - ((cancellationDate - activationDate).Days % moduloAmount));

            // Mark the cancellation date of the user's subscription
            currentUser.Subscription.CancellationDate = DateTime.UtcNow;
            currentUser.SubscriptionExpiryDate        = subscriptionExpiryDate;
            currentUser.Subscription = null;

            // Cancel any auto trading if the user has some
            Subscription autoTradingSubscription = currentUser.AutoTradingSubscription;

            if (autoTradingSubscription != null)
            {
                gateway.CancelSubscription(autoTradingSubscription.AuthorizeNETSubscriptionId);
                autoTradingSubscription.CancellationDate = DateTime.UtcNow;
            }

            _database.SaveChanges();

            ViewBag.SubscriptionExpiryDate = subscriptionExpiryDate.ToLongDateString();
            ViewBag.ActivationDate         = activationDate.ToLongDateString();

            // Mark the subscription as cancelled
            model.Cancelled = true;

            return(this.View(model));
        }
示例#7
0
        private static void RunMethod(string methodName)
        {
            // These are default transaction keys.
            // You can create your own keys in seconds by signing up for a sandbox account here: https://developer.authorize.net/sandbox/
            string apiLoginId     = "5KP3u95bQpv";
            string transactionKey = "4Ktq966gC55GAX7S";

            string transactionAmount;
            string transactionId = string.Empty;

            switch (methodName)
            {
            case "ValidateCustomerPaymentProfile":
                ValidateCustomerPaymentProfile.Run(apiLoginId, transactionKey);
                break;

            case "UpdateCustomerShippingAddress":
                UpdateCustomerShippingAddress.Run(apiLoginId, transactionKey);
                break;

            case "UpdateCustomerProfile":
                UpdateCustomerProfile.Run(apiLoginId, transactionKey);
                break;

            case "UpdateCustomerPaymentProfile":
                UpdateCustomerPaymentProfile.Run(apiLoginId, transactionKey);
                break;

            case "GetCustomerShippingAddress":
                GetCustomerShippingAddress.Run(apiLoginId, transactionKey);
                break;

            case "GetCustomerProfileIds":
                GetCustomerProfileIds.Run(apiLoginId, transactionKey);
                break;

            case "GetCustomerProfile":
                GetCustomerProfile.Run(apiLoginId, transactionKey);
                break;

            case "GetCustomerPaymentProfile":
                GetCustomerPaymentProfile.Run(apiLoginId, transactionKey);
                break;

            case "DeleteCustomerShippingAddress":
                DeleteCustomerShippingAddress.Run(apiLoginId, transactionKey);
                break;

            case "DeleteCustomerProfile":
                DeleteCustomerProfile.Run(apiLoginId, transactionKey);
                break;

            case "DeleteCustomerPaymentProfile":
                DeleteCustomerPaymentProfile.Run(apiLoginId, transactionKey);
                break;

            case "CreateCustomerShippingAddress":
                CreateCustomerShippingAddress.Run(apiLoginId, transactionKey);
                break;

            case "CreateCustomerProfileFromTransaction":
                CreateCustomerProfileFromTransaction.Run(apiLoginId, transactionKey);
                break;

            case "GetTransactionDetails":
                GetTransactionDetails.Run(apiLoginId, transactionKey);
                break;

            case "GetTransactionList":
                GetTransactionList.Run(apiLoginId, transactionKey);
                break;

            //case "CreateAnApplePayTransaction":
            //    CreateAnApplePayTransaction.Run(apiLoginId, transactionKey);
            //    break;
            case "DecryptVisaCheckoutData":
                DecryptVisaCheckoutData.Run(apiLoginId, transactionKey);
                break;

            case "CreateVisaCheckoutTransaction":
                CreateVisaCheckoutTransaction.Run(apiLoginId, transactionKey);
                break;

            case "ChargeCreditCard":
                ChargeCreditCard.Run(apiLoginId, transactionKey);
                break;

            case "CaptureOnly":
                CaptureOnly.Run(apiLoginId, transactionKey);
                break;

            case "CapturePreviouslyAuthorizedAmount":
                Console.WriteLine("Enter An Transaction Amount");
                transactionAmount = Console.ReadLine();

                Console.WriteLine("Enter An Transaction ID");
                transactionId = Console.ReadLine();

                CapturePreviouslyAuthorizedAmount.Run(apiLoginId, transactionKey, Convert.ToDecimal(transactionAmount), transactionId);
                break;

            case "CaptureFundsAuthorizedThroughAnotherChannel":
                CaptureFundsAuthorizedThroughAnotherChannel.Run(apiLoginId, transactionKey);
                break;

            case "AuthorizeCreditCard":
                AuthorizeCreditCard.Run(apiLoginId, transactionKey);
                break;

            case "Refund":
                Console.WriteLine("Enter An Transaction Amount");
                transactionAmount = Console.ReadLine();

                Console.WriteLine("Enter An Transaction ID");
                transactionId = Console.ReadLine();

                RefundTransaction.Run(apiLoginId, transactionKey, Convert.ToDecimal(transactionAmount), transactionId);
                break;

            case "Void":
                Console.WriteLine("Enter An Transaction ID");
                transactionId = Console.ReadLine();

                VoidTransaction.Run(apiLoginId, transactionKey, transactionId);
                break;

            case "DebitBankAccount":
                DebitBankAccount.Run(apiLoginId, transactionKey);
                break;

            case "CreditBankAccount":
                Console.WriteLine("Enter An Transaction ID");
                transactionId = Console.ReadLine();

                CreditBankAccount.Run(apiLoginId, transactionKey, transactionId);
                break;

            case "ChargeCustomerProfile":
                ChargeCustomerProfile.Run(apiLoginId, transactionKey);
                break;

            case "ChargeTokenizedCard":
                ChargeTokenizedCreditCard.Run(apiLoginId, transactionKey);
                break;

            case "PayPalVoid":
                PayPalVoid.Run(apiLoginId, transactionKey, transactionId);
                break;

            case "PayPalAuthorizeCapture":
                PayPalAuthorizeCapture.Run(apiLoginId, transactionKey);
                break;

            case "PayPalAuthorizeCaptureContinue":
                PayPalAuthorizeCaptureContinue.Run(apiLoginId, transactionKey, transactionId);
                break;

            case "PayPalAuthorizeOnly":
                PayPalAuthorizeOnly.Run(apiLoginId, transactionKey);
                break;

            case "PayPalAuthorizeOnlyContinue":
                PayPalAuthorizeCaptureContinue.Run(apiLoginId, transactionKey, transactionId);
                break;

            case "PayPalCredit":
                PayPalCredit.Run(apiLoginId, transactionKey, transactionId);
                break;

            case "PayPalGetDetails":
                PayPalGetDetails.Run(apiLoginId, transactionKey, transactionId);
                break;

            case "PayPalPriorAuthorizationCapture":
                PayPalPriorAuthorizationCapture.Run(apiLoginId, transactionKey, transactionId);
                break;

            case "CancelSubscription":
                CancelSubscription.Run(apiLoginId, transactionKey);
                break;

            case "CreateSubscription":
                CreateSubscription.Run(apiLoginId, transactionKey);
                break;

            case "GetSubscriptionList":
                GetListSubscriptions.Run(apiLoginId, transactionKey);
                break;

            case "GetSubscriptionStatus":
                GetSubscriptionStatus.Run(apiLoginId, transactionKey);
                break;

            case "UpdateSubscription":
                UpdateSubscription.Run(apiLoginId, transactionKey);
                break;

            case "CreateCustomerProfile":
                CreateCustomerProfile.Run(apiLoginId, transactionKey);
                break;

            case "CreateCustomerPaymentProfile":
                CreateCustomerPaymentProfile.Run(apiLoginId, transactionKey);
                break;

            case "GetUnsettledTransactionList":
                GetUnsettledTransactionList.Run(apiLoginId, transactionKey);
                break;

            case "GetBatchStatistics":
                GetBatchStatistics.Run(apiLoginId, transactionKey);
                break;

            case "GetSettledBatchList":
                GetSettledBatchList.Run(apiLoginId, transactionKey);
                break;

            default:
                ShowUsage();
                break;
            }
        }