Permalink
Browse files

Added basic fields to the billing request entity

  • Loading branch information...
1 parent d1c4835 commit 1ea6070f0f9023e69ee51613568c1f846d0243d5 @inspiran inspiran committed with iampersistent Mar 13, 2013
View
156 lib/Vespolina/Entity/Billing/BillingRequest.php
@@ -9,26 +9,176 @@
namespace Vespolina\Entity\Billing;
use Vespolina\Entity\Billing\BillingRequestInterface;
+use Vespolina\Entity\Partner\PaymentProfileInterface;
class BillingRequest implements BillingRequestInterface
{
- public function getBillingDate()
+
+ /**
+ * A typical billing request flow will be:
+ * 1) initial state
+ * 2) pending: billing request is ready to be executed when the time has come
+ * 3) paid: the payment was succesfully
+ * 4) closed: post processing have been executed (eg. notifications)
+ *
+ * After (2) it's possible that a clerk blocks the billing request temporarily or
+ * cancels the billing request.
+ *
+ */
+
+ const STATE_INITIAL = 'initial'; //Initial, just created
+ const STATE_PENDING = 'pending'; //Ready to be billed
+ const STATE_BLOCKED = 'blocked'; //Blocked by administration
+ const STATE_CANCELLED = 'cancelled'; //Cancelled by administration
+ const STATE_PAID = 'paid'; //Cancelled by administration
+ const STATE_CLOSED = 'closed'; //(optional) processing after payment received was completed
+
+ protected $billingAgreements;
+ protected $createdAt;
+ protected $billingDate;
+ protected $plannedBillingDate;
+ protected $owner;
+ protected $paymentProfile;
+ protected $pricingSet;
+ protected $state;
+
+ public function __construct()
{
+ $this->billingAgreements = array();
+ }
+ public function addBillingAgreement(BillingAgreementInterface $billingAgreement)
+ {
+ $this->billingAgreements[] = $billingAgreement;
}
- public function getBillingParty()
+ public function getBillingAgreements()
{
+ return $this->billingAgreements;
+ }
+ public function setPlannedBillingDate(\DateTime $date)
+ {
+ $this->plannedBillingDate = $date;
+
+ return $this;
}
- public function getPlannedBillingDate()
+ public function getBillingDate()
+ {
+ return $this->billingDate;
+ }
+
+ public function setBillingDate(\DateTime $date)
{
+ $this->billingDate = $date;
+ return $this;
+ }
+
+ public function getPlannedBillingDate()
+ {
+ return $this->plannedBillingDate;
}
public function isBlocked()
{
+ return $this->state == self::STATE_BLOCKED;
+ }
+
+
+
+ public function autoSetCreatedAt()
+ {
+ if (null === $this->createdAt) {
+ $this->createdAt = new \DateTime();
+ }
+
+ return $this;
+ }
+
+ /**
+ * @param \DateTime $date
+ * @return $this
+ */
+ public function setCreatedAt(\DateTime $date)
+ {
+ $this->createdAt = $date;
+
+ return $this;
+ }
+ /**
+ * @return \DateTime
+ */
+ public function getCreatedAt()
+ {
+ return $this->createdAt;
+ }
+
+ /**
+ * @param PartnerInterface $owner
+ * @return PartnerInterface
+ */
+ public function setOwner(PartnerInterface $owner)
+ {
+ $this->owner = $owner;
+
+ return $this;
+ }
+
+ public function getOwner()
+ {
+ return $this->owner;
+ }
+
+ public function setPaymentProfile(PaymentProfileInterface $paymentProfile)
+ {
+ $this->paymentProfile = $paymentProfile;
+
+ return $this;
+ }
+
+ public function getPaymentProfile()
+ {
+ return $this->paymentProfile;
+ }
+
+ /**
+ * @param $pricingSet
+ * @return BillingRequest
+ */
+ public function setPricingSet($pricingSet)
+ {
+ $this->pricingSet = $pricingSet;
+
+ return $this;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getPricingSet()
+ {
+ return $this->pricingSet;
+ }
+
+ /**
+ * @param string $state
+ * @return $this
+ */
+ public function setState($state)
+ {
+ $this->state = $state;
+
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getState()
+ {
+ return $this->state;
}
}
View
29 lib/Vespolina/Entity/Billing/BillingRequestGeneratorInterface.php
@@ -1,29 +0,0 @@
-<?php
-/**
- * (c) 2012 Vespolina Project http://www.vespolina-project.org
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
-
-namespace Vespolina\Entity\Billing;
-
-use Vespolina\Entity\Billing\BillingDataInterface;
-use Vespolina\Entity\Billing\BillingRequestInterface;
-
-/**
- * An interface to generate new billing requests
- *
- * @author Daniel Kucharski <daniel-xerias.be>
- */
-interface BillingRequestGeneratorInterface
-{
- /*
- * Generate new billing requests for a collection of subscriptions
- *
- *
- * @return array \Vespolina\Entity\Billing\BillingRequestInterface
- */
-
- function generate(array BillingDataInterface);
-}
View
26 lib/Vespolina/Entity/Billing/BillingRequestInterface.php
@@ -8,7 +8,8 @@
namespace Vespolina\Entity\Billing;
-use Vespolina\Entity\Order\OrderInterface;
+use Vespolina\Entity\Billing\BillingAgreementInterface;
+use Vespolina\Entity\Partner\PartnerInterface;
/**
* An interface for a request to bill a party
@@ -18,19 +19,36 @@
interface BillingRequestInterface
{
/**
- * Get the last date when the billing run was performed for this item
+ * Add a billing agreement which originated into this billing request.
+ * Multiple business agreements can merge into one billing request
+ *
+ * @return mixed
+ */
+ function addBillingAgreement(BillingAgreementInterface $billingAgreement);
+
+ /**
+ * Return the list of billing agreements resulting into this billing request
+ * @return mixed
+ */
+ function getBillingAgreements();
+
+ /**
+ * Get the date on which the billing was effectively performed
*
*
* @return \DateTime
*/
function getBillingDate();
+ function setBillingDate(\DateTime $billingDate);
/**
* Return the partner we would like to bill
*
* @return \Vespolina\Entity\Partner\PartnerInterface
*/
- function getBillingParty();
+ function getOwner();
+
+ function setOwner(PartnerInterface $partner);
/**
* Get the earliest moment we can execute this billing request
@@ -39,6 +57,8 @@ function getBillingParty();
*/
function getPlannedBillingDate();
+ function setPlannedBillingDate(\DateTime $plannedBillingDate);
+
/**
* Return if the billing request is blocked from being executed
*

0 comments on commit 1ea6070

Please sign in to comment.