protected function loadPage()
 {
     $table = new PhortunePurchase();
     $conn = $table->establishConnection('r');
     $rows = queryfx_all($conn, 'SELECT purchase.* FROM %T purchase %Q %Q %Q', $table->getTableName(), $this->buildWhereClause($conn), $this->buildOrderClause($conn), $this->buildLimitClause($conn));
     return $table->loadAllFromArray($rows);
 }
 public function didRefundProduct(PhortuneProduct $product, PhortunePurchase $purchase, PhortuneCurrency $amount)
 {
     $viewer = $this->getViewer();
     $backer = id(new FundBackerQuery())->setViewer($viewer)->withPHIDs(array($purchase->getMetadataValue('backerPHID')))->executeOne();
     if (!$backer) {
         throw new Exception(pht('Unable to load %s!', 'FundBacker'));
     }
     $xactions = array();
     $xactions[] = id(new FundInitiativeTransaction())->setTransactionType(FundInitiativeTransaction::TYPE_REFUND)->setMetadataValue(FundInitiativeTransaction::PROPERTY_AMOUNT, $amount->serializeForStorage())->setMetadataValue(FundInitiativeTransaction::PROPERTY_BACKER, $backer->getBackerPHID())->setNewValue($backer->getPHID());
     $editor = id(new FundInitiativeEditor())->setActor($viewer)->setContentSource($this->getContentSource());
     $editor->applyTransactions($this->getInitiative(), $xactions);
 }
Esempio n. 3
0
 public function newPurchase(PhabricatorUser $actor, PhortuneProduct $product)
 {
     $purchase = PhortunePurchase::initializeNewPurchase($actor, $product)->setAccountPHID($this->getAccount()->getPHID())->setCartPHID($this->getPHID())->save();
     $this->purchases[] = $purchase;
     return $purchase;
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $account = id(new PhortuneAccountQuery())->setViewer($user)->withIDs(array($this->accountID))->executeOne();
     if (!$account) {
         return new Aphront404Response();
     }
     $account_uri = $this->getApplicationURI($account->getID() . '/');
     $product = id(new PhortuneProductQuery())->setViewer($user)->withIDs(array($this->productID))->executeOne();
     if (!$product) {
         return new Aphront404Response();
     }
     if ($request->isFormPost()) {
         // TODO: Use ApplicationTransations.
         $cart = new PhortuneCart();
         $cart->openTransaction();
         $cart->setStatus(PhortuneCart::STATUS_READY);
         $cart->setAccountPHID($account->getPHID());
         $cart->setAuthorPHID($user->getPHID());
         $cart->save();
         $purchase = new PhortunePurchase();
         $purchase->setProductPHID($product->getPHID());
         $purchase->setAccountPHID($account->getPHID());
         $purchase->setAuthorPHID($user->getPHID());
         $purchase->setCartPHID($cart->getPHID());
         $purchase->setBasePriceInCents($product->getPriceInCents());
         $purchase->setQuantity(1);
         $purchase->setTotalPriceInCents($purchase->getBasePriceInCents() * $purchase->getQuantity());
         $purchase->setStatus(PhortunePurchase::STATUS_PENDING);
         $purchase->save();
         $cart->saveTransaction();
         $cart_id = $cart->getID();
         $cart_uri = $this->getApplicationURI('/cart/' . $cart_id . '/checkout/');
         return id(new AphrontRedirectResponse())->setURI($cart_uri);
     }
     return $this->newDialog()->setTitle(pht('Purchase Product'))->appendParagraph(pht('Really purchase this stuff?'))->addSubmitButton(pht('Checkout'))->addCancelButton($account_uri);
 }
 public function getPurchaseName(PhortuneProduct $product, PhortunePurchase $purchase)
 {
     return coalesce($purchase->getMetadataValue('adhoc.name'), $this->getName($product));
 }