Different payment methods for different product types Is there a way to have different payment methods available for different product types?

This is my scenario and what I've figured out so far:

I have two product types on my Drupal Commerce site, for selling bus travel passes. One type is just to book the bus pass where you select the date and times (custom line items) for your buss tickets. The other type is for actual payments, where you can choose a buss pass, add additional tours (with custom line items too) and then pay with Paypal.

I am using a customized version of the example payment module, for the booking payment type, and using the Drupal Commerce Paypal module for the actual payments.

What I need is to have the custom booking payment method available for one product type, and the paypal payment method for the other product type.

I have tried to add a condition for the product type and haven't been able to do this. We can add a condition for a particular product, but not for a product type. This would be ideal: https://skitch.com/ipwa/eywxa/add-a-new-condition-chasquibus

What I have done for now is to clone the Paypal rule for each payment product type, and selected that products SKU as a condition. This is not ideal, because if a user has more than one payment product, we get a duplicate Paypal payment method available for each additional payment product on the order. I guess this makes sense since we have a payment method rule for each one.

My solution would be able to have a condition for product type on the payment method rule, or be able to have the four payment products SKUs in a 'Order contains a particular product' condition.
The product's type is a property of the commerce_product entity, so you can use the built-in "Data comparison" condition to test it.

Just add a new condition of type "Data comparison", and make the data selector look like this:



When you continue you'll get a screen like this:



As you can see you get a nice drop down list of product types to choose from. I just tested that and it works a treat.

If that isn't working for whatever reason, it's pretty easy to implement your own rules condition in a custom module:

function MYMODULE_rules_condition_info() {
  return array(
    'commerce_product_is_type' =&gt; array(
      'label' =&gt; t('Product is a certain type'), 
      'parameter' =&gt; array(
        'product' =&gt; array(
          'label' =&gt; t('Product'),
          'type' =&gt; 'commerce_product',
        ),
        'type' =&gt; array(
          'label' =&gt; t('Product Type (Machine Name)'),
          'type' =&gt; 'text'
        )
      ), 
      'group' =&gt; t('Commerce Product'),
      'callbacks' =&gt; array(
        'execute' =&gt; 'MYMODULE_commerce_product_is_type',
      )
    ),
  );
}


function MYMODULE_commerce_product_is_type($product, $type) {
  return $product-&gt;type == $type;
}