Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add contexts to deal with different payment types

  • Loading branch information...
commit ff1e553b8d5f6086753794db20abbbdb480a7040 1 parent f515569
@iampersistent iampersistent authored
View
31 lib/Vespolina/Billing/Manager/BillingManager.php
@@ -10,6 +10,7 @@
use Vespolina\Billing\Gateway\BillingGatewayInterface;
use Vespolina\Entity\Billing\BillingAgreement;
+use Vespolina\Entity\Billing\BillingAgreementInterface;
use Vespolina\Entity\Order\ItemInterface;
use Vespolina\Entity\Order\OrderInterface;
use Vespolina\Entity\Partner\PartnerInterface;
@@ -20,11 +21,13 @@
class BillingManager implements BillingManagerInterface
{
- protected $cartClass;
+ protected $billingAgreementClass;
+ protected $billingRequestClass;
+ protected $contexts;
protected $eventDispatcher;
protected $gateway;
- public function __construct(BillingGatewayInterface $gateway, array $classMapping, EventDispatcherInterface $eventDispatcher = null)
+ public function __construct(BillingGatewayInterface $gateway, array $classMapping, array $contexts, EventDispatcherInterface $eventDispatcher = null)
{
$missingClasses = array();
foreach (array('billingAgreement', 'billingRequest') as $class) {
@@ -50,6 +53,12 @@ public function __construct(BillingGatewayInterface $gateway, array $classMappin
$this->eventDispatcher = $eventDispatcher;
$this->gateway = $gateway;
+ foreach ($contexts as $context) {
+ $process = $context['process'];
+ $paymentType = $context['paymentType'];
+
+ $this->context[$process][$paymentType] = $context;
+ }
}
/**
@@ -136,10 +145,17 @@ protected function addItemToAgreements(ItemInterface $item, array &$agreements)
/**
* @inheritdoc
*/
- function createBillingRequest(PartnerInterface $partner)
+ function createBillingRequest(BillingAgreementInterface $billingAgreement)
{
- $orderArray = $this->orderManager->findClosedOrdersByOwner($partner);
- //$orderArray->toArray();
+ if (!$billingAgreement->getActive()) {
+ return false;
+ }
+
+ $query = $this->gateway->createQuery('select', $this->billingAgreementClass);
+ $paymentType = $billingAgreement->getPaymentProfile()->getType();
+ $context = $this->context['billingRequest'][$paymentType];
+ // todo: find everything in the context then process ....
+
}
/**
@@ -153,11 +169,12 @@ public function findBy(array $criteria, array $orderBy = null, $limit = null, $o
/**
* Finds billing agreements that are due
*
+ * @param $context
* @param $limit
* @param int $page
* @return array
*/
- public function findEligibleBillingAgreements($limit, $page = 1)
+ public function findEligibleBillingAgreements($limit = null, $page = 1)
{
$offset = ($page - 1) * $limit;
@@ -181,6 +198,8 @@ public function findEligibleBillingAgreements($limit, $page = 1)
;
}
+
+
/**
* @todo add implementation, please don't forget to call $em->clear() after each batch
* @param array $billingAgreements
View
6 lib/Vespolina/Billing/Manager/BillingManagerInterface.php
@@ -8,8 +8,8 @@
namespace Vespolina\Billing\Manager;
+use Vespolina\Entity\Billing\BillingAgreementInterface;
use Vespolina\Entity\Order\OrderInterface;
-use Vespolina\Entity\Partner\PartnerInterface;
/**
* An interface to manage the creation of billing requests
@@ -33,10 +33,10 @@ function createBillingAgreements(OrderInterface $order);
/**
* Create a new billing request
*
- * @param \Vespolina\Entity\Partner\PartnerInterface $partner
+ * @param \Vespolina\Entity\Billing\BillingAgreementInterface $billingAgreement
* @return \Vespolina\Entity\Billing\BillingRequestInterface
*/
- function createBillingRequest(PartnerInterface $partner);
+ function createBillingRequest(BillingAgreementInterface $partner);
/**
* Find billing agreements by specified fields and values
Please sign in to comment.
Something went wrong with that request. Please try again.