/// <summary>
		/// Captures payment
		/// </summary>
		/// <param name="capturePaymentRequest">Capture payment request</param>
		/// <returns>Capture payment result</returns>
		public override CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
		{
			var result = new CapturePaymentResult()
			{
				NewPaymentStatus = PaymentStatus.Pending,
				CaptureTransactionResult = "successful"
			};

			return result;
		}
Esempio n. 2
0
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public virtual CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var paymentMethod = LoadPaymentMethodBySystemName(capturePaymentRequest.Order.PaymentMethodSystemName);

            if (paymentMethod == null)
            {
                throw new SmartException("Payment method couldn't be loaded");
            }

            try
            {
                return(paymentMethod.Value.Capture(capturePaymentRequest));
            }
            catch (NotSupportedException)
            {
                var result = new CapturePaymentResult();
                result.AddError(_localizationService.GetResource("Common.Payment.NoCaptureSupport"));
                return(result);
            }
            catch
            {
                throw;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public virtual CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var paymentMethod = LoadPaymentMethodBySystemName(capturePaymentRequest.Order.PaymentMethodSystemName);

            if (paymentMethod == null)
            {
                throw new SmartException(T("Payment.CouldNotLoadMethod"));
            }

            try
            {
                return(paymentMethod.Value.Capture(capturePaymentRequest));
            }
            catch (NotSupportedException)
            {
                var result = new CapturePaymentResult();
                result.AddError(T("Common.Payment.NoCaptureSupport"));
                return(result);
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public virtual CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var paymentMethod = LoadPaymentMethodBySystemName(capturePaymentRequest.Order.PaymentMethodSystemName);
            if (paymentMethod == null)
                throw new SmartException("Payment method couldn't be loaded");

			try
			{
				return paymentMethod.Value.Capture(capturePaymentRequest);
			}
			catch (NotSupportedException)
			{
				var result = new CapturePaymentResult();
				result.AddError(_localizationService.GetResource("Common.Payment.NoCaptureSupport"));
				return result;
			}
			catch
			{
				throw;
			}
        }
        /// <summary>
        /// Capture an order (from admin panel)
        /// </summary>
        /// <param name="order">Order</param>
        /// <returns>A list of errors; empty list if no errors</returns>
        public virtual IList<string> Capture(Order order)
        {
            if (order == null)
                throw new ArgumentNullException("order");

            if (!CanCapture(order))
                throw new SmartException("Cannot do capture for order.");

            var request = new CapturePaymentRequest();
            CapturePaymentResult result = null;
            try
            {
                //old info from placing order
                request.Order = order;
                result = _paymentService.Capture(request);

                if (result.Success)
                {
                    var paidDate = order.PaidDateUtc;
                    if (result.NewPaymentStatus == PaymentStatus.Paid)
                        paidDate = DateTime.UtcNow;

                    order.CaptureTransactionId = result.CaptureTransactionId;
                    order.CaptureTransactionResult = result.CaptureTransactionResult;
                    order.PaymentStatus = result.NewPaymentStatus;
                    order.PaidDateUtc = paidDate;
                    _orderService.UpdateOrder(order);

                    //add a note
                    order.OrderNotes.Add(new OrderNote()
                    {
                        Note = T("OrderCaptured"),
                        DisplayToCustomer = false,
                        CreatedOnUtc = DateTime.UtcNow
                    });
                    _orderService.UpdateOrder(order);

                    CheckOrderStatus(order);

                    //raise event
                    if (order.PaymentStatus == PaymentStatus.Paid)
                    {
                        _eventPublisher.PublishOrderPaid(order);
                    }
                }
            }
            catch (Exception exc)
            {
                if (result == null)
                    result = new CapturePaymentResult();
                result.AddError(string.Format("Error: {0}. Full exception: {1}", exc.Message, exc.ToString()));
            }

            //process errors
            string error = "";
            for (int i = 0; i < result.Errors.Count; i++)
            {
                error += string.Format("Error {0}: {1}", i, result.Errors[i]);
                if (i != result.Errors.Count - 1)
                    error += ". ";
            }
            if (!String.IsNullOrEmpty(error))
            {
                //add a note
                order.OrderNotes.Add(new OrderNote()
                {
                    Note = string.Format("Unable to capture order. {0}", error),
                    DisplayToCustomer = false,
                    CreatedOnUtc = DateTime.UtcNow
                });
                _orderService.UpdateOrder(order);

                //log it
                string logError = string.Format(T("OrderCaptureError"), order.GetOrderNumber(), error);
                _logger.InsertLog(LogLevel.Error, logError, logError);
            }
            return result.Errors;
        }
        public void Capture(AmazonPayClient client, CapturePaymentRequest capture, CapturePaymentResult result)
        {
            result.NewPaymentStatus = capture.Order.PaymentStatus;

            var request = new CaptureRequest();
            request.SellerId = client.Settings.SellerId;
            request.AmazonAuthorizationId = capture.Order.AuthorizationTransactionId;
            request.CaptureReferenceId = GetRandomId("Capture");
            //request.SellerCaptureNote = client.Settings.SellerNoteCapture.Truncate(255);

            request.CaptureAmount = new Price()
            {
                Amount = capture.Order.OrderTotal.ToString("0.00", CultureInfo.InvariantCulture),
                CurrencyCode = capture.Order.CustomerCurrencyCode ?? "EUR"
            };

            var response = client.Service.Capture(request);

            if (response != null && response.IsSetCaptureResult() && response.CaptureResult.IsSetCaptureDetails())
            {
                var details = response.CaptureResult.CaptureDetails;

                result.CaptureTransactionId = details.AmazonCaptureId;

                if (details.IsSetCaptureStatus() && details.CaptureStatus.IsSetState())
                {
                    result.CaptureTransactionResult = details.CaptureStatus.State.ToString().Grow(details.CaptureStatus.ReasonCode, " ");

                    if (details.CaptureStatus.State == PaymentStatus.COMPLETED)
                        result.NewPaymentStatus = Core.Domain.Payments.PaymentStatus.Paid;
                }
            }
        }
        public CapturePaymentResult Capture(CapturePaymentRequest request)
        {
            var result = new CapturePaymentResult()
            {
                NewPaymentStatus = request.Order.PaymentStatus
            };

            try
            {
                var settings = _services.Settings.LoadSetting<AmazonPaySettings>(request.Order.StoreId);
                var client = new AmazonPayClient(settings);

                _api.Capture(client, request, result);
            }
            catch (OffAmazonPaymentsServiceException exc)
            {
                LogAmazonError(exc, errors: result.Errors);
            }
            catch (Exception exc)
            {
                LogError(exc, errors: result.Errors);
            }
            return result;
        }
		/// <summary>
		/// Captures payment
		/// </summary>
		/// <param name="capturePaymentRequest">Capture payment request</param>
		/// <returns>Capture payment result</returns>
		public virtual CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
		{
			var result = new CapturePaymentResult();
			result.AddError(T("Common.Payment.NoCaptureSupport"));
			return result;
		}
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public virtual CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var paymentMethod = LoadPaymentMethodBySystemName(capturePaymentRequest.Order.PaymentMethodSystemName);
            if (paymentMethod == null)
                throw new SmartException(T("Payment.CouldNotLoadMethod"));

            try
            {
                return paymentMethod.Value.Capture(capturePaymentRequest);
            }
            catch (NotSupportedException)
            {
                var result = new CapturePaymentResult();
                result.AddError(T("Common.Payment.NoCaptureSupport"));
                return result;
            }
            catch
            {
                throw;
            }
        }
 /// <summary>
 /// Captures payment
 /// </summary>
 /// <param name="capturePaymentRequest">Capture payment request</param>
 /// <returns>Capture payment result</returns>
 public override CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
 {
     var result = new CapturePaymentResult();
     result.AddError(_localizationService.GetResource("Common.Payment.NoCaptureSupport"));
     return result;
 }
 /// <summary>
 /// Captures payment
 /// </summary>
 /// <param name="capturePaymentRequest">Capture payment request</param>
 /// <returns>Capture payment result</returns>
 public override CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
 {
     var result = new CapturePaymentResult();
     result.AddError("Capture method not supported");
     return result;
 }
        /// <summary>
        /// Capture an order (from admin panel)
        /// </summary>
        /// <param name="order">Order</param>
        /// <returns>A list of errors; empty list if no errors</returns>
        public virtual IList<string> Capture(Order order)
        {
            if (order == null)
                throw new ArgumentNullException("order");

            if (!CanCapture(order))
                throw new SmartException(T("Order.CannotCapture"));

            var request = new CapturePaymentRequest();
            CapturePaymentResult result = null;
            try
            {
                //old info from placing order
                request.Order = order;
                result = _paymentService.Capture(request);

                if (result.Success)
                {
                    var paidDate = order.PaidDateUtc;
                    if (result.NewPaymentStatus == PaymentStatus.Paid)
                    {
                        paidDate = DateTime.UtcNow;
                    }

                    order.CaptureTransactionId = result.CaptureTransactionId;
                    order.CaptureTransactionResult = result.CaptureTransactionResult;
                    order.PaymentStatus = result.NewPaymentStatus;
                    order.PaidDateUtc = paidDate;

                    _orderService.UpdateOrder(order);

                    _orderService.AddOrderNote(order, T("Admin.OrderNotice.OrderCaptured"));

                    CheckOrderStatus(order);

                    //raise event
                    if (order.PaymentStatus == PaymentStatus.Paid)
                    {
                        _eventPublisher.PublishOrderPaid(order);
                    }
                }
            }
            catch (Exception exception)
            {
                if (result == null)
                {
                    result = new CapturePaymentResult();
                }

                result.AddError(exception.ToAllMessages());
            }

            ProcessErrors(order, result.Errors, "Admin.OrderNotice.OrderCaptureError");

            return result.Errors;
        }