Jump to content

COD Payment for Specific Customer


Mark C

Recommended Posts

Found it!

In any payment module there should be a method called hookPaymentOption

This method returns a payment option to be added to the list of available payment options for customer.

If you return an empty array, then this payment options is not available for the customer.

So, you need to check customer group at the end of this method. And then if your conditions are not satisfied, you want to simply return an empty array.

A simple workaround for this problem in the module ps_wirepayment is here for you:

Just add these lines at the end of hookPaymentOption before last line:

$currentCustomerGroups = Customer::getGroupsStatic($this->context->customer->id);
$allowedCustomerGroups = [1,2,3];

if(empty(array_intersect($currentCustomerGroups, $allowedCustomerGroups))) {
	return [];
}

The final result for ps_wirepayment version 2.1.3 is:

public function hookPaymentOptions($params)
{
    if (!$this->active) {
        return [];
    }

    if (!$this->checkCurrency($params['cart'])) {
        return [];
    }

    $this->smarty->assign(
        $this->getTemplateVarInfos()
    );

    $newOption = new PaymentOption();
    $newOption->setModuleName($this->name)
            ->setCallToActionText($this->trans('Pay by bank wire', [], 'Modules.Wirepayment.Shop'))
            ->setAction($this->context->link->getModuleLink($this->name, 'validation', [], true))
            ->setAdditionalInformation($this->fetch('module:ps_wirepayment/views/templates/hook/ps_wirepayment_intro.tpl'));
    $payment_options = [
        $newOption,
    ];

    $currentCustomerGroups = Customer::getGroupsStatic($this->context->customer->id);
    $allowedCustomerGroups = [1,2,3];

    if(empty(array_intersect($currentCustomerGroups, $allowedCustomerGroups))) {
        return [];
    }

    return $payment_options;
}

As you can see in this code, $allowedCustomerGroups is a hard coded array. You can develop your own form in BO to fill this array dynamically.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...