1
0
mirror of https://github.com/bitwarden/server.git synced 2025-02-05 00:01:30 +01:00

stub out BitPay IPN endpoint

This commit is contained in:
Kyle Spearrin 2019-02-21 22:54:53 -05:00
parent fdaa9504d5
commit 31097870a1
3 changed files with 70 additions and 0 deletions

View File

@ -5,6 +5,7 @@
public virtual string JobsKey { get; set; }
public virtual string StripeWebhookKey { get; set; }
public virtual string StripeWebhookSecret { get; set; }
public virtual string BitPayWebhookKey { get; set; }
public virtual PayPalSettings PayPal { get; set; } = new PayPalSettings();
public class PayPalSettings

View File

@ -0,0 +1,68 @@
using Bit.Core.Repositories;
using Bit.Core.Services;
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace Bit.Billing.Controllers
{
[Route("bitpay")]
public class BitPayController : Controller
{
private readonly BillingSettings _billingSettings;
private readonly BitPayClient _bitPayClient;
private readonly ITransactionRepository _transactionRepository;
private readonly IOrganizationRepository _organizationRepository;
private readonly IUserRepository _userRepository;
private readonly IMailService _mailService;
private readonly IPaymentService _paymentService;
public BitPayController(
IOptions<BillingSettings> billingSettings,
BitPayClient bitPayClient,
ITransactionRepository transactionRepository,
IOrganizationRepository organizationRepository,
IUserRepository userRepository,
IMailService mailService,
IPaymentService paymentService)
{
_billingSettings = billingSettings?.Value;
_bitPayClient = bitPayClient;
_transactionRepository = transactionRepository;
_organizationRepository = organizationRepository;
_userRepository = userRepository;
_mailService = mailService;
_paymentService = paymentService;
}
[HttpPost("ipn")]
public async Task<IActionResult> PostIpn([FromQuery] string key)
{
if(key != _billingSettings.BitPayWebhookKey)
{
return new BadRequestResult();
}
if(HttpContext?.Request == null)
{
return new BadRequestResult();
}
string body = null;
using(var reader = new StreamReader(HttpContext.Request.Body, Encoding.UTF8))
{
body = await reader.ReadToEndAsync();
}
if(string.IsNullOrWhiteSpace(body))
{
return new BadRequestResult();
}
return new OkResult();
}
}
}

View File

@ -61,6 +61,7 @@
"jobsKey": "SECRET",
"stripeWebhookKey": "SECRET",
"stripeWebhookSecret": "SECRET",
"bitPayWebhookKey": "SECRET",
"payPal": {
"production": false,
"businessId": "AD3LAUZSNVPJY",