public virtual async Task <ProcessAuthorizationResponse> ProcessAuthorizationAsync(Guid contactId, string marketId, string cartName, string orderId)
        {
            var purchaseOrder = _vippsService.GetPurchaseOrderByOrderId(orderId);

            if (purchaseOrder != null)
            {
                return(new ProcessAuthorizationResponse
                {
                    PurchaseOrder = purchaseOrder,
                    Processed = true
                });
            }

            var cart        = _vippsService.GetCartByContactId(contactId, marketId, cartName);
            var paymentType = GetVippsPaymentType(cart);

            var orderDetails = await _vippsService.GetOrderDetailsAsync(orderId, marketId);

            var result = await _vippsOrderCreator.ProcessOrderDetails(orderDetails, orderId, contactId, marketId, cartName);

            if (result.PurchaseOrder != null)
            {
                return(new ProcessAuthorizationResponse(result)
                {
                    Processed = true
                });
            }

            return(new ProcessAuthorizationResponse(result)
            {
                PaymentType = paymentType,
                Processed = false
            });
        }
Пример #2
0
        public async Task Run()
        {
            if (_start && !_running && _schedulerOptions.Enabled)
            {
                _running = true;
                var pollingEntitiesToRemove = new List <VippsPollingEntity>();

                try
                {
                    var pollingEntities = _pollingEntityContext.PollingEntities.ToList();

                    if (!pollingEntities.Any())
                    {
                        _start = false;
                    }

                    foreach (var entity in pollingEntities)
                    {
                        if (entity.Created.AddMinutes(-10) < DateTime.Now)
                        {
                            var orderDetails = await _vippsService.GetOrderDetailsAsync(entity.OrderId, entity.MarketId);

                            if (orderDetails == null)
                            {
                                _logger.Warning($"No order details for vipps order {entity.OrderId}");
                                pollingEntitiesToRemove.Add(entity);
                            }

                            var result = await _vippsOrderCreator.ProcessOrderDetails(orderDetails, entity.OrderId, entity.ContactId,
                                                                                      entity.MarketId, entity.CartName);

                            if (result.PurchaseOrder != null || result.ProcessResponseErrorType != ProcessResponseErrorType.OTHER)
                            {
                                pollingEntitiesToRemove.Add(entity);
                            }
                        }

                        else
                        {
                            _logger.Information($"Vipps payment with order id {entity.OrderId} reached max recount. Stopping polling.");
                            pollingEntitiesToRemove.Add(entity);
                        }
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error(ex.Message, ex);
                }

                foreach (var entityToRemove in pollingEntitiesToRemove)
                {
                    _pollingEntityContext.PollingEntities.Remove(entityToRemove);
                }

                _pollingEntityContext.SaveChanges();
                _running = false;
            }
        }
        private ProcessOrderResponse CheckDependenciesThenProcessPayment(string orderId, Guid contactId, string marketId, string cartName)
        {
            var errorResponse = EnsureNoPurchaseOrder(orderId);

            if (errorResponse != null)
            {
                return(errorResponse);
            }

            var cart = _vippsService.GetCartByContactId(contactId, marketId, cartName);

            errorResponse = ValidateCartAndSetProcessing(orderId, cart);
            if (errorResponse != null)
            {
                return(errorResponse);
            }

            var detailsResponse = AsyncHelper.RunSync(() => _vippsService.GetOrderDetailsAsync(orderId, marketId));
            var lastTransaction = GetLastTransaction(detailsResponse);

            return(ProcessPayment(detailsResponse, lastTransaction, orderId, cart));
        }