@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 370 lines 9.7 kB view raw
1<?php 2 3final class PhortuneOrderSummaryView 4 extends PhortuneOrderView { 5 6 private $resumeURI; 7 private $printable; 8 9 public function setResumeURI($resume_uri) { 10 $this->resumeURI = $resume_uri; 11 return $this; 12 } 13 14 public function getResumeURI() { 15 return $this->resumeURI; 16 } 17 18 public function setPrintable($printable) { 19 $this->printable = $printable; 20 return $this; 21 } 22 23 public function getPrintable() { 24 return $this->printable; 25 } 26 27 public function render() { 28 $is_printable = $this->getPrintable(); 29 30 $content = array(); 31 32 if ($is_printable) { 33 $content[] = $this->newContactHeader(); 34 } 35 36 $content[] = $this->newMessagesView(); 37 $content[] = $this->newDetailsView(); 38 $content[] = $this->newDescriptionView(); 39 $content[] = $this->newItemsView(); 40 $content[] = $this->newChargesView(); 41 42 if ($is_printable) { 43 $content[] = $this->newContactFooter(); 44 } 45 46 return $content; 47 } 48 49 private function newMessagesView() { 50 $viewer = $this->getViewer(); 51 $order = $this->getOrder(); 52 53 $messages = array(); 54 $severity = null; 55 56 $resume_uri = $this->getResumeURI(); 57 58 $can_edit = PhabricatorPolicyFilter::hasCapability( 59 $viewer, 60 $order, 61 PhabricatorPolicyCapability::CAN_EDIT); 62 63 $can_merchant = PhabricatorPolicyFilter::hasCapability( 64 $viewer, 65 $order->getMerchant(), 66 PhabricatorPolicyCapability::CAN_EDIT); 67 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.'); 73 } 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.'); 88 } 89 } 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.'); 97 } 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'))); 106 } 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.'); 119 } 120 break; 121 case PhortuneCart::STATUS_PURCHASED: 122 $severity = PHUIInfoView::SEVERITY_SUCCESS; 123 $messages[] = pht('This purchase has been completed.'); 124 break; 125 } 126 127 if (!$messages) { 128 return null; 129 } 130 131 if ($severity === null) { 132 $severity = PHUIInfoView::SEVERITY_WARNING; 133 } 134 135 $messages_view = id(new PHUIInfoView()) 136 ->setSeverity($severity) 137 ->appendChild($messages); 138 139 $is_printable = $this->getPrintable(); 140 if ($is_printable) { 141 $messages_view = phutil_tag( 142 'div', 143 array( 144 'class' => 'phortune-invoice-status', 145 ), 146 $messages_view); 147 } 148 149 return $messages_view; 150 } 151 152 private function newDetailsView() { 153 $viewer = $this->getViewer(); 154 $order = $this->getOrder(); 155 $is_printable = $this->getPrintable(); 156 157 $view = id(new PHUIPropertyListView()) 158 ->setViewer($viewer) 159 ->setObject($order); 160 161 $account_phid = $order->getAccountPHID(); 162 $author_phid = $order->getAuthorPHID(); 163 $merchant_phid = $order->getMerchantPHID(); 164 165 $handles = $viewer->loadHandles( 166 array( 167 $account_phid, 168 $author_phid, 169 $merchant_phid, 170 )); 171 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(); 180 } 181 182 if ($is_printable) { 183 $view->addProperty(pht('Order Name'), $order->getName()); 184 } 185 186 $view->addProperty(pht('Account'), $account_link); 187 $view->addProperty(pht('Authorized By'), $author_link); 188 $view->addProperty(pht('Merchant'), $merchant_link); 189 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)); 199 200 return id(new PHUIObjectBoxView()) 201 ->setHeaderText(pht('Details')) 202 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 203 ->appendChild($view); 204 } 205 206 private function newChargesView() { 207 $viewer = $this->getViewer(); 208 $order = $this->getOrder(); 209 210 $charges = id(new PhortuneChargeQuery()) 211 ->setViewer($viewer) 212 ->withCartPHIDs(array($order->getPHID())) 213 ->needCarts(true) 214 ->execute(); 215 216 $charges_table = id(new PhortuneChargeTableView()) 217 ->setUser($viewer) 218 ->setCharges($charges) 219 ->setShowOrder(false); 220 221 $charges_view = id(new PHUIObjectBoxView()) 222 ->setHeaderText(pht('Charges')) 223 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 224 ->setTable($charges_table); 225 226 return $charges_view; 227 } 228 229 private function newDescriptionView() { 230 $viewer = $this->getViewer(); 231 $order = $this->getOrder(); 232 233 return id(new PhortuneOrderDescriptionView()) 234 ->setViewer($viewer) 235 ->setOrder($order); 236 } 237 238 private function newItemsView() { 239 $viewer = $this->getViewer(); 240 $order = $this->getOrder(); 241 242 return id(new PhortuneOrderItemsView()) 243 ->setViewer($viewer) 244 ->setOrder($order); 245 } 246 247 private function newContactHeader() { 248 $viewer = $this->getViewer(); 249 $order = $this->getOrder(); 250 251 $merchant = id(new PhortuneMerchantQuery()) 252 ->setViewer($viewer) 253 ->withPHIDs(array($order->getMerchant()->getPHID())) 254 ->needProfileImage(true) 255 ->executeOne(); 256 257 $merchant_name = $merchant->getName(); 258 $merchant_image = $merchant->getProfileImageURI(); 259 260 $account = $order->getAccount(); 261 $account_name = $account->getBillingName(); 262 263 $account_contact = $account->getBillingAddress(); 264 if (strlen($account_contact)) { 265 $account_contact = new PHUIRemarkupView( 266 $viewer, 267 $account_contact); 268 } 269 270 $merchant_contact = $merchant->getContactInfo(); 271 if (strlen($merchant_contact)) { 272 $merchant_contact = new PHUIRemarkupView( 273 $viewer, 274 $merchant->getContactInfo()); 275 } 276 277 $logo = phutil_tag( 278 'div', 279 array( 280 'class' => 'phortune-invoice-logo', 281 ), 282 phutil_tag( 283 'img', 284 array( 285 'height' => '50', 286 'width' => '50', 287 'alt' => $merchant_name, 288 'src' => $merchant_image, 289 ))); 290 291 $to_title = phutil_tag( 292 'div', 293 array( 294 'class' => 'phortune-mini-header', 295 ), 296 pht('Bill To:')); 297 298 $bill_to = phutil_tag( 299 'td', 300 array( 301 'class' => 'phortune-invoice-to', 302 'width' => '50%', 303 ), 304 array( 305 $to_title, 306 phutil_tag('strong', array(), $account_name), 307 phutil_tag('br', array()), 308 $account_contact, 309 )); 310 311 $from_title = phutil_tag( 312 'div', 313 array( 314 'class' => 'phortune-mini-header', 315 ), 316 pht('From:')); 317 318 $bill_from = phutil_tag( 319 'td', 320 array( 321 'class' => 'phortune-invoice-from', 322 'width' => '50%', 323 ), 324 array( 325 $from_title, 326 phutil_tag('strong', array(), $merchant_name), 327 phutil_tag('br', array()), 328 $merchant_contact, 329 )); 330 331 $contact = phutil_tag( 332 'table', 333 array( 334 'class' => 'phortune-invoice-contact', 335 'width' => '100%', 336 ), 337 phutil_tag( 338 'tr', 339 array(), 340 array( 341 $bill_to, 342 $bill_from, 343 ))); 344 345 return array( 346 $logo, 347 $contact, 348 ); 349 } 350 351 private function newContactFooter() { 352 $viewer = $this->getViewer(); 353 $order = $this->getOrder(); 354 355 $merchant = $order->getMerchant(); 356 $footer = $merchant->getInvoiceFooter(); 357 358 if (!strlen($footer)) { 359 return null; 360 } 361 362 return phutil_tag( 363 'div', 364 array( 365 'class' => 'phortune-invoice-footer', 366 ), 367 $footer); 368 } 369 370}