mirror of
https://github.com/aljazceru/BTCPayServerPlugins.git
synced 2025-12-17 07:34:24 +01:00
update subscriptions to add swagger docs
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Product>Subscriptions</Product>
|
<Product>Subscriptions</Product>
|
||||||
<Description>Offer and manage subscriptions through BTCPay Server</Description>
|
<Description>Offer and manage subscriptions through BTCPay Server</Description>
|
||||||
<Version>1.0.0</Version>
|
<Version>1.0.1</Version>
|
||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<!-- Plugin development properties -->
|
<!-- Plugin development properties -->
|
||||||
|
|||||||
@@ -34,6 +34,23 @@ public class GreenfieldSubscriptionsController : ControllerBase
|
|||||||
var ss = app.GetSettings<SubscriptionAppSettings>();
|
var ss = app.GetSettings<SubscriptionAppSettings>();
|
||||||
return Ok(ss);
|
return Ok(ss);
|
||||||
}
|
}
|
||||||
|
[HttpGet("~/api/v1/apps/subscriptions/{appId}/{subscriptionId}")]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public async Task<IActionResult> GetSubscriptionId(string appId, string subscriptionId)
|
||||||
|
{
|
||||||
|
var app = await _appService.GetApp(appId, SubscriptionApp.AppType, includeArchived: true);
|
||||||
|
if (app == null)
|
||||||
|
{
|
||||||
|
return AppNotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
var ss = app.GetSettings<SubscriptionAppSettings>();
|
||||||
|
if (!ss.Subscriptions.TryGetValue(subscriptionId, out var subscriber))
|
||||||
|
{
|
||||||
|
return this.CreateAPIError(404, "subscription-not-found", "The subscription with specified ID was not found");
|
||||||
|
}
|
||||||
|
return Ok(subscriber);
|
||||||
|
}
|
||||||
|
|
||||||
private IActionResult AppNotFound()
|
private IActionResult AppNotFound()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,230 @@
|
|||||||
|
{
|
||||||
|
"paths": {
|
||||||
|
"/api/v1/apps/subscriptions/{appId}": {
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "appId",
|
||||||
|
"in": "path",
|
||||||
|
"required": true,
|
||||||
|
"description": "The ID of the subscription app",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"get": {
|
||||||
|
"operationId": "Subscriptions_GetSubscriptionApp",
|
||||||
|
"summary": "Get a subscription app and all of its details",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Subscription details",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/SubscriptionAppSettings"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"404": {
|
||||||
|
"description": "The subscription was not found",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ProblemDetails"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"Subscriptions"
|
||||||
|
],
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"API_Key": [
|
||||||
|
"btcpay.store.canmodifystoresettings"
|
||||||
|
],
|
||||||
|
"Basic": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/api/v1/apps/subscriptions/{appId}/{subscriptionId}": {
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "appId",
|
||||||
|
"in": "path",
|
||||||
|
"required": true,
|
||||||
|
"description": "The ID of the subscription app",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "subscriptionId",
|
||||||
|
"in": "path",
|
||||||
|
"required": true,
|
||||||
|
"description": "The ID of the subscription",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"get": {
|
||||||
|
"operationId": "Subscriptions_GetSubscriptionOfApp",
|
||||||
|
"summary": "Get a subscription of a subscription app",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Subscription details",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/Subscription"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"404": {
|
||||||
|
"description": "The subscription was not found",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ProblemDetails"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"Subscriptions (Public)"
|
||||||
|
],
|
||||||
|
"security": [ ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"components": {
|
||||||
|
"schemas": {
|
||||||
|
|
||||||
|
"SubscriptionDurationType": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "",
|
||||||
|
"x-enumNames": [
|
||||||
|
"Day",
|
||||||
|
"Month"
|
||||||
|
],
|
||||||
|
"enum": [
|
||||||
|
"Day",
|
||||||
|
"Month"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"SubscriptionStatus": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "",
|
||||||
|
"x-enumNames": [
|
||||||
|
"Active",
|
||||||
|
"Inactive"
|
||||||
|
],
|
||||||
|
"enum": [
|
||||||
|
"Active",
|
||||||
|
"Inactive"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
"SubscriptionPayment": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"paymentRequestId": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The payment request Id that handles this payment."
|
||||||
|
},
|
||||||
|
|
||||||
|
"periodStart": {
|
||||||
|
"description": "What period starts with this payment",
|
||||||
|
"allOf": [ { "$ref": "#/components/schemas/UnixTimestamp" } ]
|
||||||
|
},
|
||||||
|
"periodEnd": {
|
||||||
|
"description": "What period ends with this payment",
|
||||||
|
"allOf": [ { "$ref": "#/components/schemas/UnixTimestamp" } ]
|
||||||
|
},
|
||||||
|
"settled": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Whether the payment has been settled"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Subscription": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"email": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Email of the subscription user"
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"$ref": "#/components/schemas/SubscriptionStatus"
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"description": "When the subscription was first activated",
|
||||||
|
"allOf": [ { "$ref": "#/components/schemas/UnixTimestamp" } ]
|
||||||
|
},
|
||||||
|
"payments": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/SubscriptionPayment"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},"SubscriptionSet": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": {
|
||||||
|
|
||||||
|
"$ref": "#/components/schemas/Subscription"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"SubscriptionAppSettings": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"description": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Description of the subscription app"
|
||||||
|
},
|
||||||
|
"duration": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "Duration of the subscription (type of duration is defined in the `durationType` field)"
|
||||||
|
},
|
||||||
|
"durationType": {
|
||||||
|
"$ref": "#/components/schemas/SubscriptionDurationType"
|
||||||
|
},
|
||||||
|
"formId": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Form ID to request customer data",
|
||||||
|
"nullable": true
|
||||||
|
},
|
||||||
|
"price": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The price of the subscription"
|
||||||
|
},
|
||||||
|
"currency": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The currency of the subscription"
|
||||||
|
},
|
||||||
|
"subscriptions": {
|
||||||
|
"$ref": "#/components/schemas/SubscriptionSet"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
{
|
||||||
|
"name": "Subscriptions",
|
||||||
|
"description": "Subscriptions operations"
|
||||||
|
} , {
|
||||||
|
"name": "Subscriptions (Public)",
|
||||||
|
"description": "Subscriptions public endpoints"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,16 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using BTCPayServer.Abstractions.Contracts;
|
using BTCPayServer.Abstractions.Contracts;
|
||||||
using BTCPayServer.Abstractions.Extensions;
|
using BTCPayServer.Abstractions.Extensions;
|
||||||
using BTCPayServer.Abstractions.Models;
|
using BTCPayServer.Abstractions.Models;
|
||||||
using BTCPayServer.Abstractions.Services;
|
using BTCPayServer.Abstractions.Services;
|
||||||
using BTCPayServer.HostedServices.Webhooks;
|
using BTCPayServer.HostedServices.Webhooks;
|
||||||
|
using BTCPayServer.Services;
|
||||||
using BTCPayServer.Services.Apps;
|
using BTCPayServer.Services.Apps;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.FileProviders;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace BTCPayServer.Plugins.Subscriptions
|
namespace BTCPayServer.Plugins.Subscriptions
|
||||||
{
|
{
|
||||||
@@ -17,6 +23,8 @@ namespace BTCPayServer.Plugins.Subscriptions
|
|||||||
|
|
||||||
public override void Execute(IServiceCollection applicationBuilder)
|
public override void Execute(IServiceCollection applicationBuilder)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
applicationBuilder.AddSingleton<ISwaggerProvider, SubscriptionsSwaggerProvider>();
|
||||||
applicationBuilder.AddSingleton<SubscriptionService>();
|
applicationBuilder.AddSingleton<SubscriptionService>();
|
||||||
applicationBuilder.AddSingleton<IWebhookProvider>(o => o.GetRequiredService<SubscriptionService>());
|
applicationBuilder.AddSingleton<IWebhookProvider>(o => o.GetRequiredService<SubscriptionService>());
|
||||||
applicationBuilder.AddHostedService(s => s.GetRequiredService<SubscriptionService>());
|
applicationBuilder.AddHostedService(s => s.GetRequiredService<SubscriptionService>());
|
||||||
@@ -26,4 +34,23 @@ namespace BTCPayServer.Plugins.Subscriptions
|
|||||||
base.Execute(applicationBuilder);
|
base.Execute(applicationBuilder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class SubscriptionsSwaggerProvider: ISwaggerProvider
|
||||||
|
{
|
||||||
|
private readonly IFileProvider _fileProvider;
|
||||||
|
|
||||||
|
public SubscriptionsSwaggerProvider(IWebHostEnvironment webHostEnvironment)
|
||||||
|
{
|
||||||
|
|
||||||
|
_fileProvider = webHostEnvironment.WebRootFileProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<JObject> Fetch()
|
||||||
|
{
|
||||||
|
|
||||||
|
var file = _fileProvider.GetFileInfo("Resources/swagger.subscriptions.json");
|
||||||
|
using var reader = new StreamReader(file.CreateReadStream());
|
||||||
|
return JObject.Parse(await reader.ReadToEndAsync());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user