Validate email in the api

This commit is contained in:
nicolas.dorier 2017-10-13 16:59:02 +09:00
parent d1961e0938
commit 9ddceae824
2 changed files with 7 additions and 2 deletions

View file

@ -69,6 +69,7 @@ namespace BTCPayServer.Tests
user.GrantAccess();
var invoice = user.BitPay.CreateInvoice(new Invoice()
{
Buyer = new Buyer() { email = "test@fwf.com" },
Price = 5000.0,
Currency = "USD",
PosData = "posData",

View file

@ -97,8 +97,12 @@ namespace BTCPayServer.Controllers
entity.BuyerInformation = Map<Invoice, BuyerInformation>(invoice);
//Another way of passing buyer info to support
FillBuyerInfo(invoice.Buyer, entity.BuyerInformation);
entity.RefundMail = EmailValidator.IsEmail(entity?.BuyerInformation?.BuyerEmail) ? entity.BuyerInformation.BuyerEmail : null;
if(entity?.BuyerInformation?.BuyerEmail != null)
{
if(!EmailValidator.IsEmail(entity.BuyerInformation.BuyerEmail))
throw new BitpayHttpException(400, "Invalid email");
entity.RefundMail = entity.BuyerInformation.BuyerEmail;
}
entity.ProductInformation = Map<Invoice, ProductInformation>(invoice);
entity.RedirectURL = invoice.RedirectURL ?? store.StoreWebsite;
entity.Status = "new";