I'm developing a module that will have a cash payment type that should be accepted only in-store, never online. I know this could be handled with rules and permissions, but for the sake of cleanliness, it would be nice if I could make this payment method never, ever available during the checkout process. This functionality currently exists in reverse; setting the terminal flag to FALSE for a payment method means it will never be available to administrators in the payment terminal - only in checkout.
Comments
Comment #1
rbayliss commentedComment #2
rszrama commentedHmm, I like the idea - and perhaps we can couple it with a bit of description on the Payment UI payment method list that indicates where a payment method is usable. I can add that in unless you wanna give it a shot.
Comment #3
rbayliss commentedOh yeah, that'd be nice. This is a rules overview table - is there a way we can hook into the rule description?
Comment #4
rszrama commentedYou can do it using hook_page_alter() from other modules; for an example, check out the Commerce PayPal project. It was for that project that I added a #page_callback property to the content array used to build the overview table.
Comment #5
rbayliss commentedOK, I rerolled to add the messaging. I chose to do this in commerce_payment_ui_admin_page, but can move it to an alter hook if you'd prefer.
Comment #6
rbayliss commentedAnd a screenshot to show what it looks like.

Comment #7
rbayliss commentedJust released Commerce Point of Sale which contains this cash payment method. Does this need any more work?
Comment #8
rszrama commentedI'll review it on Monday - just fell off the radar while I worked through my backlog.
Comment #9
rszrama commentedHmm, I'm pretty sure I meant I'd check this out last Monday but only got to it this Monday. In looking the code over, I noticed that the way you're decorating the payment method overview page only updates the default payment method rules. If I were to add another rule for the same payment method, it would not get the information about where it was enabled for use. It looks like we could extract the machine name from the data in the rows array, even though it won't be pretty, and then determine from there what payment method the rule can enable. There should be code that demonstrates this in the Payment module somewhere.
Comment #10
rszrama commentedMeant to attach a patch that had a bit of syntax cleanup.
Comment #11
rszrama commentedRealized I left a dpm() in there. :-/
Comment #12
rbayliss commentedCertainly not pretty, but here it is.
Comment #13
rszrama commentedYou nailed it - the extraction and the description. I was pretty surprised to see that the data structure didn't include any properties identifying the Rule each row was for, and I definitely can't wait to rewrite how we implemented payment methods in Commerce 2.x. No more of this action based storage funny business...
Two small updates I made to the loop were to not worry about loading the instance (we can get the checkout / terminal properties from the payment method itself without the settings from the action) and to build the items array earlier instead of inline for a bit of improved readability.
Commit: http://drupalcode.org/project/commerce.git/commitdiff/cb2ab8f
Comment #14
rbayliss commentedSounds good. I agree it's pretty shocking that's the only way to extract the rule's machine name. Thanks!