Skip to content

Commit a65244c

Browse files
author
epriestley
committed
Build a very basic subscription detail page in Phortune
Summary: Ref T6881. - Add a subscription detail page. Minor cosmetics: - Fix glyph, from "X" (old "X marks the spot" icon) to "diamond" (new gem icon). - Name the initial account "Default Account" instead of "Personal Account", since this seems more general. Test Plan: {F278623} And I got two full days to test that Jan 30/31 -> Feb 28 billing logic! Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T6881 Differential Revision: https://secure.phabricator.com/D11576
1 parent 4adc2d8 commit a65244c

12 files changed

+164
-17
lines changed

src/__phutil_library_map__.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2815,6 +2815,7 @@
28152815
'PhortuneSubscriptionQuery' => 'applications/phortune/query/PhortuneSubscriptionQuery.php',
28162816
'PhortuneSubscriptionSearchEngine' => 'applications/phortune/query/PhortuneSubscriptionSearchEngine.php',
28172817
'PhortuneSubscriptionTableView' => 'applications/phortune/view/PhortuneSubscriptionTableView.php',
2818+
'PhortuneSubscriptionViewController' => 'applications/phortune/controller/PhortuneSubscriptionViewController.php',
28182819
'PhortuneTestPaymentProvider' => 'applications/phortune/provider/PhortuneTestPaymentProvider.php',
28192820
'PhortuneWePayPaymentProvider' => 'applications/phortune/provider/PhortuneWePayPaymentProvider.php',
28202821
'PhragmentBrowseController' => 'applications/phragment/controller/PhragmentBrowseController.php',
@@ -6168,6 +6169,7 @@
61686169
'PhortuneSubscriptionQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
61696170
'PhortuneSubscriptionSearchEngine' => 'PhabricatorApplicationSearchEngine',
61706171
'PhortuneSubscriptionTableView' => 'AphrontView',
6172+
'PhortuneSubscriptionViewController' => 'PhortuneController',
61716173
'PhortuneTestPaymentProvider' => 'PhortunePaymentProvider',
61726174
'PhortuneWePayPaymentProvider' => 'PhortunePaymentProvider',
61736175
'PhragmentBrowseController' => 'PhragmentController',

src/applications/phortune/application/PhabricatorPhortuneApplication.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function getFontIcon() {
2323
}
2424

2525
public function getTitleGlyph() {
26-
return "\xE2\x9C\x98";
26+
return "\xE2\x97\x87";
2727
}
2828

2929
public function getApplicationGroup() {
@@ -45,8 +45,12 @@ public function getRoutes() {
4545
),
4646
'order/(?:query/(?P<queryKey>[^/]+)/)?'
4747
=> 'PhortuneCartListController',
48-
'subscription/(?:query/(?P<queryKey>[^/]+)/)?'
49-
=> 'PhortuneSubscriptionListController',
48+
'subscription/' => array(
49+
'(?:query/(?P<queryKey>[^/]+)/)?'
50+
=> 'PhortuneSubscriptionListController',
51+
'view/(?P<id>\d+)/'
52+
=> 'PhortuneSubscriptionViewController',
53+
),
5054
'charge/(?:query/(?P<queryKey>[^/]+)/)?'
5155
=> 'PhortuneChargeListController',
5256
),
@@ -81,8 +85,12 @@ public function getRoutes() {
8185
'edit/(?:(?P<id>\d+)/)?' => 'PhortuneMerchantEditController',
8286
'orders/(?P<merchantID>\d+)/(?:query/(?P<queryKey>[^/]+)/)?'
8387
=> 'PhortuneCartListController',
84-
'subscription/(?P<merchantID>\d+)/(?:query/(?P<queryKey>[^/]+)/)?'
85-
=> 'PhortuneSubscriptionListController',
88+
'(?P<merchantID>\d+)/subscription/' => array(
89+
'(?:query/(?P<queryKey>[^/]+)/)?'
90+
=> 'PhortuneSubscriptionListController',
91+
'view/(?P<id>\d+)/'
92+
=> 'PhortuneSubscriptionViewController',
93+
),
8694
'(?P<id>\d+)/' => 'PhortuneMerchantViewController',
8795
),
8896
),

