@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 154 lines 4.2 kB view raw
1<?php 2 3final class PhortuneAccountPaymentMethodViewController 4 extends PhortuneAccountController { 5 6 protected function shouldRequireAccountEditCapability() { 7 return false; 8 } 9 10 protected function handleAccountRequest(AphrontRequest $request) { 11 $viewer = $this->getViewer(); 12 $account = $this->getAccount(); 13 14 $method = id(new PhortunePaymentMethodQuery()) 15 ->setViewer($viewer) 16 ->withAccountPHIDs(array($account->getPHID())) 17 ->withIDs(array($request->getURIData('id'))) 18 ->withStatuses( 19 array( 20 PhortunePaymentMethod::STATUS_ACTIVE, 21 )) 22 ->executeOne(); 23 if (!$method) { 24 return new Aphront404Response(); 25 } 26 27 $crumbs = $this->buildApplicationCrumbs() 28 ->addTextCrumb(pht('Payment Methods'), $account->getPaymentMethodsURI()) 29 ->addTextCrumb($method->getObjectName()) 30 ->setBorder(true); 31 32 $header = id(new PHUIHeaderView()) 33 ->setHeader($method->getFullDisplayName()); 34 35 $details = $this->newDetailsView($method); 36 37 $timeline = $this->buildTransactionTimeline( 38 $method, 39 new PhortunePaymentMethodTransactionQuery()); 40 $timeline->setShouldTerminate(true); 41 42 $autopay = $this->newAutopayView($method); 43 44 $curtain = $this->buildCurtainView($method); 45 46 $view = id(new PHUITwoColumnView()) 47 ->setHeader($header) 48 ->setCurtain($curtain) 49 ->setMainColumn( 50 array( 51 $details, 52 $autopay, 53 $timeline, 54 )); 55 56 return $this->newPage() 57 ->setTitle($method->getObjectName()) 58 ->setCrumbs($crumbs) 59 ->appendChild($view); 60 } 61 62 private function buildCurtainView(PhortunePaymentMethod $method) { 63 $viewer = $this->getViewer(); 64 65 $can_edit = PhabricatorPolicyFilter::hasCapability( 66 $viewer, 67 $method, 68 PhabricatorPolicyCapability::CAN_EDIT); 69 70 $edit_uri = $this->getApplicationURI( 71 urisprintf( 72 'card/%d/edit/', 73 $method->getID())); 74 75 $remove_uri = $this->getApplicationURI( 76 urisprintf( 77 'card/%d/disable/', 78 $method->getID())); 79 80 $curtain = $this->newCurtainView($method); 81 82 $curtain->addAction( 83 id(new PhabricatorActionView()) 84 ->setName(pht('Edit Payment Method')) 85 ->setIcon('fa-pencil') 86 ->setHref($edit_uri) 87 ->setDisabled(!$can_edit) 88 ->setWorkflow(!$can_edit)); 89 90 $curtain->addAction( 91 id(new PhabricatorActionView()) 92 ->setName(pht('Remove Payment Method')) 93 ->setIcon('fa-times') 94 ->setHref($remove_uri) 95 ->setDisabled(!$can_edit) 96 ->setWorkflow(true)); 97 98 return $curtain; 99 } 100 101 private function newDetailsView(PhortunePaymentMethod $method) { 102 $viewer = $this->getViewer(); 103 104 $merchant_phid = $method->getMerchantPHID(); 105 $handles = $viewer->loadHandles( 106 array( 107 $merchant_phid, 108 )); 109 110 $view = id(new PHUIPropertyListView()) 111 ->setUser($viewer); 112 113 if (strlen($method->getName())) { 114 $view->addProperty(pht('Name'), $method->getDisplayName()); 115 } 116 117 $view->addProperty(pht('Summary'), $method->getSummary()); 118 $view->addProperty(pht('Expires'), $method->getDisplayExpires()); 119 120 $view->addProperty( 121 pht('Merchant'), 122 $handles[$merchant_phid]->renderLink()); 123 124 return id(new PHUIObjectBoxView()) 125 ->setHeaderText(pht('Payment Method Details')) 126 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 127 ->addPropertyList($view); 128 } 129 130 private function newAutopayView(PhortunePaymentMethod $method) { 131 $viewer = $this->getViewer(); 132 133 $subscriptions = id(new PhortuneSubscriptionQuery()) 134 ->setViewer($viewer) 135 ->withPaymentMethodPHIDs(array($method->getPHID())) 136 ->execute(); 137 138 $table = id(new PhortuneSubscriptionTableView()) 139 ->setViewer($viewer) 140 ->setSubscriptions($subscriptions) 141 ->newTableView(); 142 143 $table->setNoDataString( 144 pht( 145 'This payment method is not the default payment method for '. 146 'any subscriptions.')); 147 148 return id(new PHUIObjectBoxView()) 149 ->setHeaderText(pht('Autopay Subscriptions')) 150 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 151 ->setTable($table); 152 } 153 154}