Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phortune/controller/PhortuneController.php
<?php | <?php | ||||
abstract class PhortuneController extends PhabricatorController { | abstract class PhortuneController extends PhabricatorController { | ||||
protected function addAccountCrumb( | |||||
$crumbs, | |||||
PhortuneAccount $account, | |||||
$link = true) { | |||||
$name = $account->getName(); | |||||
$href = null; | |||||
if ($link) { | |||||
$href = $this->getApplicationURI($account->getID().'/'); | |||||
$crumbs->addTextCrumb($name, $href); | |||||
} else { | |||||
$crumbs->addTextCrumb($name); | |||||
} | |||||
} | |||||
protected function addMerchantCrumb( | |||||
$crumbs, | |||||
PhortuneMerchant $merchant, | |||||
$link = true) { | |||||
$name = $merchant->getName(); | |||||
$href = null; | |||||
$crumbs->addTextCrumb( | |||||
pht('Merchants'), | |||||
$this->getApplicationURI('merchant/')); | |||||
if ($link) { | |||||
$href = $this->getApplicationURI('merchant/'.$merchant->getID().'/'); | |||||
$crumbs->addTextCrumb($name, $href); | |||||
} else { | |||||
$crumbs->addTextCrumb($name); | |||||
} | |||||
} | |||||
private function loadEnabledProvidersForMerchant(PhortuneMerchant $merchant) { | private function loadEnabledProvidersForMerchant(PhortuneMerchant $merchant) { | ||||
$viewer = $this->getRequest()->getUser(); | $viewer = $this->getRequest()->getUser(); | ||||
$provider_configs = id(new PhortunePaymentProviderConfigQuery()) | $provider_configs = id(new PhortunePaymentProviderConfigQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withMerchantPHIDs(array($merchant->getPHID())) | ->withMerchantPHIDs(array($merchant->getPHID())) | ||||
->execute(); | ->execute(); | ||||
$providers = mpull($provider_configs, 'buildProvider', 'getID'); | $providers = mpull($provider_configs, 'buildProvider', 'getID'); | ||||
Show All 30 Lines | foreach ($providers as $key => $provider) { | ||||
unset($providers[$key]); | unset($providers[$key]); | ||||
continue; | continue; | ||||
} | } | ||||
} | } | ||||
return $providers; | return $providers; | ||||
} | } | ||||
protected function loadMerchantAuthority() { | |||||
$request = $this->getRequest(); | |||||
$viewer = $this->getViewer(); | |||||
$is_merchant = (bool)$request->getURIData('merchantID'); | |||||
if (!$is_merchant) { | |||||
return null; | |||||
} | |||||
$merchant = id(new PhortuneMerchantQuery()) | |||||
->setViewer($viewer) | |||||
->withIDs(array($request->getURIData('merchantID'))) | |||||
->requireCapabilities( | |||||
array( | |||||
PhabricatorPolicyCapability::CAN_VIEW, | |||||
PhabricatorPolicyCapability::CAN_EDIT, | |||||
)) | |||||
->executeOne(); | |||||
if (!$merchant) { | |||||
return null; | |||||
} | |||||
$viewer->grantAuthority($merchant); | |||||
return $merchant; | |||||
} | |||||
} | } |