コード例 #1
0
        public async Task <IActionResult> ResolvePaymentAssets(string merchantId, [FromQuery] string settlementAssetId)
        {
            IMerchant merchant = await _merchantService.GetAsync(merchantId);

            if (merchant == null)
            {
                return(NotFound(ErrorResponse.Create("Couldn't find merchant")));
            }

            string lykkeAssetId = await _lykkeAssetsResolver.GetLykkeId(settlementAssetId);

            Asset asset = await _assetsLocalCache.GetAssetByIdAsync(lykkeAssetId);

            if (asset == null)
            {
                return(NotFound(ErrorResponse.Create("Couldn't find asset")));
            }

            try
            {
                IReadOnlyList <string> assets =
                    await _assetsAvailabilityService.ResolvePaymentAsync(merchantId, settlementAssetId);

                return(Ok(new AvailableAssetsResponseModel {
                    Assets = assets
                }));
            }
            catch (AssetUnknownException assetEx)
            {
                await _log.WriteErrorAsync(nameof(MerchantsController), nameof(ResolvePaymentAssets),
                                           new { assetEx.Asset }.ToJson(), assetEx);

                return(BadRequest(ErrorResponse.Create(assetEx.Message)));
            }
            catch (Exception ex)
            {
                await _log.WriteErrorAsync(nameof(MerchantsController), nameof(ResolvePaymentAssets), new
                {
                    merchantId,
                    settlementAssetId
                }.ToJson(), ex);

                throw;
            }
        }
コード例 #2
0
        public async Task <IActionResult> CreateAsync([FromBody] CreatePaymentRequestModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new ErrorResponse().AddErrors(ModelState)));
            }

            try
            {
                IReadOnlyList <string> settlementAssets =
                    await _assetsAvailabilityService.ResolveSettlementAsync(model.MerchantId);

                if (!settlementAssets.Contains(model.SettlementAssetId))
                {
                    return(BadRequest(ErrorResponse.Create("Settlement asset is not available")));
                }

                IReadOnlyList <string> paymentAssets =
                    await _assetsAvailabilityService.ResolvePaymentAsync(model.MerchantId, model.SettlementAssetId);

                if (!paymentAssets.Contains(model.PaymentAssetId))
                {
                    return(BadRequest(ErrorResponse.Create("Payment asset is not available")));
                }

                var paymentRequest = Mapper.Map <PaymentRequest>(model);

                IPaymentRequest createdPaymentRequest = await _paymentRequestService.CreateAsync(paymentRequest);

                return(Ok(Mapper.Map <PaymentRequestModel>(createdPaymentRequest)));
            }
            catch (AssetUnknownException assetEx)
            {
                await _log.WriteErrorAsync(nameof(PaymentRequestsController), nameof(CreateAsync),
                                           new { assetEx.Asset }.ToJson(), assetEx);

                return(BadRequest(ErrorResponse.Create($"Asset {assetEx.Asset} can't be resolved")));
            }
            catch (Exception ex)
            {
                await _log.WriteErrorAsync(nameof(CreateAsync), model.ToJson(), ex);

                throw;
            }
        }