/**
     * {@inheritdoc}
     */
    public function addConfiguration(ArrayNodeDefinition $builder)
    {
        parent::addConfiguration($builder);

        $builder->children()
            ->scalarNode('type')->isRequired()->cannotBeEmpty()->end()
            ->arrayNode('options')->isRequired()
                ->useAttributeAsKey('key')
                ->prototype('scalar')->end()
            ->end()
        ->end();

        $builder
            ->validate()
            ->ifTrue(function ($v) {
                $gatewayFactory = Omnipay::getFactory();
                $gatewayFactory->find();

                $supportedTypes = $gatewayFactory->all();
                if (false == in_array($v['type'], $supportedTypes) && !class_exists($v['type'])) {
                    throw new LogicException(sprintf(
                        'Given type %s is not supported. Try one of supported types: %s or use the gateway full class name.',
                        $v['type'],
                        implode(', ', $supportedTypes)
                    ));
                }

                return false;
            })
            ->thenInvalid('A message')
        ;
    }
 /**
  * {@inheritDoc}
  */
 public function createConfig(array $config = array())
 {
     $config = ArrayObject::ensureArrayObject($config);
     $config->defaults($this->defaultConfig);
     $config->defaults($this->coreGatewayFactory->createConfig());
     $config->defaults(array('payum.action.capture' => new CaptureAction(), 'payum.action.convert_payment' => new ConvertPaymentAction(), 'payum.action.status' => new StatusAction()));
     if (false == $config['payum.api']) {
         $config['payum.required_options'] = array('type');
         $config->defaults(array('options' => array()));
         $config['payum.api.gateway'] = function (ArrayObject $config) {
             $config->validateNotEmpty($config['payum.required_options']);
             $gatewayFactory = Omnipay::getFactory();
             $gatewayFactory->find();
             $supportedTypes = $gatewayFactory->all();
             if (false == in_array($config['type'], $supportedTypes)) {
                 throw new LogicException(sprintf('Given type %s is not supported. Try one of supported types: %s.', $config['type'], implode(', ', $supportedTypes)));
             }
             $gateway = $gatewayFactory->create($config['type']);
             foreach ($config['options'] as $name => $value) {
                 $gateway->{'set' . strtoupper($name)}($value);
             }
             return $gateway;
         };
     }
     return (array) $config;
 }
Exemplo n.º 3
0
 /**
  * @covers ::refund
  */
 public function testRefund()
 {
     $gateway = Omnipay::getFactory()->create('Dummy');
     $refund = $this->getMock('CL\\Purchases\\Refund', ['execute']);
     $params = ['test', 'test2'];
     $response = 'result response';
     $refund->expects($this->once())->method('execute')->with($this->identicalTo($gateway), $this->equalTo('refund'), $this->equalTo($params))->will($this->returnValue($response));
     $result = $refund->refund($gateway, $params);
     $this->assertEquals($response, $result);
 }
 public function createGateway(array $parameters)
 {
     if (array_key_exists($parameters['name'], $this->gateways)) {
         return $this->gateways[$parameters['name']];
     }
     /** @var $gateway \Omnipay\Common\AbstractGateway */
     $gateway = Omnipay::getFactory()->create($parameters['name']);
     $this->gatewayBuilders[$parameters['name']]->build($gateway, $parameters);
     $this->gateways[$parameters['name']] = $gateway;
     return $gateway;
 }
Exemplo n.º 5
0
 public function testStorePurchase()
 {
     $purchase = new Purchase();
     $address = Address::find(1);
     $product1 = Product::find(5);
     $product2 = Product::find(6);
     $product3 = Product::find(7);
     $purchase->setBilling($address);
     $purchase->addProduct($product1, 4)->addProduct($product2)->addProduct($product3)->addProduct($product1);
     Purchase::save($purchase);
     $gateway = Omnipay::getFactory()->create('Dummy');
     $parameters = ['card' => ['number' => '4242424242424242', 'expiryMonth' => 12, 'expiryYear' => date('Y'), 'cvv' => 123], 'clientIp' => '192.168.0.1'];
     $response = $purchase->purchase($gateway, $parameters);
     $this->assertTrue($response->isSuccessful());
     $this->assertEquals('Success', $response->getMessage());
 }
