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 renderOneTimePaymentButton(PhortuneAccount $account, PhortuneCart $cart, PhabricatorUser $user) { require_celerity_resource('phortune-css'); $description = $this->getPaymentMethodProviderDescription(); $details = $this->getPaymentMethodDescription(); $icon = id(new PHUIIconView())->setSpriteSheet(PHUIIconView::SPRITE_LOGIN)->setSpriteIcon($this->getPaymentMethodIcon()); $button = id(new PHUIButtonView())->setSize(PHUIButtonView::BIG)->setColor(PHUIButtonView::GREY)->setIcon($icon)->setText($description)->setSubtext($details); // NOTE: We generate a local URI to make sure the form picks up CSRF tokens. $uri = $this->getControllerURI('checkout', array('cartID' => $cart->getID()), $local = true); return phabricator_form($user, array('action' => $uri, 'method' => 'POST'), $button); }
private function buildActionListView(PhortuneCart $cart, $can_edit, $authority, $resume_uri) { $viewer = $this->getRequest()->getUser(); $id = $cart->getID(); $view = id(new PhabricatorActionListView())->setUser($viewer)->setObject($cart); $can_cancel = $can_edit && $cart->canCancelOrder(); if ($authority) { $prefix = 'merchant/' . $authority->getID() . '/'; } else { $prefix = ''; } $cancel_uri = $this->getApplicationURI("{$prefix}cart/{$id}/cancel/"); $refund_uri = $this->getApplicationURI("{$prefix}cart/{$id}/refund/"); $update_uri = $this->getApplicationURI("{$prefix}cart/{$id}/update/"); $accept_uri = $this->getApplicationURI("{$prefix}cart/{$id}/accept/"); $view->addAction(id(new PhabricatorActionView())->setName(pht('Cancel Order'))->setIcon('fa-times')->setDisabled(!$can_cancel)->setWorkflow(true)->setHref($cancel_uri)); if ($authority) { if ($cart->getStatus() == PhortuneCart::STATUS_REVIEW) { $view->addAction(id(new PhabricatorActionView())->setName(pht('Accept Order'))->setIcon('fa-check')->setWorkflow(true)->setHref($accept_uri)); } $view->addAction(id(new PhabricatorActionView())->setName(pht('Refund Order'))->setIcon('fa-reply')->setWorkflow(true)->setHref($refund_uri)); } $view->addAction(id(new PhabricatorActionView())->setName(pht('Update Status'))->setIcon('fa-refresh')->setHref($update_uri)); if ($can_edit && $resume_uri) { $view->addAction(id(new PhabricatorActionView())->setName(pht('Continue Checkout'))->setIcon('fa-shopping-cart')->setHref($resume_uri)); } return $view; }
private function buildCurtainView(PhortuneCart $cart, $can_edit, $authority, $resume_uri) { $viewer = $this->getViewer(); $id = $cart->getID(); $curtain = $this->newCurtainView($cart); $can_cancel = $can_edit && $cart->canCancelOrder(); if ($authority) { $prefix = 'merchant/' . $authority->getID() . '/'; } else { $prefix = ''; } $cancel_uri = $this->getApplicationURI("{$prefix}cart/{$id}/cancel/"); $refund_uri = $this->getApplicationURI("{$prefix}cart/{$id}/refund/"); $update_uri = $this->getApplicationURI("{$prefix}cart/{$id}/update/"); $accept_uri = $this->getApplicationURI("{$prefix}cart/{$id}/accept/"); $print_uri = $this->getApplicationURI("{$prefix}cart/{$id}/?__print__=1"); $curtain->addAction(id(new PhabricatorActionView())->setName(pht('Cancel Order'))->setIcon('fa-times')->setDisabled(!$can_cancel)->setWorkflow(true)->setHref($cancel_uri)); if ($authority) { if ($cart->getStatus() == PhortuneCart::STATUS_REVIEW) { $curtain->addAction(id(new PhabricatorActionView())->setName(pht('Accept Order'))->setIcon('fa-check')->setWorkflow(true)->setHref($accept_uri)); } $curtain->addAction(id(new PhabricatorActionView())->setName(pht('Refund Order'))->setIcon('fa-reply')->setWorkflow(true)->setHref($refund_uri)); } $curtain->addAction(id(new PhabricatorActionView())->setName(pht('Update Status'))->setIcon('fa-refresh')->setHref($update_uri)); if ($can_edit && $resume_uri) { $curtain->addAction(id(new PhabricatorActionView())->setName(pht('Continue Checkout'))->setIcon('fa-shopping-cart')->setHref($resume_uri)); } $curtain->addAction(id(new PhabricatorActionView())->setName(pht('Printable Version'))->setHref($print_uri)->setOpenInNewWindow(true)->setIcon('fa-print')); return $curtain; }
public function renderOneTimePaymentButton(PhortuneAccount $account, PhortuneCart $cart, PhabricatorUser $user) { require_celerity_resource('phortune-css'); $icon_uri = $this->getPaymentMethodIcon(); $description = $this->getPaymentMethodProviderDescription(); $details = $this->getPaymentMethodDescription(); $icon = id(new PHUIIconView())->setImage($icon_uri)->addClass('phortune-payment-icon'); $button = id(new PHUIButtonView())->setSize(PHUIButtonView::BIG)->setColor(PHUIButtonView::GREY)->setIcon($icon)->setText($description)->setSubtext($details); $uri = $this->getControllerURI('checkout', array('cartID' => $cart->getID())); return phabricator_form($user, array('action' => $uri, 'method' => 'POST'), $button); }