[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class FundBackerProduct extends PhortuneProductImplementation { 4 5 private $initiativePHID; 6 private $initiative; 7 private $viewer; 8 9 public function setViewer(PhabricatorUser $viewer) { 10 $this->viewer = $viewer; 11 return $this; 12 } 13 14 public function getViewer() { 15 return $this->viewer; 16 } 17 18 public function getRef() { 19 return $this->getInitiativePHID(); 20 } 21 22 public function getName(PhortuneProduct $product) { 23 $initiative = $this->getInitiative(); 24 return pht( 25 'Fund %s %s', 26 $initiative->getMonogram(), 27 $initiative->getName()); 28 } 29 30 public function getPriceAsCurrency(PhortuneProduct $product) { 31 return PhortuneCurrency::newEmptyCurrency(); 32 } 33 34 public function setInitiativePHID($initiative_phid) { 35 $this->initiativePHID = $initiative_phid; 36 return $this; 37 } 38 39 public function getInitiativePHID() { 40 return $this->initiativePHID; 41 } 42 43 public function setInitiative(FundInitiative $initiative) { 44 $this->initiative = $initiative; 45 return $this; 46 } 47 48 public function getInitiative() { 49 return $this->initiative; 50 } 51 52 public function loadImplementationsForRefs( 53 PhabricatorUser $viewer, 54 array $refs) { 55 56 $initiatives = id(new FundInitiativeQuery()) 57 ->setViewer($viewer) 58 ->withPHIDs($refs) 59 ->execute(); 60 $initiatives = mpull($initiatives, null, 'getPHID'); 61 62 $objects = array(); 63 foreach ($refs as $ref) { 64 $object = id(new FundBackerProduct()) 65 ->setViewer($viewer) 66 ->setInitiativePHID($ref); 67 68 $initiative = idx($initiatives, $ref); 69 if ($initiative) { 70 $object->setInitiative($initiative); 71 } 72 73 $objects[] = $object; 74 } 75 76 return $objects; 77 } 78 79 public function didPurchaseProduct( 80 PhortuneProduct $product, 81 PhortunePurchase $purchase) { 82 $viewer = $this->getViewer(); 83 84 $backer = id(new FundBackerQuery()) 85 ->setViewer($viewer) 86 ->withPHIDs(array($purchase->getMetadataValue('backerPHID'))) 87 ->executeOne(); 88 if (!$backer) { 89 throw new Exception(pht('Unable to load FundBacker!')); 90 } 91 92 // Load the actual backing user -- they may not be the curent viewer if this 93 // product purchase is completing from a background worker or a merchant 94 // action. 95 96 $actor = id(new PhabricatorPeopleQuery()) 97 ->setViewer($viewer) 98 ->withPHIDs(array($backer->getBackerPHID())) 99 ->executeOne(); 100 101 $xactions = array(); 102 $xactions[] = id(new FundInitiativeTransaction()) 103 ->setTransactionType(FundInitiativeTransaction::TYPE_BACKER) 104 ->setMetadataValue( 105 FundInitiativeTransaction::PROPERTY_AMOUNT, 106 $backer->getAmountAsCurrency()->serializeForStorage()) 107 ->setNewValue($backer->getPHID()); 108 109 $editor = id(new FundInitiativeEditor()) 110 ->setActor($actor) 111 ->setContentSource($this->getContentSource()); 112 113 $editor->applyTransactions($this->getInitiative(), $xactions); 114 } 115 116 public function didRefundProduct( 117 PhortuneProduct $product, 118 PhortunePurchase $purchase, 119 PhortuneCurrency $amount) { 120 $viewer = $this->getViewer(); 121 122 $backer = id(new FundBackerQuery()) 123 ->setViewer($viewer) 124 ->withPHIDs(array($purchase->getMetadataValue('backerPHID'))) 125 ->executeOne(); 126 if (!$backer) { 127 throw new Exception(pht('Unable to load FundBacker!')); 128 } 129 130 $xactions = array(); 131 $xactions[] = id(new FundInitiativeTransaction()) 132 ->setTransactionType(FundInitiativeTransaction::TYPE_REFUND) 133 ->setMetadataValue( 134 FundInitiativeTransaction::PROPERTY_AMOUNT, 135 $amount->serializeForStorage()) 136 ->setMetadataValue( 137 FundInitiativeTransaction::PROPERTY_BACKER, 138 $backer->getBackerPHID()) 139 ->setNewValue($backer->getPHID()); 140 141 $editor = id(new FundInitiativeEditor()) 142 ->setActor($viewer) 143 ->setContentSource($this->getContentSource()); 144 145 $editor->applyTransactions($this->getInitiative(), $xactions); 146 } 147 148 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |