Skip to content

Commit

Permalink
Add expense email method to MaintainerMailer
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jan 22, 2025
1 parent bcd7031 commit 6d56025
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/mailers/maintainer_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,16 @@ def invitation_email(maintainer_email, package, funders, amount, invite_token, d

mail(to: maintainer_email, subject: "Thank you for your work maintaining #{@project}")
end

def expense_email(invitation, maintainer_email, package, funders, amount, invite_token, decline_deadline, fund)
@invitation = invitation
@project = package
@funders = funders
@fund = fund
@amount = amount
@invite_token = invite_token
@decline_deadline = decline_deadline

mail(to: maintainer_email, subject: "Payment details for your work maintaining #{@project}")
end
end
14 changes: 14 additions & 0 deletions app/models/invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ def send_email
).deliver_now
end

def send_expense_invite_email
return if draft_key.blank?
MaintainerMailer.expense_email(
self,
email,
project_allocation.project.to_s,
project_allocation.funder_names,
"$#{project_allocation.amount_cents / 100.0}",
token,
decline_deadline.strftime("%B %d, %Y"),
fund
).deliver_now
end

def draft_key
data['draftKey']
end
Expand Down
121 changes: 121 additions & 0 deletions app/views/maintainer_mailer/expense_email.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<table class="ecosystems-mail-wrapper" cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td>
<table class="ecosystems-mail-body" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td class="header">
<%= image_tag("[email protected]", alt: "ecosyste.ms", size: "282x68") %>
<p class="tagline">Collaboratively funding the software we all depend upon</p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<p>Dear Maintainer,</p>
<p><%= @funders %> would like to donate <b><%= @amount %></b> to <b><%= @project %></b> as part of the <b><%= link_to "#{@fund} Ecosystem Fund", fund_url(@fund) %></b>. If you’d like to accept this invitation, read on…</p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="40" style="vertical-align:top;">
<%= image_tag("stone-1.png", alt: " ", class: "bullet-image", size: "24x24") %>
</td>
<td class="explanation">
<h3>What’s this all about?</h3>
<p>Open Source Collective is a non-profit organisation committed to supporting those who create and use open-source software. We’ve created a way to fund the most critical open source projects within their respective ecosystems. <a href="<%= overview_url %>">Read more here</a>.</p>

<p class="mb">You’re receiving this message because this email address is publicly linked to <%= @project %>.</p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<h2 class="green">Accepting this invitation personally</h2>

<p>If you complete <a href="<%= invitation_url(token: @invite_token) %>">the enclosed invitation</a>, we will pay you <b><%= @amount %></b> directly within the next two weeks for your work maintaining <b><%= @project %></b>:</p>

<p class="mb"><a href="<%= invitation_url(token: @invite_token) %>" class="button">Respond to the invite</a></p>

<h2 class="green">Accepting as part of a community</h2>
<p>If you or your community already accept financial support for <%= @project %>, add this information to your <code>funding.yml</code> file in your repository, and we’ll direct this and future contributions there. For more information on formats, see <a href="<%= 'https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/displaying-a-sponsor-button-in-your-repository' %>">GitHub’s documentation</a> — your repository does not have to be on GitHub.</p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="40" style="vertical-align:top;">
<%= image_tag("stone-2.png", alt: " ", class: "bullet-image", size: "24x24") %>
</td>
<td class="explanation">
<h3>Not thought about funding yet?</h3>
<p class="mb">Many open-source communities accept donations and sponsorships to support their work. Whether it’s paying for hosting, tools, hardware, travel, or paying contributors for their time, money is an essential resource for modern open-source projects. <a href="<%= faq_url %>">Read more about funding platforms here</a>.</p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<h2 class="orange">Declining this invitation (and future participation)</h2>
<p>This invitation will remain open until <b><%= @decline_deadline %></b>. If you wish to decline this invitation, and future invitations, please indicate so using <a href="<%= invitation_url(token: @invite_token) %>">the invitation itself</a>:</p>
<p class="mb"><a href="<%= invitation_url(token: @invite_token) %>" class="button button--red">Respond to the invite</a></p>

<p>If you decline this invitation, we will not contact you again concerning <b><%= @project %></b>.</p>

<p class="mb">Thanks,</p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="40" style="vertical-align:top;">
<%= image_tag("stone-3.png", alt: " ", class: "bullet-image", size: "24x24") %>
</td>
<td class="explanation">
<h3>Find out more</h3>
<p class="mb">If you’d like to know more about Open Source Collective, ecosyste.ms, and this project check out <a href="<%= about_url %>"><%= about_url %></a></p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="footer" cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td>
<%= image_tag("stones.png", alt: " ", class: "bullet-image", size: "344x173") %>
</td>
</tr>
</table>
36 changes: 36 additions & 0 deletions app/views/maintainer_mailer/expense_email.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Dear Maintainer,

<%= @funders %> would like to donate <%= @amount %> to <%= @project %> as part of the <%="#{@fund} Ecosystem Fund" %>.

<% if @invitation.accepted? %>
It's time to submit an expense for this donation. Please follow the link below to submit your expense:

<%= @invitation.invite_url %>
<% else %>
You're receiving this message because this email address is publicly linked to <%= @project %>.

We're still waiting for you to accept the invitation. Please follow the link below to accept the invitation and submit your expense:

<%= @invitation.invite_url %>

Declining this invitation (and future participation):
This invitation will remain open until <%= @decline_deadline %>. If you wish to decline this invitation, and future invitations, please indicate so using the invitation itself:

<%= invitation_url(token: @invite_token) %>

If you decline this invitation, we will not contact you again concerning <%= @project %>.

<% end %>

Accepting as part of a community:
If you or your community already accept financial support for <%= @project %>, add this information to your funding.yml file in your repository, and we’ll direct this and future contributions there. For more information on formats, see GitHub’s documentation <%= 'https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/displaying-a-sponsor-button-in-your-repository' %> — your repository does not have to be on GitHub.

Not thought about funding yet?
Many open-source communities accept donations and sponsorships to support their work. Whether it’s paying for hosting, tools, hardware, travel, or paying contributors for their time, money is an essential resource for modern open-source projects. Read more about funding platforms here: <%= faq_url %>.

Thanks,

Find out more
If you’d like to know more about Open Source Collective, ecosyste.ms, and this project check out <%= about_url %>.

Open Source Collective is a non-profit organisation committed to supporting those who create and use open-source software. We’ve created a way to fund the most critical open source projects within their respective ecosystems. Read more at <%= overview_url %>.
1 change: 1 addition & 0 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions test/mailers/previews/maintainer_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,19 @@ def invitation_email
Fund.first
)
end

def expense_email
data = {"draftKey" => "123"}
invitation = Invitation.create!(email: "[email protected]", project_allocation: ProjectAllocation.first, data: data, member_invitation_id: 123)
MaintainerMailer.expense_email(
invitation,
"[email protected]",
"example-project",
"Sentry",
"$500.00",
"123456",
(Time.now + 14.days).strftime("%B %d, %Y"),
Fund.first
)
end
end

0 comments on commit 6d56025

Please sign in to comment.