/// <summary> /// Create offchain transfer to Lykke wallet /// </summary> /// <returns></returns> //[HttpPost("transferToLykkeWallet")] --reserved for version 2 //[SwaggerOperation("TransferToLykkeWallet")] //[ProducesResponseType(typeof(OffchainTradeRespModel), (int)HttpStatusCode.OK)] //[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] //[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.NotFound)] private async Task <IActionResult> TransferToLykkeWallet([FromBody] TransferToLykkeWallet model) { var clientId = model.ClientId; var refLink = await _referralLinksService.GetReferralLinkById(model.ReferralLinkId); if (refLink == null) { return(await LogAndReturnBadRequest(model, ControllerContext, "Ref link Id not found ot missing")); } var asset = (await _assets.GetDictionaryAsync()).Values.FirstOrDefault(v => v.Id == refLink.Asset); if (asset == null) { return(await LogAndReturnBadRequest(model, ControllerContext, $"Specified asset id {refLink.Asset} in reflink id {refLink.Id} not found ")); } await CheckOffchain(clientId); if (await _srvKycForAsset.IsKycNeeded(clientId, asset.Id)) { return(await LogAndReturnBadRequest(model, ControllerContext, $"KYC needed for sender client id {model.ClientId} before sending asset {refLink.Asset}")); } try { var response = await _offchainService.CreateDirectTransfer(clientId, asset.Id, (decimal)refLink.Amount, model.PrevTempPrivateKey); var exchangeOpResult = await _exchangeOperationsService.StartTransferAsync( response.TransferId, _settings.ReferralLinksService.LykkeReferralClientId, //send to shared lykke wallet where coins will be temporary stored until claimed by the recipient clientId, TransferType.Common.ToString() ); await LogInfo(new { Method = "StartTransferAsync", response.TransferId, SourceClientId = clientId }, ControllerContext, exchangeOpResult.ToJson()); return(Ok(new OffchainTradeRespModel { TransferId = response.TransferId, TransactionHex = response.TransactionHex, OperationResult = response.OperationResult })); } catch (OffchainException ex) { return(await LogOffchainExceptionAndReturn(model, ControllerContext, ex)); } catch (Exception ex) { return(await LogAndReturnNotFound(model, ControllerContext, ex.Message)); } }
//[HttpPut("giftCoinLinks/{refLinkId}/claim")] - reserved for version 2 //[SwaggerOperation("ClaimGiftCoins")] //[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] //[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.NotFound)] //[ProducesResponseType(typeof(ClaimRefLinkResponse), (int)HttpStatusCode.OK)] private async Task <IActionResult> ClaimGiftCoins([FromBody] ClaimReferralLinkRequest request, string refLinkId) { var refLink = await _referralLinksService.GetReferralLinkById(refLinkId ?? ""); var validationError = ValidateClaimRefLinkAndRequest(refLink, request, refLinkId); if (!String.IsNullOrEmpty(validationError)) { return(await LogAndReturnBadRequest(request, ControllerContext, validationError)); } var asset = (await _assets.GetDictionaryAsync()).Values.FirstOrDefault(v => v.Id == refLink.Asset); if (asset == null) { return(await LogAndReturnBadRequest(request, ControllerContext, $"Asset with id {refLink.Asset} for Referral link {refLink.Id} not found. Check transfer's history.")); } if (await _srvKycForAsset.IsKycNeeded(request.RecipientClientId, asset.Id)) { return(await LogAndReturnBadRequest(request, ControllerContext, $"KYC needed for recipient client id {request.RecipientClientId} before claiming asset {refLink.Asset}")); } var newRefLinkClaimRecipient = await CreateNewRefLinkClaim(refLink, request.RecipientClientId, true, request.IsNewClient); var transactionRewardRecipient = await _exchangeService.TransferRewardCoins(refLink, request.IsNewClient, request.RecipientClientId, ControllerContext.GetControllerAndAction()); try { if (transactionRewardRecipient.IsOk()) { using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { await SetRefLinkClaimTransactionId(transactionRewardRecipient, newRefLinkClaimRecipient); await UpdateRefLinkState(refLink, ReferralLinkState.Claimed); scope.Complete(); } return(Ok(new ClaimRefLinkResponse { TransactionRewardRecipient = transactionRewardRecipient.TransactionId, SenderOffchainTransferId = refLink.SenderOffchainTransferId })); } return(await LogAndReturnNotFound(request, ControllerContext, $"TransactionRewardRecipientError: Code: {transactionRewardRecipient.Code}, Message: {transactionRewardRecipient.Message}")); } catch (TransactionAbortedException ex) { await LogError(new { Request = request, RefLink = refLink ?? new ReferralLink() }, ControllerContext, ex); return(NotFound(ex.Message)); } catch (ApplicationException ex) { await LogError(new { Request = request, RefLink = refLink ?? new ReferralLink() }, ControllerContext, ex); return(NotFound(ex.Message)); } catch (Exception ex) { await LogError(new { Request = request, RefLink = refLink ?? new ReferralLink() }, ControllerContext, ex); return(NotFound(ex.Message)); } }