mirror of
https://github.com/bitwarden/server
synced 2025-12-23 19:53:40 +00:00
paypal client and stub out webhook
This commit is contained in:
56
src/Billing/Controllers/PaypalController.cs
Normal file
56
src/Billing/Controllers/PaypalController.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Bit.Billing.Utilities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.Billing.Controllers
|
||||
{
|
||||
[Route("paypal")]
|
||||
public class PaypalController : Controller
|
||||
{
|
||||
private readonly BillingSettings _billingSettings;
|
||||
private readonly PaypalClient _paypalClient;
|
||||
|
||||
public PaypalController(
|
||||
IOptions<BillingSettings> billingSettings,
|
||||
PaypalClient paypalClient)
|
||||
{
|
||||
_billingSettings = billingSettings?.Value;
|
||||
_paypalClient = paypalClient;
|
||||
}
|
||||
|
||||
[HttpPost("webhook")]
|
||||
public async Task<IActionResult> PostWebhook([FromQuery] string key)
|
||||
{
|
||||
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(body == null)
|
||||
{
|
||||
return new BadRequestResult();
|
||||
}
|
||||
|
||||
var verified = await _paypalClient.VerifyWebhookAsync(body, HttpContext.Request.Headers,
|
||||
_billingSettings.Paypal.WebhookId);
|
||||
if(!verified)
|
||||
{
|
||||
return new BadRequestResult();
|
||||
}
|
||||
|
||||
var webhook = JsonConvert.DeserializeObject(body);
|
||||
// TODO: process webhook
|
||||
return new OkResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user