1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00

Update Phortune Merchant UI to bring it in line with Account UI

Summary:
Depends on D20732. Ref T13366. This generally makes the "Merchant" UI look and work like the "Payment Account" UI.

This is mostly simpler since the permissions have largely been sorted out already and there's less going on here and less weirdness around view/edit policies.

Test Plan: Browsed all Merchant functions as a merchant member and non-member.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13366

Differential Revision: https://secure.phabricator.com/D20733
This commit is contained in:
epriestley 2019-08-22 16:58:12 -07:00
parent c93ac91dc6
commit 9bcd683c08
36 changed files with 1122 additions and 749 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_phortune.phortune_merchant
DROP viewPolicy;

View file

@ -5271,7 +5271,6 @@ phutil_register_library_map(array(
'PhortuneCartController' => 'applications/phortune/controller/cart/PhortuneCartController.php',
'PhortuneCartEditor' => 'applications/phortune/editor/PhortuneCartEditor.php',
'PhortuneCartImplementation' => 'applications/phortune/cart/PhortuneCartImplementation.php',
'PhortuneCartListController' => 'applications/phortune/controller/cart/PhortuneCartListController.php',
'PhortuneCartPHIDType' => 'applications/phortune/phid/PhortuneCartPHIDType.php',
'PhortuneCartQuery' => 'applications/phortune/query/PhortuneCartQuery.php',
'PhortuneCartReplyHandler' => 'applications/phortune/mail/PhortuneCartReplyHandler.php',
@ -5304,6 +5303,7 @@ phutil_register_library_map(array(
'PhortuneMerchantContactInfoTransaction' => 'applications/phortune/xaction/PhortuneMerchantContactInfoTransaction.php',
'PhortuneMerchantController' => 'applications/phortune/controller/merchant/PhortuneMerchantController.php',
'PhortuneMerchantDescriptionTransaction' => 'applications/phortune/xaction/PhortuneMerchantDescriptionTransaction.php',
'PhortuneMerchantDetailsController' => 'applications/phortune/controller/merchant/PhortuneMerchantDetailsController.php',
'PhortuneMerchantEditController' => 'applications/phortune/controller/merchant/PhortuneMerchantEditController.php',
'PhortuneMerchantEditEngine' => 'applications/phortune/editor/PhortuneMerchantEditEngine.php',
'PhortuneMerchantEditor' => 'applications/phortune/editor/PhortuneMerchantEditor.php',
@ -5313,18 +5313,26 @@ phutil_register_library_map(array(
'PhortuneMerchantInvoiceEmailTransaction' => 'applications/phortune/xaction/PhortuneMerchantInvoiceEmailTransaction.php',
'PhortuneMerchantInvoiceFooterTransaction' => 'applications/phortune/xaction/PhortuneMerchantInvoiceFooterTransaction.php',
'PhortuneMerchantListController' => 'applications/phortune/controller/merchant/PhortuneMerchantListController.php',
'PhortuneMerchantManagerController' => 'applications/phortune/controller/merchant/PhortuneMerchantManagerController.php',
'PhortuneMerchantManagersController' => 'applications/phortune/controller/merchant/PhortuneMerchantManagersController.php',
'PhortuneMerchantNameTransaction' => 'applications/phortune/xaction/PhortuneMerchantNameTransaction.php',
'PhortuneMerchantOrderListController' => 'applications/phortune/controller/merchant/PhortuneMerchantOrderListController.php',
'PhortuneMerchantOrdersController' => 'applications/phortune/controller/merchant/PhortuneMerchantOrdersController.php',
'PhortuneMerchantOverviewController' => 'applications/phortune/controller/merchant/PhortuneMerchantOverviewController.php',
'PhortuneMerchantPHIDType' => 'applications/phortune/phid/PhortuneMerchantPHIDType.php',
'PhortuneMerchantPictureController' => 'applications/phortune/controller/merchant/PhortuneMerchantPictureController.php',
'PhortuneMerchantPictureTransaction' => 'applications/phortune/xaction/PhortuneMerchantPictureTransaction.php',
'PhortuneMerchantProfileController' => 'applications/phortune/controller/merchant/PhortuneMerchantProfileController.php',
'PhortuneMerchantProviderDisableController' => 'applications/phortune/controller/merchant/PhortuneMerchantProviderDisableController.php',
'PhortuneMerchantProviderEditController' => 'applications/phortune/controller/merchant/PhortuneMerchantProviderEditController.php',
'PhortuneMerchantProviderViewController' => 'applications/phortune/controller/merchant/PhortuneMerchantProviderViewController.php',
'PhortuneMerchantProvidersController' => 'applications/phortune/controller/merchant/PhortuneMerchantProvidersController.php',
'PhortuneMerchantQuery' => 'applications/phortune/query/PhortuneMerchantQuery.php',
'PhortuneMerchantSearchEngine' => 'applications/phortune/query/PhortuneMerchantSearchEngine.php',
'PhortuneMerchantSubscriptionListController' => 'applications/phortune/controller/merchant/PhortuneMerchantSubscriptionListController.php',
'PhortuneMerchantSubscriptionsController' => 'applications/phortune/controller/merchant/PhortuneMerchantSubscriptionsController.php',
'PhortuneMerchantTransaction' => 'applications/phortune/storage/PhortuneMerchantTransaction.php',
'PhortuneMerchantTransactionQuery' => 'applications/phortune/query/PhortuneMerchantTransactionQuery.php',
'PhortuneMerchantTransactionType' => 'applications/phortune/xaction/PhortuneMerchantTransactionType.php',
'PhortuneMerchantViewController' => 'applications/phortune/controller/merchant/PhortuneMerchantViewController.php',
'PhortuneMonthYearExpiryControl' => 'applications/phortune/control/PhortuneMonthYearExpiryControl.php',
'PhortuneOrderTableView' => 'applications/phortune/view/PhortuneOrderTableView.php',
'PhortunePayPalPaymentProvider' => 'applications/phortune/provider/PhortunePayPalPaymentProvider.php',
@ -5356,8 +5364,6 @@ phutil_register_library_map(array(
'PhortuneProductQuery' => 'applications/phortune/query/PhortuneProductQuery.php',
'PhortuneProductViewController' => 'applications/phortune/controller/product/PhortuneProductViewController.php',
'PhortuneProviderActionController' => 'applications/phortune/controller/provider/PhortuneProviderActionController.php',
'PhortuneProviderDisableController' => 'applications/phortune/controller/provider/PhortuneProviderDisableController.php',
'PhortuneProviderEditController' => 'applications/phortune/controller/provider/PhortuneProviderEditController.php',
'PhortunePurchase' => 'applications/phortune/storage/PhortunePurchase.php',
'PhortunePurchasePHIDType' => 'applications/phortune/phid/PhortunePurchasePHIDType.php',
'PhortunePurchaseQuery' => 'applications/phortune/query/PhortunePurchaseQuery.php',
@ -11847,7 +11853,6 @@ phutil_register_library_map(array(
'PhortuneCartController' => 'PhortuneController',
'PhortuneCartEditor' => 'PhabricatorApplicationTransactionEditor',
'PhortuneCartImplementation' => 'Phobject',
'PhortuneCartListController' => 'PhortuneController',
'PhortuneCartPHIDType' => 'PhabricatorPHIDType',
'PhortuneCartQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhortuneCartReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
@ -11883,32 +11888,41 @@ phutil_register_library_map(array(
'PhabricatorApplicationTransactionInterface',
'PhabricatorPolicyInterface',
),
'PhortuneMerchantAddManagerController' => 'PhortuneController',
'PhortuneMerchantAddManagerController' => 'PhortuneMerchantController',
'PhortuneMerchantCapability' => 'PhabricatorPolicyCapability',
'PhortuneMerchantContactInfoTransaction' => 'PhortuneMerchantTransactionType',
'PhortuneMerchantController' => 'PhortuneController',
'PhortuneMerchantDescriptionTransaction' => 'PhortuneMerchantTransactionType',
'PhortuneMerchantEditController' => 'PhortuneMerchantController',
'PhortuneMerchantDetailsController' => 'PhortuneMerchantProfileController',
'PhortuneMerchantEditController' => 'PhortuneController',
'PhortuneMerchantEditEngine' => 'PhabricatorEditEngine',
'PhortuneMerchantEditor' => 'PhabricatorApplicationTransactionEditor',
'PhortuneMerchantHasAccountEdgeType' => 'PhabricatorEdgeType',
'PhortuneMerchantHasMemberEdgeType' => 'PhabricatorEdgeType',
'PhortuneMerchantInvoiceCreateController' => 'PhortuneMerchantProfileController',
'PhortuneMerchantInvoiceCreateController' => 'PhortuneMerchantController',
'PhortuneMerchantInvoiceEmailTransaction' => 'PhortuneMerchantTransactionType',
'PhortuneMerchantInvoiceFooterTransaction' => 'PhortuneMerchantTransactionType',
'PhortuneMerchantListController' => 'PhortuneMerchantController',
'PhortuneMerchantManagerController' => 'PhortuneMerchantProfileController',
'PhortuneMerchantListController' => 'PhortuneController',
'PhortuneMerchantManagersController' => 'PhortuneMerchantProfileController',
'PhortuneMerchantNameTransaction' => 'PhortuneMerchantTransactionType',
'PhortuneMerchantOrderListController' => 'PhortuneMerchantProfileController',
'PhortuneMerchantOrdersController' => 'PhortuneMerchantProfileController',
'PhortuneMerchantOverviewController' => 'PhortuneMerchantProfileController',
'PhortuneMerchantPHIDType' => 'PhabricatorPHIDType',
'PhortuneMerchantPictureController' => 'PhortuneMerchantProfileController',
'PhortuneMerchantPictureController' => 'PhortuneMerchantController',
'PhortuneMerchantPictureTransaction' => 'PhortuneMerchantTransactionType',
'PhortuneMerchantProfileController' => 'PhortuneController',
'PhortuneMerchantProfileController' => 'PhortuneMerchantController',
'PhortuneMerchantProviderDisableController' => 'PhortuneMerchantController',
'PhortuneMerchantProviderEditController' => 'PhortuneMerchantController',
'PhortuneMerchantProviderViewController' => 'PhortuneMerchantController',
'PhortuneMerchantProvidersController' => 'PhortuneMerchantProfileController',
'PhortuneMerchantQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhortuneMerchantSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhortuneMerchantSubscriptionListController' => 'PhortuneMerchantProfileController',
'PhortuneMerchantSubscriptionsController' => 'PhortuneMerchantProfileController',
'PhortuneMerchantTransaction' => 'PhabricatorModularTransaction',
'PhortuneMerchantTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'PhortuneMerchantTransactionType' => 'PhabricatorModularTransactionType',
'PhortuneMerchantViewController' => 'PhortuneMerchantProfileController',
'PhortuneMonthYearExpiryControl' => 'AphrontFormControl',
'PhortuneOrderTableView' => 'AphrontView',
'PhortunePayPalPaymentProvider' => 'PhortunePaymentProvider',
@ -11953,8 +11967,6 @@ phutil_register_library_map(array(
'PhortuneProductQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhortuneProductViewController' => 'PhortuneController',
'PhortuneProviderActionController' => 'PhortuneController',
'PhortuneProviderDisableController' => 'PhortuneMerchantController',
'PhortuneProviderEditController' => 'PhortuneMerchantController',
'PhortunePurchase' => array(
'PhortuneDAO',
'PhabricatorPolicyInterface',

View file

@ -103,36 +103,40 @@ final class PhabricatorPhortuneApplication extends PhabricatorApplication {
=> 'PhortuneProviderActionController',
),
'merchant/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?' => 'PhortuneMerchantListController',
'picture/(?:(?P<id>\d+)/)?' => 'PhortuneMerchantPictureController',
$this->getQueryRoutePattern()
=> 'PhortuneMerchantListController',
$this->getEditRoutePattern('edit/')
=> 'PhortuneMerchantEditController',
'orders/(?P<merchantID>\d+)/(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PhortuneCartListController',
'manager/' => array(
'(?:(?P<id>\d+)/)?' => 'PhortuneMerchantManagerController',
'add/(?:(?P<id>\d+)/)?' => 'PhortuneMerchantAddManagerController',
),
'(?P<merchantID>\d+)/' => array(
'cart/(?P<id>\d+)/' => array(
'' => 'PhortuneCartViewController',
'(?P<action>cancel|refund)/' => 'PhortuneCartCancelController',
'update/' => 'PhortuneCartUpdateController',
'accept/' => 'PhortuneCartAcceptController',
'' => 'PhortuneMerchantOverviewController',
'details/' => 'PhortuneMerchantDetailsController',
'providers/' => array(
'' => 'PhortuneMerchantProvidersController',
'(?P<providerID>\d+)/' => array(
'' => 'PhortuneMerchantProviderViewController',
'disable/' => 'PhortuneMerchantProviderDisableController',
),
$this->getEditRoutePattern('edit/')
=> 'PhortuneMerchantProviderEditController',
),
'subscription/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PhortuneSubscriptionListController',
'view/(?P<id>\d+)/'
=> 'PhortuneAccountSubscriptionViewController',
'order/(?P<subscriptionID>\d+)/'
=> 'PhortuneCartListController',
'orders/' => array(
'' => 'PhortuneMerchantOrdersController',
$this->getQueryRoutePattern('list/')
=> 'PhortuneMerchantOrderListController',
),
'invoice/' => array(
'new/' => 'PhortuneMerchantInvoiceCreateController',
'picture/' => array(
'edit/' => 'PhortuneMerchantPictureController',
),
'subscriptions/' => array(
'' => 'PhortuneMerchantSubscriptionsController',
$this->getQueryRoutePattern('list/')
=> 'PhortuneMerchantSubscriptionListController',
),
'managers/' => array(
'' => 'PhortuneMerchantManagersController',
'new/' => 'PhortuneMerchantAddManagerController',
),
),
'(?P<id>\d+)/' => 'PhortuneMerchantViewController',
),
),
);

View file

@ -11,7 +11,7 @@ final class PhortuneLandingController extends PhortuneController {
if (count($accounts) == 1) {
$account = head($accounts);
$next_uri = $this->getApplicationURI($account->getID().'/');
$next_uri = $account->getURI();
} else {
$next_uri = $this->getApplicationURI('account/');
}

View file

@ -50,7 +50,6 @@ final class PhortuneAccountEmailViewController
->setTitle($address->getObjectName())
->setCrumbs($crumbs)
->appendChild($view);
}
private function buildCurtainView(PhortuneAccountEmail $address) {

View file

@ -38,7 +38,7 @@ final class PhortuneAccountListController extends PhortuneController {
$item = id(new PHUIObjectItemView())
->setSubhead(pht('Account %d', $account->getID()))
->setHeader($account->getName())
->setHref($this->getApplicationURI($account->getID().'/'))
->setHref($account->getURI())
->setObject($account)
->setImageIcon('fa-user-circle');

View file

@ -44,11 +44,8 @@ final class PhortuneAccountOrderListController
$subscription->getURI());
} else if ($this->hasAccount()) {
$account = $this->getAccount();
$id = $account->getID();
$crumbs->addTextCrumb(
pht('Orders'),
$account->getOrdersURI());
$crumbs->addTextCrumb(pht('Orders'), $account->getOrdersURI());
}
return $crumbs;

View file

@ -66,22 +66,11 @@ final class PhortuneAccountOverviewController
$viewer = $this->getViewer();
$phids = array();
foreach ($carts as $cart) {
$phids[] = $cart->getPHID();
$phids[] = $cart->getMerchantPHID();
foreach ($cart->getPurchases() as $purchase) {
$phids[] = $purchase->getPHID();
}
}
$handles = $this->loadViewerHandles($phids);
$table = id(new PhortuneOrderTableView())
->setNoDataString(pht('You have no unpaid invoices.'))
->setIsInvoices(true)
->setUser($viewer)
->setCarts($carts)
->setHandles($handles);
->setCarts($carts);
$header = id(new PHUIHeaderView())
->setHeader(pht('Invoices Due'));

View file

@ -117,21 +117,11 @@ abstract class PhortuneAccountProfileController
->setLimit($limit)
->execute();
$phids = array();
foreach ($carts as $cart) {
$phids[] = $cart->getPHID();
foreach ($cart->getPurchases() as $purchase) {
$phids[] = $purchase->getPHID();
}
}
$handles = $this->loadViewerHandles($phids);
$orders_uri = $account->getOrderListURI();
$table = id(new PhortuneOrderTableView())
->setUser($viewer)
->setCarts($carts)
->setHandles($handles);
->setCarts($carts);
$header = id(new PHUIHeaderView())
->setHeader(pht('Recent Orders'))

View file

@ -92,21 +92,10 @@ final class PhortuneAccountSubscriptionViewController
->withInvoices(true)
->execute();
$phids = array();
foreach ($invoices as $invoice) {
$phids[] = $invoice->getPHID();
$phids[] = $invoice->getMerchantPHID();
foreach ($invoice->getPurchases() as $purchase) {
$phids[] = $purchase->getPHID();
}
}
$handles = $this->loadViewerHandles($phids);
$invoice_table = id(new PhortuneOrderTableView())
->setUser($viewer)
->setCarts($invoices)
->setIsInvoices(true)
->setHandles($handles);
->setIsInvoices(true);
$invoice_header = id(new PHUIHeaderView())
->setHeader(pht('Invoices Due'));
@ -135,19 +124,9 @@ final class PhortuneAccountSubscriptionViewController
->setLimit(50)
->execute();
$phids = array();
foreach ($invoices as $invoice) {
$phids[] = $invoice->getPHID();
foreach ($invoice->getPurchases() as $purchase) {
$phids[] = $purchase->getPHID();
}
}
$handles = $this->loadViewerHandles($phids);
$invoice_table = id(new PhortuneOrderTableView())
->setUser($viewer)
->setCarts($invoices)
->setHandles($handles);
->setCarts($invoices);
$account = $subscription->getAccount();
$merchant = $subscription->getMerchant();

View file

@ -1,134 +0,0 @@
<?php
final class PhortuneCartListController
extends PhortuneController {
private $merchant;
private $account;
private $subscription;
private $engine;
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$merchant_id = $request->getURIData('merchantID');
$account_id = $request->getURIData('accountID');
$subscription_id = $request->getURIData('subscriptionID');
$engine = id(new PhortuneCartSearchEngine())
->setViewer($viewer);
if ($merchant_id) {
$merchant = id(new PhortuneMerchantQuery())
->setViewer($viewer)
->withIDs(array($merchant_id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$merchant) {
return new Aphront404Response();
}
$this->merchant = $merchant;
$viewer->grantAuthority($merchant);
$engine->setMerchant($merchant);
} else if ($account_id) {
$account = id(new PhortuneAccountQuery())
->setViewer($viewer)
->withIDs(array($account_id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$account) {
return new Aphront404Response();
}
$this->account = $account;
$engine->setAccount($account);
} else {
return new Aphront404Response();
}
// NOTE: We must process this after processing the merchant authority, so
// it becomes visible in merchant contexts.
if ($subscription_id) {
$subscription = id(new PhortuneSubscriptionQuery())
->setViewer($viewer)
->withIDs(array($subscription_id))
->executeOne();
if (!$subscription) {
return new Aphront404Response();
}
$this->subscription = $subscription;
$engine->setSubscription($subscription);
}
$this->engine = $engine;
$controller = id(new PhabricatorApplicationSearchController())
->setQueryKey($request->getURIData('queryKey'))
->setSearchEngine($engine)
->setNavigation($this->buildSideNavView());
return $this->delegateToController($controller);
}
public function buildSideNavView() {
$viewer = $this->getRequest()->getUser();
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
$this->engine->addNavigationItems($nav->getMenu());
$nav->selectFilter(null);
return $nav;
}
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$subscription = $this->subscription;
$merchant = $this->merchant;
if ($merchant) {
$id = $merchant->getID();
$this->addMerchantCrumb($crumbs, $merchant);
if (!$subscription) {
$crumbs->addTextCrumb(
pht('Orders'),
$this->getApplicationURI("merchant/orders/{$id}/"));
}
}
$account = $this->account;
if ($account) {
$id = $account->getID();
$this->addAccountCrumb($crumbs, $account);
if (!$subscription) {
$crumbs->addTextCrumb(
pht('Orders'),
$this->getApplicationURI("{$id}/order/"));
}
}
if ($subscription) {
if ($merchant) {
$subscription_uri = $subscription->getMerchantURI();
} else {
$subscription_uri = $subscription->getURI();
}
$crumbs->addTextCrumb(
$subscription->getSubscriptionName(),
$subscription_uri);
}
return $crumbs;
}
}

View file

@ -1,32 +1,23 @@
<?php
final class PhortuneMerchantAddManagerController extends PhortuneController {
final class PhortuneMerchantAddManagerController
extends PhortuneMerchantController {
public function handleRequest(AphrontRequest $request) {
protected function shouldRequireMerchantEditCapability() {
return true;
}
protected function handleMerchantRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$merchant = id(new PhortuneMerchantQuery())
->setViewer($viewer)
->withIDs(array($id))
->needProfileImage(true)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$merchant) {
return new Aphront404Response();
}
$merchant = $this->getMerchant();
$v_members = array();
$e_members = null;
$merchant_uri = $this->getApplicationURI("/merchant/manager/{$id}/");
$merchant_uri = $merchant->getManagersURI();
if ($request->isFormPost()) {
if ($request->isFormOrHiSecPost()) {
$xactions = array();
$v_members = $request->getArr('memberPHIDs');
$v_members = $request->getArr('managerPHIDs');
$type_edge = PhabricatorTransactions::TYPE_EDGE;
$xactions[] = id(new PhortuneMerchantTransaction())
@ -59,13 +50,13 @@ final class PhortuneMerchantAddManagerController extends PhortuneController {
->appendControl(
id(new AphrontFormTokenizerControl())
->setDatasource(new PhabricatorPeopleDatasource())
->setLabel(pht('Members'))
->setName('memberPHIDs')
->setLabel(pht('New Managers'))
->setName('managerPHIDs')
->setValue($v_members)
->setError($e_members));
return $this->newDialog()
->setTitle(pht('Add New Manager'))
->setTitle(pht('Add New Managers'))
->appendForm($form)
->setWidth(AphrontDialogView::WIDTH_FORM)
->addCancelButton($merchant_uri)

View file

@ -3,11 +3,80 @@
abstract class PhortuneMerchantController
extends PhortuneController {
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$crumbs->addTextCrumb(
pht('Merchants'),
$this->getApplicationURI('merchant/'));
return $crumbs;
private $merchant;
final protected function setMerchant(PhortuneMerchant $merchant) {
$this->merchant = $merchant;
return $this;
}
final protected function getMerchant() {
return $this->merchant;
}
final protected function hasMerchant() {
return (bool)$this->merchant;
}
final public function handleRequest(AphrontRequest $request) {
if ($this->shouldRequireMerchantEditCapability()) {
$response = $this->loadMerchantForEdit();
} else {
$response = $this->loadMerchantForView();
}
if ($response) {
return $response;
}
return $this->handleMerchantRequest($request);
}
abstract protected function shouldRequireMerchantEditCapability();
abstract protected function handleMerchantRequest(AphrontRequest $request);
private function loadMerchantForEdit() {
return $this->loadMerchantWithCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
));
}
private function loadMerchantForView() {
return $this->loadMerchantWithCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
));
}
private function loadMerchantWithCapabilities(array $capabilities) {
$viewer = $this->getViewer();
$request = $this->getRequest();
$merchant_id = $request->getURIData('merchantID');
if (!$merchant_id) {
throw new Exception(
pht(
'Controller ("%s") extends controller "%s", but is reachable '.
'with no "merchantID" in URI.',
get_class($this),
__CLASS__));
}
$merchant = id(new PhortuneMerchantQuery())
->setViewer($viewer)
->withIDs(array($merchant_id))
->needProfileImage(true)
->requireCapabilities($capabilities)
->executeOne();
if (!$merchant) {
return new Aphront404Response();
}
$this->setMerchant($merchant);
return null;
}
}

View file

@ -0,0 +1,151 @@
<?php
final class PhortuneMerchantDetailsController
extends PhortuneMerchantProfileController {
protected function shouldRequireMerchantEditCapability() {
return true;
}
protected function handleMerchantRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$merchant = $this->getMerchant();
$crumbs = $this->buildApplicationCrumbs()
->addTextCrumb(pht('Account Details'))
->setBorder(true);
$header = $this->buildHeaderView();
$title = pht(
'%s %s',
$merchant->getObjectName(),
$merchant->getName());
$details = $this->buildDetailsView($merchant);
$curtain = $this->buildCurtainView($merchant);
$timeline = $this->buildTransactionTimeline(
$merchant,
new PhortuneMerchantTransactionQuery());
$timeline->setShouldTerminate(true);
$navigation = $this->buildSideNavView('details');
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setCurtain($curtain)
->setMainColumn(array(
$details,
$timeline,
));
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->setNavigation($navigation)
->appendChild($view);
}
private function buildDetailsView(PhortuneMerchant $merchant) {
$viewer = $this->getViewer();
$view = id(new PHUIPropertyListView())
->setUser($viewer)
->setObject($merchant);
$invoice_from = $merchant->getInvoiceEmail();
if (!$invoice_from) {
$invoice_from = pht('No email address set');
$invoice_from = phutil_tag('em', array(), $invoice_from);
}
$view->addProperty(pht('Invoice From'), $invoice_from);
$description = $merchant->getDescription();
if (strlen($description)) {
$description = new PHUIRemarkupView($viewer, $description);
$view->addSectionHeader(
pht('Description'),
PHUIPropertyListView::ICON_SUMMARY);
$view->addTextContent($description);
}
$contact_info = $merchant->getContactInfo();
if (strlen($contact_info)) {
$contact_info = new PHUIRemarkupView($viewer, $contact_info);
$view->addSectionHeader(
pht('Contact Information'),
PHUIPropertyListView::ICON_SUMMARY);
$view->addTextContent($contact_info);
}
$footer_info = $merchant->getInvoiceFooter();
if (strlen($footer_info)) {
$footer_info = new PHUIRemarkupView($viewer, $footer_info);
$view->addSectionHeader(
pht('Invoice Footer'),
PHUIPropertyListView::ICON_SUMMARY);
$view->addTextContent($footer_info);
}
return id(new PHUIObjectBoxView())
->setHeaderText(pht('Details'))
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->appendChild($view);
}
private function buildCurtainView(PhortuneMerchant $merchant) {
$viewer = $this->getRequest()->getUser();
$id = $merchant->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$merchant,
PhabricatorPolicyCapability::CAN_EDIT);
$curtain = $this->newCurtainView($merchant);
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Merchant'))
->setIcon('fa-pencil')
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit)
->setHref($this->getApplicationURI("merchant/edit/{$id}/")));
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Logo'))
->setIcon('fa-picture-o')
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit)
->setHref($this->getApplicationURI("merchant/{$id}/picture/edit/")));
$member_phids = $merchant->getMemberPHIDs();
$handles = $viewer->loadHandles($member_phids);
$member_list = id(new PHUIObjectItemListView())
->setSimple(true);
foreach ($member_phids as $member_phid) {
$image_uri = $handles[$member_phid]->getImageURI();
$image_href = $handles[$member_phid]->getURI();
$person = $handles[$member_phid];
$member = id(new PHUIObjectItemView())
->setImageURI($image_uri)
->setHref($image_href)
->setHeader($person->getFullName());
$member_list->addItem($member);
}
$curtain->newPanel()
->setHeaderText(pht('Managers'))
->appendChild($member_list);
return $curtain;
}
}

View file

@ -1,7 +1,7 @@
<?php
final class PhortuneMerchantEditController
extends PhortuneMerchantController {
extends PhortuneController {
public function handleRequest(AphrontRequest $request) {
return id(new PhortuneMerchantEditEngine())

View file

@ -1,9 +1,16 @@
<?php
final class PhortuneMerchantInvoiceCreateController
extends PhortuneMerchantProfileController {
extends PhortuneMerchantController {
protected function shouldRequireMerchantEditCapability() {
return true;
}
protected function handleMerchantRequest(AphrontRequest $request) {
// TODO: Make this work again, or destroy it.
return new Aphront404Response();
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getUser();
$merchant = $this->loadMerchantAuthority();

View file

@ -1,37 +1,12 @@
<?php
final class PhortuneMerchantListController
extends PhortuneMerchantController {
public function shouldAllowPublic() {
return true;
}
extends PhortuneController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$querykey = $request->getURIData('queryKey');
$controller = id(new PhabricatorApplicationSearchController())
->setQueryKey($querykey)
->setSearchEngine(new PhortuneMerchantSearchEngine())
->setNavigation($this->buildSideNavView());
return $this->delegateToController($controller);
}
public function buildSideNavView() {
$viewer = $this->getViewer();
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
id(new PhortuneMerchantSearchEngine())
->setViewer($viewer)
->addNavigationItems($nav->getMenu());
$nav->selectFilter(null);
return $nav;
return id(new PhortuneMerchantSearchEngine())
->setController($this)
->buildResponse();
}
protected function buildApplicationCrumbs() {

View file

@ -1,35 +1,29 @@
<?php
final class PhortuneMerchantManagerController
final class PhortuneMerchantManagersController
extends PhortuneMerchantProfileController {
public function handleRequest(AphrontRequest $request) {
protected function shouldRequireMerchantEditCapability() {
return false;
}
protected function handleMerchantRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$merchant = $this->getMerchant();
$merchant = id(new PhortuneMerchantQuery())
->setViewer($viewer)
->withIDs(array($id))
->needProfileImage(true)
->executeOne();
if (!$merchant) {
return new Aphront404Response();
}
$this->setMerchant($merchant);
$header = $this->buildHeaderView();
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Managers'));
$crumbs = $this->buildApplicationCrumbs()
->addTextCrumb(pht('Managers'))
->setBorder(true);
$header = $this->buildHeaderView();
$members = $this->buildMembersSection($merchant);
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setFooter(array(
$members,
));
->setFooter(
array(
$members,
));
$navigation = $this->buildSideNavView('managers');
@ -38,7 +32,6 @@ final class PhortuneMerchantManagerController
->setCrumbs($crumbs)
->setNavigation($navigation)
->appendChild($view);
}
private function buildMembersSection(PhortuneMerchant $merchant) {
@ -51,12 +44,18 @@ final class PhortuneMerchantManagerController
$id = $merchant->getID();
$add_uri = urisprintf(
'merchant/%d/managers/new/',
$merchant->getID());
$add_uri = $this->getApplicationURI($add_uri);
$add = id(new PHUIButtonView())
->setTag('a')
->setText(pht('New Manager'))
->setIcon('fa-plus')
->setWorkflow(true)
->setHref("/phortune/merchant/manager/add/{$id}/");
->setDisabled(!$can_edit)
->setHref($add_uri);
$header = id(new PHUIHeaderView())
->setHeader(pht('Merchant Account Managers'))

View file

@ -0,0 +1,55 @@
<?php
final class PhortuneMerchantOrderListController
extends PhortuneMerchantProfileController {
private $subscription;
protected function shouldRequireMerchantEditCapability() {
return true;
}
protected function handleMerchantRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$merchant = $this->getMerchant();
$engine = id(new PhortuneCartSearchEngine())
->setController($this)
->setMerchant($merchant);
$subscription_id = $request->getURIData('subscriptionID');
if ($subscription_id) {
$subscription = id(new PhortuneSubscriptionQuery())
->setViewer($viewer)
->withIDs(array($subscription_id))
->executeOne();
if (!$subscription) {
return new Aphront404Response();
}
$engine->setSubscription($subscription);
$this->subscription = $subscription;
}
return $engine->buildResponse();
}
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$subscription = $this->subscription;
if ($subscription) {
$crumbs->addTextCrumb(
$subscription->getObjectName(),
$subscription->getURI());
} else if ($this->hasMerchant()) {
$merchant = $this->getMerchant();
$crumbs->addTextCrumb(pht('Orders'), $merchant->getOrdersURI());
}
return $crumbs;
}
}

View file

@ -0,0 +1,78 @@
<?php
final class PhortuneMerchantOrdersController
extends PhortuneMerchantProfileController {
protected function shouldRequireMerchantEditCapability() {
return true;
}
protected function handleMerchantRequest(AphrontRequest $request) {
$merchant = $this->getMerchant();
$title = $merchant->getName();
$crumbs = $this->buildApplicationCrumbs()
->addTextCrumb(pht('Orders'))
->setBorder(true);
$header = $this->buildHeaderView();
$order_history = $this->newRecentOrdersView($merchant, 100);
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setFooter(
array(
$order_history,
));
$navigation = $this->buildSideNavView('orders');
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->setNavigation($navigation)
->appendChild($view);
}
private function newRecentOrdersView(
PhortuneMerchant $merchant,
$limit) {
$viewer = $this->getViewer();
$carts = id(new PhortuneCartQuery())
->setViewer($viewer)
->withMerchantPHIDs(array($merchant->getPHID()))
->needPurchases(true)
->withStatuses(
array(
PhortuneCart::STATUS_PURCHASING,
PhortuneCart::STATUS_CHARGED,
PhortuneCart::STATUS_HOLD,
PhortuneCart::STATUS_REVIEW,
PhortuneCart::STATUS_PURCHASED,
))
->setLimit($limit)
->execute();
$orders_uri = $merchant->getOrderListURI();
$table = id(new PhortuneOrderTableView())
->setUser($viewer)
->setCarts($carts);
$header = id(new PHUIHeaderView())
->setHeader(pht('Recent Orders'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setIcon('fa-list')
->setHref($orders_uri)
->setText(pht('View All Orders')));
return id(new PHUIObjectBoxView())
->setHeader($header)
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->setTable($table);
}
}

View file

@ -0,0 +1,136 @@
<?php
final class PhortuneMerchantOverviewController
extends PhortuneMerchantProfileController {
protected function shouldRequireMerchantEditCapability() {
return false;
}
protected function handleMerchantRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$merchant = $this->getMerchant();
$crumbs = $this->buildApplicationCrumbs()
->setBorder(true);
$header = $this->buildHeaderView();
$title = pht(
'%s %s',
$merchant->getObjectName(),
$merchant->getName());
$providers = id(new PhortunePaymentProviderConfigQuery())
->setViewer($viewer)
->withMerchantPHIDs(array($merchant->getPHID()))
->execute();
$details = $this->buildDetailsView($merchant, $providers);
$navigation = $this->buildSideNavView('overview');
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setFooter(
array(
$details,
));
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->setNavigation($navigation)
->appendChild($view);
}
private function buildDetailsView(
PhortuneMerchant $merchant,
array $providers) {
$viewer = $this->getRequest()->getUser();
$view = id(new PHUIPropertyListView())
->setUser($viewer)
->setObject($merchant);
$status_view = new PHUIStatusListView();
$have_any = false;
$any_test = false;
foreach ($providers as $provider_config) {
$provider = $provider_config->buildProvider();
if ($provider->isEnabled()) {
$have_any = true;
}
if (!$provider->isAcceptingLivePayments()) {
$any_test = true;
}
}
if ($have_any) {
$status_view->addItem(
id(new PHUIStatusItemView())
->setIcon(PHUIStatusItemView::ICON_ACCEPT, 'green')
->setTarget(pht('Accepts Payments'))
->setNote(pht('This merchant can accept payments.')));
if ($any_test) {
$status_view->addItem(
id(new PHUIStatusItemView())
->setIcon(PHUIStatusItemView::ICON_WARNING, 'yellow')
->setTarget(pht('Test Mode'))
->setNote(pht('This merchant is accepting test payments.')));
} else {
$status_view->addItem(
id(new PHUIStatusItemView())
->setIcon(PHUIStatusItemView::ICON_ACCEPT, 'green')
->setTarget(pht('Live Mode'))
->setNote(pht('This merchant is accepting live payments.')));
}
} else if ($providers) {
$status_view->addItem(
id(new PHUIStatusItemView())
->setIcon(PHUIStatusItemView::ICON_REJECT, 'red')
->setTarget(pht('No Enabled Providers'))
->setNote(
pht(
'All of the payment providers for this merchant are '.
'disabled.')));
} else {
$status_view->addItem(
id(new PHUIStatusItemView())
->setIcon(PHUIStatusItemView::ICON_WARNING, 'yellow')
->setTarget(pht('No Providers'))
->setNote(
pht(
'This merchant does not have any payment providers configured '.
'yet, so it can not accept payments. Add a provider.')));
}
$view->addProperty(pht('Status'), $status_view);
$description = $merchant->getDescription();
if (strlen($description)) {
$description = new PHUIRemarkupView($viewer, $description);
$view->addSectionHeader(
pht('Description'),
PHUIPropertyListView::ICON_SUMMARY);
$view->addTextContent($description);
}
$contact_info = $merchant->getContactInfo();
if (strlen($contact_info)) {
$contact_info = new PHUIRemarkupView($viewer, $contact_info);
$view->addSectionHeader(
pht('Contact Information'),
PHUIPropertyListView::ICON_SUMMARY);
$view->addTextContent($contact_info);
}
return id(new PHUIObjectBoxView())
->setHeaderText(pht('Details'))
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->appendChild($view);
}
}

View file

@ -1,28 +1,17 @@
<?php
final class PhortuneMerchantPictureController
extends PhortuneMerchantProfileController {
extends PhortuneMerchantController {
public function handleRequest(AphrontRequest $request) {
protected function shouldRequireMerchantEditCapability() {
return true;
}
protected function handleMerchantRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$merchant = $this->getMerchant();
$merchant = id(new PhortuneMerchantQuery())
->setViewer($viewer)
->withIDs(array($id))
->needProfileImage(true)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$merchant) {
return new Aphront404Response();
}
$this->setMerchant($merchant);
$uri = $merchant->getURI();
$uri = $merchant->getDetailsURI();
$supported_formats = PhabricatorFile::getTransformableImageFormats();
$e_file = true;
@ -222,12 +211,9 @@ final class PhortuneMerchantPictureController
$upload_box,
));
$navigation = $this->buildSideNavView();
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->setNavigation($navigation)
->appendChild(
array(
$view,

View file

@ -1,22 +1,7 @@
<?php
abstract class PhortuneMerchantProfileController
extends PhortuneController {
private $merchant;
public function setMerchant(PhortuneMerchant $merchant) {
$this->merchant = $merchant;
return $this;
}
public function getMerchant() {
return $this->merchant;
}
public function buildApplicationMenu() {
return $this->buildSideNavView()->getMenu();
}
extends PhortuneMerchantController {
protected function buildHeaderView() {
$viewer = $this->getViewer();
@ -26,20 +11,20 @@ abstract class PhortuneMerchantProfileController
$header = id(new PHUIHeaderView())
->setHeader($title)
->setUser($viewer)
->setPolicyObject($merchant)
->setImage($merchant->getProfileImageURI());
return $header;
}
protected function buildApplicationCrumbs() {
$merchant = $this->getMerchant();
$id = $merchant->getID();
$merchant_uri = $this->getApplicationURI("/merchant/{$id}/");
$crumbs = parent::buildApplicationCrumbs();
$crumbs->addTextCrumb($merchant->getName(), $merchant_uri);
$crumbs->setBorder(true);
if ($this->hasMerchant()) {
$merchant = $this->getMerchant();
$merchant_uri = $merchant->getURI();
$crumbs->addTextCrumb($merchant->getName(), $merchant_uri);
}
return $crumbs;
}
@ -58,31 +43,47 @@ abstract class PhortuneMerchantProfileController
$nav->addLabel(pht('Merchant'));
$nav->addFilter(
'overview',
pht('Overview'),
$this->getApplicationURI("/merchant/{$id}/"),
'fa-building-o');
$nav->newLink('overview')
->setName(pht('Overview'))
->setHref($merchant->getURI())
->setIcon('fa-building-o');
if ($can_edit) {
$nav->addFilter(
'orders',
pht('Orders'),
$this->getApplicationURI("merchant/orders/{$id}/"),
'fa-retweet');
$nav->newLink('details')
->setName(pht('Account Details'))
->setHref($merchant->getDetailsURI())
->setIcon('fa-address-card-o')
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit);
$nav->addFilter(
'subscriptions',
pht('Subscriptions'),
$this->getApplicationURI("merchant/{$id}/subscription/"),
'fa-shopping-cart');
$nav->addLabel(pht('Payments'));
$nav->addFilter(
'managers',
pht('Managers'),
$this->getApplicationURI("/merchant/manager/{$id}/"),
'fa-group');
}
$nav->newLink('providers')
->setName(pht('Payment Providers'))
->setHref($merchant->getPaymentProvidersURI())
->setIcon('fa-credit-card')
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit);
$nav->newLink('orders')
->setName(pht('Orders'))
->setHref($merchant->getOrdersURI())
->setIcon('fa-shopping-bag')
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit);
$nav->newLink('subscriptions')
->setName(pht('Subscriptions'))
->setHref($merchant->getSubscriptionsURI())
->setIcon('fa-retweet')
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit);
$nav->addLabel(pht('Personnel'));
$nav->newLink('managers')
->setName(pht('Managers'))
->setHref($merchant->getManagersURI())
->setIcon('fa-group');
$nav->selectFilter($filter);

View file

@ -1,11 +1,17 @@
<?php
final class PhortuneProviderDisableController
final class PhortuneMerchantProviderDisableController
extends PhortuneMerchantController {
public function handleRequest(AphrontRequest $request) {
protected function shouldRequireMerchantEditCapability() {
return true;
}
protected function handleMerchantRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$merchant = $this->getMerchant();
$id = $request->getURIData('providerID');
$provider_config = id(new PhortunePaymentProviderConfigQuery())
->setViewer($viewer)
@ -20,9 +26,8 @@ final class PhortuneProviderDisableController
return new Aphront404Response();
}
$merchant = $provider_config->getMerchant();
$merchant_id = $merchant->getID();
$cancel_uri = $this->getApplicationURI("merchant/{$merchant_id}/");
$cancel_uri = $provider_config->getURI();
$provider = $provider_config->buildProvider();

View file

@ -1,16 +1,23 @@
<?php
final class PhortuneProviderEditController
final class PhortuneMerchantProviderEditController
extends PhortuneMerchantController {
public function handleRequest(AphrontRequest $request) {
protected function shouldRequireMerchantEditCapability() {
return true;
}
protected function handleMerchantRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$merchant = $this->getMerchant();
$id = $request->getURIData('id');
if ($id) {
$provider_config = id(new PhortunePaymentProviderConfigQuery())
->setViewer($viewer)
->withIDs(array($id))
->withMerchantPHIDs(array($merchant->getPHID()))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
@ -25,20 +32,8 @@ final class PhortuneProviderEditController
$merchant = $provider_config->getMerchant();
$merchant_id = $merchant->getID();
$cancel_uri = $this->getApplicationURI("merchant/{$merchant_id}/");
$cancel_uri = $provider_config->getURI();
} else {
$merchant = id(new PhortuneMerchantQuery())
->setViewer($viewer)
->withIDs(array($request->getStr('merchantID')))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$merchant) {
return new Aphront404Response();
}
$merchant_id = $merchant->getID();
$current_providers = id(new PhortunePaymentProviderConfigQuery())
@ -62,9 +57,7 @@ final class PhortuneProviderEditController
}
$provider_config->setProviderClass($class);
$cancel_uri = $this->getApplicationURI(
'provider/edit/?merchantID='.$merchant_id);
$cancel_uri = $merchant->getPaymentProvidersURI();
}
$provider = $provider_config->buildProvider();
@ -123,10 +116,12 @@ final class PhortuneProviderEditController
$xactions = array();
$xactions[] = id(new PhortunePaymentProviderConfigTransaction())
->setTransactionType(
PhortunePaymentProviderConfigTransaction::TYPE_CREATE)
->setNewValue(true);
if (!$provider_config->getID()) {
$xactions[] = id(new PhortunePaymentProviderConfigTransaction())
->setTransactionType(
PhortunePaymentProviderConfigTransaction::TYPE_CREATE)
->setNewValue(true);
}
foreach ($xaction_values as $key => $value) {
$xactions[] = id(clone $template)
@ -143,9 +138,9 @@ final class PhortuneProviderEditController
$editor->applyTransactions($provider_config, $xactions);
$merchant_uri = $this->getApplicationURI(
'merchant/'.$merchant->getID().'/');
return id(new AphrontRedirectResponse())->setURI($merchant_uri);
$next_uri = $provider_config->getURI();
return id(new AphrontRedirectResponse())->setURI($next_uri);
}
}
} else {
@ -155,7 +150,6 @@ final class PhortuneProviderEditController
$form = id(new AphrontFormView())
->setUser($viewer)
->addHiddenInput('merchantID', $merchant->getID())
->addHiddenInput('class', $provider_config->getProviderClass())
->addHiddenInput('edit', true)
->appendChild(
@ -261,7 +255,6 @@ final class PhortuneProviderEditController
$form = id(new AphrontFormView())
->setUser($viewer)
->addHiddenInput('merchantID', $merchant->getID())
->appendRemarkupInstructions(
pht('Choose the type of payment provider to add:'))
->appendChild($panel_classes)

View file

@ -0,0 +1,127 @@
<?php
final class PhortuneMerchantProviderViewController
extends PhortuneMerchantController {
protected function shouldRequireMerchantEditCapability() {
return true;
}
protected function handleMerchantRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$merchant = $this->getMerchant();
$provider = id(new PhortunePaymentProviderConfigQuery())
->setViewer($viewer)
->withIDs(array($request->getURIData('providerID')))
->executeOne();
if (!$provider) {
return new Aphront404Response();
}
$provider_type = $provider->buildProvider();
$crumbs = $this->buildApplicationCrumbs()
->addTextCrumb($merchant->getName(), $merchant->getURI())
->addTextCrumb(
pht('Payment Providers'),
$merchant->getPaymentProvidersURI())
->addTextCrumb($provider->getObjectName())
->setBorder(true);
$header = id(new PHUIHeaderView())
->setHeader(pht('Payment Provider: %s', $provider_type->getName()));
$details = $this->newDetailsView($provider);
$timeline = $this->buildTransactionTimeline(
$provider,
new PhortunePaymentProviderConfigTransactionQuery());
$timeline->setShouldTerminate(true);
$curtain = $this->buildCurtainView($provider);
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setCurtain($curtain)
->setMainColumn(
array(
$details,
$timeline,
));
return $this->newPage()
->setTitle($provider->getObjectName())
->setCrumbs($crumbs)
->appendChild($view);
}
private function buildCurtainView(PhortunePaymentProviderConfig $provider) {
$viewer = $this->getViewer();
$merchant = $this->getMerchant();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$provider,
PhabricatorPolicyCapability::CAN_EDIT);
$edit_uri = $this->getApplicationURI(
urisprintf(
'merchant/%d/providers/edit/%d/',
$merchant->getID(),
$provider->getID()));
$disable_uri = $this->getApplicationURI(
urisprintf(
'merchant/%d/providers/%d/disable/',
$merchant->getID(),
$provider->getID()));
$curtain = $this->newCurtainView($provider);
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Provider'))
->setIcon('fa-pencil')
->setHref($edit_uri)
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
$provider_type = $provider->buildProvider();
if ($provider_type->isEnabled()) {
$disable_icon = 'fa-times';
$disable_name = pht('Disable Provider');
} else {
$disable_icon = 'fa-check';
$disable_name = pht('Enable Provider');
}
$curtain->addAction(
id(new PhabricatorActionView())
->setName($disable_name)
->setIcon($disable_icon)
->setHref($disable_uri)
->setDisabled(!$can_edit)
->setWorkflow(true));
return $curtain;
}
private function newDetailsView(PhortunePaymentProviderConfig $provider) {
$viewer = $this->getViewer();
$view = id(new PHUIPropertyListView())
->setUser($viewer);
$provider_type = $provider->buildProvider();
$view->addProperty(pht('Provider Type'), $provider_type->getName());
return id(new PHUIObjectBoxView())
->setHeaderText(pht('Payment Provider Details'))
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->addPropertyList($view);
}
}

View file

@ -0,0 +1,116 @@
<?php
final class PhortuneMerchantProvidersController
extends PhortuneMerchantProfileController {
protected function shouldRequireMerchantEditCapability() {
return true;
}
protected function handleMerchantRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$merchant = $this->getMerchant();
$crumbs = $this->buildApplicationCrumbs()
->addTextCrumb(pht('Payment Providers'))
->setBorder(true);
$header = $this->buildHeaderView();
$title = pht(
'%s %s',
$merchant->getObjectName(),
$merchant->getName());
$providers = id(new PhortunePaymentProviderConfigQuery())
->setViewer($viewer)
->withMerchantPHIDs(array($merchant->getPHID()))
->execute();
$provider_list = $this->buildProviderList(
$merchant,
$providers);
$navigation = $this->buildSideNavView('providers');
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setFooter(
array(
$provider_list,
));
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->setNavigation($navigation)
->appendChild($view);
}
private function buildProviderList(
PhortuneMerchant $merchant,
array $providers) {
$viewer = $this->getRequest()->getUser();
$id = $merchant->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$merchant,
PhabricatorPolicyCapability::CAN_EDIT);
$provider_list = id(new PHUIObjectItemListView())
->setNoDataString(pht('This merchant has no payment providers.'));
foreach ($providers as $provider_config) {
$provider = $provider_config->buildProvider();
$provider_id = $provider_config->getID();
$item = id(new PHUIObjectItemView())
->setObjectName($provider_config->getObjectName())
->setHeader($provider->getName())
->setHref($provider_config->getURI());
if ($provider->isEnabled()) {
if ($provider->isAcceptingLivePayments()) {
$item->setStatusIcon('fa-check green');
} else {
$item->setStatusIcon('fa-warning yellow');
$item->addIcon('fa-exclamation-triangle', pht('Test Mode'));
}
$item->addAttribute($provider->getConfigureProvidesDescription());
} else {
$item->setDisabled(true);
$item->addAttribute(
phutil_tag('em', array(), pht('This payment provider is disabled.')));
}
$provider_list->addItem($item);
}
$add_uri = urisprintf(
'merchant/%d/providers/edit/',
$merchant->getID());
$add_uri = $this->getApplicationURI($add_uri);
$add_action = id(new PHUIButtonView())
->setTag('a')
->setHref($add_uri)
->setText(pht('Add Payment Provider'))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit)
->setIcon('fa-plus');
$header = id(new PHUIHeaderView())
->setHeader(pht('Payment Providers'))
->addActionLink($add_action);
return id(new PHUIObjectBoxView())
->setHeader($header)
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->setObjectList($provider_list);
}
}

View file

@ -0,0 +1,50 @@
<?php
final class PhortuneMerchantSubscriptionListController
extends PhortuneMerchantProfileController {
protected function shouldRequireMerchantEditCapability() {
return true;
}
protected function handleMerchantRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$merchant = $this->getMerchant();
$engine = id(new PhortuneCartSearchEngine())
->setController($this)
->setMerchant($merchant);
$subscription_id = $request->getURIData('subscriptionID');
if ($subscription_id) {
$subscription = id(new PhortuneSubscriptionQuery())
->setViewer($viewer)
->withIDs(array($subscription_id))
->executeOne();
if (!$subscription) {
return new Aphront404Response();
}
$engine->setSubscription($subscription);
$this->subscription = $subscription;
}
return $engine->buildResponse();
}
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
if ($this->hasMerchant()) {
$merchant = $this->getMerchant();
$crumbs->addTextCrumb(
pht('Subscriptions'),
$merchant->getSubscriptionsURI());
}
return $crumbs;
}
}

View file

@ -0,0 +1,68 @@
<?php
final class PhortuneMerchantSubscriptionsController
extends PhortuneMerchantProfileController {
protected function shouldRequireMerchantEditCapability() {
return true;
}
protected function handleMerchantRequest(AphrontRequest $request) {
$merchant = $this->getMerchant();
$title = $merchant->getName();
$crumbs = $this->buildApplicationCrumbs()
->addTextCrumb(pht('Subscriptions'))
->setBorder(true);
$header = $this->buildHeaderView();
$subscriptions = $this->buildSubscriptionsSection($merchant);
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setFooter(
array(
$subscriptions,
));
$navigation = $this->buildSideNavView('subscriptions');
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->setNavigation($navigation)
->appendChild($view);
}
private function buildSubscriptionsSection(PhortuneMerchant $merchant) {
$viewer = $this->getViewer();
$subscriptions = id(new PhortuneSubscriptionQuery())
->setViewer($viewer)
->withMerchantPHIDs(array($merchant->getPHID()))
->setLimit(25)
->execute();
$subscriptions_uri = $merchant->getSubscriptionListURI();
$table = id(new PhortuneSubscriptionTableView())
->setUser($viewer)
->setSubscriptions($subscriptions);
$header = id(new PHUIHeaderView())
->setHeader(pht('Subscriptions'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setIcon('fa-list')
->setHref($subscriptions_uri)
->setText(pht('View All Subscriptions')));
return id(new PHUIObjectBoxView())
->setHeader($header)
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->setTable($table);
}
}

View file

@ -1,324 +0,0 @@
<?php
final class PhortuneMerchantViewController
extends PhortuneMerchantProfileController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$merchant = id(new PhortuneMerchantQuery())
->setViewer($viewer)
->withIDs(array($id))
->needProfileImage(true)
->executeOne();
if (!$merchant) {
return new Aphront404Response();
}
$this->setMerchant($merchant);
$crumbs = $this->buildApplicationCrumbs();
$header = $this->buildHeaderView();
$title = pht(
'Merchant %d %s',
$merchant->getID(),
$merchant->getName());
$providers = id(new PhortunePaymentProviderConfigQuery())
->setViewer($viewer)
->withMerchantPHIDs(array($merchant->getPHID()))
->execute();
$details = $this->buildDetailsView($merchant, $providers);
$curtain = $this->buildCurtainView($merchant);
$provider_list = $this->buildProviderList(
$merchant,
$providers);
$timeline = $this->buildTransactionTimeline(
$merchant,
new PhortuneMerchantTransactionQuery());
$timeline->setShouldTerminate(true);
$navigation = $this->buildSideNavView('overview');
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setCurtain($curtain)
->setMainColumn(array(
$details,
$provider_list,
$timeline,
));
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->setNavigation($navigation)
->appendChild($view);
}
private function buildDetailsView(
PhortuneMerchant $merchant,
array $providers) {
$viewer = $this->getRequest()->getUser();
$view = id(new PHUIPropertyListView())
->setUser($viewer)
->setObject($merchant);
$status_view = new PHUIStatusListView();
$have_any = false;
$any_test = false;
foreach ($providers as $provider_config) {
$provider = $provider_config->buildProvider();
if ($provider->isEnabled()) {
$have_any = true;
}
if (!$provider->isAcceptingLivePayments()) {
$any_test = true;
}
}
if ($have_any) {
$status_view->addItem(
id(new PHUIStatusItemView())
->setIcon(PHUIStatusItemView::ICON_ACCEPT, 'green')
->setTarget(pht('Accepts Payments'))
->setNote(pht('This merchant can accept payments.')));
if ($any_test) {
$status_view->addItem(
id(new PHUIStatusItemView())
->setIcon(PHUIStatusItemView::ICON_WARNING, 'yellow')
->setTarget(pht('Test Mode'))
->setNote(pht('This merchant is accepting test payments.')));
} else {
$status_view->addItem(
id(new PHUIStatusItemView())
->setIcon(PHUIStatusItemView::ICON_ACCEPT, 'green')
->setTarget(pht('Live Mode'))
->setNote(pht('This merchant is accepting live payments.')));
}
} else if ($providers) {
$status_view->addItem(
id(new PHUIStatusItemView())
->setIcon(PHUIStatusItemView::ICON_REJECT, 'red')
->setTarget(pht('No Enabled Providers'))
->setNote(
pht(
'All of the payment providers for this merchant are '.
'disabled.')));
} else {
$status_view->addItem(
id(new PHUIStatusItemView())
->setIcon(PHUIStatusItemView::ICON_WARNING, 'yellow')
->setTarget(pht('No Providers'))
->setNote(
pht(
'This merchant does not have any payment providers configured '.
'yet, so it can not accept payments. Add a provider.')));
}
$view->addProperty(pht('Status'), $status_view);
$invoice_from = $merchant->getInvoiceEmail();
if (!$invoice_from) {
$invoice_from = pht('No email address set');
$invoice_from = phutil_tag('em', array(), $invoice_from);
}
$view->addProperty(pht('Invoice From'), $invoice_from);
$description = $merchant->getDescription();
if (strlen($description)) {
$description = new PHUIRemarkupView($viewer, $description);
$view->addSectionHeader(
pht('Description'),
PHUIPropertyListView::ICON_SUMMARY);
$view->addTextContent($description);
}
$contact_info = $merchant->getContactInfo();
if (strlen($contact_info)) {
$contact_info = new PHUIRemarkupView($viewer, $contact_info);
$view->addSectionHeader(
pht('Contact Info'),
PHUIPropertyListView::ICON_SUMMARY);
$view->addTextContent($contact_info);
}
$footer_info = $merchant->getInvoiceFooter();
if (strlen($footer_info)) {
$footer_info = new PHUIRemarkupView($viewer, $footer_info);
$view->addSectionHeader(
pht('Invoice Footer'),
PHUIPropertyListView::ICON_SUMMARY);
$view->addTextContent($footer_info);
}
return id(new PHUIObjectBoxView())
->setHeaderText(pht('Details'))
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->appendChild($view);
}
private function buildCurtainView(PhortuneMerchant $merchant) {
$viewer = $this->getRequest()->getUser();
$id = $merchant->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$merchant,
PhabricatorPolicyCapability::CAN_EDIT);
$curtain = $this->newCurtainView($merchant);
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Merchant'))
->setIcon('fa-pencil')
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit)
->setHref($this->getApplicationURI("merchant/edit/{$id}/")));
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Logo'))
->setIcon('fa-camera')
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit)
->setHref($this->getApplicationURI("merchant/picture/{$id}/")));
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('New Invoice'))
->setIcon('fa-fax')
->setHref($this->getApplicationURI("merchant/{$id}/invoice/new/"))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
$member_phids = $merchant->getMemberPHIDs();
$handles = $viewer->loadHandles($member_phids);
$member_list = id(new PHUIObjectItemListView())
->setSimple(true);
foreach ($member_phids as $member_phid) {
$image_uri = $handles[$member_phid]->getImageURI();
$image_href = $handles[$member_phid]->getURI();
$person = $handles[$member_phid];
$member = id(new PHUIObjectItemView())
->setImageURI($image_uri)
->setHref($image_href)
->setHeader($person->getFullName());
$member_list->addItem($member);
}
$curtain->newPanel()
->setHeaderText(pht('Managers'))
->appendChild($member_list);
return $curtain;
}
private function buildProviderList(
PhortuneMerchant $merchant,
array $providers) {
$viewer = $this->getRequest()->getUser();
$id = $merchant->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$merchant,
PhabricatorPolicyCapability::CAN_EDIT);
$provider_list = id(new PHUIObjectItemListView())
->setFlush(true)
->setNoDataString(pht('This merchant has no payment providers.'));
foreach ($providers as $provider_config) {
$provider = $provider_config->buildProvider();
$provider_id = $provider_config->getID();
$item = id(new PHUIObjectItemView())
->setHeader($provider->getName());
if ($provider->isEnabled()) {
if ($provider->isAcceptingLivePayments()) {
$item->setStatusIcon('fa-check green');
} else {
$item->setStatusIcon('fa-warning yellow');
$item->addIcon('fa-exclamation-triangle', pht('Test Mode'));
}
$item->addAttribute($provider->getConfigureProvidesDescription());
} else {
// Don't show disabled providers to users who can't manage the merchant
// account.
if (!$can_edit) {
continue;
}
$item->setDisabled(true);
$item->addAttribute(
phutil_tag('em', array(), pht('This payment provider is disabled.')));
}
if ($can_edit) {
$edit_uri = $this->getApplicationURI(
"/provider/edit/{$provider_id}/");
$disable_uri = $this->getApplicationURI(
"/provider/disable/{$provider_id}/");
if ($provider->isEnabled()) {
$disable_icon = 'fa-times';
$disable_name = pht('Disable');
} else {
$disable_icon = 'fa-check';
$disable_name = pht('Enable');
}
$item->addAction(
id(new PHUIListItemView())
->setIcon($disable_icon)
->setHref($disable_uri)
->setName($disable_name)
->setWorkflow(true));
$item->addAction(
id(new PHUIListItemView())
->setIcon('fa-pencil')
->setHref($edit_uri)
->setName(pht('Edit')));
}
$provider_list->addItem($item);
}
$add_action = id(new PHUIButtonView())
->setTag('a')
->setHref($this->getApplicationURI('provider/edit/?merchantID='.$id))
->setText(pht('Add Payment Provider'))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit)
->setIcon('fa-plus');
$header = id(new PHUIHeaderView())
->setHeader(pht('Payment Providers'))
->addActionLink($add_action);
return id(new PHUIObjectBoxView())
->setHeader($header)
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->setObjectList($provider_list);
}
}

