@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+1122 -749
+2
resources/sql/autopatches/20190822.merchant.01.view.sql
··· 1 + ALTER TABLE {$NAMESPACE}_phortune.phortune_merchant 2 + DROP viewPolicy;
+28 -16
src/__phutil_library_map__.php
··· 5271 5271 'PhortuneCartController' => 'applications/phortune/controller/cart/PhortuneCartController.php', 5272 5272 'PhortuneCartEditor' => 'applications/phortune/editor/PhortuneCartEditor.php', 5273 5273 'PhortuneCartImplementation' => 'applications/phortune/cart/PhortuneCartImplementation.php', 5274 - 'PhortuneCartListController' => 'applications/phortune/controller/cart/PhortuneCartListController.php', 5275 5274 'PhortuneCartPHIDType' => 'applications/phortune/phid/PhortuneCartPHIDType.php', 5276 5275 'PhortuneCartQuery' => 'applications/phortune/query/PhortuneCartQuery.php', 5277 5276 'PhortuneCartReplyHandler' => 'applications/phortune/mail/PhortuneCartReplyHandler.php', ··· 5304 5303 'PhortuneMerchantContactInfoTransaction' => 'applications/phortune/xaction/PhortuneMerchantContactInfoTransaction.php', 5305 5304 'PhortuneMerchantController' => 'applications/phortune/controller/merchant/PhortuneMerchantController.php', 5306 5305 'PhortuneMerchantDescriptionTransaction' => 'applications/phortune/xaction/PhortuneMerchantDescriptionTransaction.php', 5306 + 'PhortuneMerchantDetailsController' => 'applications/phortune/controller/merchant/PhortuneMerchantDetailsController.php', 5307 5307 'PhortuneMerchantEditController' => 'applications/phortune/controller/merchant/PhortuneMerchantEditController.php', 5308 5308 'PhortuneMerchantEditEngine' => 'applications/phortune/editor/PhortuneMerchantEditEngine.php', 5309 5309 'PhortuneMerchantEditor' => 'applications/phortune/editor/PhortuneMerchantEditor.php', ··· 5313 5313 'PhortuneMerchantInvoiceEmailTransaction' => 'applications/phortune/xaction/PhortuneMerchantInvoiceEmailTransaction.php', 5314 5314 'PhortuneMerchantInvoiceFooterTransaction' => 'applications/phortune/xaction/PhortuneMerchantInvoiceFooterTransaction.php', 5315 5315 'PhortuneMerchantListController' => 'applications/phortune/controller/merchant/PhortuneMerchantListController.php', 5316 - 'PhortuneMerchantManagerController' => 'applications/phortune/controller/merchant/PhortuneMerchantManagerController.php', 5316 + 'PhortuneMerchantManagersController' => 'applications/phortune/controller/merchant/PhortuneMerchantManagersController.php', 5317 5317 'PhortuneMerchantNameTransaction' => 'applications/phortune/xaction/PhortuneMerchantNameTransaction.php', 5318 + 'PhortuneMerchantOrderListController' => 'applications/phortune/controller/merchant/PhortuneMerchantOrderListController.php', 5319 + 'PhortuneMerchantOrdersController' => 'applications/phortune/controller/merchant/PhortuneMerchantOrdersController.php', 5320 + 'PhortuneMerchantOverviewController' => 'applications/phortune/controller/merchant/PhortuneMerchantOverviewController.php', 5318 5321 'PhortuneMerchantPHIDType' => 'applications/phortune/phid/PhortuneMerchantPHIDType.php', 5319 5322 'PhortuneMerchantPictureController' => 'applications/phortune/controller/merchant/PhortuneMerchantPictureController.php', 5320 5323 'PhortuneMerchantPictureTransaction' => 'applications/phortune/xaction/PhortuneMerchantPictureTransaction.php', 5321 5324 'PhortuneMerchantProfileController' => 'applications/phortune/controller/merchant/PhortuneMerchantProfileController.php', 5325 + 'PhortuneMerchantProviderDisableController' => 'applications/phortune/controller/merchant/PhortuneMerchantProviderDisableController.php', 5326 + 'PhortuneMerchantProviderEditController' => 'applications/phortune/controller/merchant/PhortuneMerchantProviderEditController.php', 5327 + 'PhortuneMerchantProviderViewController' => 'applications/phortune/controller/merchant/PhortuneMerchantProviderViewController.php', 5328 + 'PhortuneMerchantProvidersController' => 'applications/phortune/controller/merchant/PhortuneMerchantProvidersController.php', 5322 5329 'PhortuneMerchantQuery' => 'applications/phortune/query/PhortuneMerchantQuery.php', 5323 5330 'PhortuneMerchantSearchEngine' => 'applications/phortune/query/PhortuneMerchantSearchEngine.php', 5331 + 'PhortuneMerchantSubscriptionListController' => 'applications/phortune/controller/merchant/PhortuneMerchantSubscriptionListController.php', 5332 + 'PhortuneMerchantSubscriptionsController' => 'applications/phortune/controller/merchant/PhortuneMerchantSubscriptionsController.php', 5324 5333 'PhortuneMerchantTransaction' => 'applications/phortune/storage/PhortuneMerchantTransaction.php', 5325 5334 'PhortuneMerchantTransactionQuery' => 'applications/phortune/query/PhortuneMerchantTransactionQuery.php', 5326 5335 'PhortuneMerchantTransactionType' => 'applications/phortune/xaction/PhortuneMerchantTransactionType.php', 5327 - 'PhortuneMerchantViewController' => 'applications/phortune/controller/merchant/PhortuneMerchantViewController.php', 5328 5336 'PhortuneMonthYearExpiryControl' => 'applications/phortune/control/PhortuneMonthYearExpiryControl.php', 5329 5337 'PhortuneOrderTableView' => 'applications/phortune/view/PhortuneOrderTableView.php', 5330 5338 'PhortunePayPalPaymentProvider' => 'applications/phortune/provider/PhortunePayPalPaymentProvider.php', ··· 5356 5364 'PhortuneProductQuery' => 'applications/phortune/query/PhortuneProductQuery.php', 5357 5365 'PhortuneProductViewController' => 'applications/phortune/controller/product/PhortuneProductViewController.php', 5358 5366 'PhortuneProviderActionController' => 'applications/phortune/controller/provider/PhortuneProviderActionController.php', 5359 - 'PhortuneProviderDisableController' => 'applications/phortune/controller/provider/PhortuneProviderDisableController.php', 5360 - 'PhortuneProviderEditController' => 'applications/phortune/controller/provider/PhortuneProviderEditController.php', 5361 5367 'PhortunePurchase' => 'applications/phortune/storage/PhortunePurchase.php', 5362 5368 'PhortunePurchasePHIDType' => 'applications/phortune/phid/PhortunePurchasePHIDType.php', 5363 5369 'PhortunePurchaseQuery' => 'applications/phortune/query/PhortunePurchaseQuery.php', ··· 11847 11853 'PhortuneCartController' => 'PhortuneController', 11848 11854 'PhortuneCartEditor' => 'PhabricatorApplicationTransactionEditor', 11849 11855 'PhortuneCartImplementation' => 'Phobject', 11850 - 'PhortuneCartListController' => 'PhortuneController', 11851 11856 'PhortuneCartPHIDType' => 'PhabricatorPHIDType', 11852 11857 'PhortuneCartQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 11853 11858 'PhortuneCartReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', ··· 11883 11888 'PhabricatorApplicationTransactionInterface', 11884 11889 'PhabricatorPolicyInterface', 11885 11890 ), 11886 - 'PhortuneMerchantAddManagerController' => 'PhortuneController', 11891 + 'PhortuneMerchantAddManagerController' => 'PhortuneMerchantController', 11887 11892 'PhortuneMerchantCapability' => 'PhabricatorPolicyCapability', 11888 11893 'PhortuneMerchantContactInfoTransaction' => 'PhortuneMerchantTransactionType', 11889 11894 'PhortuneMerchantController' => 'PhortuneController', 11890 11895 'PhortuneMerchantDescriptionTransaction' => 'PhortuneMerchantTransactionType', 11891 - 'PhortuneMerchantEditController' => 'PhortuneMerchantController', 11896 + 'PhortuneMerchantDetailsController' => 'PhortuneMerchantProfileController', 11897 + 'PhortuneMerchantEditController' => 'PhortuneController', 11892 11898 'PhortuneMerchantEditEngine' => 'PhabricatorEditEngine', 11893 11899 'PhortuneMerchantEditor' => 'PhabricatorApplicationTransactionEditor', 11894 11900 'PhortuneMerchantHasAccountEdgeType' => 'PhabricatorEdgeType', 11895 11901 'PhortuneMerchantHasMemberEdgeType' => 'PhabricatorEdgeType', 11896 - 'PhortuneMerchantInvoiceCreateController' => 'PhortuneMerchantProfileController', 11902 + 'PhortuneMerchantInvoiceCreateController' => 'PhortuneMerchantController', 11897 11903 'PhortuneMerchantInvoiceEmailTransaction' => 'PhortuneMerchantTransactionType', 11898 11904 'PhortuneMerchantInvoiceFooterTransaction' => 'PhortuneMerchantTransactionType', 11899 - 'PhortuneMerchantListController' => 'PhortuneMerchantController', 11900 - 'PhortuneMerchantManagerController' => 'PhortuneMerchantProfileController', 11905 + 'PhortuneMerchantListController' => 'PhortuneController', 11906 + 'PhortuneMerchantManagersController' => 'PhortuneMerchantProfileController', 11901 11907 'PhortuneMerchantNameTransaction' => 'PhortuneMerchantTransactionType', 11908 + 'PhortuneMerchantOrderListController' => 'PhortuneMerchantProfileController', 11909 + 'PhortuneMerchantOrdersController' => 'PhortuneMerchantProfileController', 11910 + 'PhortuneMerchantOverviewController' => 'PhortuneMerchantProfileController', 11902 11911 'PhortuneMerchantPHIDType' => 'PhabricatorPHIDType', 11903 - 'PhortuneMerchantPictureController' => 'PhortuneMerchantProfileController', 11912 + 'PhortuneMerchantPictureController' => 'PhortuneMerchantController', 11904 11913 'PhortuneMerchantPictureTransaction' => 'PhortuneMerchantTransactionType', 11905 - 'PhortuneMerchantProfileController' => 'PhortuneController', 11914 + 'PhortuneMerchantProfileController' => 'PhortuneMerchantController', 11915 + 'PhortuneMerchantProviderDisableController' => 'PhortuneMerchantController', 11916 + 'PhortuneMerchantProviderEditController' => 'PhortuneMerchantController', 11917 + 'PhortuneMerchantProviderViewController' => 'PhortuneMerchantController', 11918 + 'PhortuneMerchantProvidersController' => 'PhortuneMerchantProfileController', 11906 11919 'PhortuneMerchantQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 11907 11920 'PhortuneMerchantSearchEngine' => 'PhabricatorApplicationSearchEngine', 11921 + 'PhortuneMerchantSubscriptionListController' => 'PhortuneMerchantProfileController', 11922 + 'PhortuneMerchantSubscriptionsController' => 'PhortuneMerchantProfileController', 11908 11923 'PhortuneMerchantTransaction' => 'PhabricatorModularTransaction', 11909 11924 'PhortuneMerchantTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 11910 11925 'PhortuneMerchantTransactionType' => 'PhabricatorModularTransactionType', 11911 - 'PhortuneMerchantViewController' => 'PhortuneMerchantProfileController', 11912 11926 'PhortuneMonthYearExpiryControl' => 'AphrontFormControl', 11913 11927 'PhortuneOrderTableView' => 'AphrontView', 11914 11928 'PhortunePayPalPaymentProvider' => 'PhortunePaymentProvider', ··· 11953 11967 'PhortuneProductQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 11954 11968 'PhortuneProductViewController' => 'PhortuneController', 11955 11969 'PhortuneProviderActionController' => 'PhortuneController', 11956 - 'PhortuneProviderDisableController' => 'PhortuneMerchantController', 11957 - 'PhortuneProviderEditController' => 'PhortuneMerchantController', 11958 11970 'PhortunePurchase' => array( 11959 11971 'PhortuneDAO', 11960 11972 'PhabricatorPolicyInterface',
+27 -23
src/applications/phortune/application/PhabricatorPhortuneApplication.php
··· 103 103 => 'PhortuneProviderActionController', 104 104 ), 105 105 'merchant/' => array( 106 - '(?:query/(?P<queryKey>[^/]+)/)?' => 'PhortuneMerchantListController', 107 - 'picture/(?:(?P<id>\d+)/)?' => 'PhortuneMerchantPictureController', 106 + $this->getQueryRoutePattern() 107 + => 'PhortuneMerchantListController', 108 108 $this->getEditRoutePattern('edit/') 109 109 => 'PhortuneMerchantEditController', 110 - 'orders/(?P<merchantID>\d+)/(?:query/(?P<queryKey>[^/]+)/)?' 111 - => 'PhortuneCartListController', 112 - 'manager/' => array( 113 - '(?:(?P<id>\d+)/)?' => 'PhortuneMerchantManagerController', 114 - 'add/(?:(?P<id>\d+)/)?' => 'PhortuneMerchantAddManagerController', 115 - ), 116 110 '(?P<merchantID>\d+)/' => array( 117 - 'cart/(?P<id>\d+)/' => array( 118 - '' => 'PhortuneCartViewController', 119 - '(?P<action>cancel|refund)/' => 'PhortuneCartCancelController', 120 - 'update/' => 'PhortuneCartUpdateController', 121 - 'accept/' => 'PhortuneCartAcceptController', 111 + '' => 'PhortuneMerchantOverviewController', 112 + 'details/' => 'PhortuneMerchantDetailsController', 113 + 'providers/' => array( 114 + '' => 'PhortuneMerchantProvidersController', 115 + '(?P<providerID>\d+)/' => array( 116 + '' => 'PhortuneMerchantProviderViewController', 117 + 'disable/' => 'PhortuneMerchantProviderDisableController', 118 + ), 119 + $this->getEditRoutePattern('edit/') 120 + => 'PhortuneMerchantProviderEditController', 122 121 ), 123 - 'subscription/' => array( 124 - '(?:query/(?P<queryKey>[^/]+)/)?' 125 - => 'PhortuneSubscriptionListController', 126 - 'view/(?P<id>\d+)/' 127 - => 'PhortuneAccountSubscriptionViewController', 128 - 'order/(?P<subscriptionID>\d+)/' 129 - => 'PhortuneCartListController', 122 + 'orders/' => array( 123 + '' => 'PhortuneMerchantOrdersController', 124 + $this->getQueryRoutePattern('list/') 125 + => 'PhortuneMerchantOrderListController', 126 + ), 127 + 'picture/' => array( 128 + 'edit/' => 'PhortuneMerchantPictureController', 129 + ), 130 + 'subscriptions/' => array( 131 + '' => 'PhortuneMerchantSubscriptionsController', 132 + $this->getQueryRoutePattern('list/') 133 + => 'PhortuneMerchantSubscriptionListController', 130 134 ), 131 - 'invoice/' => array( 132 - 'new/' => 'PhortuneMerchantInvoiceCreateController', 135 + 'managers/' => array( 136 + '' => 'PhortuneMerchantManagersController', 137 + 'new/' => 'PhortuneMerchantAddManagerController', 133 138 ), 134 139 ), 135 - '(?P<id>\d+)/' => 'PhortuneMerchantViewController', 136 140 ), 137 141 ), 138 142 );
+1 -1
src/applications/phortune/controller/PhortuneLandingController.php
··· 11 11 12 12 if (count($accounts) == 1) { 13 13 $account = head($accounts); 14 - $next_uri = $this->getApplicationURI($account->getID().'/'); 14 + $next_uri = $account->getURI(); 15 15 } else { 16 16 $next_uri = $this->getApplicationURI('account/'); 17 17 }
-1
src/applications/phortune/controller/account/PhortuneAccountEmailViewController.php
··· 50 50 ->setTitle($address->getObjectName()) 51 51 ->setCrumbs($crumbs) 52 52 ->appendChild($view); 53 - 54 53 } 55 54 56 55 private function buildCurtainView(PhortuneAccountEmail $address) {
+1 -1
src/applications/phortune/controller/account/PhortuneAccountListController.php
··· 38 38 $item = id(new PHUIObjectItemView()) 39 39 ->setSubhead(pht('Account %d', $account->getID())) 40 40 ->setHeader($account->getName()) 41 - ->setHref($this->getApplicationURI($account->getID().'/')) 41 + ->setHref($account->getURI()) 42 42 ->setObject($account) 43 43 ->setImageIcon('fa-user-circle'); 44 44
+1 -4
src/applications/phortune/controller/account/PhortuneAccountOrderListController.php
··· 44 44 $subscription->getURI()); 45 45 } else if ($this->hasAccount()) { 46 46 $account = $this->getAccount(); 47 - $id = $account->getID(); 48 47 49 - $crumbs->addTextCrumb( 50 - pht('Orders'), 51 - $account->getOrdersURI()); 48 + $crumbs->addTextCrumb(pht('Orders'), $account->getOrdersURI()); 52 49 } 53 50 54 51 return $crumbs;
+1 -12
src/applications/phortune/controller/account/PhortuneAccountOverviewController.php
··· 66 66 67 67 $viewer = $this->getViewer(); 68 68 69 - $phids = array(); 70 - foreach ($carts as $cart) { 71 - $phids[] = $cart->getPHID(); 72 - $phids[] = $cart->getMerchantPHID(); 73 - foreach ($cart->getPurchases() as $purchase) { 74 - $phids[] = $purchase->getPHID(); 75 - } 76 - } 77 - $handles = $this->loadViewerHandles($phids); 78 - 79 69 $table = id(new PhortuneOrderTableView()) 80 70 ->setNoDataString(pht('You have no unpaid invoices.')) 81 71 ->setIsInvoices(true) 82 72 ->setUser($viewer) 83 - ->setCarts($carts) 84 - ->setHandles($handles); 73 + ->setCarts($carts); 85 74 86 75 $header = id(new PHUIHeaderView()) 87 76 ->setHeader(pht('Invoices Due'));
+1 -11
src/applications/phortune/controller/account/PhortuneAccountProfileController.php
··· 117 117 ->setLimit($limit) 118 118 ->execute(); 119 119 120 - $phids = array(); 121 - foreach ($carts as $cart) { 122 - $phids[] = $cart->getPHID(); 123 - foreach ($cart->getPurchases() as $purchase) { 124 - $phids[] = $purchase->getPHID(); 125 - } 126 - } 127 - $handles = $this->loadViewerHandles($phids); 128 - 129 120 $orders_uri = $account->getOrderListURI(); 130 121 131 122 $table = id(new PhortuneOrderTableView()) 132 123 ->setUser($viewer) 133 - ->setCarts($carts) 134 - ->setHandles($handles); 124 + ->setCarts($carts); 135 125 136 126 $header = id(new PHUIHeaderView()) 137 127 ->setHeader(pht('Recent Orders'))
+2 -23
src/applications/phortune/controller/account/PhortuneAccountSubscriptionViewController.php
··· 92 92 ->withInvoices(true) 93 93 ->execute(); 94 94 95 - $phids = array(); 96 - foreach ($invoices as $invoice) { 97 - $phids[] = $invoice->getPHID(); 98 - $phids[] = $invoice->getMerchantPHID(); 99 - foreach ($invoice->getPurchases() as $purchase) { 100 - $phids[] = $purchase->getPHID(); 101 - } 102 - } 103 - $handles = $this->loadViewerHandles($phids); 104 - 105 95 $invoice_table = id(new PhortuneOrderTableView()) 106 96 ->setUser($viewer) 107 97 ->setCarts($invoices) 108 - ->setIsInvoices(true) 109 - ->setHandles($handles); 98 + ->setIsInvoices(true); 110 99 111 100 $invoice_header = id(new PHUIHeaderView()) 112 101 ->setHeader(pht('Invoices Due')); ··· 135 124 ->setLimit(50) 136 125 ->execute(); 137 126 138 - $phids = array(); 139 - foreach ($invoices as $invoice) { 140 - $phids[] = $invoice->getPHID(); 141 - foreach ($invoice->getPurchases() as $purchase) { 142 - $phids[] = $purchase->getPHID(); 143 - } 144 - } 145 - $handles = $this->loadViewerHandles($phids); 146 - 147 127 $invoice_table = id(new PhortuneOrderTableView()) 148 128 ->setUser($viewer) 149 - ->setCarts($invoices) 150 - ->setHandles($handles); 129 + ->setCarts($invoices); 151 130 152 131 $account = $subscription->getAccount(); 153 132 $merchant = $subscription->getMerchant();
-134
src/applications/phortune/controller/cart/PhortuneCartListController.php
··· 1 - <?php 2 - 3 - final class PhortuneCartListController 4 - extends PhortuneController { 5 - 6 - private $merchant; 7 - private $account; 8 - private $subscription; 9 - private $engine; 10 - 11 - public function handleRequest(AphrontRequest $request) { 12 - $viewer = $this->getViewer(); 13 - 14 - $merchant_id = $request->getURIData('merchantID'); 15 - $account_id = $request->getURIData('accountID'); 16 - $subscription_id = $request->getURIData('subscriptionID'); 17 - 18 - $engine = id(new PhortuneCartSearchEngine()) 19 - ->setViewer($viewer); 20 - 21 - if ($merchant_id) { 22 - $merchant = id(new PhortuneMerchantQuery()) 23 - ->setViewer($viewer) 24 - ->withIDs(array($merchant_id)) 25 - ->requireCapabilities( 26 - array( 27 - PhabricatorPolicyCapability::CAN_VIEW, 28 - PhabricatorPolicyCapability::CAN_EDIT, 29 - )) 30 - ->executeOne(); 31 - if (!$merchant) { 32 - return new Aphront404Response(); 33 - } 34 - $this->merchant = $merchant; 35 - $viewer->grantAuthority($merchant); 36 - $engine->setMerchant($merchant); 37 - } else if ($account_id) { 38 - $account = id(new PhortuneAccountQuery()) 39 - ->setViewer($viewer) 40 - ->withIDs(array($account_id)) 41 - ->requireCapabilities( 42 - array( 43 - PhabricatorPolicyCapability::CAN_VIEW, 44 - PhabricatorPolicyCapability::CAN_EDIT, 45 - )) 46 - ->executeOne(); 47 - if (!$account) { 48 - return new Aphront404Response(); 49 - } 50 - $this->account = $account; 51 - $engine->setAccount($account); 52 - } else { 53 - return new Aphront404Response(); 54 - } 55 - 56 - // NOTE: We must process this after processing the merchant authority, so 57 - // it becomes visible in merchant contexts. 58 - if ($subscription_id) { 59 - $subscription = id(new PhortuneSubscriptionQuery()) 60 - ->setViewer($viewer) 61 - ->withIDs(array($subscription_id)) 62 - ->executeOne(); 63 - if (!$subscription) { 64 - return new Aphront404Response(); 65 - } 66 - $this->subscription = $subscription; 67 - $engine->setSubscription($subscription); 68 - } 69 - 70 - $this->engine = $engine; 71 - 72 - $controller = id(new PhabricatorApplicationSearchController()) 73 - ->setQueryKey($request->getURIData('queryKey')) 74 - ->setSearchEngine($engine) 75 - ->setNavigation($this->buildSideNavView()); 76 - 77 - return $this->delegateToController($controller); 78 - } 79 - 80 - public function buildSideNavView() { 81 - $viewer = $this->getRequest()->getUser(); 82 - 83 - $nav = new AphrontSideNavFilterView(); 84 - $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); 85 - 86 - $this->engine->addNavigationItems($nav->getMenu()); 87 - 88 - $nav->selectFilter(null); 89 - 90 - return $nav; 91 - } 92 - 93 - protected function buildApplicationCrumbs() { 94 - $crumbs = parent::buildApplicationCrumbs(); 95 - 96 - $subscription = $this->subscription; 97 - 98 - $merchant = $this->merchant; 99 - if ($merchant) { 100 - $id = $merchant->getID(); 101 - $this->addMerchantCrumb($crumbs, $merchant); 102 - if (!$subscription) { 103 - $crumbs->addTextCrumb( 104 - pht('Orders'), 105 - $this->getApplicationURI("merchant/orders/{$id}/")); 106 - } 107 - } 108 - 109 - $account = $this->account; 110 - if ($account) { 111 - $id = $account->getID(); 112 - $this->addAccountCrumb($crumbs, $account); 113 - if (!$subscription) { 114 - $crumbs->addTextCrumb( 115 - pht('Orders'), 116 - $this->getApplicationURI("{$id}/order/")); 117 - } 118 - } 119 - 120 - if ($subscription) { 121 - if ($merchant) { 122 - $subscription_uri = $subscription->getMerchantURI(); 123 - } else { 124 - $subscription_uri = $subscription->getURI(); 125 - } 126 - $crumbs->addTextCrumb( 127 - $subscription->getSubscriptionName(), 128 - $subscription_uri); 129 - } 130 - 131 - return $crumbs; 132 - } 133 - 134 - }
+14 -23
src/applications/phortune/controller/merchant/PhortuneMerchantAddManagerController.php
··· 1 1 <?php 2 2 3 - final class PhortuneMerchantAddManagerController extends PhortuneController { 3 + final class PhortuneMerchantAddManagerController 4 + extends PhortuneMerchantController { 4 5 5 - public function handleRequest(AphrontRequest $request) { 6 + protected function shouldRequireMerchantEditCapability() { 7 + return true; 8 + } 9 + 10 + protected function handleMerchantRequest(AphrontRequest $request) { 6 11 $viewer = $request->getViewer(); 7 - $id = $request->getURIData('id'); 8 - 9 - $merchant = id(new PhortuneMerchantQuery()) 10 - ->setViewer($viewer) 11 - ->withIDs(array($id)) 12 - ->needProfileImage(true) 13 - ->requireCapabilities( 14 - array( 15 - PhabricatorPolicyCapability::CAN_VIEW, 16 - PhabricatorPolicyCapability::CAN_EDIT, 17 - )) 18 - ->executeOne(); 19 - if (!$merchant) { 20 - return new Aphront404Response(); 21 - } 12 + $merchant = $this->getMerchant(); 22 13 23 14 $v_members = array(); 24 15 $e_members = null; 25 - $merchant_uri = $this->getApplicationURI("/merchant/manager/{$id}/"); 16 + $merchant_uri = $merchant->getManagersURI(); 26 17 27 - if ($request->isFormPost()) { 18 + if ($request->isFormOrHiSecPost()) { 28 19 $xactions = array(); 29 - $v_members = $request->getArr('memberPHIDs'); 20 + $v_members = $request->getArr('managerPHIDs'); 30 21 $type_edge = PhabricatorTransactions::TYPE_EDGE; 31 22 32 23 $xactions[] = id(new PhortuneMerchantTransaction()) ··· 59 50 ->appendControl( 60 51 id(new AphrontFormTokenizerControl()) 61 52 ->setDatasource(new PhabricatorPeopleDatasource()) 62 - ->setLabel(pht('Members')) 63 - ->setName('memberPHIDs') 53 + ->setLabel(pht('New Managers')) 54 + ->setName('managerPHIDs') 64 55 ->setValue($v_members) 65 56 ->setError($e_members)); 66 57 67 58 return $this->newDialog() 68 - ->setTitle(pht('Add New Manager')) 59 + ->setTitle(pht('Add New Managers')) 69 60 ->appendForm($form) 70 61 ->setWidth(AphrontDialogView::WIDTH_FORM) 71 62 ->addCancelButton($merchant_uri)
+75 -6
src/applications/phortune/controller/merchant/PhortuneMerchantController.php
··· 3 3 abstract class PhortuneMerchantController 4 4 extends PhortuneController { 5 5 6 - protected function buildApplicationCrumbs() { 7 - $crumbs = parent::buildApplicationCrumbs(); 8 - $crumbs->addTextCrumb( 9 - pht('Merchants'), 10 - $this->getApplicationURI('merchant/')); 11 - return $crumbs; 6 + private $merchant; 7 + 8 + final protected function setMerchant(PhortuneMerchant $merchant) { 9 + $this->merchant = $merchant; 10 + return $this; 11 + } 12 + 13 + final protected function getMerchant() { 14 + return $this->merchant; 15 + } 16 + 17 + final protected function hasMerchant() { 18 + return (bool)$this->merchant; 19 + } 20 + 21 + final public function handleRequest(AphrontRequest $request) { 22 + if ($this->shouldRequireMerchantEditCapability()) { 23 + $response = $this->loadMerchantForEdit(); 24 + } else { 25 + $response = $this->loadMerchantForView(); 26 + } 27 + 28 + if ($response) { 29 + return $response; 30 + } 31 + 32 + return $this->handleMerchantRequest($request); 33 + } 34 + 35 + abstract protected function shouldRequireMerchantEditCapability(); 36 + abstract protected function handleMerchantRequest(AphrontRequest $request); 37 + 38 + private function loadMerchantForEdit() { 39 + return $this->loadMerchantWithCapabilities( 40 + array( 41 + PhabricatorPolicyCapability::CAN_VIEW, 42 + PhabricatorPolicyCapability::CAN_EDIT, 43 + )); 44 + } 45 + 46 + private function loadMerchantForView() { 47 + return $this->loadMerchantWithCapabilities( 48 + array( 49 + PhabricatorPolicyCapability::CAN_VIEW, 50 + )); 12 51 } 52 + 53 + private function loadMerchantWithCapabilities(array $capabilities) { 54 + $viewer = $this->getViewer(); 55 + $request = $this->getRequest(); 56 + 57 + $merchant_id = $request->getURIData('merchantID'); 58 + if (!$merchant_id) { 59 + throw new Exception( 60 + pht( 61 + 'Controller ("%s") extends controller "%s", but is reachable '. 62 + 'with no "merchantID" in URI.', 63 + get_class($this), 64 + __CLASS__)); 65 + } 66 + 67 + $merchant = id(new PhortuneMerchantQuery()) 68 + ->setViewer($viewer) 69 + ->withIDs(array($merchant_id)) 70 + ->needProfileImage(true) 71 + ->requireCapabilities($capabilities) 72 + ->executeOne(); 73 + if (!$merchant) { 74 + return new Aphront404Response(); 75 + } 76 + 77 + $this->setMerchant($merchant); 78 + 79 + return null; 80 + } 81 + 13 82 }
+151
src/applications/phortune/controller/merchant/PhortuneMerchantDetailsController.php
··· 1 + <?php 2 + 3 + final class PhortuneMerchantDetailsController 4 + extends PhortuneMerchantProfileController { 5 + 6 + protected function shouldRequireMerchantEditCapability() { 7 + return true; 8 + } 9 + 10 + protected function handleMerchantRequest(AphrontRequest $request) { 11 + $viewer = $request->getViewer(); 12 + $id = $request->getURIData('id'); 13 + 14 + $merchant = $this->getMerchant(); 15 + 16 + $crumbs = $this->buildApplicationCrumbs() 17 + ->addTextCrumb(pht('Account Details')) 18 + ->setBorder(true); 19 + $header = $this->buildHeaderView(); 20 + 21 + $title = pht( 22 + '%s %s', 23 + $merchant->getObjectName(), 24 + $merchant->getName()); 25 + 26 + $details = $this->buildDetailsView($merchant); 27 + $curtain = $this->buildCurtainView($merchant); 28 + 29 + $timeline = $this->buildTransactionTimeline( 30 + $merchant, 31 + new PhortuneMerchantTransactionQuery()); 32 + $timeline->setShouldTerminate(true); 33 + 34 + $navigation = $this->buildSideNavView('details'); 35 + 36 + $view = id(new PHUITwoColumnView()) 37 + ->setHeader($header) 38 + ->setCurtain($curtain) 39 + ->setMainColumn(array( 40 + $details, 41 + $timeline, 42 + )); 43 + 44 + return $this->newPage() 45 + ->setTitle($title) 46 + ->setCrumbs($crumbs) 47 + ->setNavigation($navigation) 48 + ->appendChild($view); 49 + } 50 + 51 + private function buildDetailsView(PhortuneMerchant $merchant) { 52 + $viewer = $this->getViewer(); 53 + 54 + $view = id(new PHUIPropertyListView()) 55 + ->setUser($viewer) 56 + ->setObject($merchant); 57 + 58 + $invoice_from = $merchant->getInvoiceEmail(); 59 + if (!$invoice_from) { 60 + $invoice_from = pht('No email address set'); 61 + $invoice_from = phutil_tag('em', array(), $invoice_from); 62 + } 63 + $view->addProperty(pht('Invoice From'), $invoice_from); 64 + 65 + $description = $merchant->getDescription(); 66 + if (strlen($description)) { 67 + $description = new PHUIRemarkupView($viewer, $description); 68 + $view->addSectionHeader( 69 + pht('Description'), 70 + PHUIPropertyListView::ICON_SUMMARY); 71 + $view->addTextContent($description); 72 + } 73 + 74 + $contact_info = $merchant->getContactInfo(); 75 + if (strlen($contact_info)) { 76 + $contact_info = new PHUIRemarkupView($viewer, $contact_info); 77 + $view->addSectionHeader( 78 + pht('Contact Information'), 79 + PHUIPropertyListView::ICON_SUMMARY); 80 + $view->addTextContent($contact_info); 81 + } 82 + 83 + $footer_info = $merchant->getInvoiceFooter(); 84 + if (strlen($footer_info)) { 85 + $footer_info = new PHUIRemarkupView($viewer, $footer_info); 86 + $view->addSectionHeader( 87 + pht('Invoice Footer'), 88 + PHUIPropertyListView::ICON_SUMMARY); 89 + $view->addTextContent($footer_info); 90 + } 91 + 92 + return id(new PHUIObjectBoxView()) 93 + ->setHeaderText(pht('Details')) 94 + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 95 + ->appendChild($view); 96 + } 97 + 98 + private function buildCurtainView(PhortuneMerchant $merchant) { 99 + $viewer = $this->getRequest()->getUser(); 100 + $id = $merchant->getID(); 101 + 102 + $can_edit = PhabricatorPolicyFilter::hasCapability( 103 + $viewer, 104 + $merchant, 105 + PhabricatorPolicyCapability::CAN_EDIT); 106 + 107 + $curtain = $this->newCurtainView($merchant); 108 + 109 + $curtain->addAction( 110 + id(new PhabricatorActionView()) 111 + ->setName(pht('Edit Merchant')) 112 + ->setIcon('fa-pencil') 113 + ->setDisabled(!$can_edit) 114 + ->setWorkflow(!$can_edit) 115 + ->setHref($this->getApplicationURI("merchant/edit/{$id}/"))); 116 + 117 + $curtain->addAction( 118 + id(new PhabricatorActionView()) 119 + ->setName(pht('Edit Logo')) 120 + ->setIcon('fa-picture-o') 121 + ->setDisabled(!$can_edit) 122 + ->setWorkflow(!$can_edit) 123 + ->setHref($this->getApplicationURI("merchant/{$id}/picture/edit/"))); 124 + 125 + $member_phids = $merchant->getMemberPHIDs(); 126 + $handles = $viewer->loadHandles($member_phids); 127 + 128 + $member_list = id(new PHUIObjectItemListView()) 129 + ->setSimple(true); 130 + 131 + foreach ($member_phids as $member_phid) { 132 + $image_uri = $handles[$member_phid]->getImageURI(); 133 + $image_href = $handles[$member_phid]->getURI(); 134 + $person = $handles[$member_phid]; 135 + 136 + $member = id(new PHUIObjectItemView()) 137 + ->setImageURI($image_uri) 138 + ->setHref($image_href) 139 + ->setHeader($person->getFullName()); 140 + 141 + $member_list->addItem($member); 142 + } 143 + 144 + $curtain->newPanel() 145 + ->setHeaderText(pht('Managers')) 146 + ->appendChild($member_list); 147 + 148 + return $curtain; 149 + } 150 + 151 + }
+1 -1
src/applications/phortune/controller/merchant/PhortuneMerchantEditController.php
··· 1 1 <?php 2 2 3 3 final class PhortuneMerchantEditController 4 - extends PhortuneMerchantController { 4 + extends PhortuneController { 5 5 6 6 public function handleRequest(AphrontRequest $request) { 7 7 return id(new PhortuneMerchantEditEngine())
+9 -2
src/applications/phortune/controller/merchant/PhortuneMerchantInvoiceCreateController.php
··· 1 1 <?php 2 2 3 3 final class PhortuneMerchantInvoiceCreateController 4 - extends PhortuneMerchantProfileController { 4 + extends PhortuneMerchantController { 5 + 6 + protected function shouldRequireMerchantEditCapability() { 7 + return true; 8 + } 9 + 10 + protected function handleMerchantRequest(AphrontRequest $request) { 11 + // TODO: Make this work again, or destroy it. 12 + return new Aphront404Response(); 5 13 6 - public function handleRequest(AphrontRequest $request) { 7 14 $viewer = $request->getUser(); 8 15 9 16 $merchant = $this->loadMerchantAuthority();
+4 -29
src/applications/phortune/controller/merchant/PhortuneMerchantListController.php
··· 1 1 <?php 2 2 3 3 final class PhortuneMerchantListController 4 - extends PhortuneMerchantController { 5 - 6 - public function shouldAllowPublic() { 7 - return true; 8 - } 4 + extends PhortuneController { 9 5 10 6 public function handleRequest(AphrontRequest $request) { 11 - $viewer = $request->getViewer(); 12 - $querykey = $request->getURIData('queryKey'); 13 - 14 - $controller = id(new PhabricatorApplicationSearchController()) 15 - ->setQueryKey($querykey) 16 - ->setSearchEngine(new PhortuneMerchantSearchEngine()) 17 - ->setNavigation($this->buildSideNavView()); 18 - 19 - return $this->delegateToController($controller); 20 - } 21 - 22 - public function buildSideNavView() { 23 - $viewer = $this->getViewer(); 24 - 25 - $nav = new AphrontSideNavFilterView(); 26 - $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); 27 - 28 - id(new PhortuneMerchantSearchEngine()) 29 - ->setViewer($viewer) 30 - ->addNavigationItems($nav->getMenu()); 31 - 32 - $nav->selectFilter(null); 33 - 34 - return $nav; 7 + return id(new PhortuneMerchantSearchEngine()) 8 + ->setController($this) 9 + ->buildResponse(); 35 10 } 36 11 37 12 protected function buildApplicationCrumbs() {
+21 -22
src/applications/phortune/controller/merchant/PhortuneMerchantManagerController.php src/applications/phortune/controller/merchant/PhortuneMerchantManagersController.php
··· 1 1 <?php 2 2 3 - final class PhortuneMerchantManagerController 3 + final class PhortuneMerchantManagersController 4 4 extends PhortuneMerchantProfileController { 5 5 6 - public function handleRequest(AphrontRequest $request) { 6 + protected function shouldRequireMerchantEditCapability() { 7 + return false; 8 + } 9 + 10 + protected function handleMerchantRequest(AphrontRequest $request) { 7 11 $viewer = $request->getViewer(); 8 - $id = $request->getURIData('id'); 12 + $merchant = $this->getMerchant(); 9 13 10 - $merchant = id(new PhortuneMerchantQuery()) 11 - ->setViewer($viewer) 12 - ->withIDs(array($id)) 13 - ->needProfileImage(true) 14 - ->executeOne(); 15 - if (!$merchant) { 16 - return new Aphront404Response(); 17 - } 18 - 19 - $this->setMerchant($merchant); 20 - $header = $this->buildHeaderView(); 21 - 22 - $crumbs = $this->buildApplicationCrumbs(); 23 - $crumbs->addTextCrumb(pht('Managers')); 14 + $crumbs = $this->buildApplicationCrumbs() 15 + ->addTextCrumb(pht('Managers')) 16 + ->setBorder(true); 24 17 25 18 $header = $this->buildHeaderView(); 26 19 $members = $this->buildMembersSection($merchant); 27 20 28 21 $view = id(new PHUITwoColumnView()) 29 22 ->setHeader($header) 30 - ->setFooter(array( 31 - $members, 32 - )); 23 + ->setFooter( 24 + array( 25 + $members, 26 + )); 33 27 34 28 $navigation = $this->buildSideNavView('managers'); 35 29 ··· 38 32 ->setCrumbs($crumbs) 39 33 ->setNavigation($navigation) 40 34 ->appendChild($view); 41 - 42 35 } 43 36 44 37 private function buildMembersSection(PhortuneMerchant $merchant) { ··· 51 44 52 45 $id = $merchant->getID(); 53 46 47 + $add_uri = urisprintf( 48 + 'merchant/%d/managers/new/', 49 + $merchant->getID()); 50 + $add_uri = $this->getApplicationURI($add_uri); 51 + 54 52 $add = id(new PHUIButtonView()) 55 53 ->setTag('a') 56 54 ->setText(pht('New Manager')) 57 55 ->setIcon('fa-plus') 58 56 ->setWorkflow(true) 59 - ->setHref("/phortune/merchant/manager/add/{$id}/"); 57 + ->setDisabled(!$can_edit) 58 + ->setHref($add_uri); 60 59 61 60 $header = id(new PHUIHeaderView()) 62 61 ->setHeader(pht('Merchant Account Managers'))
+55
src/applications/phortune/controller/merchant/PhortuneMerchantOrderListController.php
··· 1 + <?php 2 + 3 + final class PhortuneMerchantOrderListController 4 + extends PhortuneMerchantProfileController { 5 + 6 + private $subscription; 7 + 8 + protected function shouldRequireMerchantEditCapability() { 9 + return true; 10 + } 11 + 12 + protected function handleMerchantRequest(AphrontRequest $request) { 13 + $viewer = $request->getViewer(); 14 + $merchant = $this->getMerchant(); 15 + 16 + $engine = id(new PhortuneCartSearchEngine()) 17 + ->setController($this) 18 + ->setMerchant($merchant); 19 + 20 + $subscription_id = $request->getURIData('subscriptionID'); 21 + if ($subscription_id) { 22 + $subscription = id(new PhortuneSubscriptionQuery()) 23 + ->setViewer($viewer) 24 + ->withIDs(array($subscription_id)) 25 + ->executeOne(); 26 + if (!$subscription) { 27 + return new Aphront404Response(); 28 + } 29 + 30 + $engine->setSubscription($subscription); 31 + $this->subscription = $subscription; 32 + } 33 + 34 + return $engine->buildResponse(); 35 + } 36 + 37 + protected function buildApplicationCrumbs() { 38 + $crumbs = parent::buildApplicationCrumbs(); 39 + 40 + $subscription = $this->subscription; 41 + if ($subscription) { 42 + $crumbs->addTextCrumb( 43 + $subscription->getObjectName(), 44 + $subscription->getURI()); 45 + } else if ($this->hasMerchant()) { 46 + $merchant = $this->getMerchant(); 47 + 48 + $crumbs->addTextCrumb(pht('Orders'), $merchant->getOrdersURI()); 49 + } 50 + 51 + return $crumbs; 52 + } 53 + 54 + 55 + }
+78
src/applications/phortune/controller/merchant/PhortuneMerchantOrdersController.php
··· 1 + <?php 2 + 3 + final class PhortuneMerchantOrdersController 4 + extends PhortuneMerchantProfileController { 5 + 6 + protected function shouldRequireMerchantEditCapability() { 7 + return true; 8 + } 9 + 10 + protected function handleMerchantRequest(AphrontRequest $request) { 11 + $merchant = $this->getMerchant(); 12 + $title = $merchant->getName(); 13 + 14 + $crumbs = $this->buildApplicationCrumbs() 15 + ->addTextCrumb(pht('Orders')) 16 + ->setBorder(true); 17 + 18 + $header = $this->buildHeaderView(); 19 + $order_history = $this->newRecentOrdersView($merchant, 100); 20 + 21 + $view = id(new PHUITwoColumnView()) 22 + ->setHeader($header) 23 + ->setFooter( 24 + array( 25 + $order_history, 26 + )); 27 + 28 + $navigation = $this->buildSideNavView('orders'); 29 + 30 + return $this->newPage() 31 + ->setTitle($title) 32 + ->setCrumbs($crumbs) 33 + ->setNavigation($navigation) 34 + ->appendChild($view); 35 + } 36 + 37 + private function newRecentOrdersView( 38 + PhortuneMerchant $merchant, 39 + $limit) { 40 + 41 + $viewer = $this->getViewer(); 42 + 43 + $carts = id(new PhortuneCartQuery()) 44 + ->setViewer($viewer) 45 + ->withMerchantPHIDs(array($merchant->getPHID())) 46 + ->needPurchases(true) 47 + ->withStatuses( 48 + array( 49 + PhortuneCart::STATUS_PURCHASING, 50 + PhortuneCart::STATUS_CHARGED, 51 + PhortuneCart::STATUS_HOLD, 52 + PhortuneCart::STATUS_REVIEW, 53 + PhortuneCart::STATUS_PURCHASED, 54 + )) 55 + ->setLimit($limit) 56 + ->execute(); 57 + 58 + $orders_uri = $merchant->getOrderListURI(); 59 + 60 + $table = id(new PhortuneOrderTableView()) 61 + ->setUser($viewer) 62 + ->setCarts($carts); 63 + 64 + $header = id(new PHUIHeaderView()) 65 + ->setHeader(pht('Recent Orders')) 66 + ->addActionLink( 67 + id(new PHUIButtonView()) 68 + ->setTag('a') 69 + ->setIcon('fa-list') 70 + ->setHref($orders_uri) 71 + ->setText(pht('View All Orders'))); 72 + 73 + return id(new PHUIObjectBoxView()) 74 + ->setHeader($header) 75 + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 76 + ->setTable($table); 77 + } 78 + }
+136
src/applications/phortune/controller/merchant/PhortuneMerchantOverviewController.php
··· 1 + <?php 2 + 3 + final class PhortuneMerchantOverviewController 4 + extends PhortuneMerchantProfileController { 5 + 6 + protected function shouldRequireMerchantEditCapability() { 7 + return false; 8 + } 9 + 10 + protected function handleMerchantRequest(AphrontRequest $request) { 11 + $viewer = $request->getViewer(); 12 + $merchant = $this->getMerchant(); 13 + 14 + $crumbs = $this->buildApplicationCrumbs() 15 + ->setBorder(true); 16 + 17 + $header = $this->buildHeaderView(); 18 + 19 + $title = pht( 20 + '%s %s', 21 + $merchant->getObjectName(), 22 + $merchant->getName()); 23 + 24 + $providers = id(new PhortunePaymentProviderConfigQuery()) 25 + ->setViewer($viewer) 26 + ->withMerchantPHIDs(array($merchant->getPHID())) 27 + ->execute(); 28 + 29 + $details = $this->buildDetailsView($merchant, $providers); 30 + $navigation = $this->buildSideNavView('overview'); 31 + 32 + $view = id(new PHUITwoColumnView()) 33 + ->setHeader($header) 34 + ->setFooter( 35 + array( 36 + $details, 37 + )); 38 + 39 + return $this->newPage() 40 + ->setTitle($title) 41 + ->setCrumbs($crumbs) 42 + ->setNavigation($navigation) 43 + ->appendChild($view); 44 + } 45 + 46 + private function buildDetailsView( 47 + PhortuneMerchant $merchant, 48 + array $providers) { 49 + 50 + $viewer = $this->getRequest()->getUser(); 51 + 52 + $view = id(new PHUIPropertyListView()) 53 + ->setUser($viewer) 54 + ->setObject($merchant); 55 + 56 + $status_view = new PHUIStatusListView(); 57 + 58 + $have_any = false; 59 + $any_test = false; 60 + foreach ($providers as $provider_config) { 61 + $provider = $provider_config->buildProvider(); 62 + if ($provider->isEnabled()) { 63 + $have_any = true; 64 + } 65 + if (!$provider->isAcceptingLivePayments()) { 66 + $any_test = true; 67 + } 68 + } 69 + 70 + if ($have_any) { 71 + $status_view->addItem( 72 + id(new PHUIStatusItemView()) 73 + ->setIcon(PHUIStatusItemView::ICON_ACCEPT, 'green') 74 + ->setTarget(pht('Accepts Payments')) 75 + ->setNote(pht('This merchant can accept payments.'))); 76 + 77 + if ($any_test) { 78 + $status_view->addItem( 79 + id(new PHUIStatusItemView()) 80 + ->setIcon(PHUIStatusItemView::ICON_WARNING, 'yellow') 81 + ->setTarget(pht('Test Mode')) 82 + ->setNote(pht('This merchant is accepting test payments.'))); 83 + } else { 84 + $status_view->addItem( 85 + id(new PHUIStatusItemView()) 86 + ->setIcon(PHUIStatusItemView::ICON_ACCEPT, 'green') 87 + ->setTarget(pht('Live Mode')) 88 + ->setNote(pht('This merchant is accepting live payments.'))); 89 + } 90 + } else if ($providers) { 91 + $status_view->addItem( 92 + id(new PHUIStatusItemView()) 93 + ->setIcon(PHUIStatusItemView::ICON_REJECT, 'red') 94 + ->setTarget(pht('No Enabled Providers')) 95 + ->setNote( 96 + pht( 97 + 'All of the payment providers for this merchant are '. 98 + 'disabled.'))); 99 + } else { 100 + $status_view->addItem( 101 + id(new PHUIStatusItemView()) 102 + ->setIcon(PHUIStatusItemView::ICON_WARNING, 'yellow') 103 + ->setTarget(pht('No Providers')) 104 + ->setNote( 105 + pht( 106 + 'This merchant does not have any payment providers configured '. 107 + 'yet, so it can not accept payments. Add a provider.'))); 108 + } 109 + 110 + $view->addProperty(pht('Status'), $status_view); 111 + 112 + $description = $merchant->getDescription(); 113 + if (strlen($description)) { 114 + $description = new PHUIRemarkupView($viewer, $description); 115 + $view->addSectionHeader( 116 + pht('Description'), 117 + PHUIPropertyListView::ICON_SUMMARY); 118 + $view->addTextContent($description); 119 + } 120 + 121 + $contact_info = $merchant->getContactInfo(); 122 + if (strlen($contact_info)) { 123 + $contact_info = new PHUIRemarkupView($viewer, $contact_info); 124 + $view->addSectionHeader( 125 + pht('Contact Information'), 126 + PHUIPropertyListView::ICON_SUMMARY); 127 + $view->addTextContent($contact_info); 128 + } 129 + 130 + return id(new PHUIObjectBoxView()) 131 + ->setHeaderText(pht('Details')) 132 + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 133 + ->appendChild($view); 134 + } 135 + 136 + }
+8 -22
src/applications/phortune/controller/merchant/PhortuneMerchantPictureController.php
··· 1 1 <?php 2 2 3 3 final class PhortuneMerchantPictureController 4 - extends PhortuneMerchantProfileController { 4 + extends PhortuneMerchantController { 5 + 6 + protected function shouldRequireMerchantEditCapability() { 7 + return true; 8 + } 5 9 6 - public function handleRequest(AphrontRequest $request) { 10 + protected function handleMerchantRequest(AphrontRequest $request) { 7 11 $viewer = $request->getViewer(); 8 - $id = $request->getURIData('id'); 12 + $merchant = $this->getMerchant(); 9 13 10 - $merchant = id(new PhortuneMerchantQuery()) 11 - ->setViewer($viewer) 12 - ->withIDs(array($id)) 13 - ->needProfileImage(true) 14 - ->requireCapabilities( 15 - array( 16 - PhabricatorPolicyCapability::CAN_VIEW, 17 - PhabricatorPolicyCapability::CAN_EDIT, 18 - )) 19 - ->executeOne(); 20 - if (!$merchant) { 21 - return new Aphront404Response(); 22 - } 23 - 24 - $this->setMerchant($merchant); 25 - $uri = $merchant->getURI(); 14 + $uri = $merchant->getDetailsURI(); 26 15 27 16 $supported_formats = PhabricatorFile::getTransformableImageFormats(); 28 17 $e_file = true; ··· 222 211 $upload_box, 223 212 )); 224 213 225 - $navigation = $this->buildSideNavView(); 226 - 227 214 return $this->newPage() 228 215 ->setTitle($title) 229 216 ->setCrumbs($crumbs) 230 - ->setNavigation($navigation) 231 217 ->appendChild( 232 218 array( 233 219 $view,
+46 -45
src/applications/phortune/controller/merchant/PhortuneMerchantProfileController.php
··· 1 1 <?php 2 2 3 3 abstract class PhortuneMerchantProfileController 4 - extends PhortuneController { 5 - 6 - private $merchant; 7 - 8 - public function setMerchant(PhortuneMerchant $merchant) { 9 - $this->merchant = $merchant; 10 - return $this; 11 - } 12 - 13 - public function getMerchant() { 14 - return $this->merchant; 15 - } 16 - 17 - public function buildApplicationMenu() { 18 - return $this->buildSideNavView()->getMenu(); 19 - } 4 + extends PhortuneMerchantController { 20 5 21 6 protected function buildHeaderView() { 22 7 $viewer = $this->getViewer(); ··· 26 11 $header = id(new PHUIHeaderView()) 27 12 ->setHeader($title) 28 13 ->setUser($viewer) 29 - ->setPolicyObject($merchant) 30 14 ->setImage($merchant->getProfileImageURI()); 31 15 32 16 return $header; 33 17 } 34 18 35 19 protected function buildApplicationCrumbs() { 36 - $merchant = $this->getMerchant(); 37 - $id = $merchant->getID(); 38 - $merchant_uri = $this->getApplicationURI("/merchant/{$id}/"); 39 - 40 20 $crumbs = parent::buildApplicationCrumbs(); 41 - $crumbs->addTextCrumb($merchant->getName(), $merchant_uri); 42 - $crumbs->setBorder(true); 21 + 22 + if ($this->hasMerchant()) { 23 + $merchant = $this->getMerchant(); 24 + $merchant_uri = $merchant->getURI(); 25 + $crumbs->addTextCrumb($merchant->getName(), $merchant_uri); 26 + } 27 + 43 28 return $crumbs; 44 29 } 45 30 ··· 58 43 59 44 $nav->addLabel(pht('Merchant')); 60 45 61 - $nav->addFilter( 62 - 'overview', 63 - pht('Overview'), 64 - $this->getApplicationURI("/merchant/{$id}/"), 65 - 'fa-building-o'); 46 + $nav->newLink('overview') 47 + ->setName(pht('Overview')) 48 + ->setHref($merchant->getURI()) 49 + ->setIcon('fa-building-o'); 50 + 51 + $nav->newLink('details') 52 + ->setName(pht('Account Details')) 53 + ->setHref($merchant->getDetailsURI()) 54 + ->setIcon('fa-address-card-o') 55 + ->setDisabled(!$can_edit) 56 + ->setWorkflow(!$can_edit); 57 + 58 + $nav->addLabel(pht('Payments')); 59 + 60 + $nav->newLink('providers') 61 + ->setName(pht('Payment Providers')) 62 + ->setHref($merchant->getPaymentProvidersURI()) 63 + ->setIcon('fa-credit-card') 64 + ->setDisabled(!$can_edit) 65 + ->setWorkflow(!$can_edit); 66 + 67 + $nav->newLink('orders') 68 + ->setName(pht('Orders')) 69 + ->setHref($merchant->getOrdersURI()) 70 + ->setIcon('fa-shopping-bag') 71 + ->setDisabled(!$can_edit) 72 + ->setWorkflow(!$can_edit); 66 73 67 - if ($can_edit) { 68 - $nav->addFilter( 69 - 'orders', 70 - pht('Orders'), 71 - $this->getApplicationURI("merchant/orders/{$id}/"), 72 - 'fa-retweet'); 74 + $nav->newLink('subscriptions') 75 + ->setName(pht('Subscriptions')) 76 + ->setHref($merchant->getSubscriptionsURI()) 77 + ->setIcon('fa-retweet') 78 + ->setDisabled(!$can_edit) 79 + ->setWorkflow(!$can_edit); 73 80 74 - $nav->addFilter( 75 - 'subscriptions', 76 - pht('Subscriptions'), 77 - $this->getApplicationURI("merchant/{$id}/subscription/"), 78 - 'fa-shopping-cart'); 81 + $nav->addLabel(pht('Personnel')); 79 82 80 - $nav->addFilter( 81 - 'managers', 82 - pht('Managers'), 83 - $this->getApplicationURI("/merchant/manager/{$id}/"), 84 - 'fa-group'); 85 - } 83 + $nav->newLink('managers') 84 + ->setName(pht('Managers')) 85 + ->setHref($merchant->getManagersURI()) 86 + ->setIcon('fa-group'); 86 87 87 88 $nav->selectFilter($filter); 88 89
+127
src/applications/phortune/controller/merchant/PhortuneMerchantProviderViewController.php
··· 1 + <?php 2 + 3 + final class PhortuneMerchantProviderViewController 4 + extends PhortuneMerchantController { 5 + 6 + protected function shouldRequireMerchantEditCapability() { 7 + return true; 8 + } 9 + 10 + protected function handleMerchantRequest(AphrontRequest $request) { 11 + $viewer = $request->getViewer(); 12 + $merchant = $this->getMerchant(); 13 + 14 + $provider = id(new PhortunePaymentProviderConfigQuery()) 15 + ->setViewer($viewer) 16 + ->withIDs(array($request->getURIData('providerID'))) 17 + ->executeOne(); 18 + if (!$provider) { 19 + return new Aphront404Response(); 20 + } 21 + 22 + $provider_type = $provider->buildProvider(); 23 + 24 + $crumbs = $this->buildApplicationCrumbs() 25 + ->addTextCrumb($merchant->getName(), $merchant->getURI()) 26 + ->addTextCrumb( 27 + pht('Payment Providers'), 28 + $merchant->getPaymentProvidersURI()) 29 + ->addTextCrumb($provider->getObjectName()) 30 + ->setBorder(true); 31 + 32 + $header = id(new PHUIHeaderView()) 33 + ->setHeader(pht('Payment Provider: %s', $provider_type->getName())); 34 + 35 + $details = $this->newDetailsView($provider); 36 + 37 + $timeline = $this->buildTransactionTimeline( 38 + $provider, 39 + new PhortunePaymentProviderConfigTransactionQuery()); 40 + $timeline->setShouldTerminate(true); 41 + 42 + $curtain = $this->buildCurtainView($provider); 43 + 44 + $view = id(new PHUITwoColumnView()) 45 + ->setHeader($header) 46 + ->setCurtain($curtain) 47 + ->setMainColumn( 48 + array( 49 + $details, 50 + $timeline, 51 + )); 52 + 53 + return $this->newPage() 54 + ->setTitle($provider->getObjectName()) 55 + ->setCrumbs($crumbs) 56 + ->appendChild($view); 57 + } 58 + 59 + private function buildCurtainView(PhortunePaymentProviderConfig $provider) { 60 + $viewer = $this->getViewer(); 61 + $merchant = $this->getMerchant(); 62 + 63 + $can_edit = PhabricatorPolicyFilter::hasCapability( 64 + $viewer, 65 + $provider, 66 + PhabricatorPolicyCapability::CAN_EDIT); 67 + 68 + $edit_uri = $this->getApplicationURI( 69 + urisprintf( 70 + 'merchant/%d/providers/edit/%d/', 71 + $merchant->getID(), 72 + $provider->getID())); 73 + 74 + $disable_uri = $this->getApplicationURI( 75 + urisprintf( 76 + 'merchant/%d/providers/%d/disable/', 77 + $merchant->getID(), 78 + $provider->getID())); 79 + 80 + $curtain = $this->newCurtainView($provider); 81 + 82 + $curtain->addAction( 83 + id(new PhabricatorActionView()) 84 + ->setName(pht('Edit Provider')) 85 + ->setIcon('fa-pencil') 86 + ->setHref($edit_uri) 87 + ->setDisabled(!$can_edit) 88 + ->setWorkflow(!$can_edit)); 89 + 90 + $provider_type = $provider->buildProvider(); 91 + 92 + if ($provider_type->isEnabled()) { 93 + $disable_icon = 'fa-times'; 94 + $disable_name = pht('Disable Provider'); 95 + } else { 96 + $disable_icon = 'fa-check'; 97 + $disable_name = pht('Enable Provider'); 98 + } 99 + 100 + $curtain->addAction( 101 + id(new PhabricatorActionView()) 102 + ->setName($disable_name) 103 + ->setIcon($disable_icon) 104 + ->setHref($disable_uri) 105 + ->setDisabled(!$can_edit) 106 + ->setWorkflow(true)); 107 + 108 + return $curtain; 109 + } 110 + 111 + private function newDetailsView(PhortunePaymentProviderConfig $provider) { 112 + $viewer = $this->getViewer(); 113 + 114 + $view = id(new PHUIPropertyListView()) 115 + ->setUser($viewer); 116 + 117 + $provider_type = $provider->buildProvider(); 118 + 119 + $view->addProperty(pht('Provider Type'), $provider_type->getName()); 120 + 121 + return id(new PHUIObjectBoxView()) 122 + ->setHeaderText(pht('Payment Provider Details')) 123 + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 124 + ->addPropertyList($view); 125 + } 126 + 127 + }
+116
src/applications/phortune/controller/merchant/PhortuneMerchantProvidersController.php
··· 1 + <?php 2 + 3 + final class PhortuneMerchantProvidersController 4 + extends PhortuneMerchantProfileController { 5 + 6 + protected function shouldRequireMerchantEditCapability() { 7 + return true; 8 + } 9 + 10 + protected function handleMerchantRequest(AphrontRequest $request) { 11 + $viewer = $request->getViewer(); 12 + $merchant = $this->getMerchant(); 13 + 14 + $crumbs = $this->buildApplicationCrumbs() 15 + ->addTextCrumb(pht('Payment Providers')) 16 + ->setBorder(true); 17 + 18 + $header = $this->buildHeaderView(); 19 + 20 + $title = pht( 21 + '%s %s', 22 + $merchant->getObjectName(), 23 + $merchant->getName()); 24 + 25 + $providers = id(new PhortunePaymentProviderConfigQuery()) 26 + ->setViewer($viewer) 27 + ->withMerchantPHIDs(array($merchant->getPHID())) 28 + ->execute(); 29 + 30 + $provider_list = $this->buildProviderList( 31 + $merchant, 32 + $providers); 33 + 34 + $navigation = $this->buildSideNavView('providers'); 35 + 36 + $view = id(new PHUITwoColumnView()) 37 + ->setHeader($header) 38 + ->setFooter( 39 + array( 40 + $provider_list, 41 + )); 42 + 43 + return $this->newPage() 44 + ->setTitle($title) 45 + ->setCrumbs($crumbs) 46 + ->setNavigation($navigation) 47 + ->appendChild($view); 48 + } 49 + 50 + private function buildProviderList( 51 + PhortuneMerchant $merchant, 52 + array $providers) { 53 + 54 + $viewer = $this->getRequest()->getUser(); 55 + $id = $merchant->getID(); 56 + 57 + $can_edit = PhabricatorPolicyFilter::hasCapability( 58 + $viewer, 59 + $merchant, 60 + PhabricatorPolicyCapability::CAN_EDIT); 61 + 62 + $provider_list = id(new PHUIObjectItemListView()) 63 + ->setNoDataString(pht('This merchant has no payment providers.')); 64 + 65 + foreach ($providers as $provider_config) { 66 + $provider = $provider_config->buildProvider(); 67 + $provider_id = $provider_config->getID(); 68 + 69 + $item = id(new PHUIObjectItemView()) 70 + ->setObjectName($provider_config->getObjectName()) 71 + ->setHeader($provider->getName()) 72 + ->setHref($provider_config->getURI()); 73 + 74 + if ($provider->isEnabled()) { 75 + if ($provider->isAcceptingLivePayments()) { 76 + $item->setStatusIcon('fa-check green'); 77 + } else { 78 + $item->setStatusIcon('fa-warning yellow'); 79 + $item->addIcon('fa-exclamation-triangle', pht('Test Mode')); 80 + } 81 + 82 + $item->addAttribute($provider->getConfigureProvidesDescription()); 83 + } else { 84 + $item->setDisabled(true); 85 + $item->addAttribute( 86 + phutil_tag('em', array(), pht('This payment provider is disabled.'))); 87 + } 88 + 89 + $provider_list->addItem($item); 90 + } 91 + 92 + $add_uri = urisprintf( 93 + 'merchant/%d/providers/edit/', 94 + $merchant->getID()); 95 + $add_uri = $this->getApplicationURI($add_uri); 96 + 97 + $add_action = id(new PHUIButtonView()) 98 + ->setTag('a') 99 + ->setHref($add_uri) 100 + ->setText(pht('Add Payment Provider')) 101 + ->setDisabled(!$can_edit) 102 + ->setWorkflow(!$can_edit) 103 + ->setIcon('fa-plus'); 104 + 105 + $header = id(new PHUIHeaderView()) 106 + ->setHeader(pht('Payment Providers')) 107 + ->addActionLink($add_action); 108 + 109 + return id(new PHUIObjectBoxView()) 110 + ->setHeader($header) 111 + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 112 + ->setObjectList($provider_list); 113 + } 114 + 115 + 116 + }
+50
src/applications/phortune/controller/merchant/PhortuneMerchantSubscriptionListController.php
··· 1 + <?php 2 + 3 + final class PhortuneMerchantSubscriptionListController 4 + extends PhortuneMerchantProfileController { 5 + 6 + protected function shouldRequireMerchantEditCapability() { 7 + return true; 8 + } 9 + 10 + protected function handleMerchantRequest(AphrontRequest $request) { 11 + $viewer = $request->getViewer(); 12 + $merchant = $this->getMerchant(); 13 + 14 + $engine = id(new PhortuneCartSearchEngine()) 15 + ->setController($this) 16 + ->setMerchant($merchant); 17 + 18 + $subscription_id = $request->getURIData('subscriptionID'); 19 + if ($subscription_id) { 20 + $subscription = id(new PhortuneSubscriptionQuery()) 21 + ->setViewer($viewer) 22 + ->withIDs(array($subscription_id)) 23 + ->executeOne(); 24 + if (!$subscription) { 25 + return new Aphront404Response(); 26 + } 27 + 28 + $engine->setSubscription($subscription); 29 + $this->subscription = $subscription; 30 + } 31 + 32 + return $engine->buildResponse(); 33 + } 34 + 35 + protected function buildApplicationCrumbs() { 36 + $crumbs = parent::buildApplicationCrumbs(); 37 + 38 + if ($this->hasMerchant()) { 39 + $merchant = $this->getMerchant(); 40 + 41 + $crumbs->addTextCrumb( 42 + pht('Subscriptions'), 43 + $merchant->getSubscriptionsURI()); 44 + } 45 + 46 + return $crumbs; 47 + } 48 + 49 + 50 + }
+68
src/applications/phortune/controller/merchant/PhortuneMerchantSubscriptionsController.php
··· 1 + <?php 2 + 3 + final class PhortuneMerchantSubscriptionsController 4 + extends PhortuneMerchantProfileController { 5 + 6 + protected function shouldRequireMerchantEditCapability() { 7 + return true; 8 + } 9 + 10 + protected function handleMerchantRequest(AphrontRequest $request) { 11 + $merchant = $this->getMerchant(); 12 + $title = $merchant->getName(); 13 + 14 + $crumbs = $this->buildApplicationCrumbs() 15 + ->addTextCrumb(pht('Subscriptions')) 16 + ->setBorder(true); 17 + 18 + $header = $this->buildHeaderView(); 19 + 20 + $subscriptions = $this->buildSubscriptionsSection($merchant); 21 + 22 + $view = id(new PHUITwoColumnView()) 23 + ->setHeader($header) 24 + ->setFooter( 25 + array( 26 + $subscriptions, 27 + )); 28 + 29 + $navigation = $this->buildSideNavView('subscriptions'); 30 + 31 + return $this->newPage() 32 + ->setTitle($title) 33 + ->setCrumbs($crumbs) 34 + ->setNavigation($navigation) 35 + ->appendChild($view); 36 + } 37 + 38 + private function buildSubscriptionsSection(PhortuneMerchant $merchant) { 39 + $viewer = $this->getViewer(); 40 + 41 + $subscriptions = id(new PhortuneSubscriptionQuery()) 42 + ->setViewer($viewer) 43 + ->withMerchantPHIDs(array($merchant->getPHID())) 44 + ->setLimit(25) 45 + ->execute(); 46 + 47 + $subscriptions_uri = $merchant->getSubscriptionListURI(); 48 + 49 + $table = id(new PhortuneSubscriptionTableView()) 50 + ->setUser($viewer) 51 + ->setSubscriptions($subscriptions); 52 + 53 + $header = id(new PHUIHeaderView()) 54 + ->setHeader(pht('Subscriptions')) 55 + ->addActionLink( 56 + id(new PHUIButtonView()) 57 + ->setTag('a') 58 + ->setIcon('fa-list') 59 + ->setHref($subscriptions_uri) 60 + ->setText(pht('View All Subscriptions'))); 61 + 62 + return id(new PHUIObjectBoxView()) 63 + ->setHeader($header) 64 + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 65 + ->setTable($table); 66 + } 67 + 68 + }
-324
src/applications/phortune/controller/merchant/PhortuneMerchantViewController.php
··· 1 - <?php 2 - 3 - final class PhortuneMerchantViewController 4 - extends PhortuneMerchantProfileController { 5 - 6 - public function handleRequest(AphrontRequest $request) { 7 - $viewer = $request->getViewer(); 8 - $id = $request->getURIData('id'); 9 - 10 - $merchant = id(new PhortuneMerchantQuery()) 11 - ->setViewer($viewer) 12 - ->withIDs(array($id)) 13 - ->needProfileImage(true) 14 - ->executeOne(); 15 - if (!$merchant) { 16 - return new Aphront404Response(); 17 - } 18 - 19 - $this->setMerchant($merchant); 20 - $crumbs = $this->buildApplicationCrumbs(); 21 - $header = $this->buildHeaderView(); 22 - 23 - $title = pht( 24 - 'Merchant %d %s', 25 - $merchant->getID(), 26 - $merchant->getName()); 27 - 28 - $providers = id(new PhortunePaymentProviderConfigQuery()) 29 - ->setViewer($viewer) 30 - ->withMerchantPHIDs(array($merchant->getPHID())) 31 - ->execute(); 32 - 33 - $details = $this->buildDetailsView($merchant, $providers); 34 - $curtain = $this->buildCurtainView($merchant); 35 - 36 - $provider_list = $this->buildProviderList( 37 - $merchant, 38 - $providers); 39 - 40 - $timeline = $this->buildTransactionTimeline( 41 - $merchant, 42 - new PhortuneMerchantTransactionQuery()); 43 - $timeline->setShouldTerminate(true); 44 - 45 - $navigation = $this->buildSideNavView('overview'); 46 - 47 - $view = id(new PHUITwoColumnView()) 48 - ->setHeader($header) 49 - ->setCurtain($curtain) 50 - ->setMainColumn(array( 51 - $details, 52 - $provider_list, 53 - $timeline, 54 - )); 55 - 56 - return $this->newPage() 57 - ->setTitle($title) 58 - ->setCrumbs($crumbs) 59 - ->setNavigation($navigation) 60 - ->appendChild($view); 61 - } 62 - 63 - private function buildDetailsView( 64 - PhortuneMerchant $merchant, 65 - array $providers) { 66 - 67 - $viewer = $this->getRequest()->getUser(); 68 - 69 - $view = id(new PHUIPropertyListView()) 70 - ->setUser($viewer) 71 - ->setObject($merchant); 72 - 73 - $status_view = new PHUIStatusListView(); 74 - 75 - $have_any = false; 76 - $any_test = false; 77 - foreach ($providers as $provider_config) { 78 - $provider = $provider_config->buildProvider(); 79 - if ($provider->isEnabled()) { 80 - $have_any = true; 81 - } 82 - if (!$provider->isAcceptingLivePayments()) { 83 - $any_test = true; 84 - } 85 - } 86 - 87 - if ($have_any) { 88 - $status_view->addItem( 89 - id(new PHUIStatusItemView()) 90 - ->setIcon(PHUIStatusItemView::ICON_ACCEPT, 'green') 91 - ->setTarget(pht('Accepts Payments')) 92 - ->setNote(pht('This merchant can accept payments.'))); 93 - 94 - if ($any_test) { 95 - $status_view->addItem( 96 - id(new PHUIStatusItemView()) 97 - ->setIcon(PHUIStatusItemView::ICON_WARNING, 'yellow') 98 - ->setTarget(pht('Test Mode')) 99 - ->setNote(pht('This merchant is accepting test payments.'))); 100 - } else { 101 - $status_view->addItem( 102 - id(new PHUIStatusItemView()) 103 - ->setIcon(PHUIStatusItemView::ICON_ACCEPT, 'green') 104 - ->setTarget(pht('Live Mode')) 105 - ->setNote(pht('This merchant is accepting live payments.'))); 106 - } 107 - } else if ($providers) { 108 - $status_view->addItem( 109 - id(new PHUIStatusItemView()) 110 - ->setIcon(PHUIStatusItemView::ICON_REJECT, 'red') 111 - ->setTarget(pht('No Enabled Providers')) 112 - ->setNote( 113 - pht( 114 - 'All of the payment providers for this merchant are '. 115 - 'disabled.'))); 116 - } else { 117 - $status_view->addItem( 118 - id(new PHUIStatusItemView()) 119 - ->setIcon(PHUIStatusItemView::ICON_WARNING, 'yellow') 120 - ->setTarget(pht('No Providers')) 121 - ->setNote( 122 - pht( 123 - 'This merchant does not have any payment providers configured '. 124 - 'yet, so it can not accept payments. Add a provider.'))); 125 - } 126 - 127 - $view->addProperty(pht('Status'), $status_view); 128 - 129 - $invoice_from = $merchant->getInvoiceEmail(); 130 - if (!$invoice_from) { 131 - $invoice_from = pht('No email address set'); 132 - $invoice_from = phutil_tag('em', array(), $invoice_from); 133 - } 134 - $view->addProperty(pht('Invoice From'), $invoice_from); 135 - 136 - $description = $merchant->getDescription(); 137 - if (strlen($description)) { 138 - $description = new PHUIRemarkupView($viewer, $description); 139 - $view->addSectionHeader( 140 - pht('Description'), 141 - PHUIPropertyListView::ICON_SUMMARY); 142 - $view->addTextContent($description); 143 - } 144 - 145 - $contact_info = $merchant->getContactInfo(); 146 - if (strlen($contact_info)) { 147 - $contact_info = new PHUIRemarkupView($viewer, $contact_info); 148 - $view->addSectionHeader( 149 - pht('Contact Info'), 150 - PHUIPropertyListView::ICON_SUMMARY); 151 - $view->addTextContent($contact_info); 152 - } 153 - 154 - $footer_info = $merchant->getInvoiceFooter(); 155 - if (strlen($footer_info)) { 156 - $footer_info = new PHUIRemarkupView($viewer, $footer_info); 157 - $view->addSectionHeader( 158 - pht('Invoice Footer'), 159 - PHUIPropertyListView::ICON_SUMMARY); 160 - $view->addTextContent($footer_info); 161 - } 162 - 163 - return id(new PHUIObjectBoxView()) 164 - ->setHeaderText(pht('Details')) 165 - ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 166 - ->appendChild($view); 167 - } 168 - 169 - private function buildCurtainView(PhortuneMerchant $merchant) { 170 - $viewer = $this->getRequest()->getUser(); 171 - $id = $merchant->getID(); 172 - 173 - $can_edit = PhabricatorPolicyFilter::hasCapability( 174 - $viewer, 175 - $merchant, 176 - PhabricatorPolicyCapability::CAN_EDIT); 177 - 178 - $curtain = $this->newCurtainView($merchant); 179 - 180 - $curtain->addAction( 181 - id(new PhabricatorActionView()) 182 - ->setName(pht('Edit Merchant')) 183 - ->setIcon('fa-pencil') 184 - ->setDisabled(!$can_edit) 185 - ->setWorkflow(!$can_edit) 186 - ->setHref($this->getApplicationURI("merchant/edit/{$id}/"))); 187 - 188 - $curtain->addAction( 189 - id(new PhabricatorActionView()) 190 - ->setName(pht('Edit Logo')) 191 - ->setIcon('fa-camera') 192 - ->setDisabled(!$can_edit) 193 - ->setWorkflow(!$can_edit) 194 - ->setHref($this->getApplicationURI("merchant/picture/{$id}/"))); 195 - 196 - $curtain->addAction( 197 - id(new PhabricatorActionView()) 198 - ->setName(pht('New Invoice')) 199 - ->setIcon('fa-fax') 200 - ->setHref($this->getApplicationURI("merchant/{$id}/invoice/new/")) 201 - ->setDisabled(!$can_edit) 202 - ->setWorkflow(!$can_edit)); 203 - 204 - $member_phids = $merchant->getMemberPHIDs(); 205 - $handles = $viewer->loadHandles($member_phids); 206 - 207 - $member_list = id(new PHUIObjectItemListView()) 208 - ->setSimple(true); 209 - 210 - foreach ($member_phids as $member_phid) { 211 - $image_uri = $handles[$member_phid]->getImageURI(); 212 - $image_href = $handles[$member_phid]->getURI(); 213 - $person = $handles[$member_phid]; 214 - 215 - $member = id(new PHUIObjectItemView()) 216 - ->setImageURI($image_uri) 217 - ->setHref($image_href) 218 - ->setHeader($person->getFullName()); 219 - 220 - $member_list->addItem($member); 221 - } 222 - 223 - $curtain->newPanel() 224 - ->setHeaderText(pht('Managers')) 225 - ->appendChild($member_list); 226 - 227 - return $curtain; 228 - } 229 - 230 - private function buildProviderList( 231 - PhortuneMerchant $merchant, 232 - array $providers) { 233 - 234 - $viewer = $this->getRequest()->getUser(); 235 - $id = $merchant->getID(); 236 - 237 - $can_edit = PhabricatorPolicyFilter::hasCapability( 238 - $viewer, 239 - $merchant, 240 - PhabricatorPolicyCapability::CAN_EDIT); 241 - 242 - $provider_list = id(new PHUIObjectItemListView()) 243 - ->setFlush(true) 244 - ->setNoDataString(pht('This merchant has no payment providers.')); 245 - 246 - foreach ($providers as $provider_config) { 247 - $provider = $provider_config->buildProvider(); 248 - $provider_id = $provider_config->getID(); 249 - 250 - $item = id(new PHUIObjectItemView()) 251 - ->setHeader($provider->getName()); 252 - 253 - if ($provider->isEnabled()) { 254 - if ($provider->isAcceptingLivePayments()) { 255 - $item->setStatusIcon('fa-check green'); 256 - } else { 257 - $item->setStatusIcon('fa-warning yellow'); 258 - $item->addIcon('fa-exclamation-triangle', pht('Test Mode')); 259 - } 260 - 261 - $item->addAttribute($provider->getConfigureProvidesDescription()); 262 - } else { 263 - // Don't show disabled providers to users who can't manage the merchant 264 - // account. 265 - if (!$can_edit) { 266 - continue; 267 - } 268 - $item->setDisabled(true); 269 - $item->addAttribute( 270 - phutil_tag('em', array(), pht('This payment provider is disabled.'))); 271 - } 272 - 273 - 274 - if ($can_edit) { 275 - $edit_uri = $this->getApplicationURI( 276 - "/provider/edit/{$provider_id}/"); 277 - $disable_uri = $this->getApplicationURI( 278 - "/provider/disable/{$provider_id}/"); 279 - 280 - if ($provider->isEnabled()) { 281 - $disable_icon = 'fa-times'; 282 - $disable_name = pht('Disable'); 283 - } else { 284 - $disable_icon = 'fa-check'; 285 - $disable_name = pht('Enable'); 286 - } 287 - 288 - $item->addAction( 289 - id(new PHUIListItemView()) 290 - ->setIcon($disable_icon) 291 - ->setHref($disable_uri) 292 - ->setName($disable_name) 293 - ->setWorkflow(true)); 294 - 295 - $item->addAction( 296 - id(new PHUIListItemView()) 297 - ->setIcon('fa-pencil') 298 - ->setHref($edit_uri) 299 - ->setName(pht('Edit'))); 300 - } 301 - 302 - $provider_list->addItem($item); 303 - } 304 - 305 - $add_action = id(new PHUIButtonView()) 306 - ->setTag('a') 307 - ->setHref($this->getApplicationURI('provider/edit/?merchantID='.$id)) 308 - ->setText(pht('Add Payment Provider')) 309 - ->setDisabled(!$can_edit) 310 - ->setWorkflow(!$can_edit) 311 - ->setIcon('fa-plus'); 312 - 313 - $header = id(new PHUIHeaderView()) 314 - ->setHeader(pht('Payment Providers')) 315 - ->addActionLink($add_action); 316 - 317 - return id(new PHUIObjectBoxView()) 318 - ->setHeader($header) 319 - ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 320 - ->setObjectList($provider_list); 321 - } 322 - 323 - 324 - }
+10 -5
src/applications/phortune/controller/provider/PhortuneProviderDisableController.php src/applications/phortune/controller/merchant/PhortuneMerchantProviderDisableController.php
··· 1 1 <?php 2 2 3 - final class PhortuneProviderDisableController 3 + final class PhortuneMerchantProviderDisableController 4 4 extends PhortuneMerchantController { 5 5 6 - public function handleRequest(AphrontRequest $request) { 6 + protected function shouldRequireMerchantEditCapability() { 7 + return true; 8 + } 9 + 10 + protected function handleMerchantRequest(AphrontRequest $request) { 7 11 $viewer = $request->getViewer(); 8 - $id = $request->getURIData('id'); 12 + $merchant = $this->getMerchant(); 13 + 14 + $id = $request->getURIData('providerID'); 9 15 10 16 $provider_config = id(new PhortunePaymentProviderConfigQuery()) 11 17 ->setViewer($viewer) ··· 20 26 return new Aphront404Response(); 21 27 } 22 28 23 - $merchant = $provider_config->getMerchant(); 24 29 $merchant_id = $merchant->getID(); 25 - $cancel_uri = $this->getApplicationURI("merchant/{$merchant_id}/"); 30 + $cancel_uri = $provider_config->getURI(); 26 31 27 32 $provider = $provider_config->buildProvider(); 28 33
+20 -27
src/applications/phortune/controller/provider/PhortuneProviderEditController.php src/applications/phortune/controller/merchant/PhortuneMerchantProviderEditController.php
··· 1 1 <?php 2 2 3 - final class PhortuneProviderEditController 3 + final class PhortuneMerchantProviderEditController 4 4 extends PhortuneMerchantController { 5 5 6 - public function handleRequest(AphrontRequest $request) { 6 + protected function shouldRequireMerchantEditCapability() { 7 + return true; 8 + } 9 + 10 + protected function handleMerchantRequest(AphrontRequest $request) { 7 11 $viewer = $request->getViewer(); 12 + $merchant = $this->getMerchant(); 13 + 8 14 $id = $request->getURIData('id'); 9 15 10 16 if ($id) { 11 17 $provider_config = id(new PhortunePaymentProviderConfigQuery()) 12 18 ->setViewer($viewer) 13 19 ->withIDs(array($id)) 20 + ->withMerchantPHIDs(array($merchant->getPHID())) 14 21 ->requireCapabilities( 15 22 array( 16 23 PhabricatorPolicyCapability::CAN_VIEW, ··· 25 32 26 33 $merchant = $provider_config->getMerchant(); 27 34 $merchant_id = $merchant->getID(); 28 - $cancel_uri = $this->getApplicationURI("merchant/{$merchant_id}/"); 35 + $cancel_uri = $provider_config->getURI(); 29 36 } else { 30 - $merchant = id(new PhortuneMerchantQuery()) 31 - ->setViewer($viewer) 32 - ->withIDs(array($request->getStr('merchantID'))) 33 - ->requireCapabilities( 34 - array( 35 - PhabricatorPolicyCapability::CAN_VIEW, 36 - PhabricatorPolicyCapability::CAN_EDIT, 37 - )) 38 - ->executeOne(); 39 - if (!$merchant) { 40 - return new Aphront404Response(); 41 - } 42 37 $merchant_id = $merchant->getID(); 43 38 44 39 $current_providers = id(new PhortunePaymentProviderConfigQuery()) ··· 62 57 } 63 58 64 59 $provider_config->setProviderClass($class); 65 - 66 - $cancel_uri = $this->getApplicationURI( 67 - 'provider/edit/?merchantID='.$merchant_id); 60 + $cancel_uri = $merchant->getPaymentProvidersURI(); 68 61 } 69 62 70 63 $provider = $provider_config->buildProvider(); ··· 123 116 124 117 $xactions = array(); 125 118 126 - $xactions[] = id(new PhortunePaymentProviderConfigTransaction()) 127 - ->setTransactionType( 128 - PhortunePaymentProviderConfigTransaction::TYPE_CREATE) 129 - ->setNewValue(true); 119 + if (!$provider_config->getID()) { 120 + $xactions[] = id(new PhortunePaymentProviderConfigTransaction()) 121 + ->setTransactionType( 122 + PhortunePaymentProviderConfigTransaction::TYPE_CREATE) 123 + ->setNewValue(true); 124 + } 130 125 131 126 foreach ($xaction_values as $key => $value) { 132 127 $xactions[] = id(clone $template) ··· 143 138 144 139 $editor->applyTransactions($provider_config, $xactions); 145 140 146 - $merchant_uri = $this->getApplicationURI( 147 - 'merchant/'.$merchant->getID().'/'); 148 - return id(new AphrontRedirectResponse())->setURI($merchant_uri); 141 + $next_uri = $provider_config->getURI(); 142 + 143 + return id(new AphrontRedirectResponse())->setURI($next_uri); 149 144 } 150 145 } 151 146 } else { ··· 155 150 156 151 $form = id(new AphrontFormView()) 157 152 ->setUser($viewer) 158 - ->addHiddenInput('merchantID', $merchant->getID()) 159 153 ->addHiddenInput('class', $provider_config->getProviderClass()) 160 154 ->addHiddenInput('edit', true) 161 155 ->appendChild( ··· 261 255 262 256 $form = id(new AphrontFormView()) 263 257 ->setUser($viewer) 264 - ->addHiddenInput('merchantID', $merchant->getID()) 265 258 ->appendRemarkupInstructions( 266 259 pht('Choose the type of payment provider to add:')) 267 260 ->appendChild($panel_classes)
+1 -1
src/applications/phortune/editor/PhortuneMerchantEditEngine.php
··· 58 58 } 59 59 60 60 protected function getObjectViewURI($object) { 61 - return $object->getURI(); 61 + return $object->getDetailsURI(); 62 62 } 63 63 64 64 public function isEngineConfigurable() {
-1
src/applications/phortune/editor/PhortuneMerchantEditor.php
··· 18 18 public function getTransactionTypes() { 19 19 $types = parent::getTransactionTypes(); 20 20 21 - $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 22 21 $types[] = PhabricatorTransactions::TYPE_EDGE; 23 22 24 23 return $types;
+1 -1
src/applications/phortune/provider/PhortuneTestPaymentProvider.php
··· 26 26 } 27 27 28 28 public function getConfigureInstructions() { 29 - return pht('This providers does not require any special configuration.'); 29 + return pht('This provider does not require any special configuration.'); 30 30 } 31 31 32 32 public function canRunConfigurationTest() {
+44 -3
src/applications/phortune/storage/PhortuneMerchant.php
··· 6 6 PhabricatorPolicyInterface { 7 7 8 8 protected $name; 9 - protected $viewPolicy; 10 9 protected $description; 11 10 protected $contactInfo; 12 11 protected $invoiceEmail; ··· 18 17 19 18 public static function initializeNewMerchant(PhabricatorUser $actor) { 20 19 return id(new PhortuneMerchant()) 21 - ->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()) 22 20 ->attachMemberPHIDs(array()) 23 21 ->setContactInfo('') 24 22 ->setInvoiceEmail('') ··· 74 72 return pht('Merchant %d', $this->getID()); 75 73 } 76 74 75 + public function getDetailsURI() { 76 + return urisprintf( 77 + '/phortune/merchant/%d/details/', 78 + $this->getID()); 79 + } 80 + 81 + public function getOrdersURI() { 82 + return urisprintf( 83 + '/phortune/merchant/%d/orders/', 84 + $this->getID()); 85 + } 86 + 87 + public function getOrderListURI($path = '') { 88 + return urisprintf( 89 + '/phortune/merchant/%d/orders/list/%s', 90 + $this->getID(), 91 + $path); 92 + } 93 + 94 + public function getSubscriptionsURI() { 95 + return urisprintf( 96 + '/phortune/merchant/%d/subscriptions/', 97 + $this->getID()); 98 + } 99 + 100 + public function getSubscriptionListURI($path = '') { 101 + return urisprintf( 102 + '/phortune/merchant/%d/subscriptions/list/%s', 103 + $this->getID(), 104 + $path); 105 + } 106 + 107 + public function getManagersURI() { 108 + return urisprintf( 109 + '/phortune/merchant/%d/managers/', 110 + $this->getID()); 111 + } 112 + 113 + public function getPaymentProvidersURI() { 114 + return urisprintf( 115 + '/phortune/merchant/%d/providers/', 116 + $this->getID()); 117 + } 77 118 78 119 /* -( PhabricatorApplicationTransactionInterface )------------------------- */ 79 120 ··· 100 141 public function getPolicy($capability) { 101 142 switch ($capability) { 102 143 case PhabricatorPolicyCapability::CAN_VIEW: 103 - return $this->getViewPolicy(); 144 + return PhabricatorPolicies::getMostOpenPolicy(); 104 145 case PhabricatorPolicyCapability::CAN_EDIT: 105 146 return PhabricatorPolicies::POLICY_NOONE; 106 147 }
+12
src/applications/phortune/storage/PhortunePaymentProviderConfig.php
··· 17 17 PhortuneMerchant $merchant) { 18 18 return id(new PhortunePaymentProviderConfig()) 19 19 ->setMerchantPHID($merchant->getPHID()) 20 + ->attachMerchant($merchant) 20 21 ->setIsEnabled(1); 21 22 } 22 23 ··· 73 74 public function buildProvider() { 74 75 return newv($this->getProviderClass(), array()) 75 76 ->setProviderConfig($this); 77 + } 78 + 79 + public function getObjectName() { 80 + return pht('Provider %d', $this->getID()); 81 + } 82 + 83 + public function getURI() { 84 + return urisprintf( 85 + '/phortune/merchant/%d/providers/%d/', 86 + $this->getMerchant()->getID(), 87 + $this->getID()); 76 88 } 77 89 78 90
+11 -11
src/applications/phortune/view/PhortuneOrderTableView.php
··· 3 3 final class PhortuneOrderTableView extends AphrontView { 4 4 5 5 private $carts; 6 - private $handles; 7 6 private $noDataString; 8 7 private $isInvoices; 9 8 private $isMerchantView; 10 - 11 - public function setHandles(array $handles) { 12 - $this->handles = $handles; 13 - return $this; 14 - } 15 - 16 - public function getHandles() { 17 - return $this->handles; 18 - } 19 9 20 10 public function setCarts(array $carts) { 21 11 $this->carts = $carts; ··· 55 45 56 46 public function render() { 57 47 $carts = $this->getCarts(); 58 - $handles = $this->getHandles(); 59 48 $viewer = $this->getUser(); 60 49 61 50 $is_invoices = $this->getIsInvoices(); 62 51 $is_merchant = $this->getIsMerchantView(); 52 + 53 + $phids = array(); 54 + foreach ($carts as $cart) { 55 + $phids[] = $cart->getPHID(); 56 + foreach ($cart->getPurchases() as $purchase) { 57 + $phids[] = $purchase->getPHID(); 58 + } 59 + $phids[] = $cart->getMerchantPHID(); 60 + } 61 + 62 + $handles = $viewer->loadHandles($phids); 63 63 64 64 $rows = array(); 65 65 $rowc = array();