Differential D20697 Diff 49430 src/applications/phortune/controller/account/PhortuneAccountPaymentMethodsController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phortune/controller/account/PhortuneAccountPaymentMethodsController.php
- This file was moved from src/applications/phortune/controller/account/PhortuneAccountBillingController.php.
<?php | <?php | ||||
final class PhortuneAccountBillingController | final class PhortuneAccountPaymentMethodsController | ||||
extends PhortuneAccountProfileController { | extends PhortuneAccountProfileController { | ||||
public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
$response = $this->loadAccount(); | $response = $this->loadAccount(); | ||||
if ($response) { | if ($response) { | ||||
return $response; | return $response; | ||||
} | } | ||||
$account = $this->getAccount(); | $account = $this->getAccount(); | ||||
$title = $account->getName(); | $title = $account->getName(); | ||||
$crumbs = $this->buildApplicationCrumbs(); | $crumbs = $this->buildApplicationCrumbs(); | ||||
$crumbs->addTextCrumb(pht('Billing')); | $crumbs->addTextCrumb(pht('Payment Methods')); | ||||
$header = $this->buildHeaderView(); | $header = $this->buildHeaderView(); | ||||
$methods = $this->buildPaymentMethodsSection($account); | $methods = $this->buildPaymentMethodsSection($account); | ||||
$charge_history = $this->buildChargeHistorySection($account); | |||||
$view = id(new PHUITwoColumnView()) | $view = id(new PHUITwoColumnView()) | ||||
->setHeader($header) | ->setHeader($header) | ||||
->setFooter(array( | ->setFooter( | ||||
array( | |||||
$methods, | $methods, | ||||
$charge_history, | |||||
)); | )); | ||||
$navigation = $this->buildSideNavView('billing'); | $navigation = $this->buildSideNavView('methods'); | ||||
return $this->newPage() | return $this->newPage() | ||||
->setTitle($title) | ->setTitle($title) | ||||
->setCrumbs($crumbs) | ->setCrumbs($crumbs) | ||||
->setNavigation($navigation) | ->setNavigation($navigation) | ||||
->appendChild($view); | ->appendChild($view); | ||||
} | } | ||||
Show All 17 Lines | private function buildPaymentMethodsSection(PhortuneAccount $account) { | ||||
$header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
->setHeader(pht('Payment Methods')); | ->setHeader(pht('Payment Methods')); | ||||
$list = id(new PHUIObjectItemListView()) | $list = id(new PHUIObjectItemListView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->setFlush(true) | ->setFlush(true) | ||||
->setNoDataString( | ->setNoDataString( | ||||
pht('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, | ||||
)) | )) | ||||
Show All 39 Lines | private function buildPaymentMethodsSection(PhortuneAccount $account) { | ||||
} | } | ||||
return id(new PHUIObjectBoxView()) | return id(new PHUIObjectBoxView()) | ||||
->setHeader($header) | ->setHeader($header) | ||||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ||||
->setObjectList($list); | ->setObjectList($list); | ||||
} | } | ||||
private function buildChargeHistorySection(PhortuneAccount $account) { | |||||
$viewer = $this->getViewer(); | |||||
$charges = id(new PhortuneChargeQuery()) | |||||
->setViewer($viewer) | |||||
->withAccountPHIDs(array($account->getPHID())) | |||||
->needCarts(true) | |||||
->setLimit(10) | |||||
->execute(); | |||||
$phids = array(); | |||||
foreach ($charges as $charge) { | |||||
$phids[] = $charge->getProviderPHID(); | |||||
$phids[] = $charge->getCartPHID(); | |||||
$phids[] = $charge->getMerchantPHID(); | |||||
$phids[] = $charge->getPaymentMethodPHID(); | |||||
} | |||||
$handles = $this->loadViewerHandles($phids); | |||||
$charges_uri = $this->getApplicationURI($account->getID().'/charge/'); | |||||
$table = id(new PhortuneChargeTableView()) | |||||
->setUser($viewer) | |||||
->setCharges($charges) | |||||
->setHandles($handles); | |||||
$header = id(new PHUIHeaderView()) | |||||
->setHeader(pht('Charge History')) | |||||
->addActionLink( | |||||
id(new PHUIButtonView()) | |||||
->setTag('a') | |||||
->setIcon('fa-list') | |||||
->setHref($charges_uri) | |||||
->setText(pht('View All Charges'))); | |||||
return id(new PHUIObjectBoxView()) | |||||
->setHeader($header) | |||||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | |||||
->setTable($table); | |||||
} | |||||
} | } |