diff --git a/src/applications/phortune/controller/PhortuneAccountEditController.php b/src/applications/phortune/controller/PhortuneAccountEditController.php index 7847420549..f51f1293d9 100644 --- a/src/applications/phortune/controller/PhortuneAccountEditController.php +++ b/src/applications/phortune/controller/PhortuneAccountEditController.php @@ -1,135 +1,129 @@ getViewer(); + $id = $request->getURIData('id'); - public function willProcessRequest(array $data) { - $this->id = idx($data, 'id'); - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); - - if ($this->id) { + if ($id) { $account = id(new PhortuneAccountQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$account) { return new Aphront404Response(); } $is_new = false; } else { $account = PhortuneAccount::initializeNewAccount($viewer); $account->attachMemberPHIDs(array($viewer->getPHID())); $is_new = true; } $v_name = $account->getName(); $e_name = true; $v_members = $account->getMemberPHIDs(); $e_members = null; $validation_exception = null; if ($request->isFormPost()) { $v_name = $request->getStr('name'); $v_members = $request->getArr('memberPHIDs'); $type_name = PhortuneAccountTransaction::TYPE_NAME; $type_edge = PhabricatorTransactions::TYPE_EDGE; $xactions = array(); $xactions[] = id(new PhortuneAccountTransaction()) ->setTransactionType($type_name) ->setNewValue($v_name); $xactions[] = id(new PhortuneAccountTransaction()) ->setTransactionType($type_edge) ->setMetadataValue( 'edge:type', PhortuneAccountHasMemberEdgeType::EDGECONST) ->setNewValue( array( '=' => array_fuse($v_members), )); $editor = id(new PhortuneAccountEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true); try { $editor->applyTransactions($account, $xactions); $account_uri = $this->getApplicationURI($account->getID().'/'); return id(new AphrontRedirectResponse())->setURI($account_uri); } catch (PhabricatorApplicationTransactionValidationException $ex) { $validation_exception = $ex; $e_name = $ex->getShortMessage($type_name); $e_members = $ex->getShortMessage($type_edge); } } $crumbs = $this->buildApplicationCrumbs(); if ($is_new) { $cancel_uri = $this->getApplicationURI('account/'); $crumbs->addTextCrumb(pht('Accounts'), $cancel_uri); $crumbs->addTextCrumb(pht('Create Account')); $title = pht('Create Payment Account'); $submit_button = pht('Create Account'); } else { $cancel_uri = $this->getApplicationURI($account->getID().'/'); $crumbs->addTextCrumb($account->getName(), $cancel_uri); $crumbs->addTextCrumb(pht('Edit')); $title = pht('Edit %s', $account->getName()); $submit_button = pht('Save Changes'); } $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild( id(new AphrontFormTextControl()) ->setName('name') ->setLabel(pht('Name')) ->setValue($v_name) ->setError($e_name)) ->appendControl( id(new AphrontFormTokenizerControl()) ->setDatasource(new PhabricatorPeopleDatasource()) ->setLabel(pht('Members')) ->setName('memberPHIDs') ->setValue($v_members) ->setError($e_members)) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue($submit_button) ->addCancelButton($cancel_uri)); $box = id(new PHUIObjectBoxView()) ->setHeaderText($title) ->setValidationException($validation_exception) ->setForm($form); return $this->buildApplicationPage( array( $crumbs, $box, ), array( 'title' => $title, )); } } diff --git a/src/applications/phortune/controller/PhortuneAccountListController.php b/src/applications/phortune/controller/PhortuneAccountListController.php index 8613cbda4d..0de082fa01 100644 --- a/src/applications/phortune/controller/PhortuneAccountListController.php +++ b/src/applications/phortune/controller/PhortuneAccountListController.php @@ -1,104 +1,103 @@ getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); $accounts = id(new PhortuneAccountQuery()) ->setViewer($viewer) ->withMemberPHIDs(array($viewer->getPHID())) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->execute(); $merchants = id(new PhortuneMerchantQuery()) ->setViewer($viewer) ->withMemberPHIDs(array($viewer->getPHID())) ->execute(); $title = pht('Accounts'); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Accounts')); $payment_list = id(new PHUIObjectItemListView()) ->setUser($viewer) ->setNoDataString( pht( 'You are not a member of any payment accounts. Payment '. 'accounts are used to make purchases.')); foreach ($accounts as $account) { $item = id(new PHUIObjectItemView()) ->setObjectName(pht('Account %d', $account->getID())) ->setHeader($account->getName()) ->setHref($this->getApplicationURI($account->getID().'/')) ->setObject($account); $payment_list->addItem($item); } $payment_header = id(new PHUIHeaderView()) ->setHeader(pht('Payment Accounts')) ->addActionLink( id(new PHUIButtonView()) ->setTag('a') ->setHref($this->getApplicationURI('account/edit/')) ->setIcon( id(new PHUIIconView()) ->setIconFont('fa-plus')) ->setText(pht('Create Account'))); $payment_box = id(new PHUIObjectBoxView()) ->setHeader($payment_header) ->setObjectList($payment_list); $merchant_list = id(new PHUIObjectItemListView()) ->setUser($viewer) ->setNoDataString( pht( 'You do not control any merchant accounts. Merchant accounts are '. 'used to receive payments.')); foreach ($merchants as $merchant) { $item = id(new PHUIObjectItemView()) ->setObjectName(pht('Merchant %d', $merchant->getID())) ->setHeader($merchant->getName()) ->setHref($this->getApplicationURI('/merchant/'.$merchant->getID().'/')) ->setObject($merchant); $merchant_list->addItem($item); } $merchant_header = id(new PHUIHeaderView()) ->setHeader(pht('Merchant Accounts')) ->addActionLink( id(new PHUIButtonView()) ->setTag('a') ->setHref($this->getApplicationURI('merchant/')) ->setIcon( id(new PHUIIconView()) ->setIconFont('fa-list')) ->setText(pht('View All Merchants'))); $merchant_box = id(new PHUIObjectBoxView()) ->setHeader($merchant_header) ->setObjectList($merchant_list); return $this->buildApplicationPage( array( $crumbs, $payment_box, $merchant_box, ), array( 'title' => $title, )); } } diff --git a/src/applications/phortune/controller/PhortuneCartAcceptController.php b/src/applications/phortune/controller/PhortuneCartAcceptController.php index 3db7467290..cb53e66f50 100644 --- a/src/applications/phortune/controller/PhortuneCartAcceptController.php +++ b/src/applications/phortune/controller/PhortuneCartAcceptController.php @@ -1,58 +1,52 @@ id = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); // You must control the merchant to accept orders. $authority = $this->loadMerchantAuthority(); if (!$authority) { return new Aphront404Response(); } $cart = id(new PhortuneCartQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->withMerchantPHIDs(array($authority->getPHID())) ->needPurchases(true) ->executeOne(); if (!$cart) { return new Aphront404Response(); } $cancel_uri = $cart->getDetailURI($authority); if ($cart->getStatus() !== PhortuneCart::STATUS_REVIEW) { return $this->newDialog() ->setTitle(pht('Order Not in Review')) ->appendParagraph( pht( 'This order does not need manual review, so you can not '. 'accept it.')) ->addCancelButton($cancel_uri); } if ($request->isFormPost()) { $cart->didReviewCart(); return id(new AphrontRedirectResponse())->setURI($cancel_uri); } return $this->newDialog() ->setTitle(pht('Accept Order?')) ->appendParagraph( pht( 'This order has been flagged for manual review. You should review '. 'it carefully before accepting it.')) ->addCancelButton($cancel_uri) ->addSubmitButton(pht('Accept Order')); } } diff --git a/src/applications/phortune/controller/PhortuneCartCancelController.php b/src/applications/phortune/controller/PhortuneCartCancelController.php index 3aedceb6b0..c4a26c0d00 100644 --- a/src/applications/phortune/controller/PhortuneCartCancelController.php +++ b/src/applications/phortune/controller/PhortuneCartCancelController.php @@ -1,213 +1,206 @@ id = $data['id']; - $this->action = $data['action']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); + $action = $request->getURIData('action'); $authority = $this->loadMerchantAuthority(); $cart_query = id(new PhortuneCartQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->needPurchases(true); if ($authority) { $cart_query->withMerchantPHIDs(array($authority->getPHID())); } $cart = $cart_query->executeOne(); if (!$cart) { return new Aphront404Response(); } - switch ($this->action) { + switch ($action) { case 'cancel': // You must be able to edit the account to cancel an order. PhabricatorPolicyFilter::requireCapability( $viewer, $cart->getAccount(), PhabricatorPolicyCapability::CAN_EDIT); $is_refund = false; break; case 'refund': // You must be able to control the merchant to refund an order. PhabricatorPolicyFilter::requireCapability( $viewer, $cart->getMerchant(), PhabricatorPolicyCapability::CAN_EDIT); $is_refund = true; break; default: return new Aphront404Response(); } $cancel_uri = $cart->getDetailURI($authority); $merchant = $cart->getMerchant(); try { if ($is_refund) { $title = pht('Unable to Refund Order'); $cart->assertCanRefundOrder(); } else { $title = pht('Unable to Cancel Order'); $cart->assertCanCancelOrder(); } } catch (Exception $ex) { return $this->newDialog() ->setTitle($title) ->appendChild($ex->getMessage()) ->addCancelButton($cancel_uri); } $charges = id(new PhortuneChargeQuery()) ->setViewer($viewer) ->withCartPHIDs(array($cart->getPHID())) ->withStatuses( array( PhortuneCharge::STATUS_HOLD, PhortuneCharge::STATUS_CHARGED, )) ->execute(); $amounts = mpull($charges, 'getAmountAsCurrency'); $maximum = PhortuneCurrency::newFromList($amounts); $v_refund = $maximum->formatForDisplay(); $errors = array(); $e_refund = true; if ($request->isFormPost()) { if ($is_refund) { try { $refund = PhortuneCurrency::newFromUserInput( $viewer, $request->getStr('refund')); $refund->assertInRange('0.00 USD', $maximum->formatForDisplay()); } catch (Exception $ex) { $errors[] = $ex->getMessage(); $e_refund = pht('Invalid'); } } else { $refund = $maximum; } if (!$errors) { $charges = msort($charges, 'getID'); $charges = array_reverse($charges); if ($charges) { $providers = id(new PhortunePaymentProviderConfigQuery()) ->setViewer($viewer) ->withPHIDs(mpull($charges, 'getProviderPHID')) ->execute(); $providers = mpull($providers, null, 'getPHID'); } else { $providers = array(); } foreach ($charges as $charge) { $refundable = $charge->getAmountRefundableAsCurrency(); if (!$refundable->isPositive()) { // This charge is a refund, or has already been fully refunded. continue; } if ($refund->isGreaterThan($refundable)) { $refund_amount = $refundable; } else { $refund_amount = $refund; } $provider_config = idx($providers, $charge->getProviderPHID()); if (!$provider_config) { throw new Exception(pht('Unable to load provider for charge!')); } $provider = $provider_config->buildProvider(); $refund_charge = $cart->willRefundCharge( $viewer, $provider, $charge, $refund_amount); $refunded = false; try { $provider->refundCharge($charge, $refund_charge); $refunded = true; } catch (Exception $ex) { phlog($ex); $cart->didFailRefund($charge, $refund_charge); } if ($refunded) { $cart->didRefundCharge($charge, $refund_charge); $refund = $refund->subtract($refund_amount); } if (!$refund->isPositive()) { break; } } if ($refund->isPositive()) { throw new Exception(pht('Unable to refund some charges!')); } // TODO: If every HOLD and CHARGING transaction has been fully refunded // and we're in a HOLD, REVIEW, PURCHASING or CHARGED cart state we // probably need to kick the cart back to READY here (or maybe kill // it if it was in REVIEW)? return id(new AphrontRedirectResponse())->setURI($cancel_uri); } } if ($is_refund) { $title = pht('Refund Order?'); $body = pht('Really refund this order?'); $button = pht('Refund Order'); $cancel_text = pht('Cancel'); $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild( id(new AphrontFormTextControl()) ->setName('refund') ->setLabel(pht('Amount')) ->setError($e_refund) ->setValue($v_refund)); $form = $form->buildLayoutView(); } else { $title = pht('Cancel Order?'); $body = pht('Really cancel this order? Any payment will be refunded.'); $button = pht('Cancel Order'); // Don't give the user a "Cancel" button in response to a "Cancel?" // prompt, as it's confusing. $cancel_text = pht('Do Not Cancel Order'); $form = null; } return $this->newDialog() ->setTitle($title) ->setErrors($errors) ->appendChild($body) ->appendChild($form) ->addSubmitButton($button) ->addCancelButton($cancel_uri, $cancel_text); } } diff --git a/src/applications/phortune/controller/PhortuneCartCheckoutController.php b/src/applications/phortune/controller/PhortuneCartCheckoutController.php index 0d8e55f5c3..e22a9521fd 100644 --- a/src/applications/phortune/controller/PhortuneCartCheckoutController.php +++ b/src/applications/phortune/controller/PhortuneCartCheckoutController.php @@ -1,230 +1,224 @@ id = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); $cart = id(new PhortuneCartQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->needPurchases(true) ->executeOne(); if (!$cart) { return new Aphront404Response(); } $cancel_uri = $cart->getCancelURI(); $merchant = $cart->getMerchant(); switch ($cart->getStatus()) { case PhortuneCart::STATUS_BUILDING: return $this->newDialog() ->setTitle(pht('Incomplete Cart')) ->appendParagraph( pht( 'The application that created this cart did not finish putting '. 'products in it. You can not checkout with an incomplete '. 'cart.')) ->addCancelButton($cancel_uri); case PhortuneCart::STATUS_READY: // This is the expected, normal state for a cart that's ready for // checkout. break; case PhortuneCart::STATUS_CHARGED: case PhortuneCart::STATUS_PURCHASING: case PhortuneCart::STATUS_HOLD: case PhortuneCart::STATUS_REVIEW: case PhortuneCart::STATUS_PURCHASED: // For these states, kick the user to the order page to give them // information and options. return id(new AphrontRedirectResponse())->setURI($cart->getDetailURI()); default: throw new Exception( pht( 'Unknown cart status "%s"!', $cart->getStatus())); } $account = $cart->getAccount(); $account_uri = $this->getApplicationURI($account->getID().'/'); $methods = id(new PhortunePaymentMethodQuery()) ->setViewer($viewer) ->withAccountPHIDs(array($account->getPHID())) ->withMerchantPHIDs(array($merchant->getPHID())) ->withStatuses(array(PhortunePaymentMethod::STATUS_ACTIVE)) ->execute(); $e_method = null; $errors = array(); if ($request->isFormPost()) { // Require CAN_EDIT on the cart to actually make purchases. PhabricatorPolicyFilter::requireCapability( $viewer, $cart, PhabricatorPolicyCapability::CAN_EDIT); $method_id = $request->getInt('paymentMethodID'); $method = idx($methods, $method_id); if (!$method) { $e_method = pht('Required'); $errors[] = pht('You must choose a payment method.'); } if (!$errors) { $provider = $method->buildPaymentProvider(); $charge = $cart->willApplyCharge($viewer, $provider, $method); try { $provider->applyCharge($method, $charge); } catch (Exception $ex) { $cart->didFailCharge($charge); return $this->newDialog() ->setTitle(pht('Charge Failed')) ->appendParagraph( pht( 'Unable to make payment: %s', $ex->getMessage())) ->addCancelButton($cart->getCheckoutURI(), pht('Continue')); } $cart->didApplyCharge($charge); $done_uri = $cart->getCheckoutURI(); return id(new AphrontRedirectResponse())->setURI($done_uri); } } $cart_table = $this->buildCartContentTable($cart); $cart_box = id(new PHUIObjectBoxView()) ->setFormErrors($errors) ->setHeaderText(pht('Cart Contents')) ->setTable($cart_table); $title = $cart->getName(); if (!$methods) { $method_control = id(new AphrontFormStaticControl()) ->setLabel(pht('Payment Method')) ->setValue( phutil_tag('em', array(), pht('No payment methods configured.'))); } else { $method_control = id(new AphrontFormRadioButtonControl()) ->setLabel(pht('Payment Method')) ->setName('paymentMethodID') ->setValue($request->getInt('paymentMethodID')); foreach ($methods as $method) { $method_control->addButton( $method->getID(), $method->getFullDisplayName(), $method->getDescription()); } } $method_control->setError($e_method); $account_id = $account->getID(); $payment_method_uri = $this->getApplicationURI("{$account_id}/card/new/"); $payment_method_uri = new PhutilURI($payment_method_uri); $payment_method_uri->setQueryParams( array( 'merchantID' => $merchant->getID(), 'cartID' => $cart->getID(), )); $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild($method_control); $add_providers = $this->loadCreatePaymentMethodProvidersForMerchant( $merchant); if ($add_providers) { $new_method = javelin_tag( 'a', array( 'class' => 'button grey', 'href' => $payment_method_uri, ), pht('Add New Payment Method')); $form->appendChild( id(new AphrontFormMarkupControl()) ->setValue($new_method)); } if ($methods || $add_providers) { $submit = id(new AphrontFormSubmitControl()) ->setValue(pht('Submit Payment')) ->setDisabled(!$methods); if ($cart->getCancelURI() !== null) { $submit->addCancelButton($cart->getCancelURI()); } $form->appendChild($submit); } $provider_form = null; $pay_providers = $this->loadOneTimePaymentProvidersForMerchant($merchant); if ($pay_providers) { $one_time_options = array(); foreach ($pay_providers as $provider) { $one_time_options[] = $provider->renderOneTimePaymentButton( $account, $cart, $viewer); } $one_time_options = phutil_tag( 'div', array( 'class' => 'phortune-payment-onetime-list', ), $one_time_options); $provider_form = new PHUIFormLayoutView(); $provider_form->appendChild( id(new AphrontFormMarkupControl()) ->setLabel(pht('Pay With')) ->setValue($one_time_options)); } $payment_box = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Choose Payment Method')) ->appendChild($form) ->appendChild($provider_form); $description_box = $this->renderCartDescription($cart); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Checkout')); $crumbs->addTextCrumb($title); return $this->buildApplicationPage( array( $crumbs, $cart_box, $description_box, $payment_box, ), array( 'title' => $title, )); } } diff --git a/src/applications/phortune/controller/PhortuneCartUpdateController.php b/src/applications/phortune/controller/PhortuneCartUpdateController.php index ea571ccf8a..3d49611d2d 100644 --- a/src/applications/phortune/controller/PhortuneCartUpdateController.php +++ b/src/applications/phortune/controller/PhortuneCartUpdateController.php @@ -1,72 +1,66 @@ id = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); $authority = $this->loadMerchantAuthority(); $cart_query = id(new PhortuneCartQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->needPurchases(true); if ($authority) { $cart_query->withMerchantPHIDs(array($authority->getPHID())); } $cart = $cart_query->executeOne(); if (!$cart) { return new Aphront404Response(); } $charges = id(new PhortuneChargeQuery()) ->setViewer($viewer) ->withCartPHIDs(array($cart->getPHID())) ->needCarts(true) ->withStatuses( array( PhortuneCharge::STATUS_HOLD, PhortuneCharge::STATUS_CHARGED, )) ->execute(); if ($charges) { $providers = id(new PhortunePaymentProviderConfigQuery()) ->setViewer($viewer) ->withPHIDs(mpull($charges, 'getProviderPHID')) ->execute(); $providers = mpull($providers, null, 'getPHID'); } else { $providers = array(); } foreach ($charges as $charge) { if ($charge->isRefund()) { // Don't update refunds. continue; } $provider_config = idx($providers, $charge->getProviderPHID()); if (!$provider_config) { throw new Exception(pht('Unable to load provider for charge!')); } $provider = $provider_config->buildProvider(); $provider->updateCharge($charge); } return id(new AphrontRedirectResponse()) ->setURI($cart->getDetailURI($authority)); } } diff --git a/src/applications/phortune/controller/PhortuneCartViewController.php b/src/applications/phortune/controller/PhortuneCartViewController.php index 9e133002f5..f4eb0d9612 100644 --- a/src/applications/phortune/controller/PhortuneCartViewController.php +++ b/src/applications/phortune/controller/PhortuneCartViewController.php @@ -1,321 +1,315 @@ id = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); $authority = $this->loadMerchantAuthority(); $query = id(new PhortuneCartQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->needPurchases(true); if ($authority) { $query->withMerchantPHIDs(array($authority->getPHID())); } $cart = $query->executeOne(); if (!$cart) { return new Aphront404Response(); } $cart_table = $this->buildCartContentTable($cart); $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $cart, PhabricatorPolicyCapability::CAN_EDIT); $errors = array(); $error_view = null; $resume_uri = null; switch ($cart->getStatus()) { case PhortuneCart::STATUS_READY: if ($authority && $cart->getIsInvoice()) { // We arrived here by following the ad-hoc invoice workflow, and // are acting with merchant authority. $checkout_uri = PhabricatorEnv::getURI($cart->getCheckoutURI()); $invoice_message = array( pht( 'Manual invoices do not automatically notify recipients yet. '. 'Send the payer this checkout link:'), ' ', phutil_tag( 'a', array( 'href' => $checkout_uri, ), $checkout_uri), ); $error_view = id(new PHUIInfoView()) ->setSeverity(PHUIInfoView::SEVERITY_WARNING) ->setErrors(array($invoice_message)); } break; case PhortuneCart::STATUS_PURCHASING: if ($can_edit) { $resume_uri = $cart->getMetadataValue('provider.checkoutURI'); if ($resume_uri) { $errors[] = pht( 'The checkout process has been started, but not yet completed. '. 'You can continue checking out by clicking %s, or cancel the '. 'order, or contact the merchant for assistance.', phutil_tag('strong', array(), pht('Continue Checkout'))); } else { $errors[] = pht( 'The checkout process has been started, but an error occurred. '. 'You can cancel the order or contact the merchant for '. 'assistance.'); } } break; case PhortuneCart::STATUS_CHARGED: if ($can_edit) { $errors[] = pht( 'You have been charged, but processing could not be completed. '. 'You can cancel your order, or contact the merchant for '. 'assistance.'); } break; case PhortuneCart::STATUS_HOLD: if ($can_edit) { $errors[] = pht( 'Payment for this order is on hold. You can click %s to check '. 'for updates, cancel the order, or contact the merchant for '. 'assistance.', phutil_tag('strong', array(), pht('Update Status'))); } break; case PhortuneCart::STATUS_REVIEW: if ($authority) { $errors[] = pht( 'This order has been flagged for manual review. Review the order '. 'and choose %s to accept it or %s to reject it.', phutil_tag('strong', array(), pht('Accept Order')), phutil_tag('strong', array(), pht('Refund Order'))); } else if ($can_edit) { $errors[] = pht( 'This order requires manual processing and will complete once '. 'the merchant accepts it.'); } break; case PhortuneCart::STATUS_PURCHASED: $error_view = id(new PHUIInfoView()) ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) ->appendChild(pht('This purchase has been completed.')); break; } $properties = $this->buildPropertyListView($cart); $actions = $this->buildActionListView( $cart, $can_edit, $authority, $resume_uri); $properties->setActionList($actions); $header = id(new PHUIHeaderView()) ->setUser($viewer) ->setHeader(pht('Order Detail')); if ($cart->getStatus() == PhortuneCart::STATUS_PURCHASED) { $done_uri = $cart->getDoneURI(); if ($done_uri) { $header->addActionLink( id(new PHUIButtonView()) ->setTag('a') ->setHref($done_uri) ->setIcon(id(new PHUIIconView()) ->setIconFont('fa-check-square green')) ->setText($cart->getDoneActionName())); } } $cart_box = id(new PHUIObjectBoxView()) ->setHeader($header) ->addPropertyList($properties) ->setTable($cart_table); if ($errors) { $cart_box->setFormErrors($errors); } else if ($error_view) { $cart_box->setInfoView($error_view); } $description = $this->renderCartDescription($cart); $charges = id(new PhortuneChargeQuery()) ->setViewer($viewer) ->withCartPHIDs(array($cart->getPHID())) ->needCarts(true) ->execute(); $phids = array(); foreach ($charges as $charge) { $phids[] = $charge->getProviderPHID(); $phids[] = $charge->getCartPHID(); $phids[] = $charge->getMerchantPHID(); $phids[] = $charge->getPaymentMethodPHID(); } $handles = $this->loadViewerHandles($phids); $charges_table = id(new PhortuneChargeTableView()) ->setUser($viewer) ->setHandles($handles) ->setCharges($charges) ->setShowOrder(false); $charges = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Charges')) ->setTable($charges_table); $account = $cart->getAccount(); $crumbs = $this->buildApplicationCrumbs(); if ($authority) { $this->addMerchantCrumb($crumbs, $authority); } else { $this->addAccountCrumb($crumbs, $cart->getAccount()); } $crumbs->addTextCrumb(pht('Cart %d', $cart->getID())); $timeline = $this->buildTransactionTimeline( $cart, new PhortuneCartTransactionQuery()); $timeline ->setShouldTerminate(true); return $this->buildApplicationPage( array( $crumbs, $cart_box, $description, $charges, $timeline, ), array( 'title' => pht('Cart'), )); } private function buildPropertyListView(PhortuneCart $cart) { $viewer = $this->getRequest()->getUser(); $view = id(new PHUIPropertyListView()) ->setUser($viewer) ->setObject($cart); $handles = $this->loadViewerHandles( array( $cart->getAccountPHID(), $cart->getAuthorPHID(), $cart->getMerchantPHID(), )); $view->addProperty( pht('Order Name'), $cart->getName()); $view->addProperty( pht('Account'), $handles[$cart->getAccountPHID()]->renderLink()); $view->addProperty( pht('Authorized By'), $handles[$cart->getAuthorPHID()]->renderLink()); $view->addProperty( pht('Merchant'), $handles[$cart->getMerchantPHID()]->renderLink()); $view->addProperty( pht('Status'), PhortuneCart::getNameForStatus($cart->getStatus())); $view->addProperty( pht('Updated'), phabricator_datetime($cart->getDateModified(), $viewer)); return $view; } private function buildActionListView( PhortuneCart $cart, $can_edit, $authority, $resume_uri) { $viewer = $this->getRequest()->getUser(); $id = $cart->getID(); $view = id(new PhabricatorActionListView()) ->setUser($viewer) ->setObject($cart); $can_cancel = ($can_edit && $cart->canCancelOrder()); if ($authority) { $prefix = 'merchant/'.$authority->getID().'/'; } else { $prefix = ''; } $cancel_uri = $this->getApplicationURI("{$prefix}cart/{$id}/cancel/"); $refund_uri = $this->getApplicationURI("{$prefix}cart/{$id}/refund/"); $update_uri = $this->getApplicationURI("{$prefix}cart/{$id}/update/"); $accept_uri = $this->getApplicationURI("{$prefix}cart/{$id}/accept/"); $view->addAction( id(new PhabricatorActionView()) ->setName(pht('Cancel Order')) ->setIcon('fa-times') ->setDisabled(!$can_cancel) ->setWorkflow(true) ->setHref($cancel_uri)); if ($authority) { if ($cart->getStatus() == PhortuneCart::STATUS_REVIEW) { $view->addAction( id(new PhabricatorActionView()) ->setName(pht('Accept Order')) ->setIcon('fa-check') ->setWorkflow(true) ->setHref($accept_uri)); } $view->addAction( id(new PhabricatorActionView()) ->setName(pht('Refund Order')) ->setIcon('fa-reply') ->setWorkflow(true) ->setHref($refund_uri)); } $view->addAction( id(new PhabricatorActionView()) ->setName(pht('Update Status')) ->setIcon('fa-refresh') ->setHref($update_uri)); if ($can_edit && $resume_uri) { $view->addAction( id(new PhabricatorActionView()) ->setName(pht('Continue Checkout')) ->setIcon('fa-shopping-cart') ->setHref($resume_uri)); } return $view; } } diff --git a/src/applications/phortune/controller/PhortuneChargeListController.php b/src/applications/phortune/controller/PhortuneChargeListController.php index 85a5a0cfb2..b8edb92507 100644 --- a/src/applications/phortune/controller/PhortuneChargeListController.php +++ b/src/applications/phortune/controller/PhortuneChargeListController.php @@ -1,81 +1,74 @@ accountID = idx($data, 'accountID'); - $this->queryKey = idx($data, 'queryKey'); - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $querykey = $request->getURIData('queryKey'); + $account_id = $request->getURIData('accountID'); $engine = new PhortuneChargeSearchEngine(); - if ($this->accountID) { + if ($account_id) { $account = id(new PhortuneAccountQuery()) ->setViewer($viewer) - ->withIDs(array($this->accountID)) + ->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(); } $controller = id(new PhabricatorApplicationSearchController()) - ->setQueryKey($this->queryKey) + ->setQueryKey($querykey) ->setSearchEngine($engine) ->setNavigation($this->buildSideNavView()); return $this->delegateToController($controller); } public function buildSideNavView() { - $viewer = $this->getRequest()->getUser(); + $viewer = $this->getViewer(); $nav = new AphrontSideNavFilterView(); $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); id(new PhortuneChargeSearchEngine()) ->setViewer($viewer) ->addNavigationItems($nav->getMenu()); $nav->selectFilter(null); return $nav; } protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); $account = $this->account; if ($account) { $id = $account->getID(); $crumbs->addTextCrumb( $account->getName(), $this->getApplicationURI("{$id}/")); $crumbs->addTextCrumb( pht('Charges'), $this->getApplicationURI("{$id}/charge/")); } return $crumbs; } } diff --git a/src/applications/phortune/controller/PhortuneLandingController.php b/src/applications/phortune/controller/PhortuneLandingController.php index ddff75f9ec..2a019c5df9 100644 --- a/src/applications/phortune/controller/PhortuneLandingController.php +++ b/src/applications/phortune/controller/PhortuneLandingController.php @@ -1,31 +1,30 @@ getRequest(); - $user = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); $accounts = id(new PhortuneAccountQuery()) - ->setViewer($user) - ->withMemberPHIDs(array($user->getPHID())) + ->setViewer($viewer) + ->withMemberPHIDs(array($viewer->getPHID())) ->execute(); if (!$accounts) { $account = PhortuneAccount::createNewAccount( - $user, + $viewer, PhabricatorContentSource::newFromRequest($request)); $accounts = array($account); } if (count($accounts) == 1) { $account = head($accounts); $next_uri = $this->getApplicationURI($account->getID().'/'); } else { $next_uri = $this->getApplicationURI('account/'); } return id(new AphrontRedirectResponse())->setURI($next_uri); } } diff --git a/src/applications/phortune/controller/PhortuneMerchantEditController.php b/src/applications/phortune/controller/PhortuneMerchantEditController.php index adb6e39c44..d3b396ddb0 100644 --- a/src/applications/phortune/controller/PhortuneMerchantEditController.php +++ b/src/applications/phortune/controller/PhortuneMerchantEditController.php @@ -1,179 +1,173 @@ getViewer(); + $id = $request->getURIData('id'); - public function willProcessRequest(array $data) { - $this->id = idx($data, 'id'); - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); - - if ($this->id) { + if ($id) { $merchant = id(new PhortuneMerchantQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($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, )); } } diff --git a/src/applications/phortune/controller/PhortuneMerchantListController.php b/src/applications/phortune/controller/PhortuneMerchantListController.php index 6849393de7..48fb02195b 100644 --- a/src/applications/phortune/controller/PhortuneMerchantListController.php +++ b/src/applications/phortune/controller/PhortuneMerchantListController.php @@ -1,57 +1,54 @@ queryKey = idx($data, 'queryKey'); - } + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $querykey = $request->getURIData('queryKey'); - public function processRequest() { $controller = id(new PhabricatorApplicationSearchController()) - ->setQueryKey($this->queryKey) + ->setQueryKey($querykey) ->setSearchEngine(new PhortuneMerchantSearchEngine()) ->setNavigation($this->buildSideNavView()); return $this->delegateToController($controller); } public function buildSideNavView() { - $viewer = $this->getRequest()->getUser(); + $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; } protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); $can_create = $this->hasApplicationCapability( PhortuneMerchantCapability::CAPABILITY); $crumbs->addAction( id(new PHUIListItemView()) ->setName(pht('Create Merchant')) ->setHref($this->getApplicationURI('merchant/edit/')) ->setIcon('fa-plus-square') ->setWorkflow(!$can_create) ->setDisabled(!$can_create)); return $crumbs; } } diff --git a/src/applications/phortune/controller/PhortuneMerchantViewController.php b/src/applications/phortune/controller/PhortuneMerchantViewController.php index 2ca9f70c80..4b515c44c5 100644 --- a/src/applications/phortune/controller/PhortuneMerchantViewController.php +++ b/src/applications/phortune/controller/PhortuneMerchantViewController.php @@ -1,299 +1,293 @@ id = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); $merchant = id(new PhortuneMerchantQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->executeOne(); if (!$merchant) { return new Aphront404Response(); } $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($merchant->getName()); $title = pht( 'Merchant %d %s', $merchant->getID(), $merchant->getName()); $header = id(new PHUIHeaderView()) ->setHeader($merchant->getName()) ->setUser($viewer) ->setPolicyObject($merchant); $providers = id(new PhortunePaymentProviderConfigQuery()) ->setViewer($viewer) ->withMerchantPHIDs(array($merchant->getPHID())) ->execute(); $properties = $this->buildPropertyListView($merchant, $providers); $actions = $this->buildActionListView($merchant); $properties->setActionList($actions); $provider_list = $this->buildProviderList( $merchant, $providers); $box = id(new PHUIObjectBoxView()) ->setHeader($header) ->addPropertyList($properties); $timeline = $this->buildTransactionTimeline( $merchant, new PhortuneMerchantTransactionQuery()); $timeline->setShouldTerminate(true); return $this->buildApplicationPage( array( $crumbs, $box, $provider_list, $timeline, ), array( 'title' => $title, )); } private function buildPropertyListView( 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); $view->addProperty( pht('Members'), $viewer->renderHandleList($merchant->getMemberPHIDs())); $view->invokeWillRenderEvent(); $description = $merchant->getDescription(); if (strlen($description)) { $description = PhabricatorMarkupEngine::renderOneObject( id(new PhabricatorMarkupOneOff())->setContent($description), 'default', $viewer); $view->addSectionHeader(pht('Description')); $view->addTextContent($description); } return $view; } private function buildActionListView(PhortuneMerchant $merchant) { $viewer = $this->getRequest()->getUser(); $id = $merchant->getID(); $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $merchant, PhabricatorPolicyCapability::CAN_EDIT); $view = id(new PhabricatorActionListView()) ->setUser($viewer) ->setObject($merchant); $view->addAction( id(new PhabricatorActionView()) ->setName(pht('Edit Merchant')) ->setIcon('fa-pencil') ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit) ->setHref($this->getApplicationURI("merchant/edit/{$id}/"))); $view->addAction( id(new PhabricatorActionView()) ->setName(pht('View Orders')) ->setIcon('fa-shopping-cart') ->setHref($this->getApplicationURI("merchant/orders/{$id}/")) ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); $view->addAction( id(new PhabricatorActionView()) ->setName(pht('View Subscriptions')) ->setIcon('fa-moon-o') ->setHref($this->getApplicationURI("merchant/{$id}/subscription/")) ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); $view->addAction( id(new PhabricatorActionView()) ->setName(pht('New Invoice')) ->setIcon('fa-fax') ->setHref($this->getApplicationURI("merchant/{$id}/invoice/new/")) ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); return $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()) ->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(id(new PHUIIconView())->setIconFont('fa-plus')); $header = id(new PHUIHeaderView()) ->setHeader(pht('Payment Providers')) ->addActionLink($add_action); return id(new PHUIObjectBoxView()) ->setHeader($header) ->setObjectList($provider_list); } } diff --git a/src/applications/phortune/controller/PhortunePaymentMethodCreateController.php b/src/applications/phortune/controller/PhortunePaymentMethodCreateController.php index 6b7e55bb54..dd783d4c51 100644 --- a/src/applications/phortune/controller/PhortunePaymentMethodCreateController.php +++ b/src/applications/phortune/controller/PhortunePaymentMethodCreateController.php @@ -1,276 +1,270 @@ accountID = $data['accountID']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $account_id = $request->getURIData('accountID'); $account = id(new PhortuneAccountQuery()) ->setViewer($viewer) - ->withIDs(array($this->accountID)) + ->withIDs(array($account_id)) ->executeOne(); if (!$account) { return new Aphront404Response(); } $account_id = $account->getID(); $merchant = id(new PhortuneMerchantQuery()) ->setViewer($viewer) ->withIDs(array($request->getInt('merchantID'))) ->executeOne(); if (!$merchant) { return new Aphront404Response(); } $cart_id = $request->getInt('cartID'); $subscription_id = $request->getInt('subscriptionID'); if ($cart_id) { $cancel_uri = $this->getApplicationURI("cart/{$cart_id}/checkout/"); } else if ($subscription_id) { $cancel_uri = $this->getApplicationURI( "{$account_id}/subscription/edit/{$subscription_id}/"); } else { $cancel_uri = $this->getApplicationURI($account->getID().'/'); } $providers = $this->loadCreatePaymentMethodProvidersForMerchant($merchant); if (!$providers) { throw new Exception( pht( 'There are no payment providers enabled that can add payment '. 'methods.')); } if (count($providers) == 1) { // If there's only one provider, always choose it. $provider_id = head_key($providers); } else { $provider_id = $request->getInt('providerID'); if (empty($providers[$provider_id])) { $choices = array(); foreach ($providers as $provider) { $choices[] = $this->renderSelectProvider($provider); } $content = phutil_tag( 'div', array( 'class' => 'phortune-payment-method-list', ), $choices); return $this->newDialog() ->setRenderDialogAsDiv(true) ->setTitle(pht('Add Payment Method')) ->appendParagraph(pht('Choose a payment method to add:')) ->appendChild($content) ->addCancelButton($cancel_uri); } } $provider = $providers[$provider_id]; $errors = array(); if ($request->isFormPost() && $request->getBool('isProviderForm')) { $method = id(new PhortunePaymentMethod()) ->setAccountPHID($account->getPHID()) ->setAuthorPHID($viewer->getPHID()) ->setMerchantPHID($merchant->getPHID()) ->setProviderPHID($provider->getProviderConfig()->getPHID()) ->setStatus(PhortunePaymentMethod::STATUS_ACTIVE); if (!$errors) { $errors = $this->processClientErrors( $provider, $request->getStr('errors')); } if (!$errors) { $client_token_raw = $request->getStr('token'); $client_token = null; try { $client_token = phutil_json_decode($client_token_raw); } catch (PhutilJSONParserException $ex) { $errors[] = pht( 'There was an error decoding token information submitted by the '. 'client. Expected a JSON-encoded token dictionary, received: %s.', nonempty($client_token_raw, pht('nothing'))); } if (!$provider->validateCreatePaymentMethodToken($client_token)) { $errors[] = pht( 'There was an error with the payment token submitted by the '. 'client. Expected a valid dictionary, received: %s.', $client_token_raw); } if (!$errors) { $errors = $provider->createPaymentMethodFromRequest( $request, $method, $client_token); } } if (!$errors) { $method->save(); // If we added this method on a cart flow, return to the cart to // check out. if ($cart_id) { $next_uri = $this->getApplicationURI( "cart/{$cart_id}/checkout/?paymentMethodID=".$method->getID()); } else if ($subscription_id) { $next_uri = $cancel_uri; } else { $account_uri = $this->getApplicationURI($account->getID().'/'); $next_uri = new PhutilURI($account_uri); $next_uri->setFragment('payment'); } return id(new AphrontRedirectResponse())->setURI($next_uri); } else { $dialog = id(new AphrontDialogView()) ->setUser($viewer) ->setTitle(pht('Error Adding Payment Method')) ->appendChild(id(new PHUIInfoView())->setErrors($errors)) ->addCancelButton($request->getRequestURI()); return id(new AphrontDialogResponse())->setDialog($dialog); } } $form = $provider->renderCreatePaymentMethodForm($request, $errors); $form ->setUser($viewer) ->setAction($request->getRequestURI()) ->setWorkflow(true) ->addHiddenInput('providerID', $provider_id) ->addHiddenInput('cartID', $request->getInt('cartID')) ->addHiddenInput('subscriptionID', $request->getInt('subscriptionID')) ->addHiddenInput('isProviderForm', true) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue(pht('Add Payment Method')) ->addCancelButton($cancel_uri)); $box = id(new PHUIObjectBoxView()) ->setHeaderText($provider->getPaymentMethodDescription()) ->setForm($form); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Add Payment Method')); return $this->buildApplicationPage( array( $crumbs, $box, ), array( 'title' => $provider->getPaymentMethodDescription(), )); } private function renderSelectProvider( PhortunePaymentProvider $provider) { $request = $this->getRequest(); $viewer = $request->getUser(); $description = $provider->getPaymentMethodDescription(); $icon_uri = $provider->getPaymentMethodIcon(); $details = $provider->getPaymentMethodProviderDescription(); $this->requireResource('phortune-css'); $icon = id(new PHUIIconView()) ->setSpriteSheet(PHUIIconView::SPRITE_LOGIN) ->setSpriteIcon($provider->getPaymentMethodIcon()); $button = id(new PHUIButtonView()) ->setSize(PHUIButtonView::BIG) ->setColor(PHUIButtonView::GREY) ->setIcon($icon) ->setText($description) ->setSubtext($details) ->setMetadata(array('disableWorkflow' => true)); $form = id(new AphrontFormView()) ->setUser($viewer) ->setAction($request->getRequestURI()) ->addHiddenInput('providerID', $provider->getProviderConfig()->getID()) ->appendChild($button); return $form; } private function processClientErrors( PhortunePaymentProvider $provider, $client_errors_raw) { $errors = array(); $client_errors = null; try { $client_errors = phutil_json_decode($client_errors_raw); } catch (PhutilJSONParserException $ex) { $errors[] = pht( 'There was an error decoding error information submitted by the '. 'client. Expected a JSON-encoded list of error codes, received: %s.', nonempty($client_errors_raw, pht('nothing'))); } foreach (array_unique($client_errors) as $key => $client_error) { $client_errors[$key] = $provider->translateCreatePaymentMethodErrorCode( $client_error); } foreach (array_unique($client_errors) as $client_error) { switch ($client_error) { case PhortuneErrCode::ERR_CC_INVALID_NUMBER: $message = pht( 'The card number you entered is not a valid card number. Check '. 'that you entered it correctly.'); break; case PhortuneErrCode::ERR_CC_INVALID_CVC: $message = pht( 'The CVC code you entered is not a valid CVC code. Check that '. 'you entered it correctly. The CVC code is a 3-digit or 4-digit '. 'numeric code which usually appears on the back of the card.'); break; case PhortuneErrCode::ERR_CC_INVALID_EXPIRY: $message = pht( 'The card expiration date is not a valid expiration date. Check '. 'that you entered it correctly. You can not add an expired card '. 'as a payment method.'); break; default: $message = $provider->getCreatePaymentMethodErrorMessage( $client_error); if (!$message) { $message = pht( "There was an unexpected error ('%s') processing payment ". "information.", $client_error); phlog($message); } break; } $errors[$client_error] = $message; } return $errors; } } diff --git a/src/applications/phortune/controller/PhortunePaymentMethodDisableController.php b/src/applications/phortune/controller/PhortunePaymentMethodDisableController.php index 8f5124bdb4..4b8fb76010 100644 --- a/src/applications/phortune/controller/PhortunePaymentMethodDisableController.php +++ b/src/applications/phortune/controller/PhortunePaymentMethodDisableController.php @@ -1,64 +1,58 @@ methodID = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $method_id = $request->getURIData('methodID'); $method = id(new PhortunePaymentMethodQuery()) ->setViewer($viewer) - ->withIDs(array($this->methodID)) + ->withIDs(array($method_id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$method) { return new Aphront404Response(); } if ($method->getStatus() == PhortunePaymentMethod::STATUS_DISABLED) { return new Aphront400Response(); } $account = $method->getAccount(); $account_uri = $this->getApplicationURI($account->getID().'/'); if ($request->isFormPost()) { // TODO: ApplicationTransactions! $method ->setStatus(PhortunePaymentMethod::STATUS_DISABLED) ->save(); return id(new AphrontRedirectResponse())->setURI($account_uri); } return $this->newDialog() ->setTitle(pht('Disable Payment Method?')) ->setShortTitle(pht('Disable Payment Method')) ->appendParagraph( pht( 'Disable the payment method "%s"?', phutil_tag( 'strong', array(), $method->getFullDisplayName()))) ->appendParagraph( pht( 'You will no longer be able to make payments using this payment '. 'method. Disabled payment methods can not be reactivated.')) ->addCancelButton($account_uri) ->addSubmitButton(pht('Disable Payment Method')); } } diff --git a/src/applications/phortune/controller/PhortunePaymentMethodEditController.php b/src/applications/phortune/controller/PhortunePaymentMethodEditController.php index 2db514a1cf..27edd72a59 100644 --- a/src/applications/phortune/controller/PhortunePaymentMethodEditController.php +++ b/src/applications/phortune/controller/PhortunePaymentMethodEditController.php @@ -1,85 +1,79 @@ methodID = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $method_id = $request->getURIData('id'); $method = id(new PhortunePaymentMethodQuery()) ->setViewer($viewer) - ->withIDs(array($this->methodID)) + ->withIDs(array($method_id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$method) { return new Aphront404Response(); } $account = $method->getAccount(); $account_uri = $this->getApplicationURI($account->getID().'/'); if ($request->isFormPost()) { $name = $request->getStr('name'); // TODO: Use ApplicationTransactions $method->setName($name); $method->save(); return id(new AphrontRedirectResponse())->setURI($account_uri); } $provider = $method->buildPaymentProvider(); $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild( id(new AphrontFormTextControl()) ->setLabel(pht('Name')) ->setName('name') ->setValue($method->getName())) ->appendChild( id(new AphrontFormStaticControl()) ->setLabel(pht('Details')) ->setValue($method->getSummary())) ->appendChild( id(new AphrontFormStaticControl()) ->setLabel(pht('Expires')) ->setValue($method->getDisplayExpires())) ->appendChild( id(new AphrontFormSubmitControl()) ->addCancelButton($account_uri) ->setValue(pht('Save Changes'))); $box = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Edit Payment Method')) ->setForm($form); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($account->getName(), $account_uri); $crumbs->addTextCrumb($method->getDisplayName()); $crumbs->addTextCrumb(pht('Edit')); return $this->buildApplicationPage( array( $crumbs, $box, ), array( 'title' => pht('Edit Payment Method'), )); } } diff --git a/src/applications/phortune/controller/PhortuneProductListController.php b/src/applications/phortune/controller/PhortuneProductListController.php index 8a1181b33e..a82effa6d4 100644 --- a/src/applications/phortune/controller/PhortuneProductListController.php +++ b/src/applications/phortune/controller/PhortuneProductListController.php @@ -1,59 +1,58 @@ getRequest(); - $user = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); $pager = new AphrontCursorPagerView(); $pager->readFromRequest($request); $query = id(new PhortuneProductQuery()) - ->setViewer($user); + ->setViewer($viewer); $products = $query->executeWithCursorPager($pager); $title = pht('Product List'); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb( pht('Products'), $this->getApplicationURI('product/')); $crumbs->addAction( id(new PHUIListItemView()) ->setName(pht('Create Product')) ->setHref($this->getApplicationURI('product/edit/')) ->setIcon('fa-plus-square')); $product_list = id(new PHUIObjectItemListView()) - ->setUser($user) + ->setUser($viewer) ->setNoDataString(pht('No products.')); foreach ($products as $product) { $view_uri = $this->getApplicationURI( 'product/view/'.$product->getID().'/'); $price = $product->getPriceAsCurrency(); $item = id(new PHUIObjectItemView()) ->setObjectName($product->getID()) ->setHeader($product->getProductName()) ->setHref($view_uri) ->addAttribute($price->formatForDisplay()); $product_list->addItem($item); } return $this->buildApplicationPage( array( $crumbs, $product_list, $pager, ), array( 'title' => $title, )); } } diff --git a/src/applications/phortune/controller/PhortuneProductViewController.php b/src/applications/phortune/controller/PhortuneProductViewController.php index 02426f07ca..73d120bfd9 100644 --- a/src/applications/phortune/controller/PhortuneProductViewController.php +++ b/src/applications/phortune/controller/PhortuneProductViewController.php @@ -1,63 +1,57 @@ productID = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); $product = id(new PhortuneProductQuery()) - ->setViewer($user) - ->withIDs(array($this->productID)) + ->setViewer($viewer) + ->withIDs(array($id)) ->executeOne(); if (!$product) { return new Aphront404Response(); } $title = pht('Product: %s', $product->getProductName()); $header = id(new PHUIHeaderView()) ->setHeader($product->getProductName()); $edit_uri = $this->getApplicationURI('product/edit/'.$product->getID().'/'); $actions = id(new PhabricatorActionListView()) - ->setUser($user) + ->setUser($viewer) ->setObjectURI($request->getRequestURI()); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb( pht('Products'), $this->getApplicationURI('product/')); $crumbs->addTextCrumb( pht('#%d', $product->getID()), $request->getRequestURI()); $properties = id(new PHUIPropertyListView()) - ->setUser($user) + ->setUser($viewer) ->setActionList($actions) ->addProperty( pht('Price'), $product->getPriceAsCurrency()->formatForDisplay()); $object_box = id(new PHUIObjectBoxView()) ->setHeader($header) ->addPropertyList($properties); return $this->buildApplicationPage( array( $crumbs, $object_box, ), array( 'title' => $title, )); } } diff --git a/src/applications/phortune/controller/PhortuneProviderActionController.php b/src/applications/phortune/controller/PhortuneProviderActionController.php index b856b67d97..52d5453f42 100644 --- a/src/applications/phortune/controller/PhortuneProviderActionController.php +++ b/src/applications/phortune/controller/PhortuneProviderActionController.php @@ -1,85 +1,80 @@ id = $data['id']; - $this->setAction($data['action']); - } - public function setAction($action) { $this->action = $action; return $this; } public function getAction() { return $this->action; } - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); + $this->setAction($request->getURIData('action')); $provider_config = id(new PhortunePaymentProviderConfigQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->executeOne(); if (!$provider_config) { return new Aphront404Response(); } $provider = $provider_config->buildProvider(); if (!$provider->canRespondToControllerAction($this->getAction())) { return new Aphront404Response(); } $response = $provider->processControllerRequest($this, $request); if ($response instanceof AphrontResponse) { return $response; } return $this->buildApplicationPage( $response, array( 'title' => pht('Phortune'), )); } public function loadCart($id) { $request = $this->getRequest(); $viewer = $request->getUser(); return id(new PhortuneCartQuery()) ->setViewer($viewer) ->needPurchases(true) ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); } public function loadActiveCharge(PhortuneCart $cart) { $request = $this->getRequest(); $viewer = $request->getUser(); return id(new PhortuneChargeQuery()) ->setViewer($viewer) ->withCartPHIDs(array($cart->getPHID())) ->withStatuses( array( PhortuneCharge::STATUS_CHARGING, )) ->executeOne(); } } diff --git a/src/applications/phortune/controller/PhortuneProviderDisableController.php b/src/applications/phortune/controller/PhortuneProviderDisableController.php index e398cbc886..03236b54bc 100644 --- a/src/applications/phortune/controller/PhortuneProviderDisableController.php +++ b/src/applications/phortune/controller/PhortuneProviderDisableController.php @@ -1,76 +1,70 @@ id = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); $provider_config = id(new PhortunePaymentProviderConfigQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$provider_config) { return new Aphront404Response(); } $merchant = $provider_config->getMerchant(); $merchant_id = $merchant->getID(); $cancel_uri = $this->getApplicationURI("merchant/{$merchant_id}/"); $provider = $provider_config->buildProvider(); if ($request->isFormPost()) { $new_status = !$provider_config->getIsEnabled(); $xactions = array(); $xactions[] = id(new PhortunePaymentProviderConfigTransaction()) ->setTransactionType( PhortunePaymentProviderConfigTransaction::TYPE_ENABLE) ->setNewValue($new_status); $editor = id(new PhortunePaymentProviderConfigEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true) ->setContinueOnMissingFields(true); $editor->applyTransactions($provider_config, $xactions); return id(new AphrontRedirectResponse())->setURI($cancel_uri); } if ($provider_config->getIsEnabled()) { $title = pht('Disable Provider?'); $body = pht( 'If you disable this payment provider, users will no longer be able '. 'to use it to make new payments.'); $button = pht('Disable Provider'); } else { $title = pht('Enable Provider?'); $body = pht( 'If you enable this payment provider, users will be able to use it to '. 'make new payments.'); $button = pht('Enable Provider'); } return $this->newDialog() ->setTitle($title) ->appendParagraph($body) ->addSubmitButton($button) ->addCancelButton($cancel_uri); } } diff --git a/src/applications/phortune/controller/PhortuneProviderEditController.php b/src/applications/phortune/controller/PhortuneProviderEditController.php index 3ed97b5a4b..f956c41d68 100644 --- a/src/applications/phortune/controller/PhortuneProviderEditController.php +++ b/src/applications/phortune/controller/PhortuneProviderEditController.php @@ -1,291 +1,285 @@ getViewer(); + $id = $request->getURIData('id'); - public function willProcessRequest(array $data) { - $this->id = idx($data, 'id'); - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); - - if ($this->id) { + if ($id) { $provider_config = id(new PhortunePaymentProviderConfigQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$provider_config) { return new Aphront404Response(); } $is_new = false; $is_choose_type = false; $merchant = $provider_config->getMerchant(); $merchant_id = $merchant->getID(); $cancel_uri = $this->getApplicationURI("merchant/{$merchant_id}/"); } 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()) ->setViewer($viewer) ->withMerchantPHIDs(array($merchant->getPHID())) ->execute(); $current_map = mgroup($current_providers, 'getProviderClass'); $provider_config = PhortunePaymentProviderConfig::initializeNewProvider( $merchant); $is_new = true; $classes = PhortunePaymentProvider::getAllProviders(); $class = $request->getStr('class'); if (empty($classes[$class]) || isset($current_map[$class])) { return $this->processChooseClassRequest( $request, $merchant, $current_map); } $provider_config->setProviderClass($class); $cancel_uri = $this->getApplicationURI( 'provider/edit/?merchantID='.$merchant_id); } $provider = $provider_config->buildProvider(); if ($is_new) { $title = pht('Create Payment Provider'); $button_text = pht('Create Provider'); } else { $title = pht( 'Edit Payment Provider %d %s', $provider_config->getID(), $provider->getName()); $button_text = pht('Save Changes'); } $errors = array(); if ($request->isFormPost() && $request->getStr('edit')) { $form_values = $provider->readEditFormValuesFromRequest($request); list($errors, $issues, $xaction_values) = $provider->processEditForm( $request, $form_values); if (!$errors) { // Find any secret fields which we're about to set to "*******" // (indicating that the user did not edit the value) and remove them // from the list of properties to update (so we don't write "******" // to permanent configuration. $secrets = $provider->getAllConfigurableSecretProperties(); $secrets = array_fuse($secrets); foreach ($xaction_values as $key => $value) { if ($provider->isConfigurationSecret($value)) { unset($xaction_values[$key]); } } if ($provider->canRunConfigurationTest()) { $proxy = clone $provider; $proxy_config = clone $provider_config; $proxy_config->setMetadata( $xaction_values + $provider_config->getMetadata()); $proxy->setProviderConfig($proxy_config); try { $proxy->runConfigurationTest(); } catch (Exception $ex) { $errors[] = pht('Unable to connect to payment provider:'); $errors[] = $ex->getMessage(); } } if (!$errors) { $template = id(new PhortunePaymentProviderConfigTransaction()) ->setTransactionType( PhortunePaymentProviderConfigTransaction::TYPE_PROPERTY); $xactions = array(); $xactions[] = id(new PhortunePaymentProviderConfigTransaction()) ->setTransactionType( PhortunePaymentProviderConfigTransaction::TYPE_CREATE) ->setNewValue(true); foreach ($xaction_values as $key => $value) { $xactions[] = id(clone $template) ->setMetadataValue( PhortunePaymentProviderConfigTransaction::PROPERTY_KEY, $key) ->setNewValue($value); } $editor = id(new PhortunePaymentProviderConfigEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true); $editor->applyTransactions($provider_config, $xactions); $merchant_uri = $this->getApplicationURI( 'merchant/'.$merchant->getID().'/'); return id(new AphrontRedirectResponse())->setURI($merchant_uri); } } } else { $form_values = $provider->readEditFormValuesFromProviderConfig(); $issues = array(); } $form = id(new AphrontFormView()) ->setUser($viewer) ->addHiddenInput('merchantID', $merchant->getID()) ->addHiddenInput('class', $provider_config->getProviderClass()) ->addHiddenInput('edit', true) ->appendChild( id(new AphrontFormMarkupControl()) ->setLabel(pht('Provider Type')) ->setValue($provider->getName())); $provider->extendEditForm($request, $form, $form_values, $issues); $form ->appendChild( id(new AphrontFormSubmitControl()) ->setValue($button_text) ->addCancelButton($cancel_uri)) ->appendChild( id(new AphrontFormDividerControl())) ->appendRemarkupInstructions( $provider->getConfigureInstructions()); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($merchant->getName(), $cancel_uri); if ($is_new) { $crumbs->addTextCrumb(pht('Add Provider')); } else { $crumbs->addTextCrumb( pht('Edit Provider %d', $provider_config->getID())); } $box = id(new PHUIObjectBoxView()) ->setFormErrors($errors) ->setHeaderText($title) ->appendChild($form); return $this->buildApplicationPage( array( $crumbs, $box, ), array( 'title' => $title, )); } 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, )); } } diff --git a/src/applications/phortune/controller/PhortuneSubscriptionListController.php b/src/applications/phortune/controller/PhortuneSubscriptionListController.php index 4fbdb804c3..469960f4bc 100644 --- a/src/applications/phortune/controller/PhortuneSubscriptionListController.php +++ b/src/applications/phortune/controller/PhortuneSubscriptionListController.php @@ -1,107 +1,99 @@ merchantID = idx($data, 'merchantID'); - $this->accountID = idx($data, 'accountID'); - $this->queryKey = idx($data, 'queryKey'); - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $querykey = $request->getURIData('queryKey'); + $merchant_id = $request->getURIData('merchantID'); + $account_id = $request->getURIData('accountID'); $engine = new PhortuneSubscriptionSearchEngine(); - if ($this->merchantID) { + if ($merchant_id) { $merchant = id(new PhortuneMerchantQuery()) ->setViewer($viewer) - ->withIDs(array($this->merchantID)) + ->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 ($this->accountID) { + } else if ($account_id) { $account = id(new PhortuneAccountQuery()) ->setViewer($viewer) - ->withIDs(array($this->accountID)) + ->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(); } $controller = id(new PhabricatorApplicationSearchController()) - ->setQueryKey($this->queryKey) + ->setQueryKey($querykey) ->setSearchEngine($engine) ->setNavigation($this->buildSideNavView()); return $this->delegateToController($controller); } public function buildSideNavView() { - $viewer = $this->getRequest()->getUser(); + $viewer = $this->getViewer(); $nav = new AphrontSideNavFilterView(); $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); id(new PhortuneSubscriptionSearchEngine()) ->setViewer($viewer) ->addNavigationItems($nav->getMenu()); $nav->selectFilter(null); return $nav; } protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); $merchant = $this->merchant; if ($merchant) { $id = $merchant->getID(); $this->addMerchantCrumb($crumbs, $merchant); $crumbs->addTextCrumb( pht('Subscriptions'), $this->getApplicationURI("merchant/subscriptions/{$id}/")); } $account = $this->account; if ($account) { $id = $account->getID(); $this->addAccountCrumb($crumbs, $account); $crumbs->addTextCrumb( pht('Subscriptions'), $this->getApplicationURI("{$id}/subscription/")); } return $crumbs; } }