public async Task UpdateInvoicePaymentMethod(string invoiceId, PaymentMethod paymentMethod) { using var context = _applicationDbContextFactory.CreateContext(); var invoice = await context.Invoices.FindAsync(invoiceId); if (invoice == null) { return; } var network = paymentMethod.Network; var invoiceEntity = invoice.GetBlob(_btcPayNetworkProvider); var newDetails = paymentMethod.GetPaymentMethodDetails(); var existing = invoiceEntity.GetPaymentMethod(paymentMethod.GetId()); if (existing.GetPaymentMethodDetails().GetPaymentDestination() != newDetails.GetPaymentDestination() && newDetails.Activated) { await context.AddressInvoices.AddAsync(new AddressInvoiceData() { InvoiceDataId = invoiceId, CreatedTime = DateTimeOffset.UtcNow } .Set(GetDestination(paymentMethod), paymentMethod.GetId())); } invoiceEntity.SetPaymentMethod(paymentMethod); invoice.Blob = ToBytes(invoiceEntity, network); AddToTextSearch(context, invoice, paymentMethod.GetPaymentMethodDetails().GetPaymentDestination()); await context.SaveChangesAsync(); }
private static string GetDestination(PaymentMethod paymentMethod, Network network) { // For legacy reason, BitcoinLikeOnChain is putting the hashes of addresses in database if (paymentMethod.GetId().PaymentType == Payments.PaymentTypes.BTCLike) { return(((Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod)paymentMethod.GetPaymentMethodDetails()).GetDepositAddress(network).ScriptPubKey.Hash.ToString()); } /////////////// return(paymentMethod.GetPaymentMethodDetails().GetPaymentDestination()); }
private string GetDestination(PaymentMethod paymentMethod) { // For legacy reason, BitcoinLikeOnChain is putting the hashes of addresses in database if (paymentMethod.GetId().PaymentType == Payments.PaymentTypes.BTCLike) { var network = (BTCPayNetwork)paymentMethod.Network; var details = (Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod)paymentMethod.GetPaymentMethodDetails(); if (!details.Activated) { return(null); } return(details.GetDepositAddress(network.NBitcoinNetwork).ScriptPubKey.Hash.ToString()); } /////////////// return(paymentMethod.GetPaymentMethodDetails().GetPaymentDestination()); }