protected function loadPage() { $table = new PhortuneMerchant(); $conn = $table->establishConnection('r'); $rows = queryfx_all($conn, 'SELECT m.* FROM %T m %Q %Q %Q %Q', $table->getTableName(), $this->buildJoinClause($conn), $this->buildWhereClause($conn), $this->buildOrderClause($conn), $this->buildLimitClause($conn)); return $table->loadAllFromArray($rows); }
private function loadEnabledProvidersForMerchant(PhortuneMerchant $merchant) { $viewer = $this->getRequest()->getUser(); $provider_configs = id(new PhortunePaymentProviderConfigQuery())->setViewer($viewer)->withMerchantPHIDs(array($merchant->getPHID()))->execute(); $providers = mpull($provider_configs, 'buildProvider', 'getID'); foreach ($providers as $key => $provider) { if (!$provider->isEnabled()) { unset($providers[$key]); } } return $providers; }
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)->setObjectList($provider_list); }
public function processRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); if ($this->id) { $merchant = id(new PhortuneMerchantQuery())->setViewer($viewer)->withIDs(array($this->id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne(); if (!$merchant) { return new Aphront404Response(); } $is_new = false; } else { $this->requireApplicationCapability(PhortuneMerchantCapability::CAPABILITY); $merchant = PhortuneMerchant::initializeNewMerchant($viewer); $merchant->attachMemberPHIDs(array($viewer->getPHID())); $is_new = true; } if ($is_new) { $title = pht('Create Merchant'); $button_text = pht('Create Merchant'); $cancel_uri = $this->getApplicationURI('merchant/'); } else { $title = pht('Edit Merchant %d %s', $merchant->getID(), $merchant->getName()); $button_text = pht('Save Changes'); $cancel_uri = $this->getApplicationURI('/merchant/' . $merchant->getID() . '/'); } $e_name = true; $v_name = $merchant->getName(); $v_desc = $merchant->getDescription(); $v_members = $merchant->getMemberPHIDs(); $e_members = null; $validation_exception = null; if ($request->isFormPost()) { $v_name = $request->getStr('name'); $v_desc = $request->getStr('desc'); $v_view = $request->getStr('viewPolicy'); $v_edit = $request->getStr('editPolicy'); $v_members = $request->getArr('memberPHIDs'); $type_name = PhortuneMerchantTransaction::TYPE_NAME; $type_desc = PhortuneMerchantTransaction::TYPE_DESCRIPTION; $type_edge = PhabricatorTransactions::TYPE_EDGE; $type_view = PhabricatorTransactions::TYPE_VIEW_POLICY; $edge_members = PhortuneMerchantHasMemberEdgeType::EDGECONST; $xactions = array(); $xactions[] = id(new PhortuneMerchantTransaction())->setTransactionType($type_name)->setNewValue($v_name); $xactions[] = id(new PhortuneMerchantTransaction())->setTransactionType($type_desc)->setNewValue($v_desc); $xactions[] = id(new PhortuneMerchantTransaction())->setTransactionType($type_view)->setNewValue($v_view); $xactions[] = id(new PhortuneMerchantTransaction())->setTransactionType($type_edge)->setMetadataValue('edge:type', $edge_members)->setNewValue(array('=' => array_fuse($v_members))); $editor = id(new PhortuneMerchantEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true); try { $editor->applyTransactions($merchant, $xactions); $id = $merchant->getID(); $merchant_uri = $this->getApplicationURI("merchant/{$id}/"); return id(new AphrontRedirectResponse())->setURI($merchant_uri); } catch (PhabricatorApplicationTransactionValidationException $ex) { $validation_exception = $ex; $e_name = $ex->getShortMessage($type_name); $e_mbmers = $ex->getShortMessage($type_edge); $merchant->setViewPolicy($v_view); } } $policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->setObject($merchant)->execute(); $form = id(new AphrontFormView())->setUser($viewer)->appendChild(id(new AphrontFormTextControl())->setName('name')->setLabel(pht('Name'))->setValue($v_name)->setError($e_name))->appendChild(id(new PhabricatorRemarkupControl())->setUser($viewer)->setName('desc')->setLabel(pht('Description'))->setValue($v_desc))->appendControl(id(new AphrontFormTokenizerControl())->setDatasource(new PhabricatorPeopleDatasource())->setLabel(pht('Members'))->setName('memberPHIDs')->setValue($v_members)->setError($e_members))->appendChild(id(new AphrontFormPolicyControl())->setName('viewPolicy')->setPolicyObject($merchant)->setCapability(PhabricatorPolicyCapability::CAN_VIEW)->setPolicies($policies))->appendChild(id(new AphrontFormSubmitControl())->setValue($button_text)->addCancelButton($cancel_uri)); $crumbs = $this->buildApplicationCrumbs(); if ($is_new) { $crumbs->addTextCrumb(pht('Create Merchant')); } else { $crumbs->addTextCrumb(pht('Merchant %d', $merchant->getID()), $this->getApplicationURI('/merchant/' . $merchant->getID() . '/')); $crumbs->addTextCrumb(pht('Edit')); } $box = id(new PHUIObjectBoxView())->setValidationException($validation_exception)->setHeaderText($title)->setForm($form); return $this->buildApplicationPage(array($crumbs, $box), array('title' => $title)); }
public function getDetailURI(PhortuneMerchant $authority = null) { if ($authority) { $prefix = 'merchant/' . $authority->getID() . '/'; } else { $prefix = ''; } return '/phortune/' . $prefix . 'cart/' . $this->getID() . '/'; }
public static function initializeNewProvider(PhortuneMerchant $merchant) { return id(new PhortunePaymentProviderConfig())->setMerchantPHID($merchant->getPHID())->setIsEnabled(1); }
private function processChooseClassRequest(AphrontRequest $request, PhortuneMerchant $merchant, array $current_map) { $viewer = $request->getUser(); $providers = PhortunePaymentProvider::getAllProviders(); $v_class = null; $errors = array(); if ($request->isFormPost()) { $v_class = $request->getStr('class'); if (!isset($providers[$v_class])) { $errors[] = pht('You must select a valid provider type.'); } } $merchant_id = $merchant->getID(); $cancel_uri = $this->getApplicationURI("merchant/{$merchant_id}/"); if (!$v_class) { $v_class = key($providers); } $panel_classes = id(new AphrontFormRadioButtonControl())->setName('class')->setValue($v_class); $providers = msort($providers, 'getConfigureName'); foreach ($providers as $class => $provider) { $disabled = isset($current_map[$class]); if ($disabled) { $description = phutil_tag('em', array(), pht('This merchant already has a payment account configured ' . 'with this provider.')); } else { $description = $provider->getConfigureDescription(); } $panel_classes->addButton($class, $provider->getConfigureName(), $description, null, $disabled); } $form = id(new AphrontFormView())->setUser($viewer)->addHiddenInput('merchantID', $merchant->getID())->appendRemarkupInstructions(pht('Choose the type of payment provider to add:'))->appendChild($panel_classes)->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Continue'))->addCancelButton($cancel_uri)); $title = pht('Add Payment Provider'); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($merchant->getName(), $cancel_uri); $crumbs->addTextCrumb($title); $box = id(new PHUIObjectBoxView())->setHeaderText($title)->setFormErrors($errors)->setForm($form); return $this->buildApplicationPage(array($crumbs, $box), array('title' => $title)); }
protected function newEditableObject() { return PhortuneMerchant::initializeNewMerchant($this->getViewer()); }