Skip to content

Commit 3da653f

Browse files
committed
Added Kofi as donation / micro payment system
1 parent 887ae17 commit 3da653f

File tree

9 files changed

+83
-1
lines changed

9 files changed

+83
-1
lines changed

Readme.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ The appsettings.json file has a lot of options to customize the content of the b
5757
},
5858
"Disqus": {
5959
"Shortname": "blog"
60-
}
60+
},
61+
"KofiToken": "ABC123"
6162
}
6263

6364
```
@@ -88,6 +89,7 @@ The appsettings.json file has a lot of options to customize the content of the b
8889
| ProfilePictureUrl | string | Displayed profile picture |
8990
| Giscus | node | Enables the comment section via giscus. If left empty the comment secion will not be shown. For more information checkout the section about comments down below |
9091
| Disqus | node | Enables the comment section via disqus. If left empty the comment secion will not be shown. For more information checkout the section about comments down below |
92+
| KofiToken | string | Enables the "Buy me a Coffee" button of Kofi. To aquire the token head down to the "Kofi" section |
9193

9294
## Storage Provider
9395
Currently there are 4 Storage-Provider:
@@ -144,6 +146,13 @@ The main advantage of Auth0 is the easy configurable dashboard on their website.
144146

145147
For testing purposes you can use `services.UseDummyAuthentication();`. This allows every user, who presses Login, to be logged in.
146148

149+
## Donations
150+
The blog software allows you to integrate via different micro-transaction services. The following chapter will show you how to setup donations.
151+
152+
### Ko-fi
153+
You can use [Ko-fi](https://Ko-fi.com/) as payment service to receive donations. To aquire the `KofiToken` as seen in the config above, head to [wdigets page](https://Ko-fi.com/manage/widgets), click on "Ko-fi Button".
154+
Now choose "Image" as type. In the field below under `Copy & Paste Code` you see an `<a href='https://ko-fi.com/XYZ'` tag. Just take the `XYZ` part and put it into `KofiToken`.
155+
147156
## Search Engine Optimization (SEO)
148157
The blog includes some of the most important tags to get indexed by a crawler. Furthermore some aspects of the Open Graph specification are implemented.
149158

src/LinkDotNet.Blog.Web/AppConfiguration.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,8 @@ public record AppConfiguration
3030
public DisqusConfiguration DisqusConfiguration { get; init; }
3131

3232
public bool IsDisqusEnabled => DisqusConfiguration != null;
33+
34+
public string KofiToken { get; set; }
35+
36+
public bool IsKofiEnabled => !string.IsNullOrEmpty(KofiToken);
3337
}

src/LinkDotNet.Blog.Web/AppConfigurationFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static AppConfiguration Create(IConfiguration config)
2525
ProfileInformation = profileInformation,
2626
GiscusConfiguration = giscus,
2727
DisqusConfiguration = disqus,
28+
KofiToken = config["KofiToken"],
2829
};
2930

3031
return configuration;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@inject AppConfiguration appConfiguration
2+
3+
@if (appConfiguration.IsKofiEnabled)
4+
{
5+
<Kofi KofiToken="@appConfiguration.KofiToken"></Kofi>
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<a href="https://ko-fi.com/@KofiToken" target="_blank">
2+
<img height="36" style="border:0;height:36px;" src="https://cdn.ko-fi.com/cdn/kofi2.png?v=3" alt="Buy Me a Coffee at ko-fi.com"/>
3+
</a>
4+
5+
@code {
6+
[Parameter]
7+
public string KofiToken { get; set; } = string.Empty;
8+
}

src/LinkDotNet.Blog.Web/Features/ShowBlogPost/ShowBlogPostPage.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ else
4141
<Like BlogPost="@BlogPost" OnBlogPostLiked="@UpdateLikes"></Like>
4242
<ShareBlogPost></ShareBlogPost>
4343
</div>
44+
<DonationSection></DonationSection>
4445
<CommentSection></CommentSection>
4546
</div>
4647
</div>

tests/LinkDotNet.Blog.UnitTests/Web/AppConfigurationFactoryTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public void ShouldMapFromAppConfiguration()
3030
{ "Giscus:Category", "general" },
3131
{ "Giscus:CategoryId", "generalid" },
3232
{ "Disqus:Shortname", "blog" },
33+
{ "KofiToken", "ABC" },
3334
};
3435
var configuration = new ConfigurationBuilder()
3536
.AddInMemoryCollection(inMemorySettings)
@@ -60,6 +61,7 @@ public void ShouldMapFromAppConfiguration()
6061
appConfiguration.GiscusConfiguration.Category.Should().Be("general");
6162
appConfiguration.GiscusConfiguration.CategoryId.Should().Be("generalid");
6263
appConfiguration.DisqusConfiguration.Shortname.Should().Be("blog");
64+
appConfiguration.KofiToken.Should().Be("ABC");
6365
}
6466

6567
[Theory]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Bunit;
2+
using LinkDotNet.Blog.Web;
3+
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
4+
using Microsoft.Extensions.DependencyInjection;
5+
6+
namespace LinkDotNet.Blog.UnitTests.Web.Features.ShowBlogPost.Components;
7+
8+
public class DonationSectionTests : TestContext
9+
{
10+
[Fact]
11+
public void ShouldShowKofiWhenTokenIsSet()
12+
{
13+
var appConfig = new AppConfiguration
14+
{
15+
KofiToken = "set",
16+
};
17+
Services.AddScoped(_ => appConfig);
18+
19+
var cut = RenderComponent<DonationSection>();
20+
21+
cut.FindComponents<Kofi>().Should().HaveCount(1);
22+
}
23+
24+
[Fact]
25+
public void ShouldHideKofiWhenTokenNotSet()
26+
{
27+
var appConfig = new AppConfiguration();
28+
Services.AddScoped(_ => appConfig);
29+
30+
var cut = RenderComponent<DonationSection>();
31+
32+
cut.FindComponents<Kofi>().Should().HaveCount(0);
33+
}
34+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using AngleSharp.Html.Dom;
2+
using AngleSharpWrappers;
3+
using Bunit;
4+
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
5+
6+
namespace LinkDotNet.Blog.UnitTests.Web.Features.ShowBlogPost.Components;
7+
8+
public class KofiTests : TestContext
9+
{
10+
[Fact]
11+
public void ShouldSetToken()
12+
{
13+
var cut = RenderComponent<Kofi>(p => p.Add(s => s.KofiToken, "Token"));
14+
15+
((IHtmlAnchorElement)cut.Find("a").Unwrap()).Href.Should().Contain("https://ko-fi.com/Token");
16+
}
17+
}

0 commit comments

Comments
 (0)