/**
     * @test
     */
    public function shouldAddConfigFieldsIfPaymentConfigHasFactorySet()
    {
        $this->fooPaymentFactoryMock
            ->expects($this->once())
            ->method('createConfig')
            ->with(array())
            ->willReturn(array(
                'payum.default_options' => array(
                    'username' => 'defaultName',
                    'password' => 'defaultPass',
                    'sandbox' => true,
                ),
                'payum.required_options' => array(),
            ))
        ;

        $paymentConfig = new PaymentConfig();
        $paymentConfig->setFactoryName('foo');
        $paymentConfig->setPaymentName('theName');
        $paymentConfig->setConfig(array(
            'username' => 'modelName',
            'password' => 'modelPass',
            'sandbox' => false,
        ));

        $form = $this->formFactory->create('payum_payment_config', $paymentConfig);


        $this->assertTrue($form->has('config'));

        $this->assertTrue($form->get('config')->has('username'));
        $this->assertEquals('modelName', $form->get('config')->get('username')->getData());

        $this->assertTrue($form->get('config')->has('password'));
        $this->assertEquals('modelPass', $form->get('config')->get('password')->getData());

        $this->assertTrue($form->get('config')->has('sandbox'));
        $this->assertEquals(false, $form->get('config')->get('sandbox')->getData());
    }
Ejemplo n.º 2
0
    /**
     * @test
     *
     * @dataProvider providePayments
     */
    public function shouldLoadExtensionWithPayment($config, PaymentFactoryInterface $paymentFactory)
    {
        $config = array(
            'security' => array(
                'token_storage' => array(
                    'Payum\Core\Model\Token' => array(
                        'filesystem' => array(
                            'storage_dir' => sys_get_temp_dir(),
                            'id_property' => 'hash'
                        )
                    )
                )
            ),
            'payments' => array(
                'a_payment' => array(
                    $paymentFactory->getName() => $config,
                )
            )
        );

        $configs = array($config);

        $container = new ContainerBuilder();
        $container->setParameter('kernel.debug', false);
        
        $extension = new PayumExtension;
        $extension->addPaymentFactory($paymentFactory);
        $extension->addStorageFactory(new FilesystemStorageFactory);
        
        $extension->load($configs, $container);

        $this->assertTrue($container->hasDefinition('payum.'.$paymentFactory->getName().'.factory'));
        $this->assertTrue($container->hasDefinition('payum.'.$paymentFactory->getName().'.a_payment.payment'));
        $this->assertEquals(
            'payum.'.$paymentFactory->getName().'.factory',
            $container->getDefinition('payum.'.$paymentFactory->getName().'.a_payment.payment')->getFactoryService()
        );
        $this->assertEquals('create', $container->getDefinition('payum.'.$paymentFactory->getName().'.a_payment.payment')->getFactoryMethod());
    }
Ejemplo n.º 3
0
 /**
  * @param Factory\Payment\PaymentFactoryInterface $factory
  *
  * @throws \Payum\Core\Exception\InvalidArgumentException
  */
 public function addPaymentFactory(PaymentFactoryInterface $factory)
 {
     $factoryName = $factory->getName();
     if (empty($factoryName)) {
         throw new InvalidArgumentException(sprintf('The payment factory %s has empty name', get_class($factory)));
     }
     if (isset($this->paymentFactories[$factoryName])) {
         throw new InvalidArgumentException(sprintf('The payment factory with such name %s already registered', $factoryName));
     }
     
     $this->paymentFactories[$factory->getName()] = $factory;
 }