Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phortune/storage/PhortuneCart.php
<?php | <?php | ||||
final class PhortuneCart extends PhortuneDAO | final class PhortuneCart extends PhortuneDAO | ||||
implements PhabricatorPolicyInterface { | implements PhabricatorPolicyInterface { | ||||
const STATUS_BUILDING = 'cart:building'; | const STATUS_BUILDING = 'cart:building'; | ||||
const STATUS_READY = 'cart:ready'; | const STATUS_READY = 'cart:ready'; | ||||
const STATUS_PURCHASING = 'cart:purchasing'; | const STATUS_PURCHASING = 'cart:purchasing'; | ||||
const STATUS_CHARGED = 'cart:charged'; | const STATUS_CHARGED = 'cart:charged'; | ||||
const STATUS_PURCHASED = 'cart:purchased'; | const STATUS_PURCHASED = 'cart:purchased'; | ||||
protected $accountPHID; | protected $accountPHID; | ||||
protected $authorPHID; | protected $authorPHID; | ||||
protected $cartClass; | |||||
protected $status; | protected $status; | ||||
protected $metadata; | protected $metadata = array(); | ||||
private $account = self::ATTACHABLE; | private $account = self::ATTACHABLE; | ||||
private $purchases = self::ATTACHABLE; | private $purchases = self::ATTACHABLE; | ||||
private $implementation = self::ATTACHABLE; | |||||
public static function initializeNewCart( | public static function initializeNewCart( | ||||
PhabricatorUser $actor, | PhabricatorUser $actor, | ||||
PhortuneAccount $account) { | PhortuneAccount $account) { | ||||
$cart = id(new PhortuneCart()) | $cart = id(new PhortuneCart()) | ||||
->setAuthorPHID($actor->getPHID()) | ->setAuthorPHID($actor->getPHID()) | ||||
->setStatus(self::STATUS_BUILDING) | ->setStatus(self::STATUS_BUILDING) | ||||
->setAccountPHID($account->getPHID()); | ->setAccountPHID($account->getPHID()); | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | public function didApplyCharge(PhortuneCharge $charge) { | ||||
$this->setStatus(self::STATUS_PURCHASED)->save(); | $this->setStatus(self::STATUS_PURCHASED)->save(); | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getDoneURI() { | public function getDoneURI() { | ||||
// TODO: Implement properly. | return $this->getImplementation()->getDoneURI($this); | ||||
return '/phortune/cart/'.$this->getID().'/'; | |||||
} | } | ||||
public function getCancelURI() { | public function getCancelURI() { | ||||
// TODO: Implement properly. | return $this->getImplementation()->getCancelURI($this); | ||||
return '/'; | |||||
} | } | ||||
public function getDetailURI() { | public function getDetailURI() { | ||||
return '/phortune/cart/'.$this->getID().'/'; | return '/phortune/cart/'.$this->getID().'/'; | ||||
} | } | ||||
public function getCheckoutURI() { | public function getCheckoutURI() { | ||||
return '/phortune/cart/'.$this->getID().'/checkout/'; | return '/phortune/cart/'.$this->getID().'/checkout/'; | ||||
} | } | ||||
public function getConfiguration() { | public function getConfiguration() { | ||||
return array( | return array( | ||||
self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
self::CONFIG_SERIALIZATION => array( | self::CONFIG_SERIALIZATION => array( | ||||
'metadata' => self::SERIALIZATION_JSON, | 'metadata' => self::SERIALIZATION_JSON, | ||||
), | ), | ||||
self::CONFIG_COLUMN_SCHEMA => array( | self::CONFIG_COLUMN_SCHEMA => array( | ||||
'status' => 'text32', | 'status' => 'text32', | ||||
'cartClass' => 'text128', | |||||
), | ), | ||||
self::CONFIG_KEY_SCHEMA => array( | self::CONFIG_KEY_SCHEMA => array( | ||||
'key_account' => array( | 'key_account' => array( | ||||
'columns' => array('accountPHID'), | 'columns' => array('accountPHID'), | ||||
), | ), | ||||
), | ), | ||||
) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
} | } | ||||
Show All 17 Lines | public function attachAccount(PhortuneAccount $account) { | ||||
$this->account = $account; | $this->account = $account; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getAccount() { | public function getAccount() { | ||||
return $this->assertAttached($this->account); | return $this->assertAttached($this->account); | ||||
} | } | ||||
public function attachImplementation( | |||||
PhortuneCartImplementation $implementation) { | |||||
$this->implementation = $implementation; | |||||
return $this; | |||||
} | |||||
public function getImplementation() { | |||||
return $this->assertAttached($this->implementation); | |||||
} | |||||
public function getTotalPriceAsCurrency() { | public function getTotalPriceAsCurrency() { | ||||
$prices = array(); | $prices = array(); | ||||
foreach ($this->getPurchases() as $purchase) { | foreach ($this->getPurchases() as $purchase) { | ||||
$prices[] = $purchase->getTotalPriceAsCurrency(); | $prices[] = $purchase->getTotalPriceAsCurrency(); | ||||
} | } | ||||
return PhortuneCurrency::newFromList($prices); | return PhortuneCurrency::newFromList($prices); | ||||
} | } | ||||
public function setMetadataValue($key, $value) { | |||||
$this->metadata[$key] = $value; | |||||
return $this; | |||||
} | |||||
public function getMetadataValue($key, $default = null) { | |||||
return idx($this->metadata, $key, $default); | |||||
} | |||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */ | /* -( PhabricatorPolicyInterface )----------------------------------------- */ | ||||
public function getCapabilities() { | public function getCapabilities() { | ||||
return array( | return array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
Show All 16 Lines |