/**
  * Gets a the gateway based on the payment
  * 
  * @param  Payment\Payment $payment The payment
  * @return GatewayInterface         The found gateway
  */
 public function getGatewayByPayment(Payment\Payment $payment)
 {
     $result = $this->_queryBuilderFactory->getQueryBuilder()->select('`gateway`')->from('`payment_gateway`')->where('`payment_id` = ?i', [$payment->id])->run();
     if (!$result->count() || !$result->value()) {
         throw new GatewayNotFoundException("No record found for the given payment.");
     }
     $result = $result->value();
     return $this->_gatewayCollection->get($result);
 }
コード例 #2
0
 /**
  * Register the available payment gateways. Construct each gateway adapter,
  * add to the gateway collection and define the default gateway service.
  *
  * @param  \Message\Cog\Bootstrap\Services $services
  */
 public function registerPaymentGateways($services)
 {
     // Local payments adapter
     $services['gateway.adapter.local-payment'] = function ($c) {
         return new Gateway\LocalPayment\Gateway();
     };
     // Zero payment adapter
     $services['gateway.adapter.zero-payment'] = function ($c) {
         return new Gateway\ZeroPayment\Gateway();
     };
     // Gateway collection
     $services['gateway.collection'] = function ($c) {
         return new Gateway\Collection([$c['gateway.adapter.local-payment'], $c['gateway.adapter.zero-payment']]);
     };
     // Validation collection
     $services['gateway.validation'] = $services->factory(function ($c) {
         return new Gateway\Validation\Collection();
     });
     $services['gateway.validation.address'] = $services->factory(function ($c) {
         return new Gateway\Validation\AddressValidator($c['country.list'], $c['state.list']);
     });
     // Active gateway service
     // @deprecated call `gateways` instead and select the appropriate gateway
     $services['gateway'] = function ($c) {
         $gateway = $c['cfg']->payment->gateway;
         if (is_array($gateway)) {
             $gateway = array_shift($gateway);
         }
         return $c['gateway.collection']->get($gateway);
     };
     $services['gateways'] = function ($c) {
         $gateways = $c['cfg']->payment->gateway;
         if (!is_array($gateways)) {
             $gateways = [$gateways];
         }
         $collection = $c['gateway.collection'];
         array_walk($gateways, function (&$gateway) use($collection) {
             $gateway = $collection->get($gateway);
         });
         $gateways = new Gateway\Collection($gateways);
         $gateways->setSort(null);
         return $gateways;
     };
     $services['payment.gateway.loader'] = function ($c) {
         return new Ecommerce\Payment\PaymentGatewayRecordLoader($c['payment.loader'], $c['gateway.collection'], $c['db.query.builder.factory']);
     };
     $services['payment.gateway.edit'] = function ($c) {
         return new Ecommerce\Payment\PaymentGatewayRecordEdit($c['db.query']);
     };
 }