Forums / Built-in Shipping and Payment Modules / Conditional enable for payment method

Conditional enable for payment method

Locked

Started by s_p_ike on 6 Sep 2007, 10:13 AM · Views: 1,398

Results 1 to 3 of 3
This thread is locked. New replies are disabled.
6 Sep 2007, 10:13 AM
#1
s_p_ike avatar

s_p_ike

Zen Follower

Join Date:
Feb 2005
Location:
Italy
Posts:
178
Plugin Contributions:
0

Conditional enable for payment method

Hi, first forgive my english :)

Well, I've been asked to evaluate a method to enable specific payment method depending on the customer which is doing the checkout.

Moreover, the parameter to check is not a default customer data.

Another thing for a complete description: this parameter is the number of days for which the customer is allowed to delay the payment. The payment itslef will be accomplished through bank (something similar bank wire transfer, but not completely, here is named Ricevuta Bancaria, that stands for Bank Receipt and usually has this temporal expiration: 30 days, 60 days, 90 days, 120 days...

This means that the customer receive a communication from his bank saying that he'll must pay the amount due at expiration date and he reply with his authorization to make the payment).

Ok all this just to explain, it doesn't involve Zen Cart.

So, now, before starting to work on it, I'd just like to hear from you if what I thought is right.

Well, I'll create a new table where to store customer ID and the value of this parameter (30 or 60 or 90 ...).

For my need this table will not be managed inside Zen Cart administration, but with an external bridge with the client software (once again, this is not important, I could easily create a managent tool in ZC admin, but the client asked for first solution).

Ok, here comes the core of my question:

In the payment method (that I'll create specifically) is ok to write, after

$this->enabled = ((MODULE_PAYMENT_MONEYORDER_STATUS == 'True') ? true : false);

a code that query my new table and if find a match with user who is checking out, then enable the method (and after will retrieve the parameter value to print the right expiration time), otherwise disable the method?

Another question is, in this point of the payment method file, it should be available the customer id (in the session, I believe), no?

Thanks.

Paolo De Dionigi
Co-maintainer of Zen Cart Italia

6 Sep 2007, 3:09 PM
#2
drbyte avatar

drbyte

Sensei

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

Re: Conditional enable for payment method

You should probably put your logic for detecting the customer's eligibility into the update_status() function, since that area is used to verify that the customer's address fits within a qualifying zone. It would be logical to include your additional check inside that section.

Since you're using the money-order module as an example, you'd put it in this section of code:```
function update_status() {
global $order, $db;

  if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_MONEYORDER_ZONE > 0) ) {
    $check_flag = false;
    $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_MONEYORDER_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
    while (!$check->EOF) {
      if ($check->fields['zone_id'] < 1) {
        $check_flag = true;
        break;
      } elseif ($check->fields['zone_id'] == $order->billing['zone_id']) {
        $check_flag = true;
        break;
      }
      $check->MoveNext();
    }

[B]// add new code here
// do lookup customer using $_SESSION['customer_id']
if (customer is qualified) {
$check_flag = true;
$this->allowed_days = [number of days retrieved from lookup]
} else {
$check_flag = false
}
// end of added code[/B]

    if ($check_flag == false) {
      $this->enabled = false;
    }
  }
}

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

6 Sep 2007, 3:24 PM
#3
s_p_ike avatar

s_p_ike

Zen Follower

Join Date:
Feb 2005
Location:
Italy
Posts:
178
Plugin Contributions:
0

Re: Conditional enable for payment method

Great, Doc!

Thank you very much.

Paolo De Dionigi
Co-maintainer of Zen Cart Italia