1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 22:40:55 +01:00
phorge-phorge/src/applications/phortune/controller/PhortuneProviderDisableController.php
epriestley 19db3fbb60 Allow merchants to disable payment providers and show more UI info
Summary:
Ref T2787.

  - Allow merchants to disable payment providers.
  - Show more useful information about providers on the payments page.
  - Make test vs live more clear.
  - Show merchant status.
  - Add a description to merchants to flesh them out a bit -- the merchant areas of responsibilities seem to be fitting well with accounts, etc.

Test Plan: {F215109}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2787

Differential Revision: https://secure.phabricator.com/D10662
2014-10-08 08:31:24 -07:00

76 lines
2.2 KiB
PHP

<?php
final class PhortuneProviderDisableController
extends PhortuneMerchantController {
private $id;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$provider_config = id(new PhortunePaymentProviderConfigQuery())
->setViewer($viewer)
->withIDs(array($this->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);
}
}