Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from inspiran/master
Billing refactoring
- Loading branch information
Showing
24 changed files
with
1,942 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
45 changes: 45 additions & 0 deletions
45
lib/Vespolina/Billing/Generator/BillingRequestGeneratorInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.