2013-10-04 78 views
0

我想創建一個使用Symfony2的JMS付款捆綁的自定義付款方式。 我有PayPal捆綁設置罰款 - 但我想通過銀行轉賬支付第二個選項。JMS自定義付款插件 - Symfony2

下面是我的代碼 - 但這不顯示新的付款選項。

Form類:

namespace JMS\Payment\BanktransferBundle\Form; 

use Symfony\Component\Form\AbstractType; 
use Symfony\Component\Form\FormBuilderInterface; 

class BanktransferType extends AbstractType { 

public function buildForm(FormBuilderInterface $builder, array $options) { 

    $builder 
      ->add('holder', 'text', array('required' => false)) 
      ->add('number', 'text', array('required' => false)) 
      ->add('expires', 'date', array('required' => false)) 
      ->add('code', 'text', array('required' => false)) 
    ; 
} 

public function getName() { 
    return 'credit_card'; 
} 

} 

插件類:

namespace JMS\Payment\BanktransferBundle\Form; 

use Symfony\Component\Form\AbstractType; 
use Symfony\Component\Form\FormBuilderInterface; 

class BanktransferType extends AbstractType { 

public function buildForm(FormBuilderInterface $builder, array $options) { 

    $builder 
      ->add('holder', 'text', array('required' => false)) 
      ->add('number', 'text', array('required' => false)) 
      ->add('expires', 'date', array('required' => false)) 
      ->add('code', 'text', array('required' => false)) 
    ; 
} 

public function getName() { 
    return 'credit_card'; 
} 

} 

Services.yml

services: 
payment.plugin.banktransfer: 
    class: JMS\Payment\BanktransferBundle\Plugin\BanktransferPlugin 
    tags: [{name: payment.plugin}] 

credit_card_type: 
    class: JMS\Payment\BanktransferBundle\Form\BanktransferType 
    tags: 
     - { name: form.type, alias: credit_card } 
     - { name: payment.method_type } 

需要什麼條件才能做的JMS支付捆綁找到我插入?

回答

0

好的。我似乎通過使用XML而不是YML來顯示它。

的services.xml

<?xml version="1.0" ?> 
<container xmlns="http://symfony.com/schema/dic/services" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema /dic/services/services-1.0.xsd"> 

<parameters> 
    <parameter key="payment.plugin.cash_checkout.class">JMS\Payment\CashBundle\Plugin\CashPlugin</parameter> 
    <parameter key="payment.form.cash_checkout_type.class">JMS\Payment\CashBundle\Form\CashType</parameter> 
</parameters> 

<services> 
    <service id="payment.form.cash_checkout_type" class="%payment.form.cash_checkout_type.class%"> 
     <tag name="payment.method_form_type" /> 
     <tag name="form.type" alias="cash_checkout" /> 
    </service> 
</services> 
</container> 
0

你能告訴我們真正的插件類?我認爲你發佈了錯誤的內容。 我有同樣的問題,我遵循基於JMS documentation的說明。

我的插件級(輕度):

<?php 
    //... 

    use \JMS\Payment\CoreBundle\Plugin\AbstractPlugin; 

    class DebitPlugin extends AbstractPlugin { 
     public function processes($name) { 
     return 'debit' === $name; 
     } 
    } 

而在你的控制器,你必須添加的名稱,這取決於你的插件(在我的情況「借方」)。

<?php 
    //... 
    $form = $this->getFormFactory()->create('debit', null, array()); 
    //... 

希望有幫助!