Skip to content

Commit

Permalink
Merge pull request #739 from readthedocs/davidfischer/small-payout-im…
Browse files Browse the repository at this point in the history
…provements

Payout improvements
  • Loading branch information
davidfischer committed May 11, 2023
2 parents 492b36d + b1917f5 commit 7124fb8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
4 changes: 2 additions & 2 deletions adserver/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ def __init__(self, *args, **kwargs):
)
stripe_block = HTML(
format_html(
"<a href='{}' target='_blank' class='btn btn-sm btn-outline-info'>"
"<a href='{}' target='_blank' class='btn btn-sm btn-outline-info mb-4'>"
"<span class='fa fa-cc-stripe fa-fw mr-2' aria-hidden='true'></span> {}"
"</a>",
link_obj.url,
Expand All @@ -773,7 +773,7 @@ def __init__(self, *args, **kwargs):
)
stripe_block = HTML(
format_html(
"<a href='{}' target='_blank' class='btn btn-sm btn-outline-info'>"
"<a href='{}' target='_blank' class='btn btn-sm btn-outline-info mb-4'>"
"<span class='fa fa-cc-stripe fa-fw mr-2' aria-hidden='true'></span> {}"
"</a>",
connect_url,
Expand Down
9 changes: 6 additions & 3 deletions adserver/staff/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,13 @@ class StartPublisherPayoutForm(forms.Form):
# Advertiser information
sender = forms.CharField(label=_("Sender"), max_length=200)
subject = forms.CharField(label=_("Subject"), max_length=200)
body = forms.CharField(label=_("body"), widget=forms.Textarea)
body = forms.CharField(label=_("Body"), widget=forms.Textarea)
amount = forms.DecimalField(
label=_("Amount"), disabled=True, max_digits=8, decimal_places=2
)
payout_method = forms.CharField(
label=_("Payout method"), disabled=True, max_length=200, required=False
)
archive = forms.BooleanField(
label=_("Archive after sending?"), initial=True, required=False
)
Expand Down Expand Up @@ -386,13 +389,13 @@ def _send_email(self):
# Author is required on drafts..
payload["author_id"] = getattr(settings, "FRONT_AUTHOR")

log.info(
log.debug(
"Sending email draft=%s archive=%s",
self.cleaned_data["draft"],
self.cleaned_data["archive"],
)
response = requests.request("POST", url, json=payload, headers=headers)
log.info("Response: %s", response.status_code)
log.debug("Response: %s", response.status_code)

def save(self):
"""Do the work to save the payout."""
Expand Down
1 change: 1 addition & 0 deletions adserver/staff/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def get_initial(self):
initial["subject"] = f"EthicalAds Payout - {self.publisher.name}"
initial["body"] = email_html
initial["amount"] = "%.2f" % self.get_amount(self.data["due_report"])
initial["payout_method"] = self.publisher.get_payout_method_display()
return initial

def form_valid(self, form):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h1>{% block heading %}{% trans 'Finish Payout' %}{% endblock heading %}</h1>
<div id="content" class="colM delete-confirmation">
<form method="post">
{% csrf_token %}
<input type="submit" value="{% trans "Finish payout" %}">
<input type="submit" value="{% trans "Finish payout" %}" class="btn btn-primary">
<p class="small">{% trans "This will mark the payout as paid" %}</p>
</form>
</div>
Expand Down
16 changes: 16 additions & 0 deletions adserver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from django.views.generic import UpdateView
from django.views.generic.base import RedirectView
from djstripe.enums import InvoiceStatus
from djstripe.models import Account
from djstripe.models import Invoice
from rest_framework.authtoken.models import Token
from user_agents import parse as parse_user_agent
Expand All @@ -48,6 +49,7 @@
from .constants import FLIGHT_STATE_CURRENT
from .constants import FLIGHT_STATE_UPCOMING
from .constants import PAID
from .constants import PAYOUT_STRIPE
from .constants import PUBLISHER_HOUSE_CAMPAIGN
from .constants import VIEWS
from .forms import AccountForm
Expand Down Expand Up @@ -1987,7 +1989,21 @@ def publisher_stripe_oauth_return(request):

if response:
connected_account_id = response["stripe_user_id"]

try:
# Retrieve the Stripe connected account and save it on the publisher
publisher.djstripe_account = Account.sync_from_stripe_data(
stripe.Account.retrieve(connected_account_id)
)
except stripe.error.StripeError:
log.exception(
"Stripe returned a connected account, but it could not be retrieved."
)

# Deprecated field
publisher.stripe_connected_account_id = connected_account_id

publisher.payout_method = PAYOUT_STRIPE
publisher.save()
messages.success(request, _("Successfully connected your Stripe account"))

Expand Down

0 comments on commit 7124fb8

Please sign in to comment.