コード例 #1
0
ファイル: Program.cs プロジェクト: fooberichu150/solid-isp
        private void RunAfter()
        {
            var factory     = new PaymentProcessors.After.PaymentProcessorFactory();
            var cashPayment = new Models.PaymentItem
            {
                Amount      = 50m,
                PaymentType = Models.PaymentType.Cash
            };

            var authorizable = factory.GetAuthorizableProcessor(cashPayment);
            var capturable   = factory.GetCapturablePaymentProcessor(cashPayment);
            var creditable   = factory.GetCreditablePaymentProcessor(cashPayment);
            var voidable     = factory.GetVoidablePaymentProcessor(cashPayment);

            Console.Out.WriteLine("Running cash transactions...");
            Console.Out.WriteLine($"Trying cash authorization: {authorizable?.Authorize() ?? false}");
            Console.Out.WriteLine($"Trying cash capture: {capturable?.Capture() ?? false}");
            Console.Out.WriteLine($"Trying cash credit: {creditable?.Credit() ?? false}");
            Console.Out.WriteLine($"Trying cash voidPayment: {voidable?.Void() ?? false}");

            var creditPayment = new Models.CreditCardPaymentItem
            {
                Amount               = 50m,
                PaymentType          = Models.PaymentType.CreditCard,
                CardNumber           = "4556210085229628",
                CardVerificationCode = "123",
                ExpirationDate       = DateTime.Today
            };

            authorizable = factory.GetAuthorizableProcessor(creditPayment);
            capturable   = factory.GetCapturablePaymentProcessor(creditPayment);
            creditable   = factory.GetCreditablePaymentProcessor(creditPayment);
            voidable     = factory.GetVoidablePaymentProcessor(creditPayment);

            Console.Out.WriteLine("Running credit card transactions...");
            Console.Out.WriteLine($"Trying credit card authorization: {authorizable?.Authorize() ?? false}");
            Console.Out.WriteLine($"Trying credit card capture: {capturable?.Capture() ?? false}");
            Console.Out.WriteLine($"Trying credit card credit: {creditable?.Credit() ?? false}");
            Console.Out.WriteLine($"Trying credit card voidPayment: {voidable?.Void() ?? false}");
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: fooberichu150/solid-isp
        private void RunBefore()
        {
            var factory     = new PaymentProcessors.Before.PaymentProcessorFactory();
            var cashPayment = new Models.PaymentItem
            {
                Amount      = 50m,
                PaymentType = Models.PaymentType.Cash
            };

            var processor = factory.Build(cashPayment);

            var authorize   = new Func <PaymentProcessors.Before.PaymentProcessorBase, bool>((processor) => processor.Authorize());
            var capture     = new Func <PaymentProcessors.Before.PaymentProcessorBase, bool>((processor) => processor.Capture());
            var credit      = new Func <PaymentProcessors.Before.PaymentProcessorBase, bool>((processor) => processor.Credit());
            var voidPayment = new Func <PaymentProcessors.Before.PaymentProcessorBase, bool>((processor) => processor.Void());

            Console.Out.WriteLine("Running cash transactions...");
            Console.Out.WriteLine($"Trying cash authorization: {TryRun(authorize, processor)}");
            Console.Out.WriteLine($"Trying cash capture: {TryRun(capture, processor)}");
            Console.Out.WriteLine($"Trying cash credit: {TryRun(credit, processor)}");
            Console.Out.WriteLine($"Trying cash voidPayment: {TryRun(voidPayment, processor)}");

            var creditPayment = new Models.CreditCardPaymentItem
            {
                Amount               = 50m,
                PaymentType          = Models.PaymentType.CreditCard,
                CardNumber           = "4556210085229628",
                CardVerificationCode = "123",
                ExpirationDate       = DateTime.Today
            };

            processor = factory.Build(creditPayment);

            Console.Out.WriteLine("Running credit card transactions...");
            Console.Out.WriteLine($"Trying credit card authorization: {TryRun(authorize, processor)}");
            Console.Out.WriteLine($"Trying credit card capture: {TryRun(capture, processor)}");
            Console.Out.WriteLine($"Trying credit card credit: {TryRun(credit, processor)}");
            Console.Out.WriteLine($"Trying credit card voidPayment: {TryRun(voidPayment, processor)}");
        }