Skip to content

Commit

Permalink
Merge pull request #830 from readthedocs/davidfischer/support-github-…
Browse files Browse the repository at this point in the history
…sponsors

Support GitHub sponsors as a payout option
  • Loading branch information
davidfischer committed Feb 19, 2024
2 parents a0c1fcc + 2a1af2b commit 97ac91f
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
2 changes: 2 additions & 0 deletions adserver/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
)

Expand Down
9 changes: 9 additions & 0 deletions adserver/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
Expand Down Expand Up @@ -1242,6 +1250,7 @@ class Meta:
"payout_method",
"open_collective_name",
"paypal_email",
"github_sponsors_name",
"skip_payouts",
"allow_affiliate_campaigns",
"allow_community_campaigns",
Expand Down
103 changes: 103 additions & 0 deletions adserver/migrations/0092_payout_method_github_sponsors.py
Original file line number Diff line number Diff line change
@@ -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,
),
),
]
10 changes: 10 additions & 0 deletions adserver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 97ac91f

Please sign in to comment.