public async Task <IActionResult> InitiatePayment(PaymentMethodId paymentMethodId, string[] payoutIds)
    {
        await using var ctx = this._dbContextFactory.CreateContext();
        ctx.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
        var pmi = paymentMethodId.ToString();

        var payouts = await ctx.Payouts.Include(data => data.PullPaymentData)
                      .Where(data => payoutIds.Contains(data.Id) &&
                             pmi == data.PaymentMethodId &&
                             data.State == PayoutState.AwaitingPayment)
                      .ToListAsync();

        var           pullPaymentIds = payouts.Select(data => data.PullPaymentDataId).Distinct().Where(s => s != null).ToArray();
        var           storeId        = payouts.First().StoreDataId;
        var           network        = _btcPayNetworkProvider.GetNetwork <BTCPayNetwork>(paymentMethodId.CryptoCode);
        List <string> bip21          = new List <string>();

        foreach (var payout in payouts)
        {
            if (payout.Proof != null)
            {
                continue;
            }
            var blob = payout.GetBlob(_jsonSerializerSettings);
            if (payout.GetPaymentMethodId() != paymentMethodId)
            {
                continue;
            }
            var claim = await ParseClaimDestination(paymentMethodId, blob.Destination);

            switch (claim.destination)
            {
            case UriClaimDestination uriClaimDestination:
                uriClaimDestination.BitcoinUrl.Amount = new Money(blob.CryptoAmount.Value, MoneyUnit.BTC);
                var newUri = new UriBuilder(uriClaimDestination.BitcoinUrl.Uri);
                BTCPayServerClient.AppendPayloadToQuery(newUri, new KeyValuePair <string, object>("payout", payout.Id));
                bip21.Add(newUri.Uri.ToString());
                break;

            case AddressClaimDestination addressClaimDestination:
                var bip21New = network.GenerateBIP21(addressClaimDestination.Address.ToString(), new Money(blob.CryptoAmount.Value, MoneyUnit.BTC));
                bip21New.QueryParams.Add("payout", payout.Id);
                bip21.Add(bip21New.ToString());
                break;
            }
        }
        if (bip21.Any())
        {
            return(new RedirectToActionResult("WalletSend", "UIWallets", new { walletId = new WalletId(storeId, paymentMethodId.CryptoCode).ToString(), bip21 }));
        }
        return(new RedirectToActionResult("Payouts", "UIWallets", new
        {
            walletId = new WalletId(storeId, paymentMethodId.CryptoCode).ToString(),
            pullPaymentId = pullPaymentIds.Length == 1 ? pullPaymentIds.First() : null
        }));
    }
Beispiel #2
0
        private string GetRedirectToApplicationUrl(Uri redirect, APIKeyData key)
        {
            var uri         = new UriBuilder(redirect);
            var permissions = key.GetBlob().Permissions;

            BTCPayServerClient.AppendPayloadToQuery(uri,
                                                    new Dictionary <string, object>()
            {
                { "key", key.Id }, { "permissions", permissions }, { "user", key.UserId }
            });
            return(uri.Uri.AbsoluteUri);
        }