Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / phortune / view / PhortuneOrderSummaryView.php
blob77152b9ff7f2caa3f9f9fee1d29a9c7159977f67
1 <?php
3 final class PhortuneOrderSummaryView
4 extends PhortuneOrderView {
6 private $resumeURI;
7 private $printable;
9 public function setResumeURI($resume_uri) {
10 $this->resumeURI = $resume_uri;
11 return $this;
14 public function getResumeURI() {
15 return $this->resumeURI;
18 public function setPrintable($printable) {
19 $this->printable = $printable;
20 return $this;
23 public function getPrintable() {
24 return $this->printable;
27 public function render() {
28 $is_printable = $this->getPrintable();
30 $content = array();
32 if ($is_printable) {
33 $content[] = $this->newContactHeader();
36 $content[] = $this->newMessagesView();
37 $content[] = $this->newDetailsView();
38 $content[] = $this->newDescriptionView();
39 $content[] = $this->newItemsView();
40 $content[] = $this->newChargesView();
42 if ($is_printable) {
43 $content[] = $this->newContactFooter();
46 return $content;
49 private function newMessagesView() {
50 $viewer = $this->getViewer();
51 $order = $this->getOrder();
53 $messages = array();
54 $severity = null;
56 $resume_uri = $this->getResumeURI();
58 $can_edit = PhabricatorPolicyFilter::hasCapability(
59 $viewer,
60 $order,
61 PhabricatorPolicyCapability::CAN_EDIT);
63 $can_merchant = PhabricatorPolicyFilter::hasCapability(
64 $viewer,
65 $order->getMerchant(),
66 PhabricatorPolicyCapability::CAN_EDIT);
68 switch ($order->getStatus()) {
69 case PhortuneCart::STATUS_READY:
70 if ($order->getIsInvoice()) {
71 $severity = PHUIInfoView::SEVERITY_NOTICE;
72 $messages[] = pht('This invoice is ready for payment.');
74 break;
75 case PhortuneCart::STATUS_PURCHASING:
76 if ($can_edit) {
77 if ($resume_uri) {
78 $messages[] = pht(
79 'The checkout process has been started, but not yet completed. '.
80 'You can continue checking out by clicking %s, or cancel the '.
81 'order, or contact the merchant for assistance.',
82 phutil_tag('strong', array(), pht('Continue Checkout')));
83 } else {
84 $messages[] = pht(
85 'The checkout process has been started, but an error occurred. '.
86 'You can cancel the order or contact the merchant for '.
87 'assistance.');
90 break;
91 case PhortuneCart::STATUS_CHARGED:
92 if ($can_edit) {
93 $messages[] = pht(
94 'You have been charged, but processing could not be completed. '.
95 'You can cancel your order, or contact the merchant for '.
96 'assistance.');
98 break;
99 case PhortuneCart::STATUS_HOLD:
100 if ($can_edit) {
101 $messages[] = pht(
102 'Payment for this order is on hold. You can click %s to check '.
103 'for updates, cancel the order, or contact the merchant for '.
104 'assistance.',
105 phutil_tag('strong', array(), pht('Update Status')));
107 break;
108 case PhortuneCart::STATUS_REVIEW:
109 if ($can_merchant) {
110 $messages[] = pht(
111 'This order has been flagged for manual review. Review the order '.
112 'and choose %s to accept it or %s to reject it.',
113 phutil_tag('strong', array(), pht('Accept Order')),
114 phutil_tag('strong', array(), pht('Refund Order')));
115 } else if ($can_edit) {
116 $messages[] = pht(
117 'This order requires manual processing and will complete once '.
118 'the merchant accepts it.');
120 break;
121 case PhortuneCart::STATUS_PURCHASED:
122 $severity = PHUIInfoView::SEVERITY_SUCCESS;
123 $messages[] = pht('This purchase has been completed.');
124 break;
127 if (!$messages) {
128 return null;
131 if ($severity === null) {
132 $severity = PHUIInfoView::SEVERITY_WARNING;
135 $messages_view = id(new PHUIInfoView())
136 ->setSeverity($severity)
137 ->appendChild($messages);
139 $is_printable = $this->getPrintable();
140 if ($is_printable) {
141 $messages_view = phutil_tag(
142 'div',
143 array(
144 'class' => 'phortune-invoice-status',
146 $messages_view);
149 return $messages_view;
152 private function newDetailsView() {
153 $viewer = $this->getViewer();
154 $order = $this->getOrder();
155 $is_printable = $this->getPrintable();
157 $view = id(new PHUIPropertyListView())
158 ->setViewer($viewer)
159 ->setObject($order);
161 $account_phid = $order->getAccountPHID();
162 $author_phid = $order->getAuthorPHID();
163 $merchant_phid = $order->getMerchantPHID();
165 $handles = $viewer->loadHandles(
166 array(
167 $account_phid,
168 $author_phid,
169 $merchant_phid,
172 if ($is_printable) {
173 $account_link = $handles[$account_phid]->getFullName();
174 $author_link = $handles[$author_phid]->getFullName();
175 $merchant_link = $handles[$merchant_phid]->getFullName();
176 } else {
177 $account_link = $handles[$account_phid]->renderLink();
178 $author_link = $handles[$author_phid]->renderLink();
179 $merchant_link = $handles[$merchant_phid]->renderLink();
182 if ($is_printable) {
183 $view->addProperty(pht('Order Name'), $order->getName());
186 $view->addProperty(pht('Account'), $account_link);
187 $view->addProperty(pht('Authorized By'), $author_link);
188 $view->addProperty(pht('Merchant'), $merchant_link);
190 $view->addProperty(
191 pht('Order Status'),
192 PhortuneCart::getNameForStatus($order->getStatus()));
193 $view->addProperty(
194 pht('Created'),
195 phabricator_datetime($order->getDateCreated(), $viewer));
196 $view->addProperty(
197 pht('Updated'),
198 phabricator_datetime($order->getDateModified(), $viewer));
200 return id(new PHUIObjectBoxView())
201 ->setHeaderText(pht('Details'))
202 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
203 ->appendChild($view);
206 private function newChargesView() {
207 $viewer = $this->getViewer();
208 $order = $this->getOrder();
210 $charges = id(new PhortuneChargeQuery())
211 ->setViewer($viewer)
212 ->withCartPHIDs(array($order->getPHID()))
213 ->needCarts(true)
214 ->execute();
216 $charges_table = id(new PhortuneChargeTableView())
217 ->setUser($viewer)
218 ->setCharges($charges)
219 ->setShowOrder(false);
221 $charges_view = id(new PHUIObjectBoxView())
222 ->setHeaderText(pht('Charges'))
223 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
224 ->setTable($charges_table);
226 return $charges_view;
229 private function newDescriptionView() {
230 $viewer = $this->getViewer();
231 $order = $this->getOrder();
233 return id(new PhortuneOrderDescriptionView())
234 ->setViewer($viewer)
235 ->setOrder($order);
238 private function newItemsView() {
239 $viewer = $this->getViewer();
240 $order = $this->getOrder();
242 return id(new PhortuneOrderItemsView())
243 ->setViewer($viewer)
244 ->setOrder($order);
247 private function newContactHeader() {
248 $viewer = $this->getViewer();
249 $order = $this->getOrder();
251 $merchant = id(new PhortuneMerchantQuery())
252 ->setViewer($viewer)
253 ->withPHIDs(array($order->getMerchant()->getPHID()))
254 ->needProfileImage(true)
255 ->executeOne();
257 $merchant_name = $merchant->getName();
258 $merchant_image = $merchant->getProfileImageURI();
260 $account = $order->getAccount();
261 $account_name = $account->getBillingName();
263 $account_contact = $account->getBillingAddress();
264 if (strlen($account_contact)) {
265 $account_contact = new PHUIRemarkupView(
266 $viewer,
267 $account_contact);
270 $merchant_contact = $merchant->getContactInfo();
271 if (strlen($merchant_contact)) {
272 $merchant_contact = new PHUIRemarkupView(
273 $viewer,
274 $merchant->getContactInfo());
277 $logo = phutil_tag(
278 'div',
279 array(
280 'class' => 'phortune-invoice-logo',
282 phutil_tag(
283 'img',
284 array(
285 'height' => '50',
286 'width' => '50',
287 'alt' => $merchant_name,
288 'src' => $merchant_image,
289 )));
291 $to_title = phutil_tag(
292 'div',
293 array(
294 'class' => 'phortune-mini-header',
296 pht('Bill To:'));
298 $bill_to = phutil_tag(
299 'td',
300 array(
301 'class' => 'phortune-invoice-to',
302 'width' => '50%',
304 array(
305 $to_title,
306 phutil_tag('strong', array(), $account_name),
307 phutil_tag('br', array()),
308 $account_contact,
311 $from_title = phutil_tag(
312 'div',
313 array(
314 'class' => 'phortune-mini-header',
316 pht('From:'));
318 $bill_from = phutil_tag(
319 'td',
320 array(
321 'class' => 'phortune-invoice-from',
322 'width' => '50%',
324 array(
325 $from_title,
326 phutil_tag('strong', array(), $merchant_name),
327 phutil_tag('br', array()),
328 $merchant_contact,
331 $contact = phutil_tag(
332 'table',
333 array(
334 'class' => 'phortune-invoice-contact',
335 'width' => '100%',
337 phutil_tag(
338 'tr',
339 array(),
340 array(
341 $bill_to,
342 $bill_from,
343 )));
345 return array(
346 $logo,
347 $contact,
351 private function newContactFooter() {
352 $viewer = $this->getViewer();
353 $order = $this->getOrder();
355 $merchant = $order->getMerchant();
356 $footer = $merchant->getInvoiceFooter();
358 if (!strlen($footer)) {
359 return null;
362 return phutil_tag(
363 'div',
364 array(
365 'class' => 'phortune-invoice-footer',
367 $footer);