Differential D20719 Diff 49436 src/applications/phortune/controller/account/PhortuneAccountPaymentMethodListController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phortune/controller/account/PhortuneAccountPaymentMethodListController.php
- This file was moved from src/applications/phortune/controller/account/PhortuneAccountPaymentMethodsController.php.
<?php | <?php | ||||
final class PhortuneAccountPaymentMethodsController | final class PhortuneAccountPaymentMethodListController | ||||
extends PhortuneAccountProfileController { | extends PhortuneAccountProfileController { | ||||
protected function shouldRequireAccountEditCapability() { | protected function shouldRequireAccountEditCapability() { | ||||
return false; | return false; | ||||
} | } | ||||
protected function handleAccountRequest(AphrontRequest $request) { | protected function handleAccountRequest(AphrontRequest $request) { | ||||
$account = $this->getAccount(); | $account = $this->getAccount(); | ||||
Show All 29 Lines | private function buildPaymentMethodsSection(PhortuneAccount $account) { | ||||
$can_edit = PhabricatorPolicyFilter::hasCapability( | $can_edit = PhabricatorPolicyFilter::hasCapability( | ||||
$viewer, | $viewer, | ||||
$account, | $account, | ||||
PhabricatorPolicyCapability::CAN_EDIT); | PhabricatorPolicyCapability::CAN_EDIT); | ||||
$id = $account->getID(); | $id = $account->getID(); | ||||
// TODO: Allow adding a card here directly | |||||
$add = id(new PHUIButtonView()) | $add = id(new PHUIButtonView()) | ||||
->setTag('a') | ->setTag('a') | ||||
->setText(pht('New Payment Method')) | ->setText(pht('Add Payment Method')) | ||||
->setIcon('fa-plus') | ->setIcon('fa-plus') | ||||
->setHref($this->getApplicationURI("{$id}/card/new/")); | ->setHref($this->getApplicationURI("{$id}/card/new/")) | ||||
->setDisabled(!$can_edit) | |||||
->setWorkflow(!$can_edit); | |||||
$header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
->setHeader(pht('Payment Methods')); | ->setHeader(pht('Payment Methods')) | ||||
->addActionLink($add); | |||||
$list = id(new PHUIObjectItemListView()) | $list = id(new PHUIObjectItemListView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->setFlush(true) | ->setFlush(true) | ||||
->setNoDataString( | ->setNoDataString( | ||||
pht('There are no payment methods associated with this account.')); | pht('There are no payment methods associated with this account.')); | ||||
$methods = id(new PhortunePaymentMethodQuery()) | $methods = id(new PhortunePaymentMethodQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withAccountPHIDs(array($account->getPHID())) | ->withAccountPHIDs(array($account->getPHID())) | ||||
->withStatuses( | ->withStatuses( | ||||
array( | array( | ||||
PhortunePaymentMethod::STATUS_ACTIVE, | PhortunePaymentMethod::STATUS_ACTIVE, | ||||
)) | )) | ||||
->execute(); | ->execute(); | ||||
foreach ($methods as $method) { | foreach ($methods as $method) { | ||||
$id = $method->getID(); | $id = $method->getID(); | ||||
$item = new PHUIObjectItemView(); | $item = id(new PHUIObjectItemView()) | ||||
$item->setHeader($method->getFullDisplayName()); | ->setObjectName($method->getObjectName()) | ||||
->setHeader($method->getFullDisplayName()) | |||||
switch ($method->getStatus()) { | ->setHref($method->getURI()); | ||||
case PhortunePaymentMethod::STATUS_ACTIVE: | |||||
$item->setStatusIcon('fa-check green'); | |||||
$disable_uri = $this->getApplicationURI('card/'.$id.'/disable/'); | |||||
$item->addAction( | |||||
id(new PHUIListItemView()) | |||||
->setIcon('fa-times') | |||||
->setHref($disable_uri) | |||||
->setDisabled(!$can_edit) | |||||
->setWorkflow(true)); | |||||
break; | |||||
case PhortunePaymentMethod::STATUS_DISABLED: | |||||
$item->setStatusIcon('fa-ban lightbluetext'); | |||||
$item->setDisabled(true); | |||||
break; | |||||
} | |||||
$provider = $method->buildPaymentProvider(); | $provider = $method->buildPaymentProvider(); | ||||
$item->addAttribute($provider->getPaymentMethodProviderDescription()); | $item->addAttribute($provider->getPaymentMethodProviderDescription()); | ||||
$edit_uri = $this->getApplicationURI('card/'.$id.'/edit/'); | |||||
$item->addAction( | |||||
id(new PHUIListItemView()) | |||||
->setIcon('fa-pencil') | |||||
->setHref($edit_uri) | |||||
->setDisabled(!$can_edit) | |||||
->setWorkflow(!$can_edit)); | |||||
$list->addItem($item); | $list->addItem($item); | ||||
} | } | ||||
return id(new PHUIObjectBoxView()) | return id(new PHUIObjectBoxView()) | ||||
->setHeader($header) | ->setHeader($header) | ||||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ||||
->setObjectList($list); | ->setObjectList($list); | ||||
} | } | ||||
} | } |