Ejemplo n.º 1
0
        public void SavePayPalPayment(PayPalPayment payment)
        {
            if (this.GetPayPalPayment(payment.Guid) == null)
            {
                // insert
                string sql = @"Insert Into VintageRabbit.PayPalPayment (Guid, OrderGuid, Status, PayPalResponse, PayPalId, Errors, DateCreated, DateLastModified)
                Values (@Guid, @OrderGuid, @Status, @PayPalResponse, @PayPalId, @Errors, @DateCreated, @DateLastModified)";

                using (SqlConnection connection = new SqlConnection(this._connectionString))
                {
                    connection.Execute(sql, new
                    {
                        Guid = payment.Guid,
                        OrderGuid = payment.OrderGuid,
                        Status = payment.Status.ToString(),
                        PayPalResponse = payment.PayPalResponse,
                        PayPalId = payment.PayPalId,
                        Errors = this._serializer.Serialize(payment.Errors),
                        DateCreated = DateTime.Now,
                        DateLastModified = DateTime.Now

                    });
                }
            }
            else
            {
                //update
                string sql = @"Update VintageRabbit.PayPalPayment Set OrderGuid = @OrderGuid, Status = @Status, PayPalResponse = @PayPalResponse, PayPalId = @PayPalId, Errors = @Errors, DateLastModified = @DateLastModified Where Guid = @Guid";

                using (SqlConnection connection = new SqlConnection(this._connectionString))
                {
                    connection.Execute(sql, new
                    {
                        Guid = payment.Guid,
                        OrderGuid = payment.OrderGuid,
                        Status = payment.Status.ToString(),
                        PayPalResponse = payment.PayPalResponse,
                        PayPalId = payment.PayPalId,
                        Errors = payment.Errors.Any() ? this._serializer.Serialize(payment.Errors) : null,
                        DateLastModified = DateTime.Now

                    });
                }
            }
        }
 public PayPalPaymentCreatedMessage(PayPalPayment payPalPayment)
 {
     this.PayPalPayment = payPalPayment;
 }
Ejemplo n.º 3
0
 public PayPalErrorMessage(PayPalPayment payPalPayment)
 {
     this.PayPalPayment = payPalPayment;
 }
Ejemplo n.º 4
0
        public string Checkout(IOrder order)
        {
            try
            {
                Guid paypalPaymentGuid = Guid.NewGuid();

                string returnUrl = string.Format("{0}/checkout-{1}/paypal/success/{2}", this._websiteUrl, order.Guid, paypalPaymentGuid);
                string cancelUrl = string.Format("{0}/checkout-{1}/paypal/cancel/{2}", this._websiteUrl, order.Guid, paypalPaymentGuid);

                PayPal.Api.Payments.Payment payment = this.CreatePayment(order, returnUrl, cancelUrl);

                PayPalPayment payPalPayment = new PayPalPayment(paypalPaymentGuid, order.Guid, payment.id);

                this._commandDispatcher.Dispatch(new SavePayPalPaymentCommand(payPalPayment));
                this._messageService.AddMessage(new PayPalPaymentCreatedMessage(payPalPayment));

                return payment.links.First(o => o.rel == "approval_url").href;
            }
            catch (Exception exception)
            {
                this._logger.Error(exception, "Unable to get paypal express checkout url");
            }

            return null;
        }
Ejemplo n.º 5
0
        private PayPalPayment ConvertToPayPalPayment(dynamic payment)
        {
            PayPalPayment payPalPayment = new PayPalPayment()
            {
                Id = payment.Id,
                Guid = payment.Guid,
                OrderGuid = payment.OrderGuid,
                Status = (PayPalPaymentStatus)Enum.Parse(typeof(PayPalPaymentStatus), payment.Status),
                PayPalResponse = payment.PayPalResponse,
                PayPalId = payment.PayPalId,
                DateCreated = payment.DateCreated,
                DateLastModified = payment.DateLastModified
            };

            if(payment.Errors != null)
            {
                payPalPayment.Errors = this._serializer.Deserialize<IList<PayPalError>>(payment.Errors);
            }

            return payPalPayment;
        }