console: transfer form, start door and transfer card
GET and POST /a/{sqid}/domains/transfer/{domain} (owners, CSRF, buy
door's gate, gateNoHostClaim): the form shows the price and the
nameservers kept from quoteTransfer, asks for the transfer code in a
password field and who it is registered to (the saved-contact picker,
now shared with the buy page), and the post starts the transfer and
303s to Checkout. The code is read from the POST body only and never
drawn back on a re-shown form.
The purchase card draws a transfer's own stages (Paid, Sent, Waiting
for the current registrar, Registered here; done; failed as Didn't move
beside Not charged or Refunded), polls the status JSON, which gains
"kind", and its step labels are the domain page's status line. Shared
CSS gains input[type=password] and .fields.transfer-code (footer
digests re-pinned); parity row, perf walk target and over record.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
20 files changed,
+1,381
−89
docs/parity.md+3 −2internal/console/accountdomainbuy.go+33 −7internal/console/accountdomains_copy.go+2 −10internal/console/accountdomainspage.go+13 −11internal/console/accountdomainspage_test.go+3 −3internal/console/accountdomaintransfer.go+224 −0internal/console/accountdomaintransfer_test.go+482 −0internal/console/apidomainbuy.go+4 −2internal/console/apidomainbuy_test.go+1 −1internal/console/appdomainbuy.go+223 −1internal/console/demo_claim_footer_test.go+12 −13internal/console/domaintransfer_copy.go+92 −0internal/console/perfwalk_test.go+85 −0internal/console/routedecls.go+7 −0internal/console/templates/account_domain_buy.html+25 −15internal/console/templates/account_domain_transfer.html+57 −0internal/console/templates/console_chrome.html+4 −1internal/console/templates/domain_buy.html+109 −23internal/console/testdata/perf-budgets.txt+1 −0parity/parity.tsv+1 −0
diff --git a/docs/parity.md b/docs/parity.md| index fe68bf72b..3eda11e60 100644 |
| --- a/docs/parity.md |
| +++ b/docs/parity.md |
| @@ -14,8 +14,8 @@ CLI rows are checked against the command registry (`parity/cli.tsv`). |
| | partial | 9 | |
| | gap | 67 | |
| | cli-only | 19 | |
| -| console-only | 18 | |
| -| Total | 160 | |
| +| console-only | 19 | |
| +| Total | 161 | |
| ## account |
| @@ -110,6 +110,7 @@ CLI rows are checked against the command registry (`parity/cli.tsv`). |
| | domains-verify | partial | `domains verify` | `POST /a/{sqid}/apps/{app}/domains/attach` | | There is no Verify button; attaching again verifies. | |
| | domains-buy | both | `domains check`<br>`domains buy` | `GET /a/{sqid}/domains/buy`<br>`POST /a/{sqid}/domains/buy/check`<br>`POST /a/{sqid}/domains/buy`<br>`GET /a/{sqid}/domains/purchases/{id}`<br>`GET /a/{sqid}/domains/purchases/{id}/status`<br>`GET /a/{sqid}/apps/{app}/domains/buy`<br>`POST /a/{sqid}/apps/{app}/domains/check`<br>`POST /a/{sqid}/apps/{app}/domains/buy`<br>`GET /a/{sqid}/apps/{app}/domains/purchases/{id}`<br>`GET /a/{sqid}/apps/{app}/domains/purchases/{id}/status` | | The app-scoped routes only redirect to the account's. | |
| | domains-contacts | both | `domains contacts list`<br>`domains contacts add`<br>`domains contacts edit`<br>`domains contacts remove` | `POST /a/{sqid}/domains/contacts`<br>`POST /a/{sqid}/domains/contacts/{id}`<br>`POST /a/{sqid}/domains/contacts/{id}/remove` | | Saved contacts are added, edited and removed on the Domains page and with domains contacts; a purchase with no contact named uses the most recently used one. | |
| +| domains-transfer | console-only | | `GET /a/{sqid}/domains/transfer/{domain}`<br>`POST /a/{sqid}/domains/transfer/{domain}` | | Moving a domain registered elsewhere here (Move to Carloku): the form and its start; the move's card is the purchase card. No CLI command yet. | |
| | domains-point | both | `domains point` | `POST /a/{sqid}/apps/{app}/domains/point` | | | |
| | domains-paths | gap | `domains paths` | | [wp-settings](#wp-settings) | | |
| | domains-placements | gap | `domains placements` | | [wp-settings](#wp-settings) | | |
diff --git a/internal/console/accountdomainbuy.go b/internal/console/accountdomainbuy.go| index 3be80cb77..69d7b89c8 100644 |
| --- a/internal/console/accountdomainbuy.go |
| +++ b/internal/console/accountdomainbuy.go |
| @@ -54,13 +54,23 @@ type accountBuyView struct { |
| // Step 3. |
| Tiles []domainTile |
| - Contacts []buyContactChoice |
| - NewPicked bool |
| - NewFields []domainBuyField |
| - Filter bool // a filter over a long contact list |
| + Pick contactPicker |
| PriceChanged bool |
| } |
| +// contactPicker is Registered to: the account's saved contacts, the most |
| +// recently used first, and a new contact's fields. The buy page's step 3 |
| +// and the transfer form draw it with the contact_pick template. |
| +type contactPicker struct { |
| + Contacts []buyContactChoice |
| + NewPicked bool |
| + NewFields []domainBuyField |
| + Filter bool // a filter over a long contact list |
| +} |
| + |
| +// Copy is the picker's words, for the template. |
| +func (contactPicker) Copy() any { return accountBuyCopy } |
| + |
| type buyStepChip struct { |
| N int |
| Label string |
| @@ -313,10 +323,24 @@ func (s *Server) buyPayStep(ctx context.Context, acct *Account, q domainreg.Quot |
| points.Value, points.Detail = accountBuyCopy.NotYet, accountBuyCopy.NotYetDetail |
| } |
| v.Tiles = []domainTile{price, points} |
| - contacts, err := s.store.SavedContacts(ctx, acct.ID) |
| + pick, err := s.contactPicker(ctx, acct, picked, country, "buy-", entered) |
| if err != nil { |
| return nil, err |
| } |
| + v.Pick = pick |
| + return v, nil |
| +} |
| + |
| +// contactPicker is the account's Registered to picker. picked is the |
| +// contact chosen ("" for the most recently used, "new" for a new one), |
| +// entered the new contact's fields as posted (nil for none, which starts |
| +// them at country). Field IDs start with idPrefix. |
| +func (s *Server) contactPicker(ctx context.Context, acct *Account, picked, country, idPrefix string, entered *registrar.Contact) (contactPicker, error) { |
| + contacts, err := s.store.SavedContacts(ctx, acct.ID) |
| + if err != nil { |
| + return contactPicker{}, err |
| + } |
| + var v contactPicker |
| known := false |
| for i, c := range contacts { |
| checked := c.ID == picked || (picked == "" && i == 0) |
| @@ -332,7 +356,7 @@ func (s *Server) buyPayStep(ctx context.Context, acct *Account, q domainreg.Quot |
| } |
| fields := buyContactFields(contact) |
| for i := range fields { |
| - fields[i].ID = "buy-" + fields[i].Name |
| + fields[i].ID = idPrefix + fields[i].Name |
| // Hidden behind a saved contact, the fields cannot be required in |
| // HTML; the purchase checks a new contact itself. |
| fields[i].Required = fields[i].Required && len(contacts) == 0 |
| @@ -463,7 +487,9 @@ func (s *Server) handleAccountDomainPurchase(w http.ResponseWriter, r *http.Requ |
| } |
| } |
| var domainState string |
| - if p.State == PurchaseDone { |
| + // A transfer's card never says whether the domain is live: it points |
| + // at no app, and its DNS is hosted elsewhere. |
| + if p.State == PurchaseDone && purchaseKindOf(p) == PurchaseKindBuy { |
| ctx, cancel := context.WithTimeout(r.Context(), instanceStoreTimeout) |
| defer cancel() |
| domainState = s.purchaseDomainState(ctx, acct, p) |
diff --git a/internal/console/accountdomains_copy.go b/internal/console/accountdomains_copy.go| index 887a4ce51..5f6c7c9b7 100644 |
| --- a/internal/console/accountdomains_copy.go |
| +++ b/internal/console/accountdomains_copy.go |
| @@ -244,13 +244,5 @@ var domainMoveCopy = struct { |
| SeeMove: "See the move", |
| } |
| -// domainTransferStatusCopy is a live transfer's one-line status on its |
| -// domain's card and page. A state not listed reads as waiting. |
| -var domainTransferStatusCopy = map[PurchaseState]string{ |
| - PurchaseAwaitingPayment: "Waiting for payment", |
| - PurchaseAuthorised: "Sending the transfer", |
| - PurchaseTransferSubmitting: "Sending the transfer", |
| - PurchaseTransferPending: "Waiting for the current registrar", |
| - PurchaseTransferRefunding: "Refunding your payment", |
| - "": "Waiting for the current registrar", |
| -} |
| +// A live transfer's one-line status on its domain's card and page is its |
| +// purchase card's (transferStatusLine), from transferCardCopy. |
diff --git a/internal/console/accountdomainspage.go b/internal/console/accountdomainspage.go| index 319224581..649e5f3bc 100644 |
| --- a/internal/console/accountdomainspage.go |
| +++ b/internal/console/accountdomainspage.go |
| @@ -31,13 +31,17 @@ import ( |
| // domainPageFields is what a page carries for domains: Plan 1's buy flow |
| // and the account's Domains pages. page embeds it. |
| type domainPageFields struct { |
| - DomainBuy *domainBuyView |
| - AccountBuy *accountBuyView |
| - DomainBuyCopy map[string]string |
| - AccountDomains *accountDomainsView |
| - DomainPage *domainPageView |
| + DomainBuy *domainBuyView |
| + AccountBuy *accountBuyView |
| + AccountTransfer *accountTransferView |
| + DomainBuyCopy map[string]string |
| + AccountDomains *accountDomainsView |
| + DomainPage *domainPageView |
| } |
| +// TransferFormCopy is the transfer form's strings. |
| +func (p page) TransferFormCopy() any { return transferFormCopy } |
| + |
| // DomainsCopy is the Domains pages' strings, for the templates. |
| func (p page) DomainsCopy() any { return domainsPageCopy } |
| @@ -295,17 +299,15 @@ func (s *Server) domainCardFor(acct *Account, c domainCard, currency string, own |
| } |
| } else if owner && ready && !v.Buying && domainRegistrable(c.Domain) != "" { |
| // Registered elsewhere, nothing in flight: Task 9's transfer form. |
| - v.MoveHref = v.Href + "/transfer" |
| + v.MoveHref = domainTransferURL(acct, c.Domain) |
| } |
| return v |
| } |
| -// transferStatusLine is a live transfer's status on its domain's card. |
| +// transferStatusLine is a live transfer's status on its domain's card and |
| +// page: its purchase card's, from the same stage labels. |
| func transferStatusLine(state PurchaseState) string { |
| - if msg, ok := domainTransferStatusCopy[state]; ok { |
| - return msg |
| - } |
| - return domainTransferStatusCopy[""] |
| + return transferStageStatus(transferStageOf(state)) |
| } |
| // detachableApps is the apps whose detach door an owner can use. |
diff --git a/internal/console/accountdomainspage_test.go b/internal/console/accountdomainspage_test.go| index 37d516c05..5bf823a88 100644 |
| --- a/internal/console/accountdomainspage_test.go |
| +++ b/internal/console/accountdomainspage_test.go |
| @@ -902,7 +902,7 @@ func TestElsewhereDomainOffersMoveToCarloku(t *testing.T) { |
| base := "/a/" + acct.Sqid |
| adClaim(t, fx, acct, "kass", "www.example.org") |
| adBought(t, fx, acct, "bought.com", time.Now().AddDate(1, 0, 0)) |
| - move := `href="` + base + `/domains/example.org/transfer"` |
| + move := `href="` + base + `/domains/transfer/example.org"` |
| owner := adSignIn(t, fx, adOwner(acct)) |
| _, body := adGet(t, fx, owner, acct, "/domains") |
| @@ -963,7 +963,7 @@ func TestDomainWithLiveTransferLinksItsCard(t *testing.T) { |
| } |
| cardLink := `href="` + domainPurchaseURL(acct.Sqid, p.ID) + `"` |
| moving := `<span class="chip chip-canary">` + domainMoveCopy.Moving + `</span>` |
| - status := html.EscapeString(domainTransferStatusCopy[PurchaseTransferPending]) |
| + status := html.EscapeString(transferCardCopy.StepWaiting) |
| owner := adSignIn(t, fx, adOwner(acct)) |
| _, body := adGet(t, fx, owner, acct, "/domains") |
| @@ -976,7 +976,7 @@ func TestDomainWithLiveTransferLinksItsCard(t *testing.T) { |
| t.Errorf("owner's %s lacks %q:\n%s", label, want, got) |
| } |
| } |
| - for _, b := range []string{"/transfer\"", domainMoveCopy.Move, domainsPageCopy.Buying, domainsPageCopy.Elsewhere, domainsPageCopy.FollowPurchase} { |
| + for _, b := range []string{"/domains/transfer/", domainMoveCopy.Move, domainsPageCopy.Buying, domainsPageCopy.Elsewhere, domainsPageCopy.FollowPurchase} { |
| if strings.Contains(got, b) { |
| t.Errorf("owner's %s shows %q:\n%s", label, b, got) |
| } |
diff --git a/internal/console/accountdomaintransfer.go b/internal/console/accountdomaintransfer.go| new file mode 100644 |
| index 000000000..bcacf65eb |
| --- /dev/null |
| +++ b/internal/console/accountdomaintransfer.go |
| @@ -0,0 +1,224 @@ |
| +package console |
| + |
| +// Moving a domain registered elsewhere here (spec §12.3; transfers in, |
| +// Task 9): the transfer form and its start door. The form shows what the |
| +// move costs and the nameservers it keeps (quoteTransfer, which checks |
| +// everything a start would before any payment), and asks for the transfer |
| +// code and who the domain is registered to. The start checks everything |
| +// again (the quote included: a changed price comes back for confirmation) |
| +// and sends the owner to Checkout; the purchase card follows the move. |
| +// |
| +// Owners only, CSRF on the post, and every refusal of a member, a stranger |
| +// or a console with buying off is the buy door's neutral 404 |
| +// (domainBuyAccountGate). The transfer code is a secret: it is read only |
| +// from the post's body, never from its URL, and a form shown again after a |
| +// refusal never carries it back. |
| + |
| +import ( |
| + "context" |
| + "net/http" |
| + "net/url" |
| + "strconv" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/domainreg" |
| + "github.com/carlosframework/platform/internal/plans" |
| + "github.com/carlosframework/platform/internal/registrar" |
| +) |
| + |
| +// accountTransferView is the transfer form, or the page that says why the |
| +// domain cannot move (Refused). |
| +type accountTransferView struct { |
| + Eyebrow, Title string |
| + Action, Back string // the form posts to Action; Back is the domain's page |
| + Alert string |
| + // Refused is a refusal before payment: the form is not drawn, only why. |
| + // Retry offers Check again, which asks again. |
| + Refused, Retry bool |
| + |
| + Quote domainreg.Quote |
| + Tiles []domainTile |
| + Nameservers []transferNS |
| + BeforeNote string |
| + Pick contactPicker |
| +} |
| + |
| +// transferNS is one nameserver the move keeps, with the words before it |
| +// ("", ", " or " and ") so the template draws the list as a sentence. |
| +type transferNS struct{ Before, Name string } |
| + |
| +// domainTransferURL is the transfer form for domain. |
| +func domainTransferURL(acct *Account, domain string) string { |
| + return domainsBase(acct) + "/domains/transfer/" + url.PathEscape(domain) |
| +} |
| + |
| +// transferNoRetry is the refusals asking again cannot change soon: the |
| +// form offers Back only. |
| +var transferNoRetry = map[string]bool{ |
| + domainTransferCopy["notOffered"]: true, |
| + domainTransferCopy["dnssec"]: true, |
| + domainTransferNotNow["not_registered"]: true, |
| + domainBuyCopy["premium"]: true, |
| +} |
| + |
| +func newAccountTransferView(acct *Account, name string) *accountTransferView { |
| + if n, err := domainreg.Normalize(name); err == nil { |
| + name = n |
| + } |
| + return &accountTransferView{ |
| + Eyebrow: domainsFill(domainsPageCopy.PageEyebrow, "{account}", acct.Name), |
| + Title: domainsFill(transferFormCopy.Title, "{domain}", name), |
| + Action: domainTransferURL(acct, name), Back: domainPageURL(acct, name), |
| + BeforeNote: domainsFill(transferFormCopy.BeforeNote, "{domain}", name), |
| + } |
| +} |
| + |
| +func (s *Server) renderAccountTransfer(w http.ResponseWriter, r *http.Request, addr, raw string, acct *Account, status int, v *accountTransferView) { |
| + p := s.accountPage(w, r, addr, raw, acct, RoleOwner) |
| + p.Title = v.Title |
| + p.ActiveNav = "domains" |
| + p.MobileParent = &navLink{Label: domainsPageCopy.Title, Href: p.Nav + "/domains"} |
| + p.AccountTransfer = v |
| + s.render(w, status, "account_domain_transfer", p) |
| +} |
| + |
| +// renderTransferRefusal is the form's page for a refusal before payment: |
| +// the refusal's own line, Back, and Check again unless asking again cannot |
| +// help. A 404 is the neutral 404. |
| +func (s *Server) renderTransferRefusal(w http.ResponseWriter, r *http.Request, addr, raw string, acct *Account, name string, ref *doorRefusal) { |
| + if ref.Status == http.StatusNotFound { |
| + http.NotFound(w, r) |
| + return |
| + } |
| + setNoCapacityRetryAfter(w, ref) |
| + v := newAccountTransferView(acct, name) |
| + v.Refused, v.Retry, v.Alert = true, !transferNoRetry[ref.Msg], ref.Msg |
| + s.renderAccountTransfer(w, r, addr, raw, acct, ref.Status, v) |
| +} |
| + |
| +// transferFormView is the form for tq. picked and entered are as for |
| +// contactPicker. |
| +func (s *Server) transferFormView(ctx context.Context, acct *Account, tq transferQuote, picked string, entered *registrar.Contact) (*accountTransferView, error) { |
| + q := tq.Quote |
| + v := newAccountTransferView(acct, q.Domain) |
| + v.Quote = q |
| + c := transferFormCopy |
| + v.Tiles = []domainTile{ |
| + {Label: c.TilePrice, Value: plans.FormatMinor(q.Currency, q.Price), Detail: c.PriceDetail}, |
| + {Label: c.TileTakes, Value: c.TakesValue, Detail: c.TakesDetail}, |
| + } |
| + for i, ns := range tq.Nameservers { |
| + before := ", " |
| + switch { |
| + case i == 0: |
| + before = "" |
| + case i == len(tq.Nameservers)-1: |
| + before = c.And |
| + } |
| + v.Nameservers = append(v.Nameservers, transferNS{Before: before, Name: ns}) |
| + } |
| + pick, err := s.contactPicker(ctx, acct, picked, "", "transfer-", entered) |
| + if err != nil { |
| + return nil, err |
| + } |
| + v.Pick = pick |
| + return v, nil |
| +} |
| + |
| +// handleAccountDomainTransfer is the transfer form for the path's domain, |
| +// priced and checked by quoteTransfer, or why it cannot move. |
| +func (s *Server) handleAccountDomainTransfer(w http.ResponseWriter, r *http.Request) { |
| + addr, raw, acct, ok := s.domainBuyAccountGate(w, r) |
| + if !ok { |
| + return |
| + } |
| + name := r.PathValue("domain") |
| + ctx, cancel := context.WithTimeout(r.Context(), 20*time.Second) |
| + defer cancel() |
| + tq, ref := s.quoteTransfer(ctx, acct, name) |
| + if ref != nil { |
| + s.renderTransferRefusal(w, r, addr, raw, acct, name, ref) |
| + return |
| + } |
| + v, err := s.transferFormView(ctx, acct, tq, "", nil) |
| + if err != nil { |
| + s.renderTransferRefusal(w, r, addr, raw, acct, name, purchaseUnavailable(PurchaseKindTransfer)) |
| + return |
| + } |
| + s.renderAccountTransfer(w, r, addr, raw, acct, http.StatusOK, v) |
| +} |
| + |
| +// handleAccountDomainTransferStart is the form's post: it starts the |
| +// transfer (startDomainTransfer, every check again) and sends the owner to |
| +// Checkout. A changed price (409), a refused code or contact (422) shows |
| +// the form again; any other refusal shows why. |
| +func (s *Server) handleAccountDomainTransferStart(w http.ResponseWriter, r *http.Request) { |
| + addr, raw, acct, ok := s.domainBuyAccountGate(w, r) |
| + if !ok { |
| + return |
| + } |
| + name := r.PathValue("domain") |
| + picked := r.PostFormValue("contact") |
| + entered := contactFromForm(r) |
| + sel := purchaseContactSelection{ID: picked} |
| + if picked == "new" { |
| + sel = purchaseContactSelection{New: &entered} |
| + } |
| + price, err := strconv.ParseInt(r.PostFormValue("price"), 10, 64) |
| + if err != nil { |
| + price = 0 |
| + } |
| + confirmed := domainreg.Quote{Currency: r.PostFormValue("currency"), Price: price} |
| + ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second) |
| + defer cancel() |
| + // PostFormValue: the body only. A code in the URL is no code. |
| + p, checkout, changed, ref := s.startDomainTransfer(ctx, acct, name, r.PostFormValue("auth_code"), sel, addr, confirmed) |
| + if changed != nil || transferFormRefusal(ref) { |
| + if ref == nil { |
| + ref = domainBuyStateRefusal("priceChanged", http.StatusConflict) |
| + } |
| + s.transferFormAgain(w, r, addr, raw, acct, name, changed, ref, picked, &entered) |
| + return |
| + } |
| + if ref != nil { |
| + s.renderTransferRefusal(w, r, addr, raw, acct, name, ref) |
| + return |
| + } |
| + if checkout == "" { |
| + checkout = domainPurchaseURL(acct.Sqid, p.ID) |
| + } |
| + http.Redirect(w, r, checkout, http.StatusSeeOther) |
| +} |
| + |
| +// transferFormRefusal is a refusal the form itself can put right: the |
| +// transfer code or the contact. |
| +func transferFormRefusal(ref *doorRefusal) bool { |
| + return ref != nil && ref.Status == http.StatusUnprocessableEntity && |
| + (ref.Msg == domainTransferCopy["authCode"] || ref.Msg == domainBuyCopy["contactError"]) |
| +} |
| + |
| +// transferFormAgain is the form again, as posted but for the transfer code, |
| +// which is never drawn back: with the changed price to confirm, or the |
| +// refusal to put right. It quotes again, for the nameservers. |
| +func (s *Server) transferFormAgain(w http.ResponseWriter, r *http.Request, addr, raw string, acct *Account, name string, changed *domainreg.Quote, ref *doorRefusal, picked string, entered *registrar.Contact) { |
| + ctx, cancel := context.WithTimeout(r.Context(), 20*time.Second) |
| + defer cancel() |
| + tq, qref := s.quoteTransfer(ctx, acct, name) |
| + if qref != nil { |
| + s.renderTransferRefusal(w, r, addr, raw, acct, name, qref) |
| + return |
| + } |
| + if changed != nil { |
| + tq.Quote.Currency, tq.Quote.Price = changed.Currency, changed.Price |
| + } |
| + if picked != "new" { |
| + entered = nil |
| + } |
| + v, err := s.transferFormView(ctx, acct, tq, picked, entered) |
| + if err != nil { |
| + s.renderTransferRefusal(w, r, addr, raw, acct, name, purchaseUnavailable(PurchaseKindTransfer)) |
| + return |
| + } |
| + v.Alert = ref.Msg |
| + s.renderAccountTransfer(w, r, addr, raw, acct, ref.Status, v) |
| +} |
diff --git a/internal/console/accountdomaintransfer_test.go b/internal/console/accountdomaintransfer_test.go| new file mode 100644 |
| index 000000000..592e4ae33 |
| --- /dev/null |
| +++ b/internal/console/accountdomaintransfer_test.go |
| @@ -0,0 +1,482 @@ |
| +package console |
| + |
| +import ( |
| + "context" |
| + "fmt" |
| + "html" |
| + "log" |
| + "net/http" |
| + "net/url" |
| + "os" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/billing" |
| + "github.com/carlosframework/platform/internal/registrar" |
| + "github.com/carlosframework/platform/internal/svcrole" |
| +) |
| + |
| +// The transfer form, its start door and the transfer card (transfers in, |
| +// Task 9): owners only, CSRF on the post, the auth code only in a POST |
| +// body and never shown back. |
| + |
| +// transferPath is the transfer form's path for name on the fixture's |
| +// account. |
| +func (tf *transferFixture) transferPath(name string) string { |
| + return "/domains/transfer/" + name |
| +} |
| + |
| +// transferForm is a start form as the page posts it, with a new contact. |
| +func (tf *transferFixture) transferForm(csrf string) url.Values { |
| + q := transferQuoteFor(tf.srv, tf.acct) |
| + return withValues(contactForm(purchaseContact()), "csrf", csrf, "auth_code", testAuthCode, "contact", "new", |
| + "currency", q.Currency, "price", fmt.Sprint(q.Price)) |
| +} |
| + |
| +func TestTransferFormShowsNameserversAndPrice(t *testing.T) { |
| + tf := newTransferFixture(t) |
| + sc, err := tf.st.AddSavedContact(context.Background(), tf.acct.ID, purchaseContact(), time.Now()) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + c, _ := tf.ownerBrowser(t) |
| + path := "/a/" + tf.acct.Sqid + tf.transferPath("shop.com") |
| + status, _, body := get(t, c, tf.acctURL(tf.transferPath("SHOP.com"))) |
| + if status != http.StatusOK { |
| + t.Fatalf("GET form: %d %s", status, body) |
| + } |
| + main := mainOf(t, body) |
| + for _, want := range []string{ |
| + html.EscapeString(domainsFill(transferFormCopy.Title, "{domain}", "shop.com")), |
| + // The nameservers it keeps, read from public DNS at check, in order. |
| + "<code>ns1.example-dns.test</code>" + transferFormCopy.And + "<code>ns2.example-dns.test</code>", |
| + "$12", |
| + `<form method="post" action="` + path + `">`, |
| + `<input type="password" id="auth-code" name="auth_code" autocomplete="off"`, |
| + `name="currency" value="usd"`, `name="price" value="1200"`, |
| + `value="` + sc.ID + `" checked`, `value="new"`, |
| + html.EscapeString(transferFormCopy.Unlock), html.EscapeString(transferFormCopy.GetCode), |
| + html.EscapeString(transferFormCopy.MoneyBack), html.EscapeString(accountBuyCopy.Pay), |
| + `href="/a/` + tf.acct.Sqid + `/domains/shop.com"`, |
| + } { |
| + if !strings.Contains(main, want) { |
| + t.Errorf("form lacks %q:\n%s", want, main) |
| + } |
| + } |
| + if strings.Contains(main, "?auth_code") || strings.Contains(main, `method="get"`) { |
| + t.Errorf("the form could send the code in a URL:\n%s", main) |
| + } |
| + if n := purchaseCalls(tf.reg.Calls, "check-transfer:"); n != 1 { |
| + t.Fatalf("registrar transfer checks %d, want 1", n) |
| + } |
| + if n := tf.purchaseCount(t); n != 0 { |
| + t.Fatalf("the form wrote %d purchase(s)", n) |
| + } |
| + // The field style the shared CSS carries for it. |
| + if !strings.Contains(body, "input[type=password]") || !strings.Contains(body, ".fields.transfer-code") { |
| + t.Error("the console's shared CSS lacks the password field rule") |
| + } |
| + |
| + // A refusal before payment: one line says why, the form is not shown, |
| + // and Check again asks again. |
| + tf.reg.TransferChecks["shop.com"] = registrar.TransferCheck{Reason: "locked"} |
| + status, _, body = get(t, c, tf.acctURL(tf.transferPath("shop.com"))) |
| + main = mainOf(t, body) |
| + if status != http.StatusUnprocessableEntity || !strings.Contains(main, html.EscapeString(domainTransferNotNow["locked"])) || |
| + strings.Contains(main, `name="auth_code"`) || !strings.Contains(main, `<form method="get" action="`+path+`"`) || |
| + !strings.Contains(main, transferFormCopy.CheckAgain) { |
| + t.Fatalf("locked: %d\n%s", status, main) |
| + } |
| + // A refusal with nothing to retry: no Check again. |
| + tf.reg.TransferChecks["shop.com"] = registrar.TransferCheck{Transferable: true, Cost: registrar.Money{Currency: "usd", Minor: 800}} |
| + tf.ds = true |
| + status, _, body = get(t, c, tf.acctURL(tf.transferPath("shop.com"))) |
| + main = mainOf(t, body) |
| + if status != http.StatusUnprocessableEntity || !strings.Contains(main, html.EscapeString(domainTransferCopy["dnssec"])) || |
| + strings.Contains(main, transferFormCopy.CheckAgain) || strings.Contains(main, `name="auth_code"`) { |
| + t.Fatalf("dnssec: %d\n%s", status, main) |
| + } |
| +} |
| + |
| +func TestTransferPostRedirectsToCheckout(t *testing.T) { |
| + tf := newTransferFixture(t) |
| + c, csrf := tf.ownerBrowser(t) |
| + status, loc, body := postForm(t, c, tf.acctURL(tf.transferPath("shop.com")), tf.transferForm(csrf)) |
| + p, err := tf.srv.ownLiveDomainPurchase(context.Background(), tf.acct.ID, "shop.com") |
| + if err != nil || p == nil { |
| + t.Fatalf("no purchase: %d %s %v", status, body, err) |
| + } |
| + info, err := tf.fake.PaymentCheckout(context.Background(), p.CheckoutSession) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if status != http.StatusSeeOther || loc != info.URL { |
| + t.Fatalf("start: %d %q, want 303 to %q", status, loc, info.URL) |
| + } |
| + if p.Kind != PurchaseKindTransfer || p.AuthCode != testAuthCode || p.Amount != 1200 || p.Currency != "usd" || |
| + strings.Join(p.Nameservers, " ") != "ns1.example-dns.test ns2.example-dns.test" { |
| + t.Fatalf("purchase %+v", p) |
| + } |
| + back := tf.srv.cfg.Origin + domainPurchaseURL(tf.acct.Sqid, p.ID) |
| + if r := tf.lastCheckout(t); r.SuccessURL != back || r.CancelURL != back { |
| + t.Fatalf("checkout return %q / %q, want %q", r.SuccessURL, r.CancelURL, back) |
| + } |
| +} |
| + |
| +// TestTransferPostReadsTheCodeOnlyFromTheBody: a code in the query string |
| +// is not a code; the post is refused for the missing one and starts |
| +// nothing. |
| +func TestTransferPostReadsTheCodeOnlyFromTheBody(t *testing.T) { |
| + tf := newTransferFixture(t) |
| + c, csrf := tf.ownerBrowser(t) |
| + form := tf.transferForm(csrf) |
| + form.Del("auth_code") |
| + status, _, body := postForm(t, c, tf.acctURL(tf.transferPath("shop.com")+"?auth_code="+url.QueryEscape(testAuthCode)), form) |
| + if status != http.StatusUnprocessableEntity || !strings.Contains(body, html.EscapeString(domainTransferCopy["authCode"])) { |
| + t.Fatalf("code in the query: %d %s", status, body) |
| + } |
| + if n := tf.purchaseCount(t); n != 0 { |
| + t.Fatalf("%d purchase(s) started", n) |
| + } |
| +} |
| + |
| +func TestTransferFormNeverEchoesAuthCode(t *testing.T) { |
| + logs := &lockedBuffer{} |
| + log.SetOutput(logs) |
| + t.Cleanup(func() { log.SetOutput(os.Stderr) }) |
| + tf := newTransferFixture(t) |
| + c, csrf := tf.ownerBrowser(t) |
| + door := tf.acctURL(tf.transferPath("shop.com")) |
| + noCode := func(label string, status, want int, body string) { |
| + t.Helper() |
| + if status != want { |
| + t.Fatalf("%s: %d, want %d:\n%s", label, status, want, body) |
| + } |
| + if strings.Contains(body, testAuthCode) { |
| + t.Fatalf("%s: the page echoes the auth code:\n%s", label, body) |
| + } |
| + } |
| + // The contact is refused: the form comes back with what was entered, |
| + // except the code. |
| + bad := withValues(tf.transferForm(csrf), "Phone", "not-digits") |
| + status, _, body := postForm(t, c, door, bad) |
| + noCode("contact refused", status, http.StatusUnprocessableEntity, body) |
| + if !strings.Contains(body, html.EscapeString(domainBuyCopy["contactError"])) || !strings.Contains(body, `value="not-digits"`) || |
| + !strings.Contains(body, `name="auth_code"`) { |
| + t.Fatalf("contact refused: the form is not shown again as posted:\n%s", body) |
| + } |
| + // The price changed: the form comes back with the new price to confirm. |
| + status, _, body = postForm(t, c, door, withValues(tf.transferForm(csrf), "price", "999")) |
| + noCode("price changed", status, http.StatusConflict, body) |
| + if !strings.Contains(body, `name="price" value="1200"`) || !strings.Contains(body, html.EscapeString(domainBuyStateRefusal("priceChanged", 0).Msg)) { |
| + t.Fatalf("price changed: no new price to confirm:\n%s", body) |
| + } |
| + // A refusal page (the domain is signed): no form, no code. |
| + tf.ds = true |
| + status, _, body = postForm(t, c, door, tf.transferForm(csrf)) |
| + noCode("refused", status, http.StatusUnprocessableEntity, body) |
| + if n := tf.purchaseCount(t); n != 0 { |
| + t.Fatalf("%d purchase(s) started", n) |
| + } |
| + // The code is not logged either. |
| + tf.ds = false |
| + if status, _, body = postForm(t, c, door, tf.transferForm(csrf)); status != http.StatusSeeOther { |
| + t.Fatalf("start: %d %s", status, body) |
| + } |
| + if strings.Contains(logs.String(), testAuthCode) { |
| + t.Fatalf("auth code logged:\n%s", logs.String()) |
| + } |
| +} |
| + |
| +func TestTransferDoorsOwnerOnlyCSRFAndBuyDoorOff(t *testing.T) { |
| + tf := newTransferFixture(t) |
| + path := tf.transferPath("shop.com") |
| + if err := tf.st.AddMember(tf.acct.ID, "member@example.com", RoleMember, time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + form := tf.transferForm("") |
| + for _, addr := range []string{"member@example.com", "stranger@example.com"} { |
| + c := newBrowser(t) |
| + tf.setUser(addr) |
| + signUp(t, tf.consoleFixture, c, "transfer-"+addr) |
| + if status, _, body := get(t, c, tf.acctURL(path)); status != 404 || body != "404 page not found\n" { |
| + t.Fatalf("%s GET: %d %q", addr, status, body) |
| + } |
| + a := rawPost(t, c, tf.acctURL(path), withValues(form, "csrf", sessionToken(t, tf.consoleFixture, c)), "") |
| + if a.Status != 404 || a.Body != "404 page not found\n" { |
| + t.Fatalf("%s POST: %+v", addr, a) |
| + } |
| + } |
| + // A service credential is not a session. |
| + service := serviceToken(t, tf.st, tf.acct.ID, "pub", "kass", svcrole.Publish) |
| + if a := rawPost(t, newBrowser(t), tf.acctURL(path), form, service); a.Status != http.StatusFound || a.Location != "/" { |
| + t.Fatalf("service POST: %+v", a) |
| + } |
| + // CSRF on the post. |
| + c, _ := tf.ownerBrowser(t) |
| + for _, token := range []string{"", "forged"} { |
| + a := rawPost(t, c, tf.acctURL(path), withValues(form, "csrf", token), "") |
| + if a.Status != http.StatusForbidden || !strings.Contains(a.Body, domainBuyCopy["csrf"]) || strings.Contains(a.Body, testAuthCode) { |
| + t.Fatalf("POST csrf=%q: %+v", token, a) |
| + } |
| + } |
| + if n := tf.purchaseCount(t); n != 0 || purchaseCalls(tf.reg.Calls, "check-transfer:") != 0 { |
| + t.Fatalf("refused doors started %d purchase(s), registrar %v", n, tf.reg.Calls) |
| + } |
| + if n := tf.sent(billing.PreparedPaymentCheckout); n != 0 { |
| + t.Fatalf("%d checkout(s) sent", n) |
| + } |
| + // Buying off: the same 404 for the owner. |
| + tf.srv.cfg.DomainCatalog.DailyCap = 0 |
| + if status, _, body := get(t, c, tf.acctURL(path)); status != 404 || body != "404 page not found\n" { |
| + t.Fatalf("buy door off GET: %d %q", status, body) |
| + } |
| + if a := rawPost(t, c, tf.acctURL(path), withValues(form, "csrf", sessionToken(t, tf.consoleFixture, c)), ""); a.Status != 404 { |
| + t.Fatalf("buy door off POST: %+v", a) |
| + } |
| + // Not registered on a host-claim console. |
| + found := 0 |
| + for _, d := range routeDecls { |
| + if d.Pattern == "GET /a/{sqid}/domains/transfer/{domain}" || d.Pattern == "POST /a/{sqid}/domains/transfer/{domain}" { |
| + found++ |
| + if d.Gate != gateNoHostClaim { |
| + t.Errorf("%s is registered on a host-claim console", d.Pattern) |
| + } |
| + } |
| + } |
| + if found != 2 { |
| + t.Fatalf("transfer doors declared %d times, want 2", found) |
| + } |
| +} |
| + |
| +// transferCardPurchase is a transfer of shop.com in state, written straight |
| +// to the store. |
| +func transferCardPurchase(t *testing.T, tf *transferFixture, state PurchaseState, edit func(*DomainPurchase)) *DomainPurchase { |
| + t.Helper() |
| + now := time.Now() |
| + p := DomainPurchase{ID: newDomainPurchaseID(), Kind: PurchaseKindTransfer, AccountID: tf.acct.ID, Domain: "shop.com", Currency: "usd", |
| + Amount: 1200, State: state, CheckoutExpires: now.Add(time.Hour), CreatedAt: now, UpdatedAt: now} |
| + if edit != nil { |
| + edit(&p) |
| + } |
| + if err := tf.st.CreateDomainPurchase(p); err != nil { |
| + t.Fatal(err) |
| + } |
| + return &p |
| +} |
| + |
| +func TestTransferCardStages(t *testing.T) { |
| + tf := newTransferFixture(t) |
| + c, _ := tf.ownerBrowser(t) |
| + form := "/a/" + tf.acct.Sqid + "/domains/transfer/shop.com" |
| + page := "/a/" + tf.acct.Sqid + "/domains/shop.com" |
| + cc := transferCardCopy |
| + type want struct { |
| + title, lede, note, status string |
| + steps []string // state:label per step; nil when the card has none |
| + chips []string // class:label |
| + primary string // the main button's href |
| + poll bool |
| + } |
| + fill := func(s string) string { return domainsFill(s, "{domain}", "shop.com") } |
| + steps := func(states ...string) []string { |
| + labels := []string{cc.StepPaid, cc.StepSending, cc.StepWaiting, cc.StepRegistered} |
| + if states[1] == "done" { |
| + labels[1] = cc.StepSent |
| + } |
| + out := make([]string, 4) |
| + for i := range out { |
| + out[i] = states[i] + ":" + labels[i] |
| + } |
| + return out |
| + } |
| + expires := time.Date(2027, 12, 2, 0, 0, 0, 0, time.UTC) |
| + cases := []struct { |
| + name string |
| + state PurchaseState |
| + edit func(*DomainPurchase) |
| + want want |
| + }{ |
| + {"sending", PurchaseAuthorised, nil, want{title: fill(cc.MovingTitle), lede: fill(cc.SendingLede), status: cc.StepSending, |
| + steps: steps("done", "active", "pending", "pending"), poll: true}}, |
| + {"pending", PurchaseTransferPending, func(p *DomainPurchase) { p.Facts.SubmittedAt = time.Now().Add(-time.Hour) }, |
| + want{title: fill(cc.MovingTitle), lede: fill(cc.WaitingLede), note: cc.WaitingNote, status: cc.StepWaiting, |
| + steps: steps("done", "done", "active", "pending"), poll: true}}, |
| + {"unknown outcome, slow", PurchaseTransferSubmitting, func(p *DomainPurchase) { |
| + p.Facts.SubmittedAt = time.Now().Add(-8 * 24 * time.Hour) |
| + p.Facts.Registrar = rUnknown |
| + }, want{title: fill(cc.MovingTitle), lede: fill(cc.SlowLede), note: cc.SlowNote, status: cc.StepWaiting, |
| + steps: steps("done", "done", "active", "pending"), poll: true}}, |
| + {"done", PurchaseDone, func(p *DomainPurchase) { |
| + p.Facts.Registrar, p.Facts.Payment = rCompleted, pCaptured |
| + p.Facts.Completed = ®istrar.Registered{Domain: "shop.com", Expires: expires} |
| + }, want{title: fill(cc.DoneTitle), lede: domainsFill(cc.DoneLede, "{date}", "2 Dec 2027"), status: fill(cc.DoneTitle), primary: page}}, |
| + {"failed, not charged", PurchaseFailed, func(p *DomainPurchase) { |
| + p.Reason, p.Facts.Registrar, p.Facts.RegistrarReason, p.Facts.Payment = "auth_code", rFailed, "auth_code", pCancelled |
| + }, want{title: fill(cc.FailedTitle), lede: transferFailureWords("auth_code"), note: cc.NotChargedNote, status: fill(cc.FailedTitle), |
| + chips: []string{"chip-expired:" + cc.ChipFailed, "chip-env:" + cc.ChipNotCharged}, primary: form}}, |
| + {"failed, refunded", PurchaseFailed, func(p *DomainPurchase) { |
| + p.Reason, p.Facts.Registrar, p.Facts.RegistrarReason, p.Facts.Payment, p.Facts.Refund = "rejected", rFailed, "rejected", pCaptured, fSucceeded |
| + }, want{title: fill(cc.FailedTitle), lede: transferFailureWords("rejected"), note: domainsFill(cc.RefundedNote, "{amount}", "$12"), |
| + status: fill(cc.FailedTitle), chips: []string{"chip-expired:" + cc.ChipFailed, "chip-env:" + cc.ChipRefunded}, primary: form}}, |
| + {"failed, unknown reason", PurchaseFailed, func(p *DomainPurchase) { |
| + p.Reason, p.Facts.Registrar, p.Facts.RegistrarReason, p.Facts.Payment = "something new", rFailed, "something new", pCancelled |
| + }, want{title: fill(cc.FailedTitle), lede: transferFailureReason[""], note: cc.NotChargedNote, status: fill(cc.FailedTitle), |
| + chips: []string{"chip-expired:" + cc.ChipFailed, "chip-env:" + cc.ChipNotCharged}, primary: form}}, |
| + {"refunding", PurchaseTransferRefunding, func(p *DomainPurchase) { |
| + p.Facts.Registrar, p.Facts.RegistrarReason, p.Facts.Payment = rFailed, "timeout", pCaptured |
| + }, want{title: fill(cc.FailedTitle), lede: transferFailureWords("timeout"), note: domainsFill(cc.RefundingNote, "{amount}", "$12"), |
| + status: cc.StatusRefunding, chips: []string{"chip-expired:" + cc.ChipFailed, "chip-env:" + cc.ChipRefunding}, poll: true}}, |
| + {"expired", PurchaseExpired, nil, want{title: fill(cc.ExpiredTitle), lede: fill(cc.ExpiredLede), status: fill(cc.ExpiredTitle), |
| + chips: []string{"chip-env:" + cc.ChipNotCharged}, primary: form}}, |
| + {"unpaid", PurchaseUnpaid, nil, want{title: fill(cc.UnpaidTitle), lede: cc.UnpaidLede, status: fill(cc.UnpaidTitle), primary: page}}, |
| + {"awaiting payment", PurchaseAwaitingPayment, nil, want{title: fill(cc.AwaitingTitle), lede: fill(cc.AwaitingLede), status: cc.StatusAwaiting, poll: true}}, |
| + // A state this build does not draw for a transfer reads as waiting. |
| + {"a state with no stage", PurchaseZoneReady, nil, want{title: fill(cc.MovingTitle), lede: fill(cc.WaitingLede), note: cc.WaitingNote, |
| + status: cc.StepWaiting, steps: steps("done", "done", "active", "pending"), poll: true}}, |
| + } |
| + for _, tc := range cases { |
| + t.Run(tc.name, func(t *testing.T) { |
| + p := transferCardPurchase(t, tf, tc.state, tc.edit) |
| + t.Cleanup(func() { |
| + if _, err := tf.st.db.Exec(`DELETE FROM domain_purchases WHERE id=?`, p.ID); err != nil { |
| + t.Fatal(err) |
| + } |
| + }) |
| + status, _, body := get(t, c, tf.ts.URL+domainPurchaseURL(tf.acct.Sqid, p.ID)) |
| + if status != http.StatusOK { |
| + t.Fatalf("card: %d %s", status, body) |
| + } |
| + w := tc.want |
| + if got := purchaseText(purchaseElement(t, body, "purchase-title")); got != w.title { |
| + t.Errorf("title %q, want %q", got, w.title) |
| + } |
| + if got := purchaseText(purchaseElement(t, body, "purchase-lede")); got != w.lede { |
| + t.Errorf("lede %q, want %q", got, w.lede) |
| + } |
| + note := purchaseElement(t, body, "purchase-note") |
| + if got := purchaseText(note); got != w.note || purchaseHidden(note) != (w.note == "") { |
| + t.Errorf("note %q (hidden %v), want %q", got, purchaseHidden(note), w.note) |
| + } |
| + if got := purchaseText(purchaseElement(t, body, "purchase-status")); got != w.status { |
| + t.Errorf("status %q, want %q", got, w.status) |
| + } |
| + if got := transferCardSteps(t, body); strings.Join(got, "|") != strings.Join(w.steps, "|") { |
| + t.Errorf("steps %q, want %q", got, w.steps) |
| + } |
| + if got := transferCardChips(t, body); strings.Join(got, "|") != strings.Join(w.chips, "|") { |
| + t.Errorf("chips %q, want %q", got, w.chips) |
| + } |
| + primary := "" |
| + if strings.Contains(body, `id="purchase-primary"`) { |
| + primary = purchaseAttr(purchaseElement(t, body, "purchase-primary"), "href") |
| + } |
| + if primary != w.primary { |
| + t.Errorf("primary %q, want %q", primary, w.primary) |
| + } |
| + if polls := strings.Contains(body, "fetch(endpoint"); polls != w.poll { |
| + t.Errorf("polls %v, want %v", polls, w.poll) |
| + } |
| + if purchaseAttr(purchaseElement(t, body, "purchase-back"), "href") != "/a/"+tf.acct.Sqid+"/domains" { |
| + t.Error("the card does not go back to the account's domains") |
| + } |
| + // The buy card's words never appear on a transfer's. |
| + for _, b := range []string{domainBuyCopy["progressTitle"], domainBuyCopy["stepRegister"], "Buy a domain"} { |
| + if strings.Contains(mainOf(t, body), html.EscapeString(fill(b))) { |
| + t.Errorf("transfer card shows the buy card's %q", b) |
| + } |
| + } |
| + // One source: a live transfer's line on its domain is the card's. |
| + if purchaseLive(tc.state) && transferStatusLine(tc.state) != w.status { |
| + t.Errorf("domain status line %q is not the card's %q", transferStatusLine(tc.state), w.status) |
| + } |
| + }) |
| + } |
| + // The domain's page during a live move: Moving here, the card's status |
| + // line, and no Move to Carloku. |
| + p := transferCardPurchase(t, tf, PurchaseTransferPending, func(p *DomainPurchase) { p.Domain = "moving.com" }) |
| + status, _, body := get(t, c, tf.acctURL("/domains/moving.com")) |
| + main := mainOf(t, body) |
| + if status != http.StatusOK || !strings.Contains(main, domainMoveCopy.Moving) || !strings.Contains(main, cc.StepWaiting) || |
| + !strings.Contains(main, domainPurchaseURL(tf.acct.Sqid, p.ID)) || strings.Contains(main, domainMoveCopy.Move) || |
| + strings.Contains(main, "/domains/transfer/") { |
| + t.Fatalf("domain page during a move: %d\n%s", status, main) |
| + } |
| +} |
| + |
| +// TestTransferCardSentDay: the done Sent step says which day, by UTC |
| +// calendar day, with its date in the time element. |
| +func TestTransferCardSentDay(t *testing.T) { |
| + now := time.Date(2026, 11, 22, 0, 30, 0, 0, time.UTC) |
| + for sent, want := range map[time.Time]string{ |
| + now.Add(-20 * time.Minute): transferCardCopy.SentToday, |
| + now.Add(-40 * time.Minute): transferCardCopy.SentYesterday, |
| + now.Add(-8 * 24 * time.Hour): strings.ReplaceAll(transferCardCopy.SentDaysAgo, "{n}", "8"), |
| + } { |
| + if got := transferSentWhen(sent, now); got != want { |
| + t.Errorf("sent %v: %q, want %q", sent, got, want) |
| + } |
| + } |
| + p := &DomainPurchase{Kind: PurchaseKindTransfer, Domain: "shop.com", State: PurchaseTransferPending, Currency: "usd", Amount: 1200} |
| + p.Facts.SubmittedAt = now.Add(-8 * 24 * time.Hour) |
| + card := transferCard(&Account{Sqid: "abc", Name: "shop"}, p, now) |
| + if s := card.Steps[1]; s.State != "done" || s.Label != transferCardCopy.StepSent || s.WhenISO != "2026-11-14" || s.When != strings.ReplaceAll(transferCardCopy.SentDaysAgo, "{n}", "8") { |
| + t.Fatalf("sent step %+v", s) |
| + } |
| + if card.Steps[0].When != "" || card.Steps[2].When != "" { |
| + t.Fatalf("only the Sent step has a day: %+v", card.Steps) |
| + } |
| +} |
| + |
| +// transferCardSteps is the card's steps as state:label, nil when hidden. |
| +func transferCardSteps(t *testing.T, body string) []string { |
| + t.Helper() |
| + ol := purchaseElement(t, body, "purchase-steps") |
| + if purchaseHidden(ol) { |
| + return nil |
| + } |
| + var out []string |
| + for li := ol.FirstChild; li != nil; li = li.NextSibling { |
| + if li.Data != "li" { |
| + continue |
| + } |
| + label := "" |
| + for n := li.FirstChild; n != nil; n = n.NextSibling { |
| + if purchaseAttr(n, "class") == "purchase-step-label" { |
| + label = purchaseText(n) |
| + } |
| + } |
| + out = append(out, purchaseAttr(li, "data-state")+":"+label) |
| + } |
| + return out |
| +} |
| + |
| +// transferCardChips is the card's chips as class:label. |
| +func transferCardChips(t *testing.T, body string) []string { |
| + t.Helper() |
| + if !strings.Contains(body, `id="purchase-chips"`) { |
| + return nil |
| + } |
| + var out []string |
| + for n := purchaseElement(t, body, "purchase-chips").FirstChild; n != nil; n = n.NextSibling { |
| + if n.Data != "span" { |
| + continue |
| + } |
| + out = append(out, strings.TrimPrefix(purchaseAttr(n, "class"), "chip ")+":"+purchaseText(n)) |
| + } |
| + return out |
| +} |
| + |
| +func TestPurchaseStatusJSONHasKind(t *testing.T) { |
| + tf := newTransferFixture(t) |
| + c, _ := tf.ownerBrowser(t) |
| + buy := tf.purchaseFixture.start(t) |
| + tr := transferCardPurchase(t, tf, PurchaseTransferPending, func(p *DomainPurchase) { p.Domain = "moving.com" }) |
| + for p, kind := range map[*DomainPurchase]string{buy: "buy", tr: "transfer"} { |
| + status, _, body := get(t, c, tf.ts.URL+domainPurchaseURL(tf.acct.Sqid, p.ID)+"/status") |
| + if status != http.StatusOK || !strings.Contains(body, `"kind":"`+kind+`"`) || !strings.Contains(body, `"state":"`+string(p.State)+`"`) { |
| + t.Fatalf("%s status: %d %s", kind, status, body) |
| + } |
| + } |
| +} |
diff --git a/internal/console/apidomainbuy.go b/internal/console/apidomainbuy.go| index af45f42fa..71b93abbb 100644 |
| --- a/internal/console/apidomainbuy.go |
| +++ b/internal/console/apidomainbuy.go |
| @@ -155,7 +155,9 @@ func (s *Server) handleAPIDomainPurchase(w http.ResponseWriter, r *http.Request) |
| } |
| type domainPurchaseReply struct { |
| - ID string `json:"id"` |
| + ID string `json:"id"` |
| + // Kind is "buy" or "transfer": a transfer's card draws its own stages. |
| + Kind PurchaseKind `json:"kind"` |
| Domain string `json:"domain"` |
| App string `json:"app"` |
| State PurchaseState `json:"state"` |
| @@ -181,7 +183,7 @@ func (s *Server) purchaseForAccount(w http.ResponseWriter, r *http.Request, acct |
| } |
| func (s *Server) writeDomainPurchaseStatus(w http.ResponseWriter, r *http.Request, acct *Account, p *DomainPurchase) { |
| s.nudgePurchase(p.ID) |
| - out := domainPurchaseReply{ID: p.ID, Domain: p.Domain, App: p.App, State: p.State, Reason: p.Reason, Pointed: !purchaseNoApp(p)} |
| + out := domainPurchaseReply{ID: p.ID, Kind: purchaseKindOf(p), Domain: p.Domain, App: p.App, State: p.State, Reason: p.Reason, Pointed: !purchaseNoApp(p)} |
| ctx, cancel := context.WithTimeout(r.Context(), instanceStoreTimeout) |
| defer cancel() |
| out.DomainState = s.purchaseDomainState(ctx, acct, p) |
diff --git a/internal/console/apidomainbuy_test.go b/internal/console/apidomainbuy_test.go| index b55c7dfb1..717dfb3de 100644 |
| --- a/internal/console/apidomainbuy_test.go |
| +++ b/internal/console/apidomainbuy_test.go |
| @@ -390,7 +390,7 @@ func TestCheckDoorQuoteAndPurchaseStatusShape(t *testing.T) { |
| if err := json.Unmarshal([]byte(b), &result); err != nil { |
| t.Fatal(err) |
| } |
| - if status != 200 || len(result) != 7 || result["state"] != "done" || result["domain_state"] != StateChecking || result["pointed"] != true { |
| + if status != 200 || len(result) != 8 || result["kind"] != "buy" || result["state"] != "done" || result["domain_state"] != StateChecking || result["pointed"] != true { |
| t.Fatalf("status %d %s", status, b) |
| } |
| } |
diff --git a/internal/console/appdomainbuy.go b/internal/console/appdomainbuy.go| index 2cddc3c88..c3a3ee226 100644 |
| --- a/internal/console/appdomainbuy.go |
| +++ b/internal/console/appdomainbuy.go |
| @@ -7,8 +7,11 @@ import ( |
| "log" |
| "net/http" |
| "net/url" |
| + "strconv" |
| "strings" |
| + "time" |
| + "github.com/carlosframework/platform/internal/plans" |
| "github.com/carlosframework/platform/internal/registrar" |
| ) |
| @@ -41,6 +44,8 @@ type domainBuyView struct { |
| Stages, StagesNoApp map[PurchaseState]domainPurchaseStage |
| NoApp bool |
| CardCopy map[string]string |
| + // Transfer is the card of a transfer in; nil for a purchase. |
| + Transfer *transferCardView |
| } |
| type domainPurchaseStage struct { |
| @@ -138,6 +143,217 @@ func purchaseCard(p *DomainPurchase, domainState string) domainPurchaseCard { |
| return card |
| } |
| +// ---- the transfer card --------------------------------------------------------- |
| +// |
| +// A transfer in draws its own card: four steps while it moves (Paid, Sent, |
| +// Waiting for the current registrar, Registered here), then done, or a |
| +// failure shown as a state (Didn't move) beside what happened to the money |
| +// (Not charged, Refunding, Refunded). The step labels are the one source of |
| +// a live transfer's status line, here and on its domain's card and page. |
| + |
| +// transferStage is how the card draws a transfer's state. |
| +type transferStage struct { |
| + Kind string // awaiting, sending, waiting, refunding, done, failed, expired, unpaid |
| + Steps [4]string |
| +} |
| + |
| +var transferStages = map[PurchaseState]transferStage{ |
| + PurchaseAwaitingPayment: {Kind: "awaiting"}, |
| + PurchaseAuthorised: {Kind: "sending", Steps: [4]string{"done", "active", "pending", "pending"}}, |
| + PurchaseTransferSubmitting: {Kind: "waiting", Steps: [4]string{"done", "done", "active", "pending"}}, |
| + PurchaseTransferPending: {Kind: "waiting", Steps: [4]string{"done", "done", "active", "pending"}}, |
| + PurchaseTransferRefunding: {Kind: "refunding"}, |
| + PurchaseDone: {Kind: "done"}, |
| + PurchaseFailed: {Kind: "failed"}, |
| + PurchaseExpired: {Kind: "expired"}, |
| + PurchaseUnpaid: {Kind: "unpaid"}, |
| +} |
| + |
| +// transferStageOf is state's stage. A state a transfer has no stage for |
| +// reads as sent and waiting: it is live, and the card says nothing it does |
| +// not know. |
| +func transferStageOf(state PurchaseState) transferStage { |
| + if st, ok := transferStages[state]; ok { |
| + return st |
| + } |
| + return transferStages[PurchaseTransferPending] |
| +} |
| + |
| +// transferStepLabels is a stage's step labels: the second is Sending while |
| +// it is under way and Sent once done. |
| +func transferStepLabels(st transferStage) [4]string { |
| + c := transferCardCopy |
| + labels := [4]string{c.StepPaid, c.StepSending, c.StepWaiting, c.StepRegistered} |
| + if st.Steps[1] == "done" { |
| + labels[1] = c.StepSent |
| + } |
| + return labels |
| +} |
| + |
| +// transferStageStatus is a stage's one-line status: its active step's |
| +// label, or for a live stage without steps its own line; "" for an ended |
| +// one (the card's title says it). |
| +func transferStageStatus(st transferStage) string { |
| + labels := transferStepLabels(st) |
| + for i, step := range st.Steps { |
| + if step == "active" { |
| + return labels[i] |
| + } |
| + } |
| + switch st.Kind { |
| + case "awaiting": |
| + return transferCardCopy.StatusAwaiting |
| + case "refunding": |
| + return transferCardCopy.StatusRefunding |
| + } |
| + return "" |
| +} |
| + |
| +// transferSlowAfter is how long after the send the wait reads as taking |
| +// longer than usual: the five days a registrar has to answer. |
| +const transferSlowAfter = 5 * 24 * time.Hour |
| + |
| +type transferCardView struct { |
| + Eyebrow, Heading string |
| + Title, Lede, Note, Status string |
| + Chips []transferChip |
| + Steps []transferStepView // nil when the card has none |
| + Done bool |
| + Primary *transferLink |
| + Ownership string |
| + // Poll is a live transfer: the card's script polls its status. Live is |
| + // the stages the script moves between in place; any other change |
| + // reloads the page, which draws it. |
| + Poll bool |
| + Live map[PurchaseState]transferLiveStage |
| + PollError string |
| +} |
| + |
| +type transferChip struct{ Class, Label string } |
| + |
| +type transferStepView struct { |
| + State, Label string |
| + When, WhenISO string // the send's day, on the done Sent step |
| +} |
| + |
| +type transferLink struct{ Href, Label string } |
| + |
| +// transferLiveStage is a stepped stage as the card's script draws it. |
| +type transferLiveStage struct { |
| + Title, Lede, Note, Status string |
| + Steps, Labels [4]string |
| +} |
| + |
| +// transferLiveStages is every stepped stage, filled for domain. |
| +func transferLiveStages(domain string) map[PurchaseState]transferLiveStage { |
| + out := map[PurchaseState]transferLiveStage{} |
| + for state, st := range transferStages { |
| + if st.Steps[0] == "" { |
| + continue |
| + } |
| + title, lede, note := transferMovingWords(st, false) |
| + fill := strings.NewReplacer("{domain}", domain) |
| + out[state] = transferLiveStage{Title: fill.Replace(title), Lede: fill.Replace(lede), Note: note, |
| + Status: transferStageStatus(st), Steps: st.Steps, Labels: transferStepLabels(st)} |
| + } |
| + return out |
| +} |
| + |
| +// transferMovingWords is a stepped stage's title, lede and note, unfilled. |
| +func transferMovingWords(st transferStage, slow bool) (title, lede, note string) { |
| + c := transferCardCopy |
| + switch { |
| + case st.Kind == "sending": |
| + return c.MovingTitle, c.SendingLede, "" |
| + case slow: |
| + return c.MovingTitle, c.SlowLede, c.SlowNote |
| + } |
| + return c.MovingTitle, c.WaitingLede, c.WaitingNote |
| +} |
| + |
| +// transferSentWhen is the send's day relative to now: today, yesterday or |
| +// some days ago, by UTC calendar day. |
| +func transferSentWhen(sent, now time.Time) string { |
| + day := func(t time.Time) time.Time { |
| + y, m, d := t.UTC().Date() |
| + return time.Date(y, m, d, 0, 0, 0, 0, time.UTC) |
| + } |
| + switch days := int(day(now).Sub(day(sent)).Hours() / 24); { |
| + case days <= 0: |
| + return transferCardCopy.SentToday |
| + case days == 1: |
| + return transferCardCopy.SentYesterday |
| + default: |
| + return strings.ReplaceAll(transferCardCopy.SentDaysAgo, "{n}", strconv.Itoa(days)) |
| + } |
| +} |
| + |
| +// transferCard is p's card at now. The failure's words come from the |
| +// reason the transfer recorded (an unknown or empty one is the generic |
| +// line), and the money chip from what the payment last read: captured is |
| +// refunded (a failure after capture ends only once refunded), anything |
| +// else was never taken. |
| +func transferCard(acct *Account, p *DomainPurchase, now time.Time) transferCardView { |
| + c := transferCardCopy |
| + st := transferStageOf(p.State) |
| + amount := plans.FormatMinor(p.Currency, p.Amount) |
| + fill := strings.NewReplacer("{domain}", p.Domain, "{amount}", amount).Replace |
| + v := transferCardView{Eyebrow: domainsFill(domainsPageCopy.PageEyebrow, "{account}", acct.Name), Heading: c.Heading, PollError: c.PollError} |
| + tryAgain := &transferLink{Href: domainTransferURL(acct, p.Domain), Label: c.TryAgain} |
| + seeDomain := &transferLink{Href: domainPageURL(acct, p.Domain), Label: fill(c.SeeDomain)} |
| + didntMove := transferChip{Class: "chip-expired", Label: c.ChipFailed} |
| + notCharged := transferChip{Class: "chip-env", Label: c.ChipNotCharged} |
| + reason := p.Facts.RegistrarReason |
| + if reason == "" { |
| + reason = p.Reason |
| + } |
| + switch st.Kind { |
| + case "awaiting": |
| + v.Title, v.Lede = fill(c.AwaitingTitle), fill(c.AwaitingLede) |
| + case "sending", "waiting": |
| + slow := st.Kind == "waiting" && !p.Facts.SubmittedAt.IsZero() && now.Sub(p.Facts.SubmittedAt) >= transferSlowAfter |
| + title, lede, note := transferMovingWords(st, slow) |
| + v.Title, v.Lede, v.Note = fill(title), fill(lede), note |
| + labels := transferStepLabels(st) |
| + for i, state := range st.Steps { |
| + step := transferStepView{State: state, Label: labels[i]} |
| + if i == 1 && state == "done" && !p.Facts.SubmittedAt.IsZero() { |
| + step.When, step.WhenISO = transferSentWhen(p.Facts.SubmittedAt, now), p.Facts.SubmittedAt.UTC().Format("2006-01-02") |
| + } |
| + v.Steps = append(v.Steps, step) |
| + } |
| + case "refunding": |
| + v.Title, v.Lede, v.Note = fill(c.FailedTitle), transferFailureWords(reason), fill(c.RefundingNote) |
| + v.Chips = []transferChip{didntMove, {Class: "chip-env", Label: c.ChipRefunding}} |
| + case "done": |
| + v.Done, v.Title, v.Lede = true, fill(c.DoneTitle), c.DoneLedeNoDate |
| + if r := p.Facts.Completed; r != nil && !r.Expires.IsZero() { |
| + v.Lede = domainsFill(c.DoneLede, "{date}", r.Expires.UTC().Format("2 Jan 2006")) |
| + } |
| + v.Primary, v.Ownership = seeDomain, c.Ownership |
| + case "failed": |
| + v.Title, v.Lede, v.Note = fill(c.FailedTitle), transferFailureWords(reason), c.NotChargedNote |
| + v.Chips = []transferChip{didntMove, notCharged} |
| + if p.Facts.Payment == pCaptured { |
| + v.Note, v.Chips[1].Label = fill(c.RefundedNote), c.ChipRefunded |
| + } |
| + v.Primary = tryAgain |
| + case "expired": |
| + v.Title, v.Lede, v.Chips, v.Primary = fill(c.ExpiredTitle), fill(c.ExpiredLede), []transferChip{notCharged}, tryAgain |
| + case "unpaid": |
| + v.Title, v.Lede, v.Primary = fill(c.UnpaidTitle), c.UnpaidLede, seeDomain |
| + } |
| + v.Status = transferStageStatus(st) |
| + if v.Status == "" { |
| + v.Status = v.Title |
| + } |
| + v.Poll = purchaseLive(p.State) |
| + if v.Poll { |
| + v.Live = transferLiveStages(p.Domain) |
| + } |
| + return v |
| +} |
| + |
| // domainPurchaseURL is a purchase's card, the page Checkout returns to. |
| // Checkouts prepared before Plan 2a return to the old app-scoped path, |
| // which redirects here (handleAppDomainPurchaseRedirect). |
| @@ -180,12 +396,18 @@ func contactFromForm(r *http.Request) registrar.Contact { |
| City: r.FormValue("City"), State: r.FormValue("State"), PostalCode: r.FormValue("PostalCode"), Country: r.FormValue("Country")} |
| } |
| -// renderPurchaseCard draws a purchase's card on the account's buy page. |
| +// renderPurchaseCard draws a purchase's card on the account's buy page, or |
| +// a transfer's card. |
| func (s *Server) renderPurchaseCard(w http.ResponseWriter, r *http.Request, addr, raw string, acct *Account, v *domainBuyView) { |
| p := s.accountPage(w, r, addr, raw, acct, RoleOwner) |
| p.Title = domainBuyCopy["title"] |
| p.ActiveNav = "domains" |
| v.Back = domainsBase(acct) + "/domains" |
| + if purchaseKindOf(v.Purchase) == PurchaseKindTransfer { |
| + card := transferCard(acct, v.Purchase, time.Now()) |
| + v.Transfer = &card |
| + p.Title = card.Heading |
| + } |
| v.Point = domainPageURL(acct, v.Purchase.Domain) |
| v.PointLabel = domainsFill(purchaseReadyCopy.OpenDomain, "{domain}", v.Purchase.Domain) |
| v.Card = purchaseCard(v.Purchase, v.DomainState) |
diff --git a/internal/console/demo_claim_footer_test.go b/internal/console/demo_claim_footer_test.go| index cb41307a8..797098ad1 100644 |
| --- a/internal/console/demo_claim_footer_test.go |
| +++ b/internal/console/demo_claim_footer_test.go |
| @@ -13,21 +13,20 @@ import ( |
| // The digests are the claim page with no footer, retaken when the page itself, |
| // its script or the console chrome's CSS changes (the script tag carries the |
| -// asset hash; last: the Domains page and buy-flow rules (.domain-head, |
| -// .contact-pick, .fields, .addr-rows) domain registration 2a added to the |
| -// chrome). With neither item configured (or both invalid) the page is these |
| -// exact bytes. |
| -const demoClaimFooterBaseStyleHash = "'sha256-59KdIK903iFOBYHjuIwQ7lOEogg6MRvpcx5s76IULto='" |
| +// asset hash; last: transfers in added input[type=password] to the base |
| +// field rule and .fields.transfer-code to the chrome). With neither item |
| +// configured (or both invalid) the page is these exact bytes. |
| +const demoClaimFooterBaseStyleHash = "'sha256-dhlPVB9IcoXJkgX1FFhDwSY2PO0eOvgOTyYJxH0HSbE='" |
| var demoClaimFooterBaseDigests = map[string]string{ |
| - "template-zero": "e5d5fe4dbb66b93ec4f6bebe53a914125f36c0bd96b426ad5bcdbaae8b7cac31", |
| - "template-missing": "131f0790886a1ffb85000699831eb7cecae673e167357a9df879612b7404263e", |
| - "template-error": "adc9807c014d76095d9c171266e1debf87dc8898ac6708f4001c92dc250e61e2", |
| - "template-claimed": "5b7ce95e678beceea1664f2af6d6849a7c6d2020569eeb2109ee5c241b2f3232", |
| - "template-proof": "fdb72bc06aaba6b504659b4d319c690a548f0024f211d82777e32661a4fe8794", |
| - "error-page": "5f7f42801154e11e129e6844a91b9334f55c258ecfe2f9a519515589a2ebc190", |
| - "get-claim": "75d60affd6aa529083f27c8cf1b130825dcf907aaec13d3a8665cf6c02cbb4c5", |
| - "get-kept": "153f9a48fa7afd5d45ce2fc65a9fcf5f12868b6e5063abdd34b4a52f0b3f5466", |
| + "template-zero": "1a52bb7c435fb25eb4f1301047c84eb1f738cb5fb83d6bd03714aa40d84bf1bb", |
| + "template-missing": "7bd8a00db880f207f23453c9a2c23035bc03f0c8c66783af3e66680195a7a14d", |
| + "template-error": "0a663f865e3426765a19711c8c0c273757312dcb9a1878df510c2c67983ec5f5", |
| + "template-claimed": "b95c4dcebcf10e64b9b2709dc0c89b50174fe8319e0780ca1044a159fd620ad3", |
| + "template-proof": "dd921ea830607fd83d09571cacca61af9ece3d20399b9a99347817cd40d348f7", |
| + "error-page": "9c5f1b2885fb94ec4943074eac6b7b6c43ba4303e2ff9fedf663d7d8534b7b20", |
| + "get-claim": "bcaf77f7588092db695cdd185df9b2303e6649fde0f4de6d7c9c543ada908847", |
| + "get-kept": "e765b77c5cbb2f53dd4c3f8cca2312d678479d62b716964d7ff1643a5ba02dec", |
| } |
| const ( |
diff --git a/internal/console/domaintransfer_copy.go b/internal/console/domaintransfer_copy.go| index 89caa0186..cac737e54 100644 |
| --- a/internal/console/domaintransfer_copy.go |
| +++ b/internal/console/domaintransfer_copy.go |
| @@ -37,6 +37,98 @@ func transferNotNowRefusal(reason string) *doorRefusal { |
| return &doorRefusal{Status: http.StatusUnprocessableEntity, Msg: msg} |
| } |
| +// transferFormCopy is the transfer form (Move to Carloku) and its refusal |
| +// page. {domain} is filled by the page; And joins the last two |
| +// nameservers. Every refusal's own line is domainTransferCopy's, |
| +// domainTransferNotNow's or the buy door's. |
| +var transferFormCopy = struct { |
| + Title, Lede, Summary string |
| + TilePrice, PriceDetail string |
| + TileTakes, TakesValue, TakesDetail string |
| + Nameservers, And string |
| + BeforeTitle, BeforeNote, Unlock, GetCode string |
| + AuthCode, RegisteredNote string |
| + Back, CheckAgain, MoneyBack string |
| +}{ |
| + Title: "Move {domain} to Carloku", |
| + Lede: "Your DNS and email don’t change. Only the registration moves.", |
| + Summary: "The move", |
| + TilePrice: "Price", |
| + PriceDetail: "adds one year to its expiry", |
| + TileTakes: "Takes", |
| + TakesValue: "5 days", |
| + TakesDetail: "at most, sooner if you approve it", |
| + Nameservers: "It keeps the nameservers it uses today:", |
| + And: " and ", |
| + BeforeTitle: "Before you start", |
| + BeforeNote: "At the registrar where {domain} is now:", |
| + Unlock: "Unlock the domain.", |
| + GetCode: "Get its transfer code. It may be called an auth code.", |
| + AuthCode: "Transfer code", |
| + RegisteredNote: "The domain is legally theirs.", |
| + Back: "Back", |
| + CheckAgain: "Check again", |
| + MoneyBack: "If the move doesn’t go through, you get your money back.", |
| +} |
| + |
| +// transferCardCopy is a transfer's purchase card: its step labels (the one |
| +// source of a live transfer's status line on its domain, too), its words by |
| +// stage and its chips. {domain}, {date} and {amount} are filled by the card. |
| +var transferCardCopy = struct { |
| + Heading string |
| + StepPaid, StepSending, StepSent, StepWaiting, StepRegistered string |
| + SentToday, SentYesterday, SentDaysAgo string |
| + StatusAwaiting, StatusRefunding string |
| + AwaitingTitle, AwaitingLede string |
| + MovingTitle, SendingLede, WaitingLede, WaitingNote string |
| + SlowLede, SlowNote string |
| + DoneTitle, DoneLede, DoneLedeNoDate, SeeDomain, Ownership string |
| + FailedTitle, ChipFailed, ChipNotCharged, ChipRefunded string |
| + ChipRefunding, NotChargedNote, RefundedNote, RefundingNote string |
| + TryAgain, ExpiredTitle, ExpiredLede, UnpaidTitle, UnpaidLede string |
| + PollError string |
| +}{ |
| + Heading: "Move to Carloku", |
| + StepPaid: "Paid", |
| + StepSending: "Sending the transfer", |
| + StepSent: "Sent", |
| + StepWaiting: "Waiting for the current registrar", |
| + StepRegistered: "Registered here", |
| + SentToday: "today", |
| + SentYesterday: "yesterday", |
| + SentDaysAgo: "{n} days ago", |
| + StatusAwaiting: "Waiting for payment", |
| + // The status line while a refund is under way. |
| + StatusRefunding: "Refunding your payment", |
| + AwaitingTitle: "Almost there", |
| + AwaitingLede: "Finish paying to move {domain} here. Your checkout stays open for an hour.", |
| + MovingTitle: "Moving {domain}", |
| + SendingLede: "Payment received, thanks. We’re sending the transfer to {domain}’s current registrar. Your DNS and email keep working.", |
| + WaitingLede: "Waiting for {domain}’s current registrar to let it go. This takes up to five days. You can approve it there to finish sooner.", |
| + WaitingNote: "To approve it, look for an email from the current registrar, or the transfers section of your account there. Your DNS and email keep working the whole time, and you can leave this page.", |
| + SlowLede: "Still waiting for {domain}’s current registrar. This is taking longer than usual. We keep checking, and this page changes when there’s an answer.", |
| + SlowNote: "You can still approve it at the current registrar. Your DNS and email keep working the whole time.", |
| + DoneTitle: "{domain} is registered here", |
| + DoneLede: "It now expires on {date}, a year later than before. Its DNS and email didn’t change.", |
| + DoneLedeNoDate: "A year was added to its registration. Its DNS and email didn’t change.", |
| + SeeDomain: "See {domain}", |
| + Ownership: "It’s registered in your name, so it’s yours to keep or take elsewhere.", |
| + FailedTitle: "{domain} didn’t move", |
| + ChipFailed: "Didn’t move", |
| + ChipNotCharged: "Not charged", |
| + ChipRefunded: "Refunded", |
| + ChipRefunding: "Refunding", |
| + NotChargedNote: "The hold on your card has been released. The domain stays where it was, and its DNS and email didn’t change.", |
| + RefundedNote: "We refunded the {amount} to your card. It can take a few days to show. The domain stays where it was, and its DNS and email didn’t change.", |
| + RefundingNote: "We’re refunding the {amount} to your card. The domain stays where it was, and its DNS and email didn’t change.", |
| + TryAgain: "Try again", |
| + ExpiredTitle: "The move didn’t start", |
| + ExpiredLede: "Nothing was charged and nothing was sent. If you still want to move {domain}, start again.", |
| + UnpaidTitle: "{domain} has moved, but the payment didn’t go through", |
| + UnpaidLede: "Its registration is here now, and its DNS and email didn’t change. We’ll be in touch about paying for it.", |
| + PollError: "We can’t check on the move just now. It carries on regardless, so try refreshing in a minute.", |
| +} |
| + |
| // transferFailureReason is a failed transfer's reason in plain words, for |
| // the owner's email and the card. An empty or unknown reason gets the |
| // generic line. |
diff --git a/internal/console/perfwalk_test.go b/internal/console/perfwalk_test.go| index 4e9712dd2..d1f4e3414 100644 |
| --- a/internal/console/perfwalk_test.go |
| +++ b/internal/console/perfwalk_test.go |
| @@ -7,6 +7,7 @@ import ( |
| "html" |
| "io" |
| "log" |
| + "net" |
| "net/http" |
| "net/http/httptrace" |
| "net/url" |
| @@ -22,12 +23,14 @@ import ( |
| "time" |
| "golang.org/x/crypto/bcrypt" |
| + "golang.org/x/net/dns/dnsmessage" |
| "github.com/carlosframework/platform/internal/analytics" |
| "github.com/carlosframework/platform/internal/appconfig" |
| "github.com/carlosframework/platform/internal/apperr" |
| "github.com/carlosframework/platform/internal/applog" |
| "github.com/carlosframework/platform/internal/certwarm" |
| + "github.com/carlosframework/platform/internal/domainreg" |
| "github.com/carlosframework/platform/internal/domains" |
| "github.com/carlosframework/platform/internal/mail" |
| "github.com/carlosframework/platform/internal/metrics" |
| @@ -35,9 +38,13 @@ import ( |
| "github.com/carlosframework/platform/internal/perf" |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/ratelimit" |
| + "github.com/carlosframework/platform/internal/registrar" |
| + "github.com/carlosframework/platform/internal/registrar/registrartest" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| "github.com/carlosframework/platform/internal/status" |
| + "github.com/carlosframework/platform/internal/zonehost" |
| + "github.com/carlosframework/platform/internal/zonehost/zonehosttest" |
| ) |
| // The CI walk (spec Part 2, §2.5 step 2): every HTML screen in the route |
| @@ -53,6 +60,10 @@ type perfTarget struct { |
| Expect int |
| Anonymous bool |
| CLI bool |
| + // Arrange, when set, runs before the target's views and returns what |
| + // puts the console back after them: configuration only this screen |
| + // needs, which would change what the others show. |
| + Arrange func(t *testing.T, fx *consoleFixture) (undo func()) |
| } |
| // perfScreenTarget is one walked request: its screen, the target and the |
| @@ -538,6 +549,10 @@ func perfTargets(fx *consoleFixture) map[string][]perfTarget { |
| m["GET /a/{sqid}/apps/{app}/domains/"+p] = []perfTarget{{ |
| Path: app + "/domains/" + strings.ReplaceAll(p, "{id}", "dp_0000000000000001"), Expect: want}} |
| } |
| + // The transfer form is drawn only with buying on, so its views turn it |
| + // on for themselves (perfArrangeTransfer). |
| + m["GET /a/{sqid}/domains/transfer/{domain}"] = []perfTarget{{ |
| + Path: fx.path("/domains/transfer/example.org"), Expect: http.StatusOK, Arrange: perfArrangeTransfer}} |
| for _, tab := range []string{"account-review", "activity", "analytics", "availability", "errors", |
| "instances", "logs", "logs/data", "protection", "protection/data", "settings"} { |
| m["GET /a/{sqid}/apps/{app}/"+tab] = ok(app + "/" + tab) |
| @@ -581,6 +596,61 @@ func perfTargets(fx *consoleFixture) map[string][]perfTarget { |
| return m |
| } |
| +// perfArrangeTransfer turns domain buying on for the transfer form's views |
| +// only: the walk otherwise leaves it off, so the buy pages answer their |
| +// gate's 404. A registrar fake whose transfer check passes for |
| +// example.org, a catalog that moves .org, the account's saved contact, and |
| +// public DNS faked: LookupNS, and the DS lookup answered by a DNS server on |
| +// 127.0.0.1. No public network. The returned func puts it all back. |
| +func perfArrangeTransfer(t *testing.T, fx *consoleFixture) func() { |
| + t.Helper() |
| + srv := fx.srv |
| + acct, err := fx.st.AccountBySqid(fx.sqid) |
| + if err != nil || acct == nil { |
| + t.Fatalf("perf: account %s: %+v %v", fx.sqid, acct, err) |
| + } |
| + cfg := srv.cfg |
| + was := struct { |
| + reg registrar.Registrar |
| + zone zonehost.Host |
| + catalog *domainreg.Catalog |
| + ns func(context.Context, string) ([]*net.NS, error) |
| + ds func(context.Context, string) (bool, error) |
| + resolver string |
| + billing *billingRuntime |
| + }{cfg.Registrar, cfg.ZoneHost, cfg.DomainCatalog, cfg.LookupNS, cfg.LookupDS, cfg.DNSServer, srv.billing} |
| + |
| + reg := registrartest.New() |
| + reg.TransferChecks["example.org"] = registrar.TransferCheck{Transferable: true, Cost: registrar.Money{Currency: "usd", Minor: 800}} |
| + usd := func(n int64) map[string]int64 { return map[string]int64{"usd": n} } |
| + srv.cfg.Registrar = reg |
| + srv.cfg.ZoneHost = zonehosttest.New("ns1.carloku.test", "ns2.carloku.test", "ns3.carloku.test", "ns4.carloku.test") |
| + srv.cfg.DomainCatalog = &domainreg.Catalog{Version: "perf", DailyCap: 3, TLDs: map[string]domainreg.TLD{"org": { |
| + Register: usd(1500), Renew: usd(1300), Transfer: usd(1200), Transferable: true, MaxCost: registrar.Money{Currency: "usd", Minor: 1000}}}} |
| + srv.cfg.LookupNS = func(context.Context, string) ([]*net.NS, error) { |
| + return []*net.NS{{Host: "ns1.example-dns.test."}, {Host: "ns2.example-dns.test."}}, nil |
| + } |
| + srv.cfg.LookupDS = nil |
| + srv.cfg.DNSServer = newDSResponder(t, func(q dnsmessage.Message) []byte { return dsReply(q, dnsmessage.RCodeSuccess, false, nil) }, nil).addr |
| + billingCfg, _ := testBillingConfig(t, examplePlanCatalog(t)) |
| + srv.billing = newBillingRuntime(billingCfg) |
| + srv.billing.ready.Store(true) |
| + sc, err := fx.st.AddSavedContact(context.Background(), acct.ID, purchaseContact(), time.Now()) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if !srv.domainBuyReady() { |
| + t.Fatal("perf: buying is still off for the transfer form") |
| + } |
| + return func() { |
| + srv.cfg.Registrar, srv.cfg.ZoneHost, srv.cfg.DomainCatalog = was.reg, was.zone, was.catalog |
| + srv.cfg.LookupNS, srv.cfg.LookupDS, srv.cfg.DNSServer, srv.billing = was.ns, was.ds, was.resolver, was.billing |
| + if err := fx.st.RemoveSavedContact(context.Background(), acct.ID, sc.ID); err != nil { |
| + t.Error(err) |
| + } |
| + } |
| +} |
| + |
| // perfOperatorTargets is the operator pages' views that a query selects, |
| // which route enumeration cannot see (it registers patterns), each over |
| // seedOperatorScale's rows: TestPerfTargetsCoverOperatorViews holds every |
| @@ -910,8 +980,22 @@ func TestConsoleScreensMeetTheBudget(t *testing.T) { |
| verdicts := map[string][]string{} |
| var verdictOrder []string |
| var table []string |
| + // undo puts back what the last target's Arrange changed, before the |
| + // next target and after the last. |
| + var undo func() |
| + putBack := func() { |
| + if undo != nil { |
| + undo() |
| + undo = nil |
| + } |
| + } |
| + defer putBack() |
| for _, w := range perfWalkTargets(fx) { |
| + putBack() |
| tg := w.Target |
| + if tg.Arrange != nil { |
| + undo = tg.Arrange(t, fx) |
| + } |
| label := w.Screen + " " + tg.Path |
| if tg.Anonymous { |
| label += " (signed out)" |
| @@ -1033,6 +1117,7 @@ func TestConsoleScreensMeetTheBudget(t *testing.T) { |
| label, maxCalls, maxS3, maxHost, allow) |
| } |
| } |
| + putBack() |
| for _, screen := range verdictOrder { |
| calls := verdicts[screen+"\x00calls"] |
| callNote := "no remote calls on a repeat view" |
diff --git a/internal/console/routedecls.go b/internal/console/routedecls.go| index adee0e46a..80c4ff9ca 100644 |
| --- a/internal/console/routedecls.go |
| +++ b/internal/console/routedecls.go |
| @@ -209,6 +209,13 @@ var routeDecls = []routeDecl{ |
| {Pattern: "POST /a/{sqid}/domains/contacts", Gate: gateNoHostClaim, Handler: (*Server).handleDomainContactAdd}, |
| {Pattern: "POST /a/{sqid}/domains/contacts/{id}", Gate: gateNoHostClaim, Handler: (*Server).handleDomainContactEdit}, |
| {Pattern: "POST /a/{sqid}/domains/contacts/{id}/remove", Gate: gateNoHostClaim, Handler: (*Server).handleDomainContactRemove}, |
| + // Moving a domain registered elsewhere here (accountdomaintransfer.go, |
| + // transfers in): the form and its start, behind the buy door's gate; |
| + // its card is the purchase card above. Under /domains/transfer/, not |
| + // /domains/{domain}/transfer, which the mux refuses beside |
| + // /domains/purchases/{id} (both match /domains/purchases/transfer). |
| + {Pattern: "GET /a/{sqid}/domains/transfer/{domain}", Gate: gateNoHostClaim, Handler: (*Server).handleAccountDomainTransfer}, |
| + {Pattern: "POST /a/{sqid}/domains/transfer/{domain}", Gate: gateNoHostClaim, Handler: (*Server).handleAccountDomainTransferStart}, |
| {Pattern: "GET /a/{sqid}/fleet", Handler: (*Server).handleAccountFleetTab}, |
| {Pattern: "GET /a/{sqid}/fleet/byo", Handler: (*Server).handleFleetBYO}, |
| {Pattern: "GET /a/{sqid}/team", Handler: (*Server).handleTeam}, |
diff --git a/internal/console/templates/account_domain_buy.html b/internal/console/templates/account_domain_buy.html| index 66dcd704f..6d72af991 100644 |
| --- a/internal/console/templates/account_domain_buy.html |
| +++ b/internal/console/templates/account_domain_buy.html |
| @@ -64,30 +64,42 @@ |
| <input type="hidden" name="price" value="{{$v.Quote.Price}}"> |
| <h2>{{.DomainsCopy.RegisteredTo}}</h2> |
| <p class="small">{{$c.RegisteredNote}}</p> |
| - {{if $v.Contacts}} |
| - {{if $v.Filter}}<label class="visually-hidden" for="contact-find">{{$c.FindContact}}</label> |
| + {{template "contact_pick" $v.Pick}} |
| + <div class="settings-row"> |
| + <a class="btn btn-secondary" href="{{$v.Back}}">{{$c.Back}}</a> |
| + <button type="submit" data-busy>{{$c.Pay}}</button> |
| + </div> |
| +</form> |
| +{{template "contact_pick_script" $v.Pick}} |
| +{{end}} |
| +{{template "bottom" .}}{{end}} |
| + |
| +{{/* Registered to, inside a form: the saved contacts (a contactPicker), |
| + the most recently used first, and a new contact's fields. The buy |
| + page's step 3 and the transfer form. */}} |
| +{{define "contact_pick"}}{{$c := .Copy}} |
| + {{if .Contacts}} |
| + {{if .Filter}}<label class="visually-hidden" for="contact-find">{{$c.FindContact}}</label> |
| <input type="search" id="contact-find" class="contact-find" placeholder="{{$c.FindContact}}" autocomplete="off">{{end}} |
| <div class="tablewrap"> |
| <ul class="envvars contact-pick" id="contact-pick"> |
| - {{range $v.Contacts}}<li><label class="envvar-row"><input type="radio" name="contact" value="{{.ID}}"{{if .Checked}} checked{{end}}><span class="envvar-name">{{.Name}}</span><span class="envvar-value small">{{.Detail}}</span></label></li> |
| - {{end}}<li><label class="envvar-row"><input type="radio" name="contact" value="new" id="contact-new"{{if $v.NewPicked}} checked{{end}}><span class="envvar-name">{{$c.AddContact}}</span></label></li> |
| + {{range .Contacts}}<li><label class="envvar-row"><input type="radio" name="contact" value="{{.ID}}"{{if .Checked}} checked{{end}}><span class="envvar-name">{{.Name}}</span><span class="envvar-value small">{{.Detail}}</span></label></li> |
| + {{end}}<li><label class="envvar-row"><input type="radio" name="contact" value="new" id="contact-new"{{if .NewPicked}} checked{{end}}><span class="envvar-name">{{$c.AddContact}}</span></label></li> |
| </ul> |
| </div> |
| <div class="newcontact"> |
| - {{template "contact_fields" $v.NewFields}} |
| + {{template "contact_fields" .NewFields}} |
| <p class="small">{{$c.SavedForNext}}</p> |
| </div> |
| {{else}} |
| <input type="hidden" name="contact" value="new"> |
| - {{template "contact_fields" $v.NewFields}} |
| + {{template "contact_fields" .NewFields}} |
| <p class="small">{{$c.SavedForNext}}</p> |
| {{end}} |
| - <div class="settings-row"> |
| - <a class="btn btn-secondary" href="{{$v.Back}}">{{$c.Back}}</a> |
| - <button type="submit" data-busy>{{$c.Pay}}</button> |
| - </div> |
| -</form> |
| -{{if $v.Filter}}<script> |
| +{{end}} |
| + |
| +{{/* The filter over a long contact list, after the form. */}} |
| +{{define "contact_pick_script"}}{{if .Filter}}<script> |
| (function () { |
| const find = document.getElementById('contact-find'); |
| const rows = document.querySelectorAll('#contact-pick li'); |
| @@ -99,6 +111,4 @@ |
| }); |
| }); |
| })(); |
| -</script>{{end}} |
| -{{end}} |
| -{{template "bottom" .}}{{end}} |
| +</script>{{end}}{{end}} |
diff --git a/internal/console/templates/account_domain_transfer.html b/internal/console/templates/account_domain_transfer.html| new file mode 100644 |
| index 000000000..d53918bc7 |
| --- /dev/null |
| +++ b/internal/console/templates/account_domain_transfer.html |
| @@ -0,0 +1,57 @@ |
| +{{define "account_domain_transfer"}}{{template "top" .}} |
| +{{$c := .TransferFormCopy}}{{$v := .AccountTransfer}} |
| +<div class="pagehead"> |
| + <p class="eyebrow">{{$v.Eyebrow}}</p> |
| + <h1>{{$v.Title}}</h1> |
| + {{if not $v.Refused}}<p class="lede">{{$c.Lede}}</p>{{end}} |
| +</div> |
| +{{with $v.Alert}}<p class="banner error" role="alert">{{.}}</p>{{end}} |
| + |
| +{{if $v.Refused}} |
| +{{if $v.Retry}}<form method="get" action="{{$v.Action}}" class="settings-row"> |
| + <a class="btn btn-secondary" href="{{$v.Back}}">{{$c.Back}}</a> |
| + <button type="submit" data-busy>{{$c.CheckAgain}}</button> |
| +</form> |
| +{{else}}<div class="settings-row"> |
| + <a class="btn btn-secondary" href="{{$v.Back}}">{{$c.Back}}</a> |
| +</div>{{end}} |
| + |
| +{{else}} |
| +<section class="tiles" aria-label="{{$c.Summary}}"> |
| + {{range $v.Tiles}}<div class="tile"> |
| + <h2>{{.Label}}</h2> |
| + <p class="tile-value">{{.Value}}</p> |
| + <p class="tile-detail">{{.Detail}}</p> |
| + </div>{{end}} |
| +</section> |
| +<p>{{$c.Nameservers}} {{range $v.Nameservers}}{{.Before}}<code>{{.Name}}</code>{{end}}.</p> |
| + |
| +{{/* The transfer code travels only in this form's body: a POST, its |
| + action without a query, and the field is never filled back in. */}} |
| +<form method="post" action="{{$v.Action}}"> |
| + <input type="hidden" name="csrf" value="{{$.CSRF}}"> |
| + <input type="hidden" name="currency" value="{{$v.Quote.Currency}}"> |
| + <input type="hidden" name="price" value="{{$v.Quote.Price}}"> |
| + <h2>{{$c.BeforeTitle}}</h2> |
| + <p class="small">{{$v.BeforeNote}}</p> |
| + <ol> |
| + <li>{{$c.Unlock}}</li> |
| + <li>{{$c.GetCode}}</li> |
| + </ol> |
| + <div class="fields transfer-code"> |
| + <p><label for="auth-code">{{$c.AuthCode}}</label><input type="password" id="auth-code" name="auth_code" autocomplete="off" autocapitalize="off" spellcheck="false" maxlength="256" required></p> |
| + </div> |
| + |
| + <h2>{{.DomainsCopy.RegisteredTo}}</h2> |
| + <p class="small">{{$c.RegisteredNote}}</p> |
| + {{template "contact_pick" $v.Pick}} |
| + |
| + <div class="settings-row"> |
| + <a class="btn btn-secondary" href="{{$v.Back}}">{{$c.Back}}</a> |
| + <button type="submit" data-busy>{{.AccountBuyCopy.Pay}}</button> |
| + </div> |
| + <p class="small">{{$c.MoneyBack}}</p> |
| +</form> |
| +{{template "contact_pick_script" $v.Pick}} |
| +{{end}} |
| +{{template "bottom" .}}{{end}} |
diff --git a/internal/console/templates/console_chrome.html b/internal/console/templates/console_chrome.html| index c5cae698e..cbbaeb83e 100644 |
| --- a/internal/console/templates/console_chrome.html |
| +++ b/internal/console/templates/console_chrome.html |
| @@ -66,7 +66,7 @@ |
| should wrap inside the box rather than force the horizontal scrollbar |
| every other <pre> on this page gets for a shell command. */ |
| .changelog { white-space: pre-wrap; } |
| - select, input[type=text], input[type=search], input[type=email], input[type=number] { |
| + select, input[type=text], input[type=search], input[type=email], input[type=number], input[type=password] { |
| font: inherit; font-family: var(--sans); font-size: 0.9rem; color: var(--ink); background: var(--field); |
| border: 1px solid var(--rst-line-strong); border-radius: var(--rst-radius-sm); padding: 0.3rem 0.5rem; |
| box-shadow: var(--shadow-inset); |
| @@ -294,6 +294,9 @@ |
| .fields p { margin: 0; } |
| .fields label { display: block; font-size: 0.9rem; font-weight: 600; margin: 0 0 0.25rem; } |
| .fields :is(input, select) { width: 100%; box-sizing: border-box; } |
| + /* One labelled field in the .fields style (the transfer code), not |
| + stretched across a desktop. */ |
| + .fields.transfer-code { grid-template-columns: minmax(0, 24rem); } |
| /* Address rows wrap on a phone, so the app and its state chip are never |
| cut off. */ |
| .addr-rows .envvar > summary, .addr-rows .envvar-row { flex-wrap: wrap; row-gap: 0.3rem; } |
diff --git a/internal/console/templates/domain_buy.html b/internal/console/templates/domain_buy.html| index 456c2f993..ad997b761 100644 |
| --- a/internal/console/templates/domain_buy.html |
| +++ b/internal/console/templates/domain_buy.html |
| @@ -1,30 +1,9 @@ |
| {{define "domain_buy"}}{{template "top" .}} |
| +{{if and .DomainBuy .DomainBuy.Transfer}}{{template "transfer_card" .}}{{else}} |
| <h1>{{.DomainBuyCopy.title}}</h1> |
| {{with .DomainBuy}} |
| {{if .Purchase}} |
| -<style> |
| - .purchase-card { box-sizing: border-box; max-width: 36rem; margin: 1.5rem auto 0; padding: 1.8rem 1.8rem 1.4rem; border: 1px solid var(--rst-line); border-radius: 0.875rem; background: var(--accent-soft); color: var(--ink); overflow-wrap: anywhere; } |
| - .purchase-card [hidden] { display: none !important; } |
| - .purchase-card h2 { margin: 0 0 0.5rem; font-size: 1.5rem; line-height: 1.2; } |
| - .purchase-card .done-lede { margin: 0 0 1.2rem; font-size: 1.02rem; } |
| - .purchase-card .done-mark { width: 3rem; height: 3rem; margin-bottom: 0.8rem; background: var(--rst-tone-positive-bg); color: var(--good); } |
| - .purchase-card .done-actions { justify-content: flex-start; margin: 1.2rem 0 0; } |
| - .purchase-card.done .done-actions { justify-content: center; } |
| - .purchase-card .purchase-ownership, .purchase-card .purchase-error { margin: 0.9rem 0 0; color: var(--muted); font-size: 0.88rem; } |
| - .purchase-steps { list-style: none; margin: 0 0 1.2rem; padding: 0; display: grid; gap: 0.55rem; text-align: left; } |
| - .purchase-steps li { display: flex; align-items: center; gap: 0.6rem; } |
| - .purchase-steps [data-state="pending"] { color: var(--muted); } |
| - .purchase-step-mark { display: inline-grid; place-items: center; flex: none; width: 1.125rem; height: 1.125rem; color: var(--accent); } |
| - .purchase-steps [data-state="done"] .purchase-step-mark { color: var(--good); } |
| - .purchase-step-mark .icon { width: 1.125rem; height: 1.125rem; stroke-width: 2.6; } |
| - .purchase-steps li:not([data-state="done"]) .icon { display: none; } |
| - .purchase-steps [data-state="active"] .purchase-step-mark::before { content: ""; width: 1rem; height: 1rem; border: 2px solid var(--rst-line); border-top-color: var(--accent); border-radius: 50%; } |
| - .purchase-steps [data-state="pending"] .purchase-step-mark::before { content: ""; width: 0.625rem; height: 0.625rem; border: 2px solid var(--rst-line-strong); border-radius: 50%; } |
| - @media (prefers-reduced-motion: no-preference) { |
| - .purchase-steps [data-state="active"] .purchase-step-mark::before { animation: purchase-spin 1s linear infinite; } |
| - } |
| - @keyframes purchase-spin { to { transform: rotate(360deg); } } |
| -</style> |
| +{{template "purchase_card_style"}} |
| {{$done := or (eq .Card.Stage.Kind "live") (eq .Card.Stage.Kind "ready")}} |
| <section id="purchase-card" class="purchase-card{{if $done}} done{{end}}" aria-labelledby="purchase-title"> |
| <span id="purchase-status" class="visually-hidden" role="status" aria-live="polite">{{.Card.Status}}</span> |
| @@ -120,4 +99,111 @@ |
| </script> |
| {{end}} |
| {{end}} |
| +{{end}} |
| {{template "bottom" .}}{{end}} |
| + |
| +{{/* The purchase card's rules, shared by a purchase's card and a transfer's. */}} |
| +{{define "purchase_card_style"}}<style> |
| + .purchase-card { box-sizing: border-box; max-width: 36rem; margin: 1.5rem auto 0; padding: 1.8rem 1.8rem 1.4rem; border: 1px solid var(--rst-line); border-radius: 0.875rem; background: var(--accent-soft); color: var(--ink); overflow-wrap: anywhere; } |
| + .purchase-card [hidden] { display: none !important; } |
| + .purchase-card h2 { margin: 0 0 0.5rem; font-size: 1.5rem; line-height: 1.2; } |
| + .purchase-card .done-lede { margin: 0 0 1.2rem; font-size: 1.02rem; } |
| + .purchase-card .done-mark { width: 3rem; height: 3rem; margin-bottom: 0.8rem; background: var(--rst-tone-positive-bg); color: var(--good); } |
| + .purchase-card .done-actions { justify-content: flex-start; margin: 1.2rem 0 0; } |
| + .purchase-card.done .done-actions { justify-content: center; } |
| + .purchase-card .purchase-ownership, .purchase-card .purchase-error { margin: 0.9rem 0 0; color: var(--muted); font-size: 0.88rem; } |
| + .purchase-card .chips { margin: 0 0 0.8rem; } |
| + .purchase-steps { list-style: none; margin: 0 0 1.2rem; padding: 0; display: grid; gap: 0.55rem; text-align: left; } |
| + .purchase-steps li { display: flex; align-items: center; gap: 0.6rem; } |
| + .purchase-steps [data-state="pending"] { color: var(--muted); } |
| + .purchase-step-mark { display: inline-grid; place-items: center; flex: none; width: 1.125rem; height: 1.125rem; color: var(--accent); } |
| + .purchase-steps [data-state="done"] .purchase-step-mark { color: var(--good); } |
| + .purchase-step-mark .icon { width: 1.125rem; height: 1.125rem; stroke-width: 2.6; } |
| + .purchase-steps li:not([data-state="done"]) .icon { display: none; } |
| + .purchase-steps [data-state="active"] .purchase-step-mark::before { content: ""; width: 1rem; height: 1rem; border: 2px solid var(--rst-line); border-top-color: var(--accent); border-radius: 50%; } |
| + .purchase-steps [data-state="pending"] .purchase-step-mark::before { content: ""; width: 0.625rem; height: 0.625rem; border: 2px solid var(--rst-line-strong); border-radius: 50%; } |
| + @media (prefers-reduced-motion: no-preference) { |
| + .purchase-steps [data-state="active"] .purchase-step-mark::before { animation: purchase-spin 1s linear infinite; } |
| + } |
| + @keyframes purchase-spin { to { transform: rotate(360deg); } } |
| +</style>{{end}} |
| + |
| +{{/* A transfer in's card (transferCard): its steps while it moves, then |
| + done, or a failure shown as a state beside what happened to the money. |
| + The script polls a live transfer's status, moves between the stepped |
| + stages in place, and reloads for any other change, which the server |
| + draws. Called with the page. */}} |
| +{{define "transfer_card"}}{{$b := .DomainBuy}}{{$t := $b.Transfer}} |
| +<div class="pagehead"> |
| + <p class="eyebrow">{{$t.Eyebrow}}</p> |
| + <h1>{{$t.Heading}}</h1> |
| +</div> |
| +{{template "purchase_card_style"}} |
| +<section id="purchase-card" class="purchase-card{{if $t.Done}} done{{end}}" aria-labelledby="purchase-title"> |
| + <span id="purchase-status" class="visually-hidden" role="status" aria-live="polite">{{$t.Status}}</span> |
| + <div id="purchase-progress"> |
| + {{if $t.Done}}<span id="purchase-mark" class="done-mark" aria-hidden="true">{{icon "check"}}</span>{{end}} |
| + <h2 id="purchase-title">{{$t.Title}}</h2> |
| + {{with $t.Chips}}<p class="chips" id="purchase-chips">{{range .}}<span class="chip {{.Class}}">{{.Label}}</span>{{end}}</p>{{end}} |
| + <p id="purchase-lede" class="done-lede">{{$t.Lede}}</p> |
| + <ol id="purchase-steps" class="purchase-steps" {{if not $t.Steps}}hidden{{end}}> |
| + {{range $t.Steps}}<li data-state="{{.State}}" {{if eq .State "active"}}aria-current="step"{{end}}><span class="purchase-step-mark" aria-hidden="true">{{icon "check"}}</span><span class="purchase-step-label">{{.Label}}</span>{{if .When}} <time datetime="{{.WhenISO}}">{{.When}}</time>{{end}}</li>{{end}} |
| + </ol> |
| + <p id="purchase-note" class="small" {{if not $t.Note}}hidden{{end}}>{{$t.Note}}</p> |
| + <p id="purchase-error" class="purchase-error" hidden></p> |
| + </div> |
| + <div class="done-actions"> |
| + {{if and $b.CheckoutURL (eq $b.Purchase.State "awaiting_payment")}}<a id="purchase-continue" class="btn" href="{{$b.CheckoutURL}}">{{.DomainBuyCopy.continuePayment}}</a>{{end}} |
| + {{with $t.Primary}}<a id="purchase-primary" class="btn" href="{{.Href}}">{{.Label}}</a>{{end}} |
| + <a id="purchase-back" class="btn btn-secondary" href="{{$b.Back}}">{{.DomainBuyCopy.back}}</a> |
| + </div> |
| + {{with $t.Ownership}}<p class="purchase-ownership">{{.}}</p>{{end}} |
| +</section> |
| +{{if $t.Poll}}<script> |
| +(function () { |
| + const endpoint = {{$b.PollURL}}, live = {{$t.Live}}, pollError = {{$t.PollError}}; |
| + const title = document.getElementById('purchase-title'), lede = document.getElementById('purchase-lede'); |
| + const note = document.getElementById('purchase-note'), error = document.getElementById('purchase-error'); |
| + const steps = document.getElementById('purchase-steps'), status = document.getElementById('purchase-status'); |
| + const started = Date.now(); |
| + let state = {{$b.Purchase.State}}; |
| + // show draws a stepped stage in place. Its steps are always four. |
| + function show(stage) { |
| + title.textContent = stage.Title; |
| + lede.textContent = stage.Lede; |
| + note.textContent = stage.Note; |
| + note.hidden = !stage.Note; |
| + steps.hidden = false; |
| + steps.querySelectorAll('li').forEach((row, i) => { |
| + row.dataset.state = stage.Steps[i]; |
| + row.querySelector('.purchase-step-label').textContent = stage.Labels[i]; |
| + if (stage.Steps[i] === 'active') row.setAttribute('aria-current', 'step'); |
| + else row.removeAttribute('aria-current'); |
| + }); |
| + if (status.textContent !== stage.Status) status.textContent = stage.Status; |
| + } |
| + async function poll() { |
| + try { |
| + const response = await fetch(endpoint, {credentials: 'same-origin', cache: 'no-store'}); |
| + if (!response.ok) throw new Error(); |
| + const purchase = await response.json(); |
| + if (purchase.kind !== 'transfer' || typeof purchase.state !== 'string') throw new Error(); |
| + error.hidden = true; |
| + if (purchase.state !== state) { |
| + const drawn = Object.prototype.hasOwnProperty.call(live, state) && steps.querySelectorAll('li').length === 4; |
| + if (!drawn || !Object.prototype.hasOwnProperty.call(live, purchase.state)) { location.reload(); return; } |
| + state = purchase.state; |
| + show(live[state]); |
| + } |
| + } catch (_) { |
| + error.textContent = pollError; |
| + error.hidden = false; |
| + } |
| + const elapsed = Date.now() - started; |
| + if (elapsed >= 3600000) return; |
| + setTimeout(poll, Math.min(elapsed < 600000 ? 5000 : 60000, 3600000 - elapsed)); |
| + } |
| + poll(); |
| +})(); |
| +</script>{{end}} |
| +{{end}} |
diff --git a/internal/console/testdata/perf-budgets.txt b/internal/console/testdata/perf-budgets.txt| index a8f33febb..5c4d501e3 100644 |
| --- a/internal/console/testdata/perf-budgets.txt |
| +++ b/internal/console/testdata/perf-budgets.txt |
| @@ -106,6 +106,7 @@ GET /a/{sqid}/apps/{app}/instances over: cold, the app-tab frame, the account ma |
| GET /a/{sqid}/apps/{app}/instances/{host} over: cold, the app-tab frame, the account manifest and the metrics sweep beside the instance record, instances.json, the edges listing and the box and fleet box reports (119 S3 calls, about 505 ms, over 500 ms); a repeat view reads the last five (14 S3 calls, 210 to 325 ms) |
| GET /a/{sqid}/domains over: reads the account's domain claims (one listing and each claim), then for each app holding addresses what the Settings Domains section reads (claims, cert-warm records, box reports), no instance records (13 S3 calls on a repeat view, about 430 ms; cold 13, about 510 ms, over 500 ms) |
| GET /a/{sqid}/domains/{domain} over: the same reads as the Domains page, narrowed to the apps holding this domain's addresses (13 S3 calls on a repeat view, about 430 ms; cold 13, about 430 to 510 ms, at or over 500 ms on a slow run) |
| +GET /a/{sqid}/domains/transfer/{domain} over: the transfer form runs the start's own checks before any payment; the claim check (heldElsewhere) reads every box's edges file through deploymentRouteTaken once for the apex and again for www, one after another, plus each claim (35 S3 calls on every view, cold or repeat, about 1,015 ms, over 500 ms); reading the edges files once per check would halve it |
| GET /a/{sqid}/apps/{app}/settings/{section} over: Domains reads the domain claims, cert-warm records, every box report and every instance record (16 S3 calls on a repeat view, 430 to 470 ms; cold 24, about 555 ms, over 500 ms); every other section passes and reads only its own data on a repeat view: General 2 (cold 9), Environments 5 (12), Storage 4 (11), Email 1 (8), Feature flags 1 (8), Errors and analytics 2 (9), the pipeline section, Placement and Delete none (7); the advanced redirect none, warm or cold |
| POST /a/{sqid}/apps/{app}/promote over: promoting v2 to stable reads and writes 18 S3 objects, about 520 ms from the body read to the first byte, over 500 ms (console-slow-writes is speeding it up) |
diff --git a/parity/parity.tsv b/parity/parity.tsv| index 4c33283a1..355620dee 100644 |
| --- a/parity/parity.tsv |
| +++ b/parity/parity.tsv |
| @@ -88,6 +88,7 @@ domains-attach domains both domains attach ; domains detach POST /a/{sqid}/apps/ |
| domains-verify domains partial domains verify POST /a/{sqid}/apps/{app}/domains/attach There is no Verify button; attaching again verifies. |
| domains-buy domains both domains check ; domains buy GET /a/{sqid}/domains/buy ; POST /a/{sqid}/domains/buy/check ; POST /a/{sqid}/domains/buy ; GET /a/{sqid}/domains/purchases/{id} ; GET /a/{sqid}/domains/purchases/{id}/status ; GET /a/{sqid}/apps/{app}/domains/buy ; POST /a/{sqid}/apps/{app}/domains/check ; POST /a/{sqid}/apps/{app}/domains/buy ; GET /a/{sqid}/apps/{app}/domains/purchases/{id} ; GET /a/{sqid}/apps/{app}/domains/purchases/{id}/status The app-scoped routes only redirect to the account's. |
| domains-contacts domains both domains contacts list ; domains contacts add ; domains contacts edit ; domains contacts remove POST /a/{sqid}/domains/contacts ; POST /a/{sqid}/domains/contacts/{id} ; POST /a/{sqid}/domains/contacts/{id}/remove Saved contacts are added, edited and removed on the Domains page and with domains contacts; a purchase with no contact named uses the most recently used one. |
| +domains-transfer domains console-only GET /a/{sqid}/domains/transfer/{domain} ; POST /a/{sqid}/domains/transfer/{domain} Moving a domain registered elsewhere here (Move to Carloku): the form and its start; the move's card is the purchase card. No CLI command yet. |
| domains-point domains both domains point POST /a/{sqid}/apps/{app}/domains/point |
| domains-paths domains gap domains paths wp-settings |
| domains-placements domains gap domains placements wp-settings |