Phortune v0
Summary:
Ref T2787. This does very little so far, but makes inroads on accounts and billing. This is mostly just modeled on what Stripe looks like. The objects are:
- **Account**: Has one or more authorized users, who can make manage the account. An example might be "Phacility", and the three of us would be able to manage it. A user may be associated with more than one account (e.g., a corporate account and a personal account) but the UI tries to simplify the common case of a single account.
- **Payment Method**: Something we can get sweet sweet money from; for now, a credit card registered with Stripe. Payment methods are associated with an account.
- **Product**: A good (one time charge) or service (recurring charge). This might be "t-shirt" or "enterprise plan" or "hourly support" or whatever else.
- **Purchase**: Represents a user purchasing a Product for an Account, using a Payment Method. e.g., you bought a shirt, or started a plan, or purchased support.
- **Charge**: Actual charges against payment methods. A Purchase can create more than one charge if it's a plan, or if the first charge fails and we re-bill.
This doesn't fully account for stuff like coupons/discounts yet but they should fit into the model without any issues.
This only implements `Account`, and that only partially.
Test Plan: {F37531}
Reviewers: chad, btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T2787
Differential Revision: https://secure.phabricator.com/D5435
2013-03-28 17:10:34 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhortuneAccountViewController extends PhortuneController {
|
|
|
|
|
|
|
|
private $accountID;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->accountID = $data['accountID'];
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
$title = $account->getName();
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
->setName(pht('Account'))
|
|
|
|
->setHref($request->getRequestURI()));
|
|
|
|
|
|
|
|
$header = id(new PhabricatorHeaderView())
|
|
|
|
->setHeader($title);
|
|
|
|
|
|
|
|
$actions = id(new PhabricatorActionListView())
|
|
|
|
->setUser($user)
|
|
|
|
->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Edit Account'))
|
|
|
|
->setIcon('edit')
|
|
|
|
->setHref('#')
|
|
|
|
->setDisabled(true))
|
|
|
|
->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Edit Members'))
|
|
|
|
->setIcon('transcript')
|
|
|
|
->setHref('#')
|
|
|
|
->setDisabled(true));
|
|
|
|
|
|
|
|
$properties = id(new PhabricatorPropertyListView())
|
|
|
|
->setObject($account)
|
|
|
|
->setUser($user);
|
|
|
|
|
|
|
|
$properties->addProperty(pht('Balance'), $account->getBalanceInCents());
|
|
|
|
|
|
|
|
$payment_methods = $this->buildPaymentMethodsSection($account);
|
2013-03-28 17:13:07 +01:00
|
|
|
$purchase_history = $this->buildPurchaseHistorySection($account);
|
Phortune v0
Summary:
Ref T2787. This does very little so far, but makes inroads on accounts and billing. This is mostly just modeled on what Stripe looks like. The objects are:
- **Account**: Has one or more authorized users, who can make manage the account. An example might be "Phacility", and the three of us would be able to manage it. A user may be associated with more than one account (e.g., a corporate account and a personal account) but the UI tries to simplify the common case of a single account.
- **Payment Method**: Something we can get sweet sweet money from; for now, a credit card registered with Stripe. Payment methods are associated with an account.
- **Product**: A good (one time charge) or service (recurring charge). This might be "t-shirt" or "enterprise plan" or "hourly support" or whatever else.
- **Purchase**: Represents a user purchasing a Product for an Account, using a Payment Method. e.g., you bought a shirt, or started a plan, or purchased support.
- **Charge**: Actual charges against payment methods. A Purchase can create more than one charge if it's a plan, or if the first charge fails and we re-bill.
This doesn't fully account for stuff like coupons/discounts yet but they should fit into the model without any issues.
This only implements `Account`, and that only partially.
Test Plan: {F37531}
Reviewers: chad, btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T2787
Differential Revision: https://secure.phabricator.com/D5435
2013-03-28 17:10:34 +01:00
|
|
|
$account_history = $this->buildAccountHistorySection($account);
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$header,
|
|
|
|
$actions,
|
|
|
|
$properties,
|
|
|
|
$payment_methods,
|
2013-03-28 17:13:07 +01:00
|
|
|
$purchase_history,
|
Phortune v0
Summary:
Ref T2787. This does very little so far, but makes inroads on accounts and billing. This is mostly just modeled on what Stripe looks like. The objects are:
- **Account**: Has one or more authorized users, who can make manage the account. An example might be "Phacility", and the three of us would be able to manage it. A user may be associated with more than one account (e.g., a corporate account and a personal account) but the UI tries to simplify the common case of a single account.
- **Payment Method**: Something we can get sweet sweet money from; for now, a credit card registered with Stripe. Payment methods are associated with an account.
- **Product**: A good (one time charge) or service (recurring charge). This might be "t-shirt" or "enterprise plan" or "hourly support" or whatever else.
- **Purchase**: Represents a user purchasing a Product for an Account, using a Payment Method. e.g., you bought a shirt, or started a plan, or purchased support.
- **Charge**: Actual charges against payment methods. A Purchase can create more than one charge if it's a plan, or if the first charge fails and we re-bill.
This doesn't fully account for stuff like coupons/discounts yet but they should fit into the model without any issues.
This only implements `Account`, and that only partially.
Test Plan: {F37531}
Reviewers: chad, btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T2787
Differential Revision: https://secure.phabricator.com/D5435
2013-03-28 17:10:34 +01:00
|
|
|
$account_history,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
'device' => true,
|
|
|
|
'dust' => true,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildPaymentMethodsSection(PhortuneAccount $account) {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$header = id(new PhabricatorHeaderView())
|
|
|
|
->setHeader(pht('Payment Methods'));
|
|
|
|
|
|
|
|
$id = $account->getID();
|
|
|
|
$add_uri = $this->getApplicationURI($id.'/paymentmethod/edit/');
|
|
|
|
|
|
|
|
$actions = id(new PhabricatorActionListView())
|
|
|
|
->setUser($user)
|
|
|
|
->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Add Payment Method'))
|
|
|
|
->setIcon('new')
|
|
|
|
->setHref($add_uri));
|
|
|
|
|
|
|
|
$list = id(new PhabricatorObjectItemListView())
|
|
|
|
->setUser($user)
|
|
|
|
->setNoDataString(
|
|
|
|
pht('No payment methods associated with this account.'));
|
|
|
|
|
2013-03-28 17:11:42 +01:00
|
|
|
$methods = id(new PhortunePaymentMethodQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withAccountPHIDs(array($account->getPHID()))
|
|
|
|
->withStatus(PhortunePaymentMethodQuery::STATUS_OPEN)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
if ($methods) {
|
|
|
|
$this->loadHandles(mpull($methods, 'getAuthorPHID'));
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($methods as $method) {
|
|
|
|
$item = new PhabricatorObjectItemView();
|
|
|
|
$item->setHeader($method->getName());
|
|
|
|
|
|
|
|
switch ($method->getStatus()) {
|
|
|
|
case PhortunePaymentMethod::STATUS_ACTIVE:
|
|
|
|
$item->addAttribute(pht('Active'));
|
|
|
|
$item->setBarColor('green');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$item->addAttribute(
|
|
|
|
pht(
|
|
|
|
'Added %s by %s',
|
|
|
|
phabricator_datetime($method->getDateCreated(), $user),
|
|
|
|
$this->getHandle($method->getAuthorPHID())->renderLink()));
|
|
|
|
|
|
|
|
if ($method->getExpiresEpoch() < time() + (60 * 60 * 24 * 30)) {
|
|
|
|
$item->addAttribute(pht('Expires Soon!'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$list->addItem($item);
|
|
|
|
}
|
|
|
|
|
Phortune v0
Summary:
Ref T2787. This does very little so far, but makes inroads on accounts and billing. This is mostly just modeled on what Stripe looks like. The objects are:
- **Account**: Has one or more authorized users, who can make manage the account. An example might be "Phacility", and the three of us would be able to manage it. A user may be associated with more than one account (e.g., a corporate account and a personal account) but the UI tries to simplify the common case of a single account.
- **Payment Method**: Something we can get sweet sweet money from; for now, a credit card registered with Stripe. Payment methods are associated with an account.
- **Product**: A good (one time charge) or service (recurring charge). This might be "t-shirt" or "enterprise plan" or "hourly support" or whatever else.
- **Purchase**: Represents a user purchasing a Product for an Account, using a Payment Method. e.g., you bought a shirt, or started a plan, or purchased support.
- **Charge**: Actual charges against payment methods. A Purchase can create more than one charge if it's a plan, or if the first charge fails and we re-bill.
This doesn't fully account for stuff like coupons/discounts yet but they should fit into the model without any issues.
This only implements `Account`, and that only partially.
Test Plan: {F37531}
Reviewers: chad, btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T2787
Differential Revision: https://secure.phabricator.com/D5435
2013-03-28 17:10:34 +01:00
|
|
|
return array(
|
|
|
|
$header,
|
|
|
|
$actions,
|
|
|
|
$list,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-03-28 17:13:07 +01:00
|
|
|
private function buildPurchaseHistorySection(PhortuneAccount $account) {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$header = id(new PhabricatorHeaderView())
|
|
|
|
->setHeader(pht('Purchase History'));
|
|
|
|
|
|
|
|
return array(
|
|
|
|
$header,
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
Phortune v0
Summary:
Ref T2787. This does very little so far, but makes inroads on accounts and billing. This is mostly just modeled on what Stripe looks like. The objects are:
- **Account**: Has one or more authorized users, who can make manage the account. An example might be "Phacility", and the three of us would be able to manage it. A user may be associated with more than one account (e.g., a corporate account and a personal account) but the UI tries to simplify the common case of a single account.
- **Payment Method**: Something we can get sweet sweet money from; for now, a credit card registered with Stripe. Payment methods are associated with an account.
- **Product**: A good (one time charge) or service (recurring charge). This might be "t-shirt" or "enterprise plan" or "hourly support" or whatever else.
- **Purchase**: Represents a user purchasing a Product for an Account, using a Payment Method. e.g., you bought a shirt, or started a plan, or purchased support.
- **Charge**: Actual charges against payment methods. A Purchase can create more than one charge if it's a plan, or if the first charge fails and we re-bill.
This doesn't fully account for stuff like coupons/discounts yet but they should fit into the model without any issues.
This only implements `Account`, and that only partially.
Test Plan: {F37531}
Reviewers: chad, btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T2787
Differential Revision: https://secure.phabricator.com/D5435
2013-03-28 17:10:34 +01:00
|
|
|
private function buildAccountHistorySection(PhortuneAccount $account) {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$header = id(new PhabricatorHeaderView())
|
|
|
|
->setHeader(pht('Account History'));
|
|
|
|
|
|
|
|
$xactions = id(new PhortuneAccountTransactionQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withObjectPHIDs(array($account->getPHID()))
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$engine = id(new PhabricatorMarkupEngine())
|
|
|
|
->setViewer($user);
|
|
|
|
|
|
|
|
$xaction_view = id(new PhabricatorApplicationTransactionView())
|
|
|
|
->setUser($user)
|
|
|
|
->setTransactions($xactions)
|
|
|
|
->setMarkupEngine($engine);
|
|
|
|
|
|
|
|
return array(
|
|
|
|
$header,
|
|
|
|
$xaction_view,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|