Beispiel #1
0
        public async Task <IActionResult> CreateWithdrawal(string storeId, string accountId,
                                                           WithdrawRequestData request, CancellationToken cancellationToken = default)
        {
            var custodianAccount = await GetCustodianAccount(storeId, accountId);

            var custodian = GetCustodianByCode(custodianAccount.CustodianCode);

            if (custodian is ICanWithdraw withdrawableCustodian)
            {
                var withdrawResult =
                    await withdrawableCustodian.WithdrawAsync(request.PaymentMethod, request.Qty, custodianAccount.GetBlob(), cancellationToken);

                var result = new WithdrawalResponseData(withdrawResult.PaymentMethod, withdrawResult.Asset, withdrawResult.LedgerEntries,
                                                        withdrawResult.WithdrawalId, accountId, custodian.Code, withdrawResult.Status, withdrawResult.CreatedTime, withdrawResult.TargetAddress, withdrawResult.TransactionId);
                return(Ok(result));
            }

            return(this.CreateAPIError(400, "withdrawals-not-supported",
                                       $"Withdrawals are not supported for \"{custodian.Name}\"."));
        }
Beispiel #2
0
        public async Task <IActionResult> GetWithdrawalInfo(string storeId, string accountId, string paymentMethod, string withdrawalId, CancellationToken cancellationToken = default)
        {
            var custodianAccount = await GetCustodianAccount(storeId, accountId);

            var custodian = GetCustodianByCode(custodianAccount.CustodianCode);

            if (custodian is ICanWithdraw withdrawableCustodian)
            {
                var withdrawResult = await withdrawableCustodian.GetWithdrawalInfoAsync(paymentMethod, withdrawalId, custodianAccount.GetBlob(), cancellationToken);

                if (withdrawResult == null)
                {
                    return(this.CreateAPIError(404, "withdrawal-not-found", "The withdrawal was not found."));
                }
                var result = new WithdrawalResponseData(withdrawResult.PaymentMethod, withdrawResult.Asset, withdrawResult.LedgerEntries,
                                                        withdrawResult.WithdrawalId, accountId, custodian.Code, withdrawResult.Status, withdrawResult.CreatedTime, withdrawResult.TargetAddress, withdrawResult.TransactionId);
                return(Ok(result));
            }

            return(this.CreateAPIError(400, "fetching-withdrawal-info-not-supported",
                                       $"Fetching withdrawal information is not supported for \"{custodian.Name}\"."));
        }