src/applications/phortune/controller/PhortuneAccountViewController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ public function processRequest() {
3535
$title = $account->getName();
3636

3737
$crumbs = $this->buildApplicationCrumbs();
38-
$crumbs->addTextCrumb(
39-
$account->getName(),
40-
$request->getRequestURI());
38+
$this->addAccountCrumb($crumbs, $account, $link = false);
4139

4240
$header = id(new PHUIHeaderView())
4341
->setHeader($title);

src/applications/phortune/controller/PhortuneController.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ protected function addAccountCrumb(
77
PhortuneAccount $account,
88
$link = true) {
99

10-
$name = pht('Account');
10+
$name = $account->getName();
1111
$href = null;
1212

1313
if ($link) {
@@ -18,6 +18,26 @@ protected function addAccountCrumb(
1818
}
1919
}
2020

21+
protected function addMerchantCrumb(
22+
$crumbs,
23+
PhortuneMerchant $merchant,
24+
$link = true) {
25+
26+
$name = $merchant->getName();
27+
$href = null;
28+
29+
$crumbs->addTextCrumb(
30+
pht('Merchants'),
31+
$this->getApplicationURI('merchant/'));
32+
33+
if ($link) {
34+
$href = $this->getApplicationURI('merchant/'.$merchant->getID().'/');
35+
$crumbs->addTextCrumb($name, $href);
36+
} else {
37+
$crumbs->addTextCrumb($name);
38+
}
39+
}
40+
2141
private function loadEnabledProvidersForMerchant(PhortuneMerchant $merchant) {
2242
$viewer = $this->getRequest()->getUser();
2343

src/applications/phortune/controller/PhortuneMerchantViewController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ private function buildActionListView(PhortuneMerchant $merchant) {
190190
id(new PhabricatorActionView())
191191
->setName(pht('View Subscriptions'))
192192
->setIcon('fa-moon-o')
193-
->setHref($this->getApplicationURI("merchant/subscription/{$id}/"))
193+
->setHref($this->getApplicationURI("merchant/{$id}/subscription/"))
194194
->setDisabled(!$can_edit)
195195
->setWorkflow(!$can_edit));
196196

src/applications/phortune/controller/PhortuneSubscriptionListController.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ protected function buildApplicationCrumbs() {
8585
$merchant = $this->merchant;
8686
if ($merchant) {
8787
$id = $merchant->getID();
88-
$crumbs->addTextCrumb(
89-
$merchant->getName(),
90-
$this->getApplicationURI("merchant/{$id}/"));
88+
$this->addMerchantCrumb($crumbs, $merchant);
9189
$crumbs->addTextCrumb(
9290
pht('Subscriptions'),
9391
$this->getApplicationURI("merchant/subscriptions/{$id}/"));
@@ -96,9 +94,7 @@ protected function buildApplicationCrumbs() {
9694
$account = $this->account;
9795
if ($account) {
9896
$id = $account->getID();
99-
$crumbs->addTextCrumb(
100-
$account->getName(),
101-
$this->getApplicationURI("{$id}/"));
97+
$this->addAccountCrumb($crumbs, $account);
10298
$crumbs->addTextCrumb(
10399
pht('Subscriptions'),
104100
$this->getApplicationURI("{$id}/subscription/"));
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
final class PhortuneSubscriptionViewController extends PhortuneController {
4+
5+
public function handleRequest(AphrontRequest $request) {
6+
$viewer = $this->getViewer();
7+
8+
$subscription = id(new PhortuneSubscriptionQuery())
9+
->setViewer($viewer)
10+
->withIDs(array($request->getURIData('id')))
11+
->needTriggers(true)
12+
->executeOne();
13+
if (!$subscription) {
14+
return new Aphront404Response();
15+
}
16+
17+
$is_merchant = (bool)$request->getURIData('merchantID');
18+
19+
$title = pht('Subscription: %s', $subscription->getSubscriptionName());
20+
21+
$header = id(new PHUIHeaderView())
22+
->setHeader($subscription->getSubscriptionName());
23+
24+
$actions = id(new PhabricatorActionListView())
25+
->setUser($viewer)
26+
->setObjectURI($request->getRequestURI());
27+
28+
$crumbs = $this->buildApplicationCrumbs();
29+
if ($is_merchant) {
30+
$this->addMerchantCrumb($crumbs, $subscription->getMerchant());
31+
} else {
32+
$this->addAccountCrumb($crumbs, $subscription->getAccount());
33+
}
34+
$crumbs->addTextCrumb(pht('Subscription %d', $subscription->getID()));
35+
36+
$properties = id(new PHUIPropertyListView())
37+
->setUser($viewer)
38+
->setActionList($actions);
39+
40+
$next_invoice = $subscription->getTrigger()->getNextEventPrediction();
41+
$properties->addProperty(
42+
pht('Next Invoice'),
43+
phabricator_datetime($next_invoice, $viewer));
44+
45+
$object_box = id(new PHUIObjectBoxView())
46+
->setHeader($header)
47+
->addPropertyList($properties);
48+
49+
return $this->buildApplicationPage(
50+
array(
51+
$crumbs,
52+
$object_box,
53+
),
54+
array(
55+
'title' => $title,
56+
));
57+
}
58+
59+
}

src/applications/phortune/query/PhortuneSubscriptionQuery.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ final class PhortuneSubscriptionQuery
99
private $merchantPHIDs;
1010
private $statuses;
1111

12+
private $needTriggers;
13+
1214
public function withIDs(array $ids) {
1315
$this->ids = $ids;
1416
return $this;
@@ -34,6 +36,11 @@ public function withStatuses(array $statuses) {
3436
return $this;
3537
}
3638

39+
public function needTriggers($need_triggers) {
40+
$this->needTriggers = $need_triggers;
41+
return $this;
42+
}
43+
3744
protected function loadPage() {
3845
$table = new PhortuneSubscription();
3946
$conn = $table->establishConnection('r');
@@ -102,6 +109,24 @@ protected function willFilterPage(array $subscriptions) {
102109
$subscription->attachImplementation($implementation);
103110
}
104111

112+
if ($this->needTriggers) {
113+
$trigger_phids = mpull($subscriptions, 'getTriggerPHID');
114+
$triggers = id(new PhabricatorWorkerTriggerQuery())
115+
->setViewer($this->getViewer())
116+
->withPHIDs($trigger_phids)
117+
->needEvents(true)
118+
->execute();
119+
$triggers = mpull($triggers, null, 'getPHID');
120+
foreach ($subscriptions as $key => $subscription) {
121+
$trigger = idx($triggers, $subscription->getTriggerPHID());
122+
if (!$trigger) {
123+
unset($subscriptions[$key]);
124+
continue;
125+
}
126+
$subscription->attachTrigger($trigger);
127+
}
128+
}
129+
105130
return $subscriptions;
106131
}
107132

src/applications/phortune/query/PhortuneSubscriptionSearchEngine.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ protected function renderResultList(
144144
$merchant = $this->getMerchant();
145145
if ($merchant) {
146146
$header = pht('Subscriptions for %s', $merchant->getName());
147+
$table->setIsMerchantView(true);
147148
} else {
148149
$header = pht('Your Subscriptions');
149150
}

src/applications/phortune/storage/PhortuneAccount.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static function createNewAccount(
3232
$xactions = array();
3333
$xactions[] = id(new PhortuneAccountTransaction())
3434
->setTransactionType(PhortuneAccountTransaction::TYPE_NAME)
35-
->setNewValue(pht('Personal Account'));
35+
->setNewValue(pht('Default Account'));
3636

3737
$xactions[] = id(new PhortuneAccountTransaction())
3838
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)

src/applications/phortune/storage/PhortuneSubscription.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public function save() {
153153
),
154154
));
155155

156+
$trigger->setPHID($trigger_phid);
156157
$trigger->setAction($trigger_action);
157158
$trigger->save();
158159
}
@@ -165,6 +166,19 @@ public function getSubscriptionName() {
165166
return $this->getImplementation()->getName($this);
166167
}
167168

169+
public function getURI() {
170+
$account_id = $this->getAccount()->getID();
171+
$id = $this->getID();
172+
173+
return "/phortune/{$account_id}/subscription/view/{$id}/";
174+
}
175+
176+
public function getMerchantURI() {
177+
$merchant_id = $this->getMerchant()->getID();
178+
$id = $this->getID();
179+
return "/phortune/merchant/{$merchant_id}/subscription/view/{$id}/";
180+
}
181+
168182

169183
/* -( PhabricatorPolicyInterface )----------------------------------------- */
170184

src/applications/phortune/view/PhortuneSubscriptionTableView.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ final class PhortuneSubscriptionTableView extends AphrontView {
44

55
private $subscriptions;
66
private $handles;
7+
private $isMerchantView;
78

89
public function setHandles(array $handles) {
910
$this->handles = $handles;
@@ -23,6 +24,15 @@ public function getSubscriptions() {
2324
return $this->subscriptions;
2425
}
2526

27+
public function setIsMerchantView($is_merchant_view) {
28+
$this->isMerchantView = $is_merchant_view;
29+
return $this;
30+
}
31+
32+
public function getIsMerchantView() {
33+
return $this->isMerchantView;
34+
}
35+
2636
public function render() {
2737
$subscriptions = $this->getSubscriptions();
2838
$handles = $this->getHandles();
@@ -31,9 +41,21 @@ public function render() {
3141
$rows = array();
3242
$rowc = array();
3343
foreach ($subscriptions as $subscription) {
44+
if ($this->getIsMerchantView()) {
45+
$uri = $subscription->getMerchantURI();
46+
} else {
47+
$uri = $subscription->getURI();
48+
}
49+
3450
$subscription_link = $handles[$subscription->getPHID()]->renderLink();
3551
$rows[] = array(
3652
$subscription->getID(),
53+
phutil_tag(
54+
'a',
55+
array(
56+
'href' => $uri,
57+
),
58+
$subscription->getSubscriptionName()),
3759
phabricator_datetime($subscription->getDateCreated(), $viewer),
3860
);
3961
}
@@ -42,11 +64,13 @@ public function render() {
4264
->setHeaders(
4365
array(
4466
pht('ID'),
67+
pht('Name'),
4568
pht('Created'),
4669
))
4770
->setColumnClasses(
4871
array(
4972
'',
73+
'wide',
5074
'right',
5175
));
5276

0 commit comments

Comments
 (0)