<?xml version="1.0"?>
<config>
   <modules>
<Jmh_PromesseDon>
 	<version>0.1.0</version>
</Jmh_PromesseDon>
   </modules>
   <global>
<events>
 	<payment_method_is_active>
<observers>
 	<jmh_payment_prevent_other_means_when_don_involved>

<method>preventOtherThanPromesseDonWhenPromesseDonInvolved</method>

 	</payment_method_is_active>
</events>
<blocks>
<payment>
 	<rewrite>

<form_promesseDon>Jmh_PromesseDon_Block_Form_PromesseDon</form_promesseDo n>

<info_promesseDon>Jmh_PromesseDon_Block_Info_PromesseDon</info_promesseDon>
>

 	<adminhtml>
<rewrite>

<system_config_source_cms_block>Jmh_PromesseDon_Model_System_Config_Source_C ms_Block</system_config_source_cms_block>
</rewrite>
 	</adminhtml>
<payment>
 	<rewrite>
<method_promesseDon>Jmh_PromesseDon_Model_Method_PromesseDon</method_pro messeDon>
 	<observer>Jmh_PromesseDon_Model_Observer</observer>
>

 	<promesseDon>Jmh_PromesseDon_Helper_PromesseDon</promesseDon>
</rewrite>
</payment>
</helpers>
<resources>
 	<jmh_promessedon_setup>

 	<class>Mage_Eav_Model_Entity_Setup</class>
</setup>
 	</jmh_promessedon_setup>
</resources>
<product>
<collection>
<attributes>
 	<promesse_don_eligible/>
</attributes>
</collection>
</product>
<sales>
<quote>
<item>
<product_attributes>
 	<promesse_don_eligible/>
</product_attributes>
</item>
</quote>
</sales>
   </global>
   <default>
<payment>
<promesseDon>
<active>1</active>
 	<model>payment/method_promesseDon</model>
 	<allowspecific>0</allowspecific>
<group>offline</group>
 	<form>promessedon_form</form>
<info>promessedon_info</info>
</promesseDon>
</payment>
   </default>
</config>

/**
*	Forbids other payment means when promesse don eligible products are involved
*	@param Varien_Object $observer
*	@event payment_method_is_active
*/
function preventOtherThanPromesseDonWhenPromesseDonInvolved($observer)
{
   $evt = $observer->getData('event');
   $result = $evt->getData('result');
   $methodInstance = $evt->getData('method_instance');
   $quote = $evt->getData('quote');
   $pdonHelper = Mage::helper('payment/promesseDon');
   if ($methodInstance->getCode() != Jmh_PromesseDon_Model_Method_PromesseDon::PROMESSE_DON_CODE

   ) {
 	$result->isAvailable = false;
   }
}

   public function checkEligibleProduct($product)
{
   $res = false;
   if ($product) {
 	$eligible = $product->getPromesseDonEligible();
if ($eligible) {
 	$res = true;
   }
   return $res;
}

$installer = $this;
$entityTypeId = $installer->getEntityTypeId('catalog_product');
$defaultSetId = $installer->getDefaultAttributeSetId($entityTypeId);
$defautGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $defaultSetId);
$installer->addAttribute(
   $entityTypeId,
   'promesse_don_eligible',
   array(
 	'label' => 'promesse_don_eligible', 'type' => 'int',
 	'required' => 0,
'default' => 0,
 	'user_defined' => 1, 'input' => 'select',
 	'source' => 'eav/entity_attribute_source_boolean',
   )
);
$attrId = $installer->getAttributeId('catalog_product', 'promesse_don_eligible');
$installer->addAttributeToGroup($entityTypeId, $defaultSetId, $defautGroupId, $attrId);

 class Jmh_PromesseDon_Model_Method_PromesseDon extends Mage_Payment_Model_Method_Abstract
{
   /**
    * payment method code constant

   const PROMESSE_DON_CODE = 'promesseDon';
    * @var bool cant be used internally

   protected $_canUseInternal = false;
    * @var bool cannot be used for recurring profiles

   protected $_canManageRecurringProfiles = false;
    * @var string payment code

   protected $_code = Jmh_PromesseDon_Model_Method_PromesseDon::PROMESSE_DON_CODE;

    * @var string form block
   protected $_formBlockType = 'payment/form_promesseDon';

    * @var string info block
   protected $_infoBlockType = 'payment/info_promesseDon';

    * @var bool do not review payment
   protected $_canReviewPayment = false;

   /** we cannot edit
    * @return bool
   public function canEdit()
   {
 	return false;
   }

/**
    *Check whether the payment method is applicable to the quote
    * @param Mage_Sales_Model_Quote $quote
    * @param int|null $checksBitMask
    * @return bool
   public function isApplicableToQuote($quote, $checksBitMask)
   {
 	$applicable = parent::isApplicableToQuote($quote, $checksBitMask);
if ($applicable) {

 	$applicable = $pdonHelper->checkOnlyEligibleItems($quote);
 	return $applicable;
   }

/**
*	checkEligibleProduct Data Provider
*	@return array
*/
public function checkEligibleProductDataProvider()
{
   return array(
array(new Varien_Object(array('promesse_don_eligible'=>1)),true),
 	array(new Varien_Object(array('promesse_don_eligible'=>0)),false), array(new Varien_Object(),false)
   );
}

/**
*	@param boolean $expected
*	@param Mage_Catalog_Model_Product $product
*	@dataProvider checkEligibleProductDataProvider
*/
public function testCheckEligibleProduct($product,$expected)
{
   //setup
   $h=Mage::helper('payment/promesseDon');
   //exercize
   $computed=$h->checkEligibleProduct($product);
   //verify
   $this->assertEquals($expected,$computed);
   //implicit teardown
}

public function tryToTest(AcceptanceTester $I)
{
   $I->amOnPage("/");
   $I->see("bienvenue sur le site pour promouvoir la tirasse");
   $I->click('test');
   $I->see('Test2');
   $I->click('tirasse',"[class=product-name]");
   $I->see('Add to Cart');
   $I->click('input[type=checkbox]');
   $I->click('Add to Cart');
   $I->see('tirasse was added to your shopping cart.');
   $I->click('Proceed to Checkout');
   $I->see('Returning Customers');
   $I->fillField('login[username]','myusername@maydomain.com');
   $I->fillField('login[password]','mypassword');
   $I->click('Login');
   $I->see('Select a billing address');
   $I->click('Continue');
   $I->wait(5);
   $I->see('Promesse Don');
   $I->click('Continue',"#payment-buttons-container");
   $I->wait(5);
   $I->click('Place Order');
   $I->wait(10);
   $I->see('Thank you for your purchase');