From 2a1af2b5f2b68f1a61bb0d6d0618985946ac3a2e Mon Sep 17 00:00:00 2001 From: David Fischer Date: Fri, 16 Feb 2024 12:59:32 -0800 Subject: [PATCH] Support GitHub sponsors as a payout option --- adserver/constants.py | 2 + adserver/forms.py | 9 ++ .../0092_payout_method_github_sponsors.py | 103 ++++++++++++++++++ adserver/models.py | 10 ++ 4 files changed, 124 insertions(+) create mode 100644 adserver/migrations/0092_payout_method_github_sponsors.py diff --git a/adserver/constants.py b/adserver/constants.py index dd353fb3..cc691efe 100644 --- a/adserver/constants.py +++ b/adserver/constants.py @@ -35,11 +35,13 @@ PAYOUT_STRIPE = "stripe" PAYOUT_PAYPAL = "paypal" PAYOUT_OPENCOLLECTIVE = "opencollective" +PAYOUT_GITHUB = "github" PAYOUT_OTHER = "other" PUBLISHER_PAYOUT_METHODS = ( (PAYOUT_STRIPE, _("Stripe (Bank transfer, debit card)")), (PAYOUT_PAYPAL, _("PayPal")), (PAYOUT_OPENCOLLECTIVE, _("Open Collective")), + (PAYOUT_GITHUB, _("GitHub sponsors")), (PAYOUT_OTHER, _("Other")), ) diff --git a/adserver/forms.py b/adserver/forms.py index b194eef0..badbc81f 100644 --- a/adserver/forms.py +++ b/adserver/forms.py @@ -1198,6 +1198,14 @@ def __init__(self, *args, **kwargs): Field("paypal_email", placeholder="you@yourdomain.com"), data_bind="visible: (payoutMethod() == 'paypal')", ), + Div( + PrependedText( + "github_sponsors_name", + "https://github.com/sponsors/", + placeholder="your-github-name", + ), + data_bind="visible: (payoutMethod() == 'github')", + ), "skip_payouts", css_class="my-3", ), @@ -1242,6 +1250,7 @@ class Meta: "payout_method", "open_collective_name", "paypal_email", + "github_sponsors_name", "skip_payouts", "allow_affiliate_campaigns", "allow_community_campaigns", diff --git a/adserver/migrations/0092_payout_method_github_sponsors.py b/adserver/migrations/0092_payout_method_github_sponsors.py new file mode 100644 index 00000000..1d7d8a6c --- /dev/null +++ b/adserver/migrations/0092_payout_method_github_sponsors.py @@ -0,0 +1,103 @@ +# Generated by Django 4.2.4 on 2024-02-16 20:54 +from django.db import migrations +from django.db import models + + +class Migration(migrations.Migration): + + dependencies = [ + ("adserver", "0091_publisher_group_default"), + ] + + operations = [ + migrations.AddField( + model_name="historicalpublisher", + name="github_sponsors_name", + field=models.CharField( + blank=True, + default=None, + max_length=200, + null=True, + verbose_name="GitHub sponsors name", + ), + ), + migrations.AddField( + model_name="publisher", + name="github_sponsors_name", + field=models.CharField( + blank=True, + default=None, + max_length=200, + null=True, + verbose_name="GitHub sponsors name", + ), + ), + migrations.AlterField( + model_name="historicalpublisher", + name="payout_method", + field=models.CharField( + blank=True, + choices=[ + ("stripe", "Stripe (Bank transfer, debit card)"), + ("paypal", "PayPal"), + ("opencollective", "Open Collective"), + ("github", "GitHub sponsors"), + ("other", "Other"), + ], + default=None, + max_length=100, + null=True, + ), + ), + migrations.AlterField( + model_name="historicalpublisherpayout", + name="method", + field=models.CharField( + blank=True, + choices=[ + ("stripe", "Stripe (Bank transfer, debit card)"), + ("paypal", "PayPal"), + ("opencollective", "Open Collective"), + ("github", "GitHub sponsors"), + ("other", "Other"), + ], + default=None, + max_length=100, + null=True, + ), + ), + migrations.AlterField( + model_name="publisher", + name="payout_method", + field=models.CharField( + blank=True, + choices=[ + ("stripe", "Stripe (Bank transfer, debit card)"), + ("paypal", "PayPal"), + ("opencollective", "Open Collective"), + ("github", "GitHub sponsors"), + ("other", "Other"), + ], + default=None, + max_length=100, + null=True, + ), + ), + migrations.AlterField( + model_name="publisherpayout", + name="method", + field=models.CharField( + blank=True, + choices=[ + ("stripe", "Stripe (Bank transfer, debit card)"), + ("paypal", "PayPal"), + ("opencollective", "Open Collective"), + ("github", "GitHub sponsors"), + ("other", "Other"), + ], + default=None, + max_length=100, + null=True, + ), + ), + ] diff --git a/adserver/models.py b/adserver/models.py index afddcc7b..befe83bc 100644 --- a/adserver/models.py +++ b/adserver/models.py @@ -46,6 +46,7 @@ from .constants import OFFERS from .constants import PAID from .constants import PAID_CAMPAIGN +from .constants import PAYOUT_GITHUB from .constants import PAYOUT_OPENCOLLECTIVE from .constants import PAYOUT_PAYPAL from .constants import PAYOUT_STATUS @@ -418,6 +419,13 @@ class Publisher(TimeStampedModel, IndestructibleModel): paypal_email = models.EmailField( _("PayPal email address"), blank=True, null=True, default=None ) + github_sponsors_name = models.CharField( + _("GitHub sponsors name"), + max_length=200, + blank=True, + null=True, + default=None, + ) # Record additional details to the offer for this publisher # This can be used for publishers where their traffic needs more scrutiny @@ -527,6 +535,8 @@ def payout_url(self): return f"https://opencollective.com/{self.open_collective_name}" if self.payout_method == PAYOUT_PAYPAL and self.paypal_email: return "https://www.paypal.com/myaccount/transfer/homepage/pay" + if self.payout_method == PAYOUT_GITHUB and self.github_sponsors_name: + return f"https://github.com/sponsors/{self.github_sponsors_name}" return "" def get_daily_earn(self):