4 * A product is something users can purchase.
6 final class PhortuneProduct
extends PhortuneDAO
7 implements PhabricatorPolicyInterface
{
9 protected $productClassKey;
10 protected $productClass;
11 protected $productRefKey;
12 protected $productRef;
13 protected $metadata = array();
15 private $implementation = self
::ATTACHABLE
;
17 protected function getConfiguration() {
19 self
::CONFIG_AUX_PHID
=> true,
20 self
::CONFIG_SERIALIZATION
=> array(
21 'metadata' => self
::SERIALIZATION_JSON
,
23 self
::CONFIG_COLUMN_SCHEMA
=> array(
24 'productClassKey' => 'bytes12',
25 'productClass' => 'text128',
26 'productRefKey' => 'bytes12',
27 'productRef' => 'text128',
29 self
::CONFIG_KEY_SCHEMA
=> array(
30 'key_product' => array(
31 'columns' => array('productClassKey', 'productRefKey'),
35 ) + parent
::getConfiguration();
38 public function generatePHID() {
39 return PhabricatorPHID
::generateNewPHID(
40 PhortuneProductPHIDType
::TYPECONST
);
43 public static function initializeNewProduct() {
44 return id(new PhortuneProduct());
47 public function attachImplementation(PhortuneProductImplementation
$impl) {
48 $this->implementation
= $impl;
51 public function getImplementation() {
52 return $this->assertAttached($this->implementation
);
55 public function save() {
56 $this->productClassKey
= PhabricatorHash
::digestForIndex(
59 $this->productRefKey
= PhabricatorHash
::digestForIndex(
62 return parent
::save();
65 public function getPriceAsCurrency() {
66 return $this->getImplementation()->getPriceAsCurrency($this);
69 public function getProductName() {
70 return $this->getImplementation()->getName($this);
73 public function getPurchaseName(PhortunePurchase
$purchase) {
74 return $this->getImplementation()->getPurchaseName($this, $purchase);
77 public function didPurchaseProduct(PhortunePurchase
$purchase) {
78 return $this->getImplementation()->didPurchaseProduct($this, $purchase);
81 public function didRefundProduct(
82 PhortunePurchase
$purchase,
83 PhortuneCurrency
$amount) {
84 return $this->getImplementation()->didRefundProduct(
90 public function getPurchaseURI(PhortunePurchase
$purchase) {
91 return $this->getImplementation()->getPurchaseURI(
96 /* -( PhabricatorPolicyInterface )----------------------------------------- */
99 public function getCapabilities() {
101 PhabricatorPolicyCapability
::CAN_VIEW
,
105 public function getPolicy($capability) {
106 return PhabricatorPolicies
::POLICY_USER
;
109 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {