Remove types from BTCPayServer.Client

This commit is contained in:
nicolas.dorier
2021-10-11 18:01:32 +09:00
parent 1037fe0b14
commit 0033aab03e
3 changed files with 16 additions and 36 deletions

View File

@@ -1,9 +0,0 @@
using System;
namespace BTCPayServer.Client.Models
{
public class FakePaymentRequest
{
public Decimal Amount { get; set; }
}
}

View File

@@ -1,12 +0,0 @@
using System;
namespace BTCPayServer.Client.Models
{
public class FakePaymentResponse
{
public Decimal AmountRemaining { get; set; }
public String Txid { get; set; }
public String SuccessMessage { get; set; }
public String ErrorMessage { get; set; }
}
}

View File

@@ -43,6 +43,10 @@ namespace BTCPayServer.Controllers
{ {
public partial class InvoiceController public partial class InvoiceController
{ {
public class FakePaymentRequest
{
public Decimal Amount { get; set; }
}
[HttpPost] [HttpPost]
[Route("i/{invoiceId}/test-payment")] [Route("i/{invoiceId}/test-payment")]
[CheatModeRoute] [CheatModeRoute]
@@ -62,33 +66,30 @@ namespace BTCPayServer.Controllers
var bitcoinAddressObj = BitcoinAddress.Create(bitcoinAddressString, network.NBitcoinNetwork); var bitcoinAddressObj = BitcoinAddress.Create(bitcoinAddressString, network.NBitcoinNetwork);
var BtcAmount = request.Amount; var BtcAmount = request.Amount;
var FakePaymentResponse = new FakePaymentResponse();
try try
{ {
var paymentMethod = invoice.GetPaymentMethod(paymentMethodId); var paymentMethod = invoice.GetPaymentMethod(paymentMethodId);
var rate = paymentMethod.Rate; var rate = paymentMethod.Rate;
FakePaymentResponse.Txid = cheater.CashCow.SendToAddress(bitcoinAddressObj, new Money(BtcAmount, MoneyUnit.BTC)).ToString(); var txid = cheater.CashCow.SendToAddress(bitcoinAddressObj, new Money(BtcAmount, MoneyUnit.BTC)).ToString();
// TODO The value of totalDue is wrong. How can we get the real total due? invoice.Price is only correct if this is the 2nd payment, not for a 3rd or 4th payment. // TODO The value of totalDue is wrong. How can we get the real total due? invoice.Price is only correct if this is the 2nd payment, not for a 3rd or 4th payment.
var totalDue = invoice.Price; var totalDue = invoice.Price;
return Ok(new
FakePaymentResponse.AmountRemaining = (totalDue - (BtcAmount * rate)) / rate; {
FakePaymentResponse.SuccessMessage = "Created transaction " + FakePaymentResponse.Txid; Txid = txid,
AmountRemaining = (totalDue - (BtcAmount * rate)) / rate,
SuccessMessage = "Created transaction " + txid
});
} }
catch (Exception e) catch (Exception e)
{ {
FakePaymentResponse.ErrorMessage = e.Message; return BadRequest(new
FakePaymentResponse.AmountRemaining = invoice.Price; {
ErrorMessage = e.Message,
AmountRemaining = invoice.Price
});
} }
if (FakePaymentResponse.Txid != null)
{
return Ok(FakePaymentResponse);
}
return BadRequest(FakePaymentResponse);
} }
[HttpPost] [HttpPost]