/// <summary>
 /// Raises the Finalizing event.
 /// </summary>
 /// <param name="result">
 /// The result.
 /// </param>
 protected void OnFinalizing(IPaymentResult result)
 {
     if (Finalizing != null)
     {
         Finalizing.RaiseEvent(new CheckoutEventArgs <IPaymentResult>(Context.Customer, result), this);
     }
 }
Пример #2
0
        /// <summary>
        /// Authorizes and Captures a Payment
        /// </summary>
        /// <param name="paymentGatewayMethod">The <see cref="IPaymentMethod"/></param>
        /// <param name="args">Additional arguments required by the payment processor</param>
        /// <returns>A <see cref="IPaymentResult"/></returns>
        public virtual IPaymentResult AuthorizeCapturePayment(IPaymentGatewayMethod paymentGatewayMethod, ProcessorArgumentCollection args)
        {
            Mandate.ParameterNotNull(paymentGatewayMethod, "paymentGatewayMethod");

            if (!IsReadyToInvoice())
            {
                return(new PaymentResult(Attempt <IPayment> .Fail(new InvalidOperationException("SalesPreparation is not ready to invoice")), null, false));
            }

            // invoice
            var invoice = PrepareInvoice(new InvoiceBuilderChain(this));

            MerchelloContext.Services.InvoiceService.Save(invoice);

            var result = invoice.AuthorizeCapturePayment(paymentGatewayMethod, args);

            Finalizing.RaiseEvent(new SalesPreparationEventArgs <IPaymentResult>(result), this);

            return(result);
        }
Пример #3
0
        public static void Initialize()
        {
            string[] args = Environment.GetCommandLineArgs();


            //  프레임워크 초기화
            {
                SpinWorker.Initialize();


                _stopRunningEvent = new EventWaitHandle(false, EventResetMode.ManualReset);
                _releaseEvent     = new EventWaitHandle(false, EventResetMode.ManualReset);
                Logger.Info(LogMask.Aegis, "Aegis Framework({0})", AegisVersion.ToString(3));
            }



            AegisTask.Run(() =>
            {
                //  컨텐츠 초기화 (UI 모드)
                if (Environment.UserInteractive)
                {
                    AegisTask.SafeAction(() =>
                    {
                        if (Initialized == null ||
                            Initialized.Invoke(args) == true)
                        {
                            Running?.Invoke();
                        }
                    });

                    AegisTask.SafeAction(() => { Finalizing?.Invoke(CloseReason.Close); });
                }
                //  컨텐츠 초기화 (서비스 모드)
                else
                {
                    ServiceMain.Instance.EventStart = () =>
                    {
                        AegisTask.SafeAction(() =>
                        {
                            if (Initialized == null ||
                                Initialized?.Invoke(System.Environment.GetCommandLineArgs()) == true)
                            {
                                //  Running이 설정된 경우에는 Running이 반환되기를 대기하고, 반환된 후 종료처리 진행
                                if (Running != null)
                                {
                                    (new Thread(() =>
                                    {
                                        AegisTask.SafeAction(() => { Running.Invoke(); });
                                        ServiceMain.Instance.Stop();
                                    })).Start();
                                }
                            }
                        });
                    };
                    ServiceMain.Instance.EventStop = () =>
                    {
                        AegisTask.SafeAction(() => { Finalizing?.Invoke(CloseReason.ServiceStop); });
                    };
                    ServiceMain.Instance.EventShutDown = () =>
                    {
                        AegisTask.SafeAction(() => { Finalizing?.Invoke(CloseReason.ShutDown); });
                    };
                    ServiceMain.Instance.Run();
                }


                _stopRunningEvent.Set();
            });


            AegisTask.Run(() =>
            {
                WaitForRunning();


                //  프레임워크 종료
                Calculate.IntervalTimer.DisposeAll();
                NamedThread.DisposeAll();
                NamedObjectManager.Clear();
                SpinWorker.Release();


                Logger.Info(LogMask.Aegis, "Aegis Framework finalized.");
                Logger.RemoveAll();


                AegisTask.SafeAction(() => { Finalized?.Invoke(); });
                Initialized = null;
                Finalizing  = null;
                Finalized   = null;
                Running     = null;

                _releaseEvent.Set();
            });
        }