Site maintenance: Sun 15 Nov, from 12:00 UTC, about 4–6 hours. Details

This cutover relies on some testing that is still incomplete so may be cancelled at short notice

Forums / Addon Payment Modules / Can I restrict a payment option by admin status?

Can I restrict a payment option by admin status?

Started by helenewallis on 3 May 2021, 9:58 PM · Views: 2,790

Results 1 to 11 of 11
3 May 2021, 9:58 PM
#1
helenewallis avatar

helenewallis

Totally Zenned

Join Date:
Jun 2016
Location:
Suffolk VA
Posts:
625
Plugin Contributions:
0

Can I restrict a payment option by admin status?

Is there a way to enable a payment module only if the order is being entered by an admin? I modified the freecharger.php module to permit entering prepaid orders, and it's working very well. The only problem is that you don't want the general public to see 'Prepaid Order' (offline payment at the market) as an option, of course. So I enable it only when I need to enter a prepaid order and hope to heck that no one else sees it while I'm doing that. Right now, I do not have time to dig into this sufficiently to display it as an option only if the person logged in is an admin. Any assistance in that direction would be greatly appreciated.

3 May 2021, 10:07 PM
#2
helenewallis avatar

helenewallis

Totally Zenned

Join Date:
Jun 2016
Location:
Suffolk VA
Posts:
625
Plugin Contributions:
0

Re: Can I restrict a payment option by admin status?

Editing to add--

I found DrByte's reply to a similar question from 2013, and have enabled it in my prepaid.php code. It will work for us now, since it depends on having a static IP address and we have that now. It won't work after the company move, because the new location only has satellite internet (no static IP). So I'm still looking for a solution that doesn't depend on the IP address.

3 May 2021, 10:08 PM
#3
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,751
Plugin Contributions:
56

Re: Can I restrict a payment option by admin status?

In 1.5.7, assuming your are using "Place Order" from admin to do this, you can just add a check to your payment module for

