Tags/topics: 
1
Answers
Vote up!
0
Vote down!

Disable payment method dynamically

I'm selling organic group membership with Drupal commerce (thanks to this tutorial http://www.drupalcommerce.org/blog/10809/selling-organic-groups-using-dr...).
The groups are events with a start date and a end date (date module) and are the product display.
I have three payment method enabled.
My question is if it is possible to disable a specific payment method 4 days before the start date of the event.

Asked by: Derio
on December 18, 2013

1 Answer

Vote up!
1
Vote down!

Yes it is! You can use rules conditions on payment gateway availability.

If you click "Edit" next to the payment method that you want to disable based on date on this page:

admin/commerce/config/payment-methods

And then you need to add a condition called "Entity has field"

And then you need to add a condition based on your date. You will need a "data comparison" and you might need to enable PHP to determine if the value of "today" is 4 days or more away from "start" of event.

Josh

Josh Miller
Answer by: Josh Miller
Posted: Dec 18, 2013

Comments

I tried but I can't retrieve the field because it is in product display and not in order.

- Derio on December 18, 2013

Derio,

Sorry I didn't see your response right away. This is still possible. You will have to create a component (it's a rule that doesn't have an event) that has a given node id and returns a date value. A component is required because it's likely a field that requires "has field" condition and you have to use components to get conditions to work within a set of actions. So to make this happen, you need to pull a list of entities based on a field value (pull all the display nodes that have this product) and limit it to 1 (otherwise you could get back an indefinite number of dates back. Finally, you'll need to remove the "enable the payment gateway" action and create a second component that can have a condition based on a date field and that component will have to have the enable a payment gateway action based around the condition of the date.

Josh

- Josh Miller on January 2, 2014

Thanks, but I don't know how to accomplish it...I will try!

- Derio on January 4, 2014