Changeset View
Changeset View
Standalone View
Standalone View
src/applications/fund/controller/FundInitiativeBackController.php
Show All 33 Lines | public function processRequest() { | ||||
if ($initiative->isClosed()) { | if ($initiative->isClosed()) { | ||||
return $this->newDialog() | return $this->newDialog() | ||||
->setTitle(pht('Initiative Closed')) | ->setTitle(pht('Initiative Closed')) | ||||
->appendParagraph( | ->appendParagraph( | ||||
pht('You can not back a closed initiative.')) | pht('You can not back a closed initiative.')) | ||||
->addCancelButton($initiative_uri); | ->addCancelButton($initiative_uri); | ||||
} | } | ||||
$accounts = PhortuneAccountQuery::loadAccountsForUser( | |||||
$viewer, | |||||
PhabricatorContentSource::newFromRequest($request)); | |||||
$v_amount = null; | $v_amount = null; | ||||
$e_amount = true; | $e_amount = true; | ||||
$v_account = head($accounts)->getPHID(); | |||||
$errors = array(); | $errors = array(); | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$v_amount = $request->getStr('amount'); | $v_amount = $request->getStr('amount'); | ||||
$v_account = $request->getStr('accountPHID'); | |||||
if (empty($accounts[$v_account])) { | |||||
$errors[] = pht('You must specify an account.'); | |||||
} else { | |||||
$account = $accounts[$v_account]; | |||||
} | |||||
if (!strlen($v_amount)) { | if (!strlen($v_amount)) { | ||||
$errors[] = pht( | $errors[] = pht( | ||||
'You must specify how much money you want to contribute to the '. | 'You must specify how much money you want to contribute to the '. | ||||
'initiative.'); | 'initiative.'); | ||||
$e_amount = pht('Required'); | $e_amount = pht('Required'); | ||||
} else { | } else { | ||||
try { | try { | ||||
Show All 14 Lines | if ($request->isFormPost()) { | ||||
->setAmountAsCurrency($currency) | ->setAmountAsCurrency($currency) | ||||
->save(); | ->save(); | ||||
$product = id(new PhortuneProductQuery()) | $product = id(new PhortuneProductQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withClassAndRef('FundBackerProduct', $initiative->getPHID()) | ->withClassAndRef('FundBackerProduct', $initiative->getPHID()) | ||||
->executeOne(); | ->executeOne(); | ||||
$account = PhortuneAccountQuery::loadActiveAccountForUser( | |||||
$viewer, | |||||
PhabricatorContentSource::newFromRequest($request)); | |||||
$cart_implementation = id(new FundBackerCart()) | $cart_implementation = id(new FundBackerCart()) | ||||
->setInitiative($initiative); | ->setInitiative($initiative); | ||||
$cart = $account->newCart($viewer, $cart_implementation, $merchant); | $cart = $account->newCart($viewer, $cart_implementation, $merchant); | ||||
$purchase = $cart->newPurchase($viewer, $product); | $purchase = $cart->newPurchase($viewer, $product); | ||||
$purchase | $purchase | ||||
->setBasePriceAsCurrency($currency) | ->setBasePriceAsCurrency($currency) | ||||
Show All 17 Lines | if ($request->isFormPost()) { | ||||
return id(new AphrontRedirectResponse()) | return id(new AphrontRedirectResponse()) | ||||
->setURI($cart->getCheckoutURI()); | ->setURI($cart->getCheckoutURI()); | ||||
} | } | ||||
} | } | ||||
$form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormSelectControl()) | |||||
->setName('accountPHID') | |||||
->setLabel(pht('Account')) | |||||
->setValue($v_account) | |||||
->setOptions(mpull($accounts, 'getName', 'getPHID'))) | |||||
->appendChild( | |||||
id(new AphrontFormTextControl()) | id(new AphrontFormTextControl()) | ||||
->setName('amount') | ->setName('amount') | ||||
->setLabel(pht('Amount')) | ->setLabel(pht('Amount')) | ||||
->setValue($v_amount) | ->setValue($v_amount) | ||||
->setError($e_amount)); | ->setError($e_amount)); | ||||
return $this->newDialog() | return $this->newDialog() | ||||
->setTitle( | ->setTitle( | ||||
pht('Back %s %s', $initiative->getMonogram(), $initiative->getName())) | pht('Back %s %s', $initiative->getMonogram(), $initiative->getName())) | ||||
->setErrors($errors) | ->setErrors($errors) | ||||
->appendChild($form->buildLayoutView()) | ->appendChild($form->buildLayoutView()) | ||||
->addCancelButton($initiative_uri) | ->addCancelButton($initiative_uri) | ||||
->addSubmitButton(pht('Continue')); | ->addSubmitButton(pht('Continue')); | ||||
} | } | ||||
} | } |