2013-03-28 17:11:42 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhortunePaymentMethodEditController
|
|
|
|
extends PhortuneController {
|
|
|
|
|
2014-08-11 21:07:35 +02:00
|
|
|
private $methodID;
|
2013-03-28 17:11:42 +01:00
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
2014-08-11 21:07:35 +02:00
|
|
|
$this->methodID = $data['id'];
|
2013-03-28 17:11:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
2014-08-11 21:07:35 +02:00
|
|
|
$viewer = $request->getUser();
|
2013-03-28 17:11:42 +01:00
|
|
|
|
2014-08-11 21:07:35 +02:00
|
|
|
$method = id(new PhortunePaymentMethodQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($this->methodID))
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
2013-03-28 17:11:42 +01:00
|
|
|
->executeOne();
|
2014-08-11 21:07:35 +02:00
|
|
|
if (!$method) {
|
2013-03-28 17:11:42 +01:00
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2014-08-11 21:07:35 +02:00
|
|
|
$account = $method->getAccount();
|
2013-03-28 17:11:42 +01:00
|
|
|
$account_uri = $this->getApplicationURI($account->getID().'/');
|
|
|
|
|
2014-08-11 21:07:35 +02:00
|
|
|
if ($request->isFormPost()) {
|
2013-03-28 17:11:42 +01:00
|
|
|
|
2014-08-11 21:07:35 +02:00
|
|
|
$name = $request->getStr('name');
|
2014-07-13 18:18:50 +02:00
|
|
|
|
2014-08-11 21:07:35 +02:00
|
|
|
// TODO: Use ApplicationTransactions
|
2013-03-28 17:11:42 +01:00
|
|
|
|
2014-08-11 21:07:35 +02:00
|
|
|
$method->setName($name);
|
|
|
|
$method->save();
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($account_uri);
|
2013-04-25 18:46:32 +02:00
|
|
|
}
|
2013-03-28 17:11:42 +01:00
|
|
|
|
2014-08-11 21:07:35 +02:00
|
|
|
$provider = $method->buildPaymentProvider();
|
2013-03-28 17:11:42 +01:00
|
|
|
|
2014-08-11 21:07:35 +02:00
|
|
|
$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()))
|
2013-04-25 18:46:32 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
2014-08-11 21:07:35 +02:00
|
|
|
->addCancelButton($account_uri)
|
|
|
|
->setValue(pht('Save Changes')));
|
2013-03-28 17:11:42 +01:00
|
|
|
|
2014-07-13 18:18:50 +02:00
|
|
|
$box = id(new PHUIObjectBoxView())
|
2014-08-11 21:07:35 +02:00
|
|
|
->setHeaderText(pht('Edit Payment Method'))
|
|
|
|
->appendChild($form);
|
2014-07-13 18:18:50 +02:00
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2014-08-11 21:07:35 +02:00
|
|
|
$crumbs->addTextCrumb($account->getName(), $account_uri);
|
|
|
|
$crumbs->addTextCrumb($method->getDisplayName());
|
|
|
|
$crumbs->addTextCrumb(pht('Edit'));
|
2013-03-28 17:11:42 +01:00
|
|
|
|
2014-07-13 18:18:50 +02:00
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$box,
|
|
|
|
),
|
|
|
|
array(
|
2014-08-11 21:07:35 +02:00
|
|
|
'title' => pht('Edit Payment Method'),
|
2014-07-13 18:18:50 +02:00
|
|
|
));
|
2013-04-25 18:46:32 +02:00
|
|
|
}
|
2013-03-28 17:11:42 +01:00
|
|
|
|
|
|
|
}
|