rastrillo / abono Public

Clone
git clone https://amadan.net/rastrillo/abono

Plain git — no account needed to clone.

Download

Download this file

1{{/* abono/owner-offers: GET /admin/offers, each plan with its prices
2 (the one on sale, and old ones whose members keep the plan; a price
3 billed other than every month or every year is marked unsupported,
4 since it is never sold), and the
5 paying subscriptions on a price no plan has, each with a form that
6 puts it, and everyone else on its price, onto a plan. With Stripe
7 on, a legacy price has a button that puts it back on sale, and a form
8 adds an existing Stripe price to a plan, on sale or legacy.
9
10 Data:
11 Title string, the page title's message key
12 On bool, Stripe (or the sandbox) is configured
13 Offers []abono.Offer
14 Unrecognised []abonoUnrecognised, {SubscriptionID, PriceID,
15 Subject, Label, ...}; empty while Stripe is off
16 PlanOptions []abonoOption, the plans, as field-select options
17 AdoptAction string, where an adopt form posts
18 PriceOptions []abonoOption, the plans, for the add-a-price form
19 PriceForm abonoPriceForm, {Plan, Price, Sold}: that form as posted
20 PriceAction string, where the add-a-price form and the
21 put-on-sale buttons post
22 StripeURL string, the Stripe page
23 Done *abonoNotice, {Kind, N, Plan}: what the last action did
24 Error string, a message key, or ""
25 L the request's localizer */}}
26{{define "content"}}{{$L := localizer $}}
27{{template "page-header" dict "L" $L "Title" (T $L .Title) "Sub" (T $L "abono.owner.offers_intro")}}
28{{with .Done}}{{if eq .Kind "adopt"}}{{template "notice" (Tf $L "abono.owner.adopted" "plan" .Plan)}}{{end}}{{end}}
29{{with .Error}}{{template "callout" dict "L" $L "Tone" "negative" "Focus" true "Body" (T $L .)}}{{end}}
30{{if not .On}}<p>{{T $L "abono.owner.nothing_for_sale"}} <a href="{{.StripeURL}}">{{T $L "abono.owner.stripe_title"}}</a></p>
31{{end}}
32{{range .Offers}}{{$plan := .Plan}}<section rst-box>
33<h2>{{.Name}}</h2>
34<ul>
35{{range .Prices}}<li><code>{{.ID}}</code>{{if .Currency}}{{$m := money $L .Amount .Currency}} {{if .Unsupported}}{{$m}}{{else if eq .Interval "month"}}{{Tf $L "abono.price.per_month" "amount" $m}}{{else if eq .Interval "year"}}{{Tf $L "abono.price.per_year" "amount" $m}}{{else}}{{$m}}{{end}}{{end}} {{if .Sold}}{{template "badge" dict "L" $L "Label" (T $L "abono.owner.price_sold") "Tone" "positive"}}{{else}}{{template "badge" dict "L" $L "Label" (T $L "abono.owner.price_legacy")}}{{end}}{{if .Unsupported}} {{template "badge" dict "L" $L "Label" (T $L "abono.owner.price_unsupported") "Tone" "warning"}}{{end}}{{if and $.On (not .Sold) (not .Unsupported)}}
36<form rst-form-actions method="post" action="{{$.PriceAction}}" data-abono-make-sold="{{.ID}}"><input type="hidden" name="plan" value="{{$plan}}"><input type="hidden" name="price" value="{{.ID}}"><input type="hidden" name="sold" value="1"><button type="submit" rst-btn>{{T $L "abono.button.make_sold"}}</button></form>{{end}}</li>
37{{end}}</ul>
38</section>
39{{else}}{{template "empty-state" dict "L" $L "Body" (T $L "abono.owner.offers_empty")}}
40{{end}}
41{{if and .On .Offers}}<section rst-box aria-labelledby="abono-add-price-title">
42<h2 id="abono-add-price-title">{{T $L "abono.owner.add_price_title"}}</h2>
43<form rst-form method="post" action="{{.PriceAction}}">
44{{template "field-select" dict "L" $L "ID" "abono-add-price-plan" "Name" "plan" "Label" (T $L "abono.owner.adopt_plan") "Options" .PriceOptions "Required" true}}
45{{template "field-text" dict "L" $L "Name" "price" "Label" (T $L "abono.owner.add_price_id") "Value" .PriceForm.Price "Required" true "Autocomplete" "off"}}
46{{template "field-check" dict "Name" "sold" "Value" "1" "Label" (T $L "abono.owner.price_sold") "Checked" .PriceForm.Sold}}
47{{template "form-foot" dict "L" $L "Submit" (T $L "abono.button.add_price")}}
48</form>
49</section>
50{{end}}
51{{if .On}}<section rst-box aria-labelledby="abono-unrecognised-title">
52<h2 id="abono-unrecognised-title">{{T $L "abono.owner.unrecognised_title"}}</h2>
53{{if .Unrecognised}}<p>{{T $L "abono.owner.unrecognised_body"}}</p>
54<p>{{T $L "abono.owner.unrecognised_warn"}}</p>
55{{range .Unrecognised}}<form rst-form method="post" action="{{$.AdoptAction}}" data-abono-unrecognised="{{.SubscriptionID}}">
56<p><code>{{.SubscriptionID}}</code> <code>{{.PriceID}}</code> {{.Label}}</p>
57<input type="hidden" name="subscription" value="{{.SubscriptionID}}">
58{{template "field-select" dict "L" $L "ID" (printf "abono-adopt-%s" .SubscriptionID) "Name" "plan" "Label" (T $L "abono.owner.adopt_plan") "Options" $.PlanOptions "Required" true}}
59<button type="submit" rst-btn>{{T $L "abono.button.adopt"}}</button>
60</form>
61{{end}}
62{{else}}<p>{{T $L "abono.owner.unrecognised_none"}}</p>
63{{end}}
64</section>
65{{end}}
66{{end}}
67