Exemplo n.º 6
0
 /**
  * @covers ::testMethod
  */
 public function testTest()
 {
     $basket = new Basket();
     $product1 = Product::find(1);
     $product2 = Product::find(2);
     $item1 = new ProductItem(['quantity' => 2]);
     $item1->setProduct($product1);
     $item2 = new ProductItem(['quantity' => 4]);
     $item2->setProduct($product2);
     $basket->getItems()->add($item1)->add($item2);
     Basket::save($basket);
     $gateway = Omnipay::getFactory()->create('Dummy');
     $parameters = ['card' => ['number' => '4242424242424242', 'expiryMonth' => 12, 'expiryYear' => date('Y'), 'cvv' => 123], 'clientIp' => '192.168.0.1'];
     $basket->freeze();
     $response = $basket->purchase($gateway, $parameters);
     $this->assertTrue($response->isSuccessful());
     $this->assertTrue($basket->isSuccessful);
     $this->assertQueries(['SELECT Product.* FROM Product WHERE (id = 1) LIMIT 1', 'SELECT Product.* FROM Product WHERE (id = 2) LIMIT 1', 'INSERT INTO Basket (id, currency, isSuccessful, completedAt, responseData, deletedAt, isFrozen, value) VALUES (NULL, "GBP", , NULL, NULL, NULL, , 0)', 'INSERT INTO ProductItem (id, basketId, productId, quantity, deletedAt, isFrozen, value) VALUES (NULL, NULL, NULL, 2, NULL, , 0), (NULL, NULL, NULL, 4, NULL, , 0)', 'UPDATE ProductItem SET basketId = CASE id WHEN 1 THEN "1" WHEN 2 THEN "1" ELSE basketId END, productId = CASE id WHEN 1 THEN 1 WHEN 2 THEN 2 ELSE productId END WHERE (id IN (1, 2))', 'UPDATE Basket SET isSuccessful = 1, completedAt = "' . $basket->completedAt . '", responseData = "{"amount":"1000.00","reference":"' . $basket->responseData['reference'] . '","success":true,"message":"Success"}", isFrozen = 1, value = 100000 WHERE (id = "1")', 'UPDATE ProductItem SET isFrozen = CASE id WHEN 1 THEN 1 WHEN 2 THEN 1 ELSE isFrozen END, value = CASE id WHEN 1 THEN 10000 WHEN 2 THEN 20000 ELSE value END WHERE (id IN (1, 2))']);
 }
Exemplo n.º 7
0
 /**
  * @throws \Zend_EventManager_Exception_InvalidArgumentException
  */
 public function attachEvents()
 {
     self::getInstall()->attachEvents();
     $activeProviders = Configuration::get("OMNIPAY.ACTIVEPROVIDERS");
     if (!is_array($activeProviders)) {
         $activeProviders = [];
     }
     foreach ($activeProviders as $provider) {
         $gateway = \Omnipay\Omnipay::getFactory()->create($provider);
         $config = Configuration::get("OMNIPAY." . strtoupper($provider));
         if (is_null($config)) {
             $config = [];
         }
         $shopProvider = new Provider($gateway, $config);
         \Pimcore::getEventManager()->attach("coreshop.payment.getProvider", function ($e) use($shopProvider) {
             return $shopProvider;
         });
     }
 }
Exemplo n.º 8
0
 /**
  * @param GatewayFactoryInterface $coreGatewayFactory
  *
  * @return GatewayFactoryInterface[]
  */
 protected function buildOmnipayGatewayFactories(GatewayFactoryInterface $coreGatewayFactory)
 {
     $gatewayFactories = [];
     if (false == class_exists(\Omnipay\Omnipay::class)) {
         return $gatewayFactories;
     }
     $factory = \Omnipay\Omnipay::getFactory();
     $gatewayFactories['omnipay'] = new OmnipayGatewayFactory('', $factory, [], $coreGatewayFactory);
     $gatewayFactories['omnipay_direct'] = new OmnipayGatewayFactory('', $factory, [], $coreGatewayFactory);
     $gatewayFactories['omnipay_offsite'] = new OmnipayGatewayFactory('', $factory, [], $coreGatewayFactory);
     foreach ($factory->getSupportedGateways() as $type) {
         // omnipay throws exception on these gateways https://github.com/thephpleague/omnipay/issues/312
         // skip them for now
         if (in_array($type, ['Buckaroo', 'Alipay Bank', 'AliPay Dual Func', 'Alipay Express', 'Alipay Mobile Express', 'Alipay Secured', 'Alipay Wap Express', 'Cybersource', 'DataCash', 'Ecopayz', 'Neteller', 'Pacnet', 'PaymentSense', 'Realex Remote', 'SecPay (PayPoint.net)', 'Sisow', 'Skrill', 'YandexMoney', 'YandexMoneyIndividual'])) {
             continue;
         }
         $gatewayFactories[strtolower('omnipay_' . $type)] = new OmnipayGatewayFactory($type, $factory, [], $coreGatewayFactory);
     }
     return $gatewayFactories;
 }
Exemplo n.º 9
0
 /**
  * @param $name
  * @return array
  */
 protected function getProviderArray($name)
 {
     $gateway = \Omnipay\Omnipay::getFactory()->create($name);
     $data = ['name' => $name, 'settings' => $gateway->getParameters()];
     return $data;
 }
Exemplo n.º 10
0
 public function testSetFactory()
 {
     $factory = m::mock('Omnipay\\Common\\GatewayFactory');
     Omnipay::setFactory($factory);
     $this->assertSame($factory, Omnipay::getFactory());
 }
 /**
  * {@inheritDoc}
  *
  * @param string $omnipayGatewayTypeOrClass
  * @param OmnipayOmnipayGatewayFactory|null $omnipayGatewayFactory
  */
 public function __construct($omnipayGatewayTypeOrClass = null, OmnipayOmnipayGatewayFactory $omnipayGatewayFactory = null, array $defaultConfig = array(), GatewayFactoryInterface $coreGatewayFactory = null)
 {
     parent::__construct($defaultConfig, $coreGatewayFactory);
     $this->omnipayGatewayTypeOrClass = $omnipayGatewayTypeOrClass;
     $this->omnipayGatewayFactory = $omnipayGatewayFactory ?: Omnipay::getFactory();
 }