Changeset View
Changeset View
Standalone View
Standalone View
src/applications/fund/phortune/FundBackerProduct.php
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | public function loadImplementationsForRefs( | ||||
} | } | ||||
return $objects; | return $objects; | ||||
} | } | ||||
public function didPurchaseProduct( | public function didPurchaseProduct( | ||||
PhortuneProduct $product, | PhortuneProduct $product, | ||||
PhortunePurchase $purchase) { | PhortunePurchase $purchase) { | ||||
// TODO: This viewer may be wrong if the purchase completes after a hold | |||||
// we should load the backer explicitly. | |||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$backer = id(new FundBackerQuery()) | $backer = id(new FundBackerQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withPHIDs(array($purchase->getMetadataValue('backerPHID'))) | ->withPHIDs(array($purchase->getMetadataValue('backerPHID'))) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$backer) { | if (!$backer) { | ||||
throw new Exception(pht('Unable to load FundBacker!')); | throw new Exception(pht('Unable to load FundBacker!')); | ||||
} | } | ||||
// Load the actual backing user --they may not be the curent viewer if this | |||||
// product purchase is completing from a background worker or a merchant | |||||
// action. | |||||
$actor = id(new PhabricatorPeopleQuery()) | |||||
->setViewer($viewer) | |||||
->withPHIDs(array($backer->getBackerPHID())) | |||||
->executeOne(); | |||||
$xactions = array(); | $xactions = array(); | ||||
$xactions[] = id(new FundBackerTransaction()) | $xactions[] = id(new FundBackerTransaction()) | ||||
->setTransactionType(FundBackerTransaction::TYPE_STATUS) | ->setTransactionType(FundBackerTransaction::TYPE_STATUS) | ||||
->setNewValue(FundBacker::STATUS_PURCHASED); | ->setNewValue(FundBacker::STATUS_PURCHASED); | ||||
$editor = id(new FundBackerEditor()) | $editor = id(new FundBackerEditor()) | ||||
->setActor($viewer) | ->setActor($actor) | ||||
->setContentSource($this->getContentSource()); | ->setContentSource($this->getContentSource()); | ||||
$editor->applyTransactions($backer, $xactions); | $editor->applyTransactions($backer, $xactions); | ||||
$xactions = array(); | $xactions = array(); | ||||
$xactions[] = id(new FundInitiativeTransaction()) | $xactions[] = id(new FundInitiativeTransaction()) | ||||
->setTransactionType(FundInitiativeTransaction::TYPE_BACKER) | ->setTransactionType(FundInitiativeTransaction::TYPE_BACKER) | ||||
->setNewValue($backer->getPHID()); | ->setNewValue($backer->getPHID()); | ||||
$editor = id(new FundInitiativeEditor()) | $editor = id(new FundInitiativeEditor()) | ||||
->setActor($viewer) | ->setActor($actor) | ||||
->setContentSource($this->getContentSource()); | ->setContentSource($this->getContentSource()); | ||||
$editor->applyTransactions($this->getInitiative(), $xactions); | $editor->applyTransactions($this->getInitiative(), $xactions); | ||||
return; | return; | ||||
} | } | ||||
public function didRefundProduct( | public function didRefundProduct( | ||||
PhortuneProduct $product, | PhortuneProduct $product, | ||||
PhortunePurchase $purchase) { | PhortunePurchase $purchase) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
// TODO: Undonate. | // TODO: Undonate. | ||||
} | } | ||||
} | } |