2022-06-29 19:46:41 -04:00
|
|
|
|
using Bit.Api.Models.Request;
|
2021-02-22 15:35:16 -06:00
|
|
|
|
using Bit.Core.Settings;
|
2019-02-21 22:43:37 -05:00
|
|
|
|
using Bit.Core.Utilities;
|
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2021-02-22 15:35:16 -06:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2019-08-09 14:06:07 -04:00
|
|
|
|
using Stripe;
|
2017-08-19 07:59:19 -04:00
|
|
|
|
|
|
|
|
|
|
namespace Bit.Api.Controllers;
|
2022-08-29 16:06:55 -04:00
|
|
|
|
|
2017-08-19 07:59:19 -04:00
|
|
|
|
public class MiscController : Controller
|
|
|
|
|
|
{
|
2019-02-21 22:43:37 -05:00
|
|
|
|
private readonly BitPayClient _bitPayClient;
|
2019-02-22 08:08:48 -05:00
|
|
|
|
private readonly GlobalSettings _globalSettings;
|
2019-02-21 22:43:37 -05:00
|
|
|
|
|
|
|
|
|
|
public MiscController(
|
|
|
|
|
|
BitPayClient bitPayClient,
|
|
|
|
|
|
GlobalSettings globalSettings)
|
|
|
|
|
|
{
|
2019-12-19 10:27:06 -05:00
|
|
|
|
_bitPayClient = bitPayClient;
|
|
|
|
|
|
_globalSettings = globalSettings;
|
2019-02-21 22:43:37 -05:00
|
|
|
|
}
|
2019-08-09 14:06:07 -04:00
|
|
|
|
|
|
|
|
|
|
[Authorize("Application")]
|
|
|
|
|
|
[HttpPost("~/bitpay-invoice")]
|
|
|
|
|
|
[SelfHosted(NotSelfHostedOnly = true)]
|
2019-02-21 22:43:37 -05:00
|
|
|
|
public async Task<string> PostBitPayInvoice([FromBody] BitPayInvoiceRequestModel model)
|
2022-08-29 15:53:48 -04:00
|
|
|
|
{
|
2019-12-19 10:27:06 -05:00
|
|
|
|
var invoice = await _bitPayClient.CreateInvoiceAsync(model.ToBitpayInvoice(_globalSettings));
|
2019-02-21 22:43:37 -05:00
|
|
|
|
return invoice.Url;
|
2022-08-29 15:53:48 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-21 22:43:37 -05:00
|
|
|
|
[Authorize("Application")]
|
|
|
|
|
|
[HttpPost("~/setup-payment")]
|
|
|
|
|
|
[SelfHosted(NotSelfHostedOnly = true)]
|
2019-08-09 14:06:07 -04:00
|
|
|
|
public async Task<string> PostSetupPayment()
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2019-08-09 14:06:07 -04:00
|
|
|
|
var options = new SetupIntentCreateOptions
|
|
|
|
|
|
{
|
|
|
|
|
|
Usage = "off_session"
|
|
|
|
|
|
};
|
|
|
|
|
|
var service = new SetupIntentService();
|
|
|
|
|
|
var setupIntent = await service.CreateAsync(options);
|
|
|
|
|
|
return setupIntent.ClientSecret;
|
2017-08-19 07:59:19 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|