Permalink
Browse files

Merge pull request #3 from inspiran/master

Billing refactoring
  • Loading branch information...
2 parents c1ee31a + d2b0b7b commit 6aa5eb3d43d17a8f2e865a62d82e6fb52337574a @iampersistent iampersistent committed Mar 23, 2013
View
@@ -2,21 +2,22 @@
"name": "vespolina/billing",
"type": "library",
"description": "Vespolina Billing.",
- "keywords": ["vespolina", "billing", "ecommerce"],
+ "keywords": ["vespolina", "billing", "ecommerce", "recurring", "plans"],
"homepage": "http://vespolina-project.org",
"license": "MIT",
"authors": [
{
"name": "Vespolina Team",
- "homepage": "https://github.com/vespolina/VespolinaPartner/contributors"
+ "homepage": "https://github.com/vespolina/VespolinaBilling"
}
],
"require": {
"php": ">=5.3.2",
- "vespolina/core": "*"
+ "vespolina/core": "1.0.*",
+ "vespolina/molino": "*"
},
"require-dev": {
- "doctrine/mongodb-odm-bundle": "2.2.*"
+ "vespolina/order": "*"
},
"minimum-stability": "dev",
"autoload": {
@@ -0,0 +1,12 @@
+<?php
+
+namespace Vespolina\Billing\Event;
+
+final class BillingEvents
+{
+ const BILLING_REQUEST_INIT = 'billing_request.init';
+
+ const BILLING_REQUEST_OFFER_FOR_PAYMENT = 'billing_request.offer_for_payment';
+
+ const BILLING_REQUEST_PAID = 'billing_request.paid';
+}
@@ -0,0 +1,129 @@
+<?php
+
+namespace Vespolina\Billing\Gateway;
+
+use Doctrine\Common\Collections\ArrayCollection;
+use Molino\MolinoInterface;
+use Molino\SelectQueryInterface;
+use Vespolina\Entity\Billing\BillingAgreementInterface;
+use Vespolina\Exception\InvalidInterfaceException;
+use Vespolina\Entity\Billing\BillingRequestInterface;
+
+class BillingGateway implements BillingGatewayInterface
+{
+ protected $molino;
+ protected $billingAgreementClass;
+
+ /**
+ * @param \Molino\MolinoInterface $molino
+ * @param string $managedClass
+ */
+ public function __construct(MolinoInterface $molino, $billingAgreementClass)
+ {
+ if (!class_exists($billingAgreementClass) ||
+ !in_array('Vespolina\Entity\Billing\BillingAgreementInterface', class_implements($billingAgreementClass))) {
+ throw new InvalidInterfaceException('Please have your BillingAgreement class implement Vespolina\Entity\Billing\BillingAgreementInterface');
+ }
+ $this->molino = $molino;
+ $this->billingAgreementClass = $billingAgreementClass;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function createQuery($type, $queryClass = null)
+ {
+ $type = ucfirst(strtolower($type));
+ if (!in_array($type, array('Delete', 'Select', 'Update'))) {
+ throw new InvalidArgumentException($type . ' is not a valid Query type');
+ }
+ $queryFunction = 'create' . $type . 'Query';
+
+ if (!$queryClass) {
+ $queryClass = $this->billingAgreementClass;
+ }
+ return $this->molino->$queryFunction($queryClass);
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function deleteBillingAgreement(BillingAgreementInterface $billingAgreement)
+ {
+ $this->molino->delete($billingAgreement);
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function findBillingAgreement(SelectQueryInterface $query)
+ {
+ return $query->one();
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function findBillingAgreements(SelectQueryInterface $query)
+ {
+ return $query->all();
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function persistBillingAgreement(BillingAgreementInterface $billingAgreement)
+ {
+ $this->molino->save($billingAgreement);
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function updateBillingAgreement(BillingAgreementInterface $billingAgreement)
+ {
+ $this->molino->save($billingAgreement);
+ }
+
+ /**
+ * @param \Vespolina\Entity\Billing\BillingRequestInterface $billingRequest
+ */
+ public function deleteBillingRequest(BillingRequestInterface $billingRequest)
+ {
+ $this->molino->delete($billingRequest);
+ }
+
+ /**
+ * @param \Molino\SelectQueryInterface $query
+ * @return \Vespolina\Entity\Billing\BillingRequestInterface
+ */
+ public function findBillingRequest(SelectQueryInterface $query)
+ {
+ return $query->one();
+ }
+
+ /**
+ * @param \Molino\SelectQueryInterface $query
+ * @return \Vespolina\Entity\Billing\BillingRequestInterface
+ */
+ public function findBillingRequests(SelectQueryInterface $query)
+ {
+ return $query->all();
+ }
+
+ /**
+ * @param \Vespolina\Entity\Billing\BillingRequestInterface $billingRequest
+ */
+ public function persistBillingRequest(BillingRequestInterface $billingRequest)
+ {
+ $this->molino->save($billingRequest);
+ }
+
+ /**
+ * @param \Vespolina\Entity\Billing\BillingRequestInterface $billingRequest
+ */
+ public function updateBillingRequest(BillingRequestInterface $billingRequest)
+ {
+ $this->molino->save($billingRequest);
+ }
+}
@@ -0,0 +1,74 @@
+<?php
+
+namespace Vespolina\Billing\Gateway;
+
+use Molino\MolinoInterface;
+use Molino\SelectQueryInterface;
+use Vespolina\Entity\Billing\BillingAgreementInterface;
+use Vespolina\Exception\InvalidInterfaceException;
+use Vespolina\Entity\Billing\BillingRequestInterface;
+
+interface BillingGatewayInterface
+{
+ /**
+ * @param string $type
+ * @param type $queryClass
+ * @return type
+ * @throws InvalidArgumentException
+ */
+ function createQuery($type, $queryClass = null);
+
+ /**
+ * @param \Vespolina\Entity\Billing\BillingAgreementInterface $billingAgreement
+ */
+ function deleteBillingAgreement(BillingAgreementInterface $billingAgreement);
+
+ /**
+ * @param \Molino\SelectQueryInterface $query
+ * @return \Vespolina\Entity\Billing\BillingAgreementInterface
+ */
+ function findBillingAgreement(SelectQueryInterface $query);
+
+ /**
+ * @param \Molino\SelectQueryInterface $query
+ * @return \Vespolina\Entity\Billing\BillingAgreementInterface
+ */
+ function findBillingAgreements(SelectQueryInterface $query);
+
+ /**
+ * @param \Vespolina\Entity\Billing\BillingAgreementInterface $billingAgreement
+ */
+ function persistBillingAgreement(BillingAgreementInterface $billingAgreement);
+
+ /**
+ * @param \Vespolina\Entity\Billing\BillingAgreementInterface $billingAgreement
+ */
+ function updateBillingAgreement(BillingAgreementInterface $billingAgreement);
+
+ /**
+ * @param \Vespolina\Entity\Billing\BillingRequestInterface $billingRequest
+ */
+ function deleteBillingRequest(BillingRequestInterface $billingRequest);
+
+ /**
+ * @param \Molino\SelectQueryInterface $query
+ * @return \Vespolina\Entity\Billing\BillingRequestInterface
+ */
+ function findBillingRequest(SelectQueryInterface $query);
+
+ /**
+ * @param \Molino\SelectQueryInterface $query
+ * @return \Vespolina\Entity\Billing\BillingRequestInterface
+ */
+ function findBillingRequests(SelectQueryInterface $query);
+
+ /**
+ * @param \Vespolina\Entity\Billing\BillingRequestInterface $billingRequest
+ */
+ function persistBillingRequest(BillingRequestInterface $billingRequest);
+
+ /**
+ * @param \Vespolina\Entity\Billing\BillingRequestInterface $billingRequest
+ */
+ function updateBillingRequest(BillingRequestInterface $billingRequest);
+}
@@ -0,0 +1,45 @@
+<?php
+/**
+ * (c) 2012 - 2013 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\Billing\Generator;
+
+use Vespolina\Entity\Billing\BillingRequestInterface;
+use Vespolina\Entity\Billing\BillingAgreementInterface;
+
+/**
+ * An interface to generate new billing requests for a billing agreement
+ *
+ * @author Daniel Kucharski <daniel@xerias.be>
+ */
+interface BillingRequestGeneratorInterface
+{
+ /*
+ * Generate all billing requests for a collection of billing agreements
+ *
+ *
+ * @return array \Vespolina\Entity\Billing\BillingRequestInterface
+ */
+
+ function generate(array $billingAgreements);
+
+ /**
+ * Generate the next (or first) billing request for provided billing agreement
+ *
+ * @param $billingAgreement
+ * @return mixed
+ */
+ function generateNext(BillingAgreementInterface $billingAgreement);
+
+ /**
+ * Determine the next billing period (start date + end date)
+ *
+ * @param BillingAgreementInterface $billingAgreement
+ * @return mixed
+ */
+ function getNextBillingPeriod(BillingAgreementInterface $billingAgreement);
+}
Oops, something went wrong.

0 comments on commit 6aa5eb3

Please sign in to comment.