Beispiel #1
0
        public void Handle(CompleteThirdPartyProcessorPayment command)
        {
            var repository = this._contextFactory();

            Console.WriteLine("Whoo Hoo...  We made our first sale!");
            using (repository as IDisposable)
            {
                var payment = repository.Find(command.PaymentId);

                if (payment != null)
                {
                    StripeCharge charge = null;

                    try
                    {
                        charge = ChargeCustomer(command.Token, (int)payment.TotalAmount);
                    }
                    catch (StripeException se)
                    {
                        Console.WriteLine("Payment failed. :(");
                        _commandBus.Send(new CancelThirdPartyProcessorPayment {
                            PaymentId = command.PaymentId, UserEmail = command.UserEmail, Username = command.UserEmail, UserId = command.UserId
                        });
                        return;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Payment failed. :(");
                        _commandBus.Send(new CancelThirdPartyProcessorPayment {
                            PaymentId = command.PaymentId, UserEmail = command.UserEmail, Username = command.UserEmail, UserId = command.UserId
                        });
                        throw;
                    }

                    if (charge != null && charge.Paid && charge.Status == "succeeded")
                    {
                        payment.Items.Add(new ThidPartyProcessorPaymentItem("payment", charge.Amount));
                        payment.Complete(charge);
                        repository.Save(payment);

                        _commandBus.Send(new NotifyUserOfSuccesfullPayment {
                            PaymentId = command.PaymentId, UserEmail = command.UserEmail, Username = command.UserEmail, UserId = command.UserId
                        });
                    }
                    else
                    {
                        Console.WriteLine("Payment failed. :(");
                        _commandBus.Send(new CancelThirdPartyProcessorPayment {
                            PaymentId = command.PaymentId, UserEmail = command.UserEmail, Username = command.UserEmail, UserId = command.UserId
                        });
                    }
                }
                else
                {
                    Trace.TraceError("Failed to locate the payment entity with id {0} for the completed third party payment.", command.PaymentId);
                }
            }
        }
        public void Handle(CompleteThirdPartyProcessorPayment command)
        {
            var payment = repository.GetByKey(command.PaymentId);

            if (payment != null)
            {
                var processor = new PaymentProcessor(payment);
                processor.Complete();
                context.RegisterModified(processor.Payment);
                context.Commit();
            }
            else
            {
                Trace.TraceError("Failed to locate the payment entity with id {0} for the completed third party payment.", command.PaymentId);
            }
        }
        public void Handle(CompleteThirdPartyProcessorPayment command)
        {
            using (var repository = this._contextFactory()) {
                var payment = repository.Find(command.PaymentId);

                if (payment != null)
                {
                    payment.Complete();
                    repository.Save(payment);
                }
                else
                {
                    Trace.TraceError("Failed to locate the payment entity with id {0} for the completed third party payment", command.PaymentId);
                }
            }
        }