View file

@ -58,7 +58,7 @@ final class PhortuneMerchantEditEngine
}
protected function getObjectViewURI($object) {
return $object->getURI();
return $object->getDetailsURI();
}
public function isEngineConfigurable() {

View file

@ -18,7 +18,6 @@ final class PhortuneMerchantEditor
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorTransactions::TYPE_EDGE;
return $types;

View file

@ -26,7 +26,7 @@ final class PhortuneTestPaymentProvider extends PhortunePaymentProvider {
}
public function getConfigureInstructions() {
return pht('This providers does not require any special configuration.');
return pht('This provider does not require any special configuration.');
}
public function canRunConfigurationTest() {

View file

@ -6,7 +6,6 @@ final class PhortuneMerchant extends PhortuneDAO
PhabricatorPolicyInterface {
protected $name;
protected $viewPolicy;
protected $description;
protected $contactInfo;
protected $invoiceEmail;
@ -18,7 +17,6 @@ final class PhortuneMerchant extends PhortuneDAO
public static function initializeNewMerchant(PhabricatorUser $actor) {
return id(new PhortuneMerchant())
->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy())
->attachMemberPHIDs(array())
->setContactInfo('')
->setInvoiceEmail('')
@ -74,6 +72,49 @@ final class PhortuneMerchant extends PhortuneDAO
return pht('Merchant %d', $this->getID());
}
public function getDetailsURI() {
return urisprintf(
'/phortune/merchant/%d/details/',
$this->getID());
}
public function getOrdersURI() {
return urisprintf(
'/phortune/merchant/%d/orders/',
$this->getID());
}
public function getOrderListURI($path = '') {
return urisprintf(
'/phortune/merchant/%d/orders/list/%s',
$this->getID(),
$path);
}
public function getSubscriptionsURI() {
return urisprintf(
'/phortune/merchant/%d/subscriptions/',
$this->getID());
}
public function getSubscriptionListURI($path = '') {
return urisprintf(
'/phortune/merchant/%d/subscriptions/list/%s',
$this->getID(),
$path);
}
public function getManagersURI() {
return urisprintf(
'/phortune/merchant/%d/managers/',
$this->getID());
}
public function getPaymentProvidersURI() {
return urisprintf(
'/phortune/merchant/%d/providers/',
$this->getID());
}
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
@ -100,7 +141,7 @@ final class PhortuneMerchant extends PhortuneDAO
public function getPolicy($capability) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return $this->getViewPolicy();
return PhabricatorPolicies::getMostOpenPolicy();
case PhabricatorPolicyCapability::CAN_EDIT:
return PhabricatorPolicies::POLICY_NOONE;
}

View file

@ -17,6 +17,7 @@ final class PhortunePaymentProviderConfig extends PhortuneDAO
PhortuneMerchant $merchant) {
return id(new PhortunePaymentProviderConfig())
->setMerchantPHID($merchant->getPHID())
->attachMerchant($merchant)
->setIsEnabled(1);
}
@ -75,6 +76,17 @@ final class PhortunePaymentProviderConfig extends PhortuneDAO
->setProviderConfig($this);
}
public function getObjectName() {
return pht('Provider %d', $this->getID());
}
public function getURI() {
return urisprintf(
'/phortune/merchant/%d/providers/%d/',
$this->getMerchant()->getID(),
$this->getID());
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */

View file

@ -3,20 +3,10 @@
final class PhortuneOrderTableView extends AphrontView {
private $carts;
private $handles;
private $noDataString;
private $isInvoices;
private $isMerchantView;
public function setHandles(array $handles) {
$this->handles = $handles;
return $this;
}
public function getHandles() {
return $this->handles;
}
public function setCarts(array $carts) {
$this->carts = $carts;
return $this;
@ -55,12 +45,22 @@ final class PhortuneOrderTableView extends AphrontView {
public function render() {
$carts = $this->getCarts();
$handles = $this->getHandles();
$viewer = $this->getUser();
$is_invoices = $this->getIsInvoices();
$is_merchant = $this->getIsMerchantView();
$phids = array();
foreach ($carts as $cart) {
$phids[] = $cart->getPHID();
foreach ($cart->getPurchases() as $purchase) {
$phids[] = $purchase->getPHID();
}
$phids[] = $cart->getMerchantPHID();
}
$handles = $viewer->loadHandles($phids);
$rows = array();
$rowc = array();
foreach ($carts as $cart) {