diff --git a/resources/sql/autopatches/20190822.merchant.01.view.sql b/resources/sql/autopatches/20190822.merchant.01.view.sql new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20190822.merchant.01.view.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_phortune.phortune_merchant + DROP viewPolicy; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -5271,7 +5271,6 @@ '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 @@ '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 @@ '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 @@ '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 @@ 'PhortuneCartController' => 'PhortuneController', 'PhortuneCartEditor' => 'PhabricatorApplicationTransactionEditor', 'PhortuneCartImplementation' => 'Phobject', - 'PhortuneCartListController' => 'PhortuneController', 'PhortuneCartPHIDType' => 'PhabricatorPHIDType', 'PhortuneCartQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhortuneCartReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', @@ -11883,32 +11888,41 @@ '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 @@ 'PhortuneProductQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhortuneProductViewController' => 'PhortuneController', 'PhortuneProviderActionController' => 'PhortuneController', - 'PhortuneProviderDisableController' => 'PhortuneMerchantController', - 'PhortuneProviderEditController' => 'PhortuneMerchantController', 'PhortunePurchase' => array( 'PhortuneDAO', 'PhabricatorPolicyInterface', diff --git a/src/applications/phortune/application/PhabricatorPhortuneApplication.php b/src/applications/phortune/application/PhabricatorPhortuneApplication.php --- a/src/applications/phortune/application/PhabricatorPhortuneApplication.php +++ b/src/applications/phortune/application/PhabricatorPhortuneApplication.php @@ -103,36 +103,40 @@ => 'PhortuneProviderActionController', ), 'merchant/' => array( - '(?:query/(?P[^/]+)/)?' => 'PhortuneMerchantListController', - 'picture/(?:(?P\d+)/)?' => 'PhortuneMerchantPictureController', + $this->getQueryRoutePattern() + => 'PhortuneMerchantListController', $this->getEditRoutePattern('edit/') => 'PhortuneMerchantEditController', - 'orders/(?P\d+)/(?:query/(?P[^/]+)/)?' - => 'PhortuneCartListController', - 'manager/' => array( - '(?:(?P\d+)/)?' => 'PhortuneMerchantManagerController', - 'add/(?:(?P\d+)/)?' => 'PhortuneMerchantAddManagerController', - ), '(?P\d+)/' => array( - 'cart/(?P\d+)/' => array( - '' => 'PhortuneCartViewController', - '(?Pcancel|refund)/' => 'PhortuneCartCancelController', - 'update/' => 'PhortuneCartUpdateController', - 'accept/' => 'PhortuneCartAcceptController', + '' => 'PhortuneMerchantOverviewController', + 'details/' => 'PhortuneMerchantDetailsController', + 'providers/' => array( + '' => 'PhortuneMerchantProvidersController', + '(?P\d+)/' => array( + '' => 'PhortuneMerchantProviderViewController', + 'disable/' => 'PhortuneMerchantProviderDisableController', + ), + $this->getEditRoutePattern('edit/') + => 'PhortuneMerchantProviderEditController', + ), + 'orders/' => array( + '' => 'PhortuneMerchantOrdersController', + $this->getQueryRoutePattern('list/') + => 'PhortuneMerchantOrderListController', ), - 'subscription/' => array( - '(?:query/(?P[^/]+)/)?' - => 'PhortuneSubscriptionListController', - 'view/(?P\d+)/' - => 'PhortuneAccountSubscriptionViewController', - 'order/(?P\d+)/' - => 'PhortuneCartListController', + 'picture/' => array( + 'edit/' => 'PhortuneMerchantPictureController', ), - 'invoice/' => array( - 'new/' => 'PhortuneMerchantInvoiceCreateController', + 'subscriptions/' => array( + '' => 'PhortuneMerchantSubscriptionsController', + $this->getQueryRoutePattern('list/') + => 'PhortuneMerchantSubscriptionListController', + ), + 'managers/' => array( + '' => 'PhortuneMerchantManagersController', + 'new/' => 'PhortuneMerchantAddManagerController', ), ), - '(?P\d+)/' => 'PhortuneMerchantViewController', ), ), ); diff --git a/src/applications/phortune/controller/PhortuneLandingController.php b/src/applications/phortune/controller/PhortuneLandingController.php --- a/src/applications/phortune/controller/PhortuneLandingController.php +++ b/src/applications/phortune/controller/PhortuneLandingController.php @@ -11,7 +11,7 @@ if (count($accounts) == 1) { $account = head($accounts); - $next_uri = $this->getApplicationURI($account->getID().'/'); + $next_uri = $account->getURI(); } else { $next_uri = $this->getApplicationURI('account/'); } diff --git a/src/applications/phortune/controller/account/PhortuneAccountEmailViewController.php b/src/applications/phortune/controller/account/PhortuneAccountEmailViewController.php --- a/src/applications/phortune/controller/account/PhortuneAccountEmailViewController.php +++ b/src/applications/phortune/controller/account/PhortuneAccountEmailViewController.php @@ -50,7 +50,6 @@ ->setTitle($address->getObjectName()) ->setCrumbs($crumbs) ->appendChild($view); - } private function buildCurtainView(PhortuneAccountEmail $address) { diff --git a/src/applications/phortune/controller/account/PhortuneAccountListController.php b/src/applications/phortune/controller/account/PhortuneAccountListController.php --- a/src/applications/phortune/controller/account/PhortuneAccountListController.php +++ b/src/applications/phortune/controller/account/PhortuneAccountListController.php @@ -38,7 +38,7 @@ $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'); diff --git a/src/applications/phortune/controller/account/PhortuneAccountOrderListController.php b/src/applications/phortune/controller/account/PhortuneAccountOrderListController.php --- a/src/applications/phortune/controller/account/PhortuneAccountOrderListController.php +++ b/src/applications/phortune/controller/account/PhortuneAccountOrderListController.php @@ -44,11 +44,8 @@ $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; diff --git a/src/applications/phortune/controller/account/PhortuneAccountOverviewController.php b/src/applications/phortune/controller/account/PhortuneAccountOverviewController.php --- a/src/applications/phortune/controller/account/PhortuneAccountOverviewController.php +++ b/src/applications/phortune/controller/account/PhortuneAccountOverviewController.php @@ -66,22 +66,11 @@ $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')); diff --git a/src/applications/phortune/controller/account/PhortuneAccountProfileController.php b/src/applications/phortune/controller/account/PhortuneAccountProfileController.php --- a/src/applications/phortune/controller/account/PhortuneAccountProfileController.php +++ b/src/applications/phortune/controller/account/PhortuneAccountProfileController.php @@ -117,21 +117,11 @@ ->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')) diff --git a/src/applications/phortune/controller/account/PhortuneAccountSubscriptionViewController.php b/src/applications/phortune/controller/account/PhortuneAccountSubscriptionViewController.php --- a/src/applications/phortune/controller/account/PhortuneAccountSubscriptionViewController.php +++ b/src/applications/phortune/controller/account/PhortuneAccountSubscriptionViewController.php @@ -92,21 +92,10 @@ ->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 @@ ->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(); diff --git a/src/applications/phortune/controller/cart/PhortuneCartListController.php b/src/applications/phortune/controller/cart/PhortuneCartListController.php deleted file mode 100644 --- a/src/applications/phortune/controller/cart/PhortuneCartListController.php +++ /dev/null @@ -1,134 +0,0 @@ -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; - } - -} diff --git a/src/applications/phortune/controller/merchant/PhortuneMerchantAddManagerController.php b/src/applications/phortune/controller/merchant/PhortuneMerchantAddManagerController.php --- a/src/applications/phortune/controller/merchant/PhortuneMerchantAddManagerController.php +++ b/src/applications/phortune/controller/merchant/PhortuneMerchantAddManagerController.php @@ -1,32 +1,23 @@ getViewer(); - $id = $request->getURIData('id'); + protected function shouldRequireMerchantEditCapability() { + return true; + } - $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(); - } + protected function handleMerchantRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $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 @@ ->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) diff --git a/src/applications/phortune/controller/merchant/PhortuneMerchantController.php b/src/applications/phortune/controller/merchant/PhortuneMerchantController.php --- a/src/applications/phortune/controller/merchant/PhortuneMerchantController.php +++ b/src/applications/phortune/controller/merchant/PhortuneMerchantController.php @@ -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; + } + } diff --git a/src/applications/phortune/controller/merchant/PhortuneMerchantDetailsController.php b/src/applications/phortune/controller/merchant/PhortuneMerchantDetailsController.php new file mode 100644 --- /dev/null +++ b/src/applications/phortune/controller/merchant/PhortuneMerchantDetailsController.php @@ -0,0 +1,151 @@ +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; + } + +} diff --git a/src/applications/phortune/controller/merchant/PhortuneMerchantEditController.php b/src/applications/phortune/controller/merchant/PhortuneMerchantEditController.php --- a/src/applications/phortune/controller/merchant/PhortuneMerchantEditController.php +++ b/src/applications/phortune/controller/merchant/PhortuneMerchantEditController.php @@ -1,7 +1,7 @@ getUser(); $merchant = $this->loadMerchantAuthority(); diff --git a/src/applications/phortune/controller/merchant/PhortuneMerchantListController.php b/src/applications/phortune/controller/merchant/PhortuneMerchantListController.php --- a/src/applications/phortune/controller/merchant/PhortuneMerchantListController.php +++ b/src/applications/phortune/controller/merchant/PhortuneMerchantListController.php @@ -1,37 +1,12 @@ 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() { diff --git a/src/applications/phortune/controller/merchant/PhortuneMerchantManagerController.php b/src/applications/phortune/controller/merchant/PhortuneMerchantManagersController.php rename from src/applications/phortune/controller/merchant/PhortuneMerchantManagerController.php rename to src/applications/phortune/controller/merchant/PhortuneMerchantManagersController.php --- a/src/applications/phortune/controller/merchant/PhortuneMerchantManagerController.php +++ b/src/applications/phortune/controller/merchant/PhortuneMerchantManagersController.php @@ -1,35 +1,29 @@ getViewer(); - $id = $request->getURIData('id'); - - $merchant = id(new PhortuneMerchantQuery()) - ->setViewer($viewer) - ->withIDs(array($id)) - ->needProfileImage(true) - ->executeOne(); - if (!$merchant) { - return new Aphront404Response(); - } + protected function shouldRequireMerchantEditCapability() { + return false; + } - $this->setMerchant($merchant); - $header = $this->buildHeaderView(); + protected function handleMerchantRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $merchant = $this->getMerchant(); - $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 @@ ->setCrumbs($crumbs) ->setNavigation($navigation) ->appendChild($view); - } private function buildMembersSection(PhortuneMerchant $merchant) { @@ -51,12 +44,18 @@ $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')) diff --git a/src/applications/phortune/controller/account/PhortuneAccountOrderListController.php b/src/applications/phortune/controller/merchant/PhortuneMerchantOrderListController.php copy from src/applications/phortune/controller/account/PhortuneAccountOrderListController.php copy to src/applications/phortune/controller/merchant/PhortuneMerchantOrderListController.php --- a/src/applications/phortune/controller/account/PhortuneAccountOrderListController.php +++ b/src/applications/phortune/controller/merchant/PhortuneMerchantOrderListController.php @@ -1,21 +1,21 @@ getViewer(); - $account = $this->getAccount(); + $merchant = $this->getMerchant(); $engine = id(new PhortuneCartSearchEngine()) ->setController($this) - ->setAccount($account); + ->setMerchant($merchant); $subscription_id = $request->getURIData('subscriptionID'); if ($subscription_id) { @@ -42,13 +42,10 @@ $crumbs->addTextCrumb( $subscription->getObjectName(), $subscription->getURI()); - } else if ($this->hasAccount()) { - $account = $this->getAccount(); - $id = $account->getID(); + } else if ($this->hasMerchant()) { + $merchant = $this->getMerchant(); - $crumbs->addTextCrumb( - pht('Orders'), - $account->getOrdersURI()); + $crumbs->addTextCrumb(pht('Orders'), $merchant->getOrdersURI()); } return $crumbs; diff --git a/src/applications/phortune/controller/merchant/PhortuneMerchantOrdersController.php b/src/applications/phortune/controller/merchant/PhortuneMerchantOrdersController.php new file mode 100644 --- /dev/null +++ b/src/applications/phortune/controller/merchant/PhortuneMerchantOrdersController.php @@ -0,0 +1,78 @@ +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); + } +} diff --git a/src/applications/phortune/controller/merchant/PhortuneMerchantOverviewController.php b/src/applications/phortune/controller/merchant/PhortuneMerchantOverviewController.php new file mode 100644 --- /dev/null +++ b/src/applications/phortune/controller/merchant/PhortuneMerchantOverviewController.php @@ -0,0 +1,136 @@ +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); + } + +} diff --git a/src/applications/phortune/controller/merchant/PhortuneMerchantPictureController.php b/src/applications/phortune/controller/merchant/PhortuneMerchantPictureController.php --- a/src/applications/phortune/controller/merchant/PhortuneMerchantPictureController.php +++ b/src/applications/phortune/controller/merchant/PhortuneMerchantPictureController.php @@ -1,28 +1,17 @@ getViewer(); - $id = $request->getURIData('id'); + protected function shouldRequireMerchantEditCapability() { + return true; + } - $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(); - } + protected function handleMerchantRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $merchant = $this->getMerchant(); - $this->setMerchant($merchant); - $uri = $merchant->getURI(); + $uri = $merchant->getDetailsURI(); $supported_formats = PhabricatorFile::getTransformableImageFormats(); $e_file = true; @@ -222,12 +211,9 @@ $upload_box, )); - $navigation = $this->buildSideNavView(); - return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) - ->setNavigation($navigation) ->appendChild( array( $view, diff --git a/src/applications/phortune/controller/merchant/PhortuneMerchantProfileController.php b/src/applications/phortune/controller/merchant/PhortuneMerchantProfileController.php --- a/src/applications/phortune/controller/merchant/PhortuneMerchantProfileController.php +++ b/src/applications/phortune/controller/merchant/PhortuneMerchantProfileController.php @@ -1,22 +1,7 @@ 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 @@ $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 @@ $nav->addLabel(pht('Merchant')); - $nav->addFilter( - 'overview', - pht('Overview'), - $this->getApplicationURI("/merchant/{$id}/"), - 'fa-building-o'); - - if ($can_edit) { - $nav->addFilter( - 'orders', - pht('Orders'), - $this->getApplicationURI("merchant/orders/{$id}/"), - 'fa-retweet'); - - $nav->addFilter( - 'subscriptions', - pht('Subscriptions'), - $this->getApplicationURI("merchant/{$id}/subscription/"), - 'fa-shopping-cart'); - - $nav->addFilter( - 'managers', - pht('Managers'), - $this->getApplicationURI("/merchant/manager/{$id}/"), - 'fa-group'); - } + $nav->newLink('overview') + ->setName(pht('Overview')) + ->setHref($merchant->getURI()) + ->setIcon('fa-building-o'); + + $nav->newLink('details') + ->setName(pht('Account Details')) + ->setHref($merchant->getDetailsURI()) + ->setIcon('fa-address-card-o') + ->setDisabled(!$can_edit) + ->setWorkflow(!$can_edit); + + $nav->addLabel(pht('Payments')); + + $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); diff --git a/src/applications/phortune/controller/provider/PhortuneProviderDisableController.php b/src/applications/phortune/controller/merchant/PhortuneMerchantProviderDisableController.php rename from src/applications/phortune/controller/provider/PhortuneProviderDisableController.php rename to src/applications/phortune/controller/merchant/PhortuneMerchantProviderDisableController.php --- a/src/applications/phortune/controller/provider/PhortuneProviderDisableController.php +++ b/src/applications/phortune/controller/merchant/PhortuneMerchantProviderDisableController.php @@ -1,11 +1,17 @@ getViewer(); - $id = $request->getURIData('id'); + $merchant = $this->getMerchant(); + + $id = $request->getURIData('providerID'); $provider_config = id(new PhortunePaymentProviderConfigQuery()) ->setViewer($viewer) @@ -20,9 +26,8 @@ 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(); diff --git a/src/applications/phortune/controller/provider/PhortuneProviderEditController.php b/src/applications/phortune/controller/merchant/PhortuneMerchantProviderEditController.php rename from src/applications/phortune/controller/provider/PhortuneProviderEditController.php rename to src/applications/phortune/controller/merchant/PhortuneMerchantProviderEditController.php --- a/src/applications/phortune/controller/provider/PhortuneProviderEditController.php +++ b/src/applications/phortune/controller/merchant/PhortuneMerchantProviderEditController.php @@ -1,16 +1,23 @@ 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 @@ $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 @@ } $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 @@ $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 @@ $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 @@ $form = id(new AphrontFormView()) ->setUser($viewer) - ->addHiddenInput('merchantID', $merchant->getID()) ->addHiddenInput('class', $provider_config->getProviderClass()) ->addHiddenInput('edit', true) ->appendChild( @@ -261,7 +255,6 @@ $form = id(new AphrontFormView()) ->setUser($viewer) - ->addHiddenInput('merchantID', $merchant->getID()) ->appendRemarkupInstructions( pht('Choose the type of payment provider to add:')) ->appendChild($panel_classes) diff --git a/src/applications/phortune/controller/merchant/PhortuneMerchantProviderViewController.php b/src/applications/phortune/controller/merchant/PhortuneMerchantProviderViewController.php new file mode 100644 --- /dev/null +++ b/src/applications/phortune/controller/merchant/PhortuneMerchantProviderViewController.php @@ -0,0 +1,127 @@ +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); + } + +} diff --git a/src/applications/phortune/controller/merchant/PhortuneMerchantProvidersController.php b/src/applications/phortune/controller/merchant/PhortuneMerchantProvidersController.php new file mode 100644 --- /dev/null +++ b/src/applications/phortune/controller/merchant/PhortuneMerchantProvidersController.php @@ -0,0 +1,116 @@ +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); + } + + +} diff --git a/src/applications/phortune/controller/account/PhortuneAccountOrderListController.php b/src/applications/phortune/controller/merchant/PhortuneMerchantSubscriptionListController.php copy from src/applications/phortune/controller/account/PhortuneAccountOrderListController.php copy to src/applications/phortune/controller/merchant/PhortuneMerchantSubscriptionListController.php --- a/src/applications/phortune/controller/account/PhortuneAccountOrderListController.php +++ b/src/applications/phortune/controller/merchant/PhortuneMerchantSubscriptionListController.php @@ -1,21 +1,19 @@ getViewer(); - $account = $this->getAccount(); + $merchant = $this->getMerchant(); $engine = id(new PhortuneCartSearchEngine()) ->setController($this) - ->setAccount($account); + ->setMerchant($merchant); $subscription_id = $request->getURIData('subscriptionID'); if ($subscription_id) { @@ -37,18 +35,12 @@ protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); - $subscription = $this->subscription; - if ($subscription) { - $crumbs->addTextCrumb( - $subscription->getObjectName(), - $subscription->getURI()); - } else if ($this->hasAccount()) { - $account = $this->getAccount(); - $id = $account->getID(); + if ($this->hasMerchant()) { + $merchant = $this->getMerchant(); $crumbs->addTextCrumb( - pht('Orders'), - $account->getOrdersURI()); + pht('Subscriptions'), + $merchant->getSubscriptionsURI()); } return $crumbs; diff --git a/src/applications/phortune/controller/merchant/PhortuneMerchantSubscriptionsController.php b/src/applications/phortune/controller/merchant/PhortuneMerchantSubscriptionsController.php new file mode 100644 --- /dev/null +++ b/src/applications/phortune/controller/merchant/PhortuneMerchantSubscriptionsController.php @@ -0,0 +1,68 @@ +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); + } + +} diff --git a/src/applications/phortune/controller/merchant/PhortuneMerchantViewController.php b/src/applications/phortune/controller/merchant/PhortuneMerchantViewController.php deleted file mode 100644 --- a/src/applications/phortune/controller/merchant/PhortuneMerchantViewController.php +++ /dev/null @@ -1,324 +0,0 @@ -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); - } - - -} diff --git a/src/applications/phortune/editor/PhortuneMerchantEditEngine.php b/src/applications/phortune/editor/PhortuneMerchantEditEngine.php --- a/src/applications/phortune/editor/PhortuneMerchantEditEngine.php +++ b/src/applications/phortune/editor/PhortuneMerchantEditEngine.php @@ -58,7 +58,7 @@ } protected function getObjectViewURI($object) { - return $object->getURI(); + return $object->getDetailsURI(); } public function isEngineConfigurable() { diff --git a/src/applications/phortune/editor/PhortuneMerchantEditor.php b/src/applications/phortune/editor/PhortuneMerchantEditor.php --- a/src/applications/phortune/editor/PhortuneMerchantEditor.php +++ b/src/applications/phortune/editor/PhortuneMerchantEditor.php @@ -18,7 +18,6 @@ public function getTransactionTypes() { $types = parent::getTransactionTypes(); - $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; $types[] = PhabricatorTransactions::TYPE_EDGE; return $types; diff --git a/src/applications/phortune/provider/PhortuneTestPaymentProvider.php b/src/applications/phortune/provider/PhortuneTestPaymentProvider.php --- a/src/applications/phortune/provider/PhortuneTestPaymentProvider.php +++ b/src/applications/phortune/provider/PhortuneTestPaymentProvider.php @@ -26,7 +26,7 @@ } 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() { diff --git a/src/applications/phortune/storage/PhortuneMerchant.php b/src/applications/phortune/storage/PhortuneMerchant.php --- a/src/applications/phortune/storage/PhortuneMerchant.php +++ b/src/applications/phortune/storage/PhortuneMerchant.php @@ -6,7 +6,6 @@ PhabricatorPolicyInterface { protected $name; - protected $viewPolicy; protected $description; protected $contactInfo; protected $invoiceEmail; @@ -18,7 +17,6 @@ public static function initializeNewMerchant(PhabricatorUser $actor) { return id(new PhortuneMerchant()) - ->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()) ->attachMemberPHIDs(array()) ->setContactInfo('') ->setInvoiceEmail('') @@ -74,6 +72,49 @@ 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 @@ public function getPolicy($capability) { switch ($capability) { case PhabricatorPolicyCapability::CAN_VIEW: - return $this->getViewPolicy(); + return PhabricatorPolicies::getMostOpenPolicy(); case PhabricatorPolicyCapability::CAN_EDIT: return PhabricatorPolicies::POLICY_NOONE; } diff --git a/src/applications/phortune/storage/PhortunePaymentProviderConfig.php b/src/applications/phortune/storage/PhortunePaymentProviderConfig.php --- a/src/applications/phortune/storage/PhortunePaymentProviderConfig.php +++ b/src/applications/phortune/storage/PhortunePaymentProviderConfig.php @@ -17,6 +17,7 @@ PhortuneMerchant $merchant) { return id(new PhortunePaymentProviderConfig()) ->setMerchantPHID($merchant->getPHID()) + ->attachMerchant($merchant) ->setIsEnabled(1); } @@ -75,6 +76,17 @@ ->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 )----------------------------------------- */ diff --git a/src/applications/phortune/view/PhortuneOrderTableView.php b/src/applications/phortune/view/PhortuneOrderTableView.php --- a/src/applications/phortune/view/PhortuneOrderTableView.php +++ b/src/applications/phortune/view/PhortuneOrderTableView.php @@ -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 @@ 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) {