Beispiel #1
0
        public PaymentResult Pay(PaymentRequest request)
        {
            var paymentMethod = _context.Database.Repository<Core.PaymentMethod>().Find(request.PaymentMethodId);
            var payment = new Kooboo.Commerce.Payments.Payment(request.OrderId, request.Amount, paymentMethod, request.Description);

            var paymentService = new Core.PaymentService(_context.Instance);

            paymentService.Create(payment);

            // TODO: Consider move ProcessPayment to PaymentService
            var processor = _paymentProcessorProvider.FindByName(paymentMethod.ProcessorName);
            object config = null;

            if (processor.ConfigType != null)
            {
                config = paymentMethod.LoadProcessorConfig(processor.ConfigType);
            }

            var processResult = processor.Process(new Kooboo.Commerce.Payments.PaymentProcessingContext(payment, config)
            {
                CurrencyCode = request.CurrencyCode,
                ReturnUrl = request.ReturnUrl,
                Parameters = request.Parameters
            });

            paymentService.AcceptProcessResult(payment, processResult);

            return new PaymentResult
            {
                Message = processResult.Message,
                PaymentId = payment.Id,
                PaymentStatus = (Kooboo.Commerce.Api.Payments.PaymentStatus)(int)processResult.PaymentStatus,
                RedirectUrl = processResult.RedirectUrl
            };
        }
 public PaymentProcessingContext(Payment payment, object processorConfig)
 {
     Require.NotNull(payment, "payment");
     Payment = payment;
     ProcessorConfig = processorConfig;
     Parameters = new Dictionary<string, string>();
 }
Beispiel #3
0
 public void AcceptProcessResult(Payment payment, ProcessPaymentResult result)
 {
     if (result.PaymentStatus == PaymentStatus.Success)
     {
         ChangeStatus(payment, PaymentStatus.Success);
     }
 }
Beispiel #4
0
        public string DecorateReturn(string returnUrl, Payment payment)
        {
            if (String.IsNullOrEmpty(returnUrl))
            {
                return null;
            }

            var parameters = new NameValueCollection();
            parameters.Add("paymentId", payment.Id.ToString());
            parameters.Add("status", payment.Status.ToString());

            var query = new StringBuilder();
            var first = true;

            foreach (var key in parameters.AllKeys)
            {
                if (!first)
                {
                    query.Append("&");
                }
                query.AppendFormat("{0}={1}", key, parameters[key]);

                first = false;
            }

            var queryString = query.ToString();

            if (returnUrl.IndexOf('?') >= 0)
            {
                return returnUrl + "&" + queryString;
            }

            return returnUrl + "?" + queryString;
        }
Beispiel #5
0
        public PaymentResult Pay(PaymentRequest request)
        {
            var paymentMethod = _context.Database.Repository <Core.PaymentMethod>().Find(request.PaymentMethodId);
            var payment       = new Kooboo.Commerce.Payments.Payment(request.OrderId, request.Amount, paymentMethod, request.Description);

            var paymentService = new Core.PaymentService(_context.Instance);

            paymentService.Create(payment);

            // TODO: Consider move ProcessPayment to PaymentService
            var    processor = _paymentProcessorProvider.FindByName(paymentMethod.ProcessorName);
            object config    = null;

            if (processor.ConfigType != null)
            {
                config = paymentMethod.LoadProcessorConfig(processor.ConfigType);
            }

            var processResult = processor.Process(new Kooboo.Commerce.Payments.PaymentProcessingContext(payment, config)
            {
                CurrencyCode = request.CurrencyCode,
                ReturnUrl    = request.ReturnUrl,
                Parameters   = request.Parameters
            });

            paymentService.AcceptProcessResult(payment, processResult);

            return(new PaymentResult
            {
                Message = processResult.Message,
                PaymentId = payment.Id,
                PaymentStatus = (Kooboo.Commerce.Api.Payments.PaymentStatus)(int) processResult.PaymentStatus,
                RedirectUrl = processResult.RedirectUrl
            });
        }
 public PaymentStatusChanged(Payment payment, PaymentStatus? oldStatus, PaymentStatus newStatus)
 {
     OrderId = payment.OrderId;
     PaymentId = payment.Id;
     Amount = payment.Amount;
     OldStatus = oldStatus;
     NewStatus = newStatus;
     PaymentMethodId = payment.PaymentMethodId;
 }
Beispiel #7
0
        private ProcessPaymentResult ProcessResponse(Payment payment, BuckarooConfig settings)
        {
            var signature = BuckarooUtil.GetSignature(Request.Form, settings.SecretKey);
            if (signature != Request["brq_signature"])
                throw new InvalidOperationException("Invalid response.");

            var statusCode = Request["brq_statuscode"];
            var transactionType = Request["brq_transaction_type"];
            var statusMessage = Request["brq_statusmessage"];
            var transactionId = Request["brq_transactions"];
            var methodId = Request["Brq_payment_method"];

            // Failed / Validation Failure / Technical Failure
            if (statusCode == "490" || statusCode == "491" || statusCode == "492")
            {
                return ProcessPaymentResult.Failed(statusCode + ": " + statusMessage);
            }
            // Rejected by the (third party) payment provider
            if (statusCode == "690")
            {
                return ProcessPaymentResult.Failed(statusCode + ": " + statusMessage);
            }
            // Cancelled by Customer / Merchant
            if (statusCode == "890" || statusCode == "891")
            {
                return ProcessPaymentResult.Cancelled();
            }

            // 190: Success (but might later become reserved)
            if (statusCode != "190")
            {
                return ProcessPaymentResult.Pending(null);
            }

            if (methodId == "simplesepadirectdebit")
            {
                // Reserved
                if (transactionType == "C501")
                {
                    return ProcessPaymentResult.Pending(transactionId);
                }

                return ProcessPaymentResult.Pending(null);
            }
            else if (methodId == "ideal")
            {
                return ProcessPaymentResult.Success(transactionId);
            }
            else if (methodId == "paypal")
            {
                return ProcessPaymentResult.Success(transactionId);
            }

            throw new NotSupportedException("Not support payment method: " + methodId + ".");
        }
Beispiel #8
0
        public void ChangeStatus(Payment payment, PaymentStatus newStatus)
        {
            if (payment.Status != newStatus)
            {
                var oldStatus = payment.Status;
                payment.Status = newStatus;

                _repository.Database.SaveChanges();

                Event.Raise(new PaymentStatusChanged(payment, oldStatus, newStatus), _instance);
            }
        }
Beispiel #9
0
        public void AcceptPayment(Order order, Payment payment)
        {
            Require.NotNull(payment, "payment");
            Require.That(payment.Status == PaymentStatus.Success, "payment", "Can only accept succeeded payment.");

            order.TotalPaid += payment.Amount;

            order.Total += payment.PaymentMethodCost;
            order.PaymentMethodCost += payment.PaymentMethodCost;

            _orderRepository.Database.SaveChanges();

            if (order.TotalPaid >= order.Total)
            {
                ChangeStatus(order, OrderStatus.Paid);
            }
        }
Beispiel #10
0
 public void Create(Payment payment)
 {
     _repository.Insert(payment);
 }
 public ProcessPaymentRequest(Payment payment)
 {
     Require.NotNull(payment, "payment");
     Payment = payment;
     Parameters = new Dictionary<string, string>();
 }