if (isset($_SESSION['emp_admin_id'])) {
... enable

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

4 May 2021, 1:01 AM
#4
helenewallis avatar

helenewallis

Totally Zenned

Join Date:
Jun 2016
Location:
Suffolk VA
Posts:
625
Plugin Contributions:
0

Re: Can I restrict a payment option by admin status?

Thanks, I will do that for the new website running 1.5.7. What I have now is working at our current location with 1.5.5.

4 May 2021, 2:19 AM
#5
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Can I restrict a payment option by admin status?

Also because you are wanting the feature to only work while accessing FROM the admin as in while logged into the admin and making changes there, then if you test (IS_ADMIN_FLAG === true) is a condition where the admin (system not a "person") is accessing the payment module from the admin side.

Otherwise, if you know your admin's customer_id, then you could check if that customer is accessing the payment module:

if (isset($_SESSION['customer_id']) && $_SESSION['customer_id'] == 15) {
  // enable
}

Where 15 is the customer id for your "admin user" logged in on the store side.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

4 May 2021, 3:53 AM
#6
helenewallis avatar

helenewallis

Totally Zenned

Join Date:
Jun 2016
Location:
Suffolk VA
Posts:
625
Plugin Contributions:
0

Re: Can I restrict a payment option by admin status?

mc12345678:

Also because you are wanting the feature to only work while accessing FROM the admin as in while logged into the admin and making changes there, then if you test (IS_ADMIN_FLAG === true) is a condition where the admin (system not a "person") is accessing the payment module from the admin side.

Otherwise, if you know your admin's customer_id, then you could check if that customer is accessing the payment module:

if (isset($_SESSION['customer_id']) && $_SESSION['customer_id'] == 15) {
// enable
}

> Where 15 is the customer id for your "admin user" logged in on the store side.

Ooh, that should work with 1.5.5 also. I won’t have the new site ready to go until well after the move, so that would handle the situation even without a static IP.
4 May 2021, 3:00 PM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Can I restrict a payment option by admin status?

mc12345678:

Also because you are wanting the feature to only work while accessing FROM the admin as in while logged into the admin and making changes there, then if you test (IS_ADMIN_FLAG === true) is a condition where the admin (system not a "person") is accessing the payment module from the admin side.Remember, unless you've added some plugin to place orders directly inside the Admin area, the suggestion above is unrelated to the discussion at hand.

mc12345678:

Otherwise, if you know your admin's customer_id, then you could check if that customer is accessing the payment module:

if (isset($_SESSION['customer_id']) && $_SESSION['customer_id'] == 15) {
// enable
}

> Where 15 is the customer id for your "admin user" logged in on the store side.
This idea assumes that you're always placing orders under a SINGLE customer account, where all your offline ("prepaid" as OP calls it) orders are entered.
If you're actually logging into separate customer accounts to place orders for specific individual customers, this suggestion won't be much help.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

4 May 2021, 7:58 PM
#8
helenewallis avatar

helenewallis

Totally Zenned

Join Date:
Jun 2016
Location:
Suffolk VA
Posts:
625
Plugin Contributions:
0

Re: Can I restrict a payment option by admin status?

The ADMIN_FLAG variable must be defined only in the latest version, as it just threw up an error. But testing for the admin's 'customer_id' worked. I'm the only one who currently would be entering customer orders, so that gets around the need for a static IP. Now I need to go do something similar with the shipping method, to have one that only admins will see but that will print 'Subscription plan' or something similar on the customer's notification email. We include shipping with these orders, so I need some way to sidestep the shipping charges. I don't want ordinary customers to see a Free Shipping option, for obvious reasons. So I have used Store Pickup as the shipping method. But I've already had one panicked phone call from a subscriber who wailed "But I live a thousand miles from you!" after she got the email notification of her order showing Store Pickup for shipping.

4 May 2021, 8:01 PM
#9
helenewallis avatar

helenewallis

Totally Zenned

Join Date:
Jun 2016
Location:
Suffolk VA
Posts:
625
Plugin Contributions:
0

Re: Can I restrict a payment option by admin status?

DrByte:

This idea assumes that you're always placing orders under a SINGLE customer account, where all your offline ("prepaid" as OP calls it) orders are entered.
If you're actually logging into separate customer accounts to place orders for specific individual customers, this suggestion won't be much help.

I long since installed the plugin to place orders from a customer account, and it's working fine for this application. The test for the admin's 'customer_id' number worked to limit visibility of the prepaid order method only when I'm entering an order. That does mean no other admin can do it, but right now I'm the only one anyway.

4 May 2021, 9:42 PM
#10
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Can I restrict a payment option by admin status?

HeleneWallis:

The ADMIN_FLAG variable must be defined only in the latest version, as it just threw up an error. But testing for the admin's 'customer_id' worked. I'm the only one who currently would be entering customer orders, so that gets around the need for a static IP. Now I need to go do something similar with the shipping method, to have one that only admins will see but that will print 'Subscription plan' or something similar on the customer's notification email. We include shipping with these orders, so I need some way to sidestep the shipping charges. I don't want ordinary customers to see a Free Shipping option, for obvious reasons. So I have used Store Pickup as the shipping method. But I've already had one panicked phone call from a subscriber who wailed "But I live a thousand miles from you!" after she got the email notification of her order showing Store Pickup for shipping.
Moot point at the moment, but looking as far back as 1.5.0, the define 'IS_ADMIN_FLAG' is set... There is/was a little bit of a misunderstanding on my part when suggesting it. I was looking at some sort of capability accessed from the admin side of the store, which is far different than a person that has been granted the permissions and power to do what is needed (admin like rights).

Again, doesn't really matter in this case because you were really looking for a feature on the catalog side that would allow you to do something unique as compared to all of the other customers. As far as the text change, Perhaps the same type of thing could be done within the language file(s) where the text to be provided for the shipping module could be set for the logged in user as compared to everyone else.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

5 May 2021, 4:36 AM
#11
helenewallis avatar

helenewallis

Totally Zenned

Join Date:
Jun 2016
Location:
Suffolk VA
Posts:
625
Plugin Contributions:
0

Re: Can I restrict a payment option by admin status?

Yes, that's exactly what I intend to do, provide a phrase that would be appropriate for subscription plan shipping for the customers who need that, and at the same time, not be displayed for other customers. The subscription plans themselves are handled completely outside of Zencart at the moment, through Paypal. I just added the code for them to one of the product pages. I have to enter those orders manually into Zencart. But the prepaid payment module and a customized shipping module will allow everything else about the order to be handled just as if it had originated within the Zencart system. Not perfect, but it will do for now.