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

rbayliss’s picture

Status: Active » Needs review
StatusFileSize
new2.21 KB
rszrama’s picture

Hmm, 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.

rbayliss’s picture

Oh yeah, that'd be nice. This is a rules overview table - is there a way we can hook into the rule description?

rszrama’s picture

You 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.

rbayliss’s picture

OK, 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.

rbayliss’s picture

StatusFileSize
new65.42 KB

And a screenshot to show what it looks like.
Screen Shot 2013-03-11 at 12.25.21 PM.png

rbayliss’s picture

Just released Commerce Point of Sale which contains this cash payment method. Does this need any more work?

rszrama’s picture

I'll review it on Monday - just fell off the radar while I worked through my backlog.

rszrama’s picture

Status: Needs review » Needs work

Hmm, 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.

rszrama’s picture

Meant to attach a patch that had a bit of syntax cleanup.

rszrama’s picture

Realized I left a dpm() in there. :-/

rbayliss’s picture

Status: Needs work » Needs review
StatusFileSize
new5.29 KB

Certainly not pretty, but here it is.

rszrama’s picture

Status: Needs review » Fixed

You 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

rbayliss’s picture

Sounds good. I agree it's pretty shocking that's the only way to extract the rule's machine name. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.