Esempio n. 1
0
        public async Task <IAssetGeneralSettings> SetAsync(IAssetGeneralSettings availability)
        {
            string partitionKey = AssetGeneralSettingsEntity.ByAsset.GeneratePartitionKey(availability.AssetId);
            string rowKey       = AssetGeneralSettingsEntity.ByAsset.GenerateRowKey(availability.AssetId);

            AssetGeneralSettingsEntity exItem = await _tableStorage.GetDataAsync(partitionKey, rowKey);

            if (exItem != null)
            {
                AssetGeneralSettingsEntity merged = await _tableStorage.MergeAsync(partitionKey, rowKey, item =>
                {
                    item.PaymentAvailable    = availability.PaymentAvailable;
                    item.SettlementAvailable = availability.SettlementAvailable;
                    item.AutoSettle          = availability.AutoSettle;
                    item.Network             = availability.Network;

                    return(item);
                });

                return(Mapper.Map <AssetGeneralSettings>(merged));
            }

            var newItem = AssetGeneralSettingsEntity.ByAsset.Create(availability);

            await _tableStorage.InsertAsync(newItem);

            return(Mapper.Map <AssetGeneralSettings>(newItem));
        }
Esempio n. 2
0
        private async Task UpdateStatusAsync(IPaymentRequest paymentRequest, PaymentRequestStatusInfo statusInfo = null)
        {
            PaymentRequestStatusInfo newStatusInfo =
                statusInfo ?? await _paymentRequestStatusResolver.GetStatus(paymentRequest.WalletAddress);

            PaymentRequestStatus          previousStatus          = paymentRequest.Status;
            PaymentRequestProcessingError previousProcessingError = paymentRequest.ProcessingError;

            paymentRequest.Status   = newStatusInfo.Status;
            paymentRequest.PaidDate = newStatusInfo.Date;

            if (newStatusInfo.Amount.HasValue)
            {
                paymentRequest.PaidAmount = newStatusInfo.Amount.Value;
            }

            paymentRequest.ProcessingError = (paymentRequest.Status == PaymentRequestStatus.Error || paymentRequest.Status == PaymentRequestStatus.SettlementError)
                ? newStatusInfo.ProcessingError
                : PaymentRequestProcessingError.None;

            await _paymentRequestRepository.UpdateAsync(paymentRequest);

            // if we are updating status from "InProcess" to any other - we have to release the lock
            if (previousStatus == PaymentRequestStatus.InProcess)
            {
                await _paymentLocksService.ReleaseLockAsync(paymentRequest.Id, paymentRequest.MerchantId);
            }

            PaymentRequestRefund refundInfo = await GetRefundInfoAsync(paymentRequest.WalletAddress);

            if (paymentRequest.Status != previousStatus ||
                (paymentRequest.Status == PaymentRequestStatus.Error &&
                 paymentRequest.ProcessingError != previousProcessingError))
            {
                await _paymentRequestPublisher.PublishAsync(paymentRequest, refundInfo);

                IAssetGeneralSettings assetSettings =
                    await _assetSettingsService.GetGeneralAsync(paymentRequest.PaymentAssetId);

                // doing auto settlement only once
                // Some flows assume we can get updates from blockchain multiple times for the same transaction
                // which leads to the same payment request status
                if (paymentRequest.StatusValidForSettlement() && (assetSettings?.AutoSettle ?? false))
                {
                    if (paymentRequest.Status != PaymentRequestStatus.Confirmed &&
                        !_autoSettleSettingsResolver.AllowToMakePartialAutoSettle(paymentRequest.PaymentAssetId))
                    {
                        return;
                    }

                    await SettleAsync(paymentRequest.MerchantId, paymentRequest.Id);
                }
            }
        }
        public async Task <BlockchainType> GetNetworkAsync(string assetId)
        {
            IAssetGeneralSettings assetAvailability = await GetGeneralAsync(assetId);

            return(assetAvailability?.Network ?? throw new AssetNetworkNotDefinedException(assetId));
        }
 public async Task <IAssetGeneralSettings> SetGeneralAsync(IAssetGeneralSettings availability)
 {
     return(await _assetGeneralSettingsRepository.SetAsync(availability));
 }