The issue is that the settings on an action of a rule need to be changed. The settings form for when you implement hook_settings_form($settings)
for your payment method maps to the settings of the rule commerce_payment_<name of your payment method>
. You need to change that rules action settings and then save. Here is an example.
Lets say that you have added a form element called txn_type
to the settings form as follows in hook_settings_form($settings)
of your payment method.
$form['txn_type'] = array(
'#type' => 'radios',
'#title' => t('Default credit card transaction type'),
'#description' => t('The default will be used to process transactions during checkout.'),
'#options' => array(
COMMERCE_CREDIT_AUTH_CAPTURE => t('Authorization and capture'),
COMMERCE_CREDIT_AUTH_ONLY => t('Authorization only (requires manual or automated capture after checkout)'),
),
'#default_value' => isset($settings['txn_type']) ? $settings['txn_type'] : COMMERCE_CREDIT_AUTH_CAPTURE,
);
To make the changes to the rule outside of the settings form, you need to load that rule and make changes to the action settings. You first load the rule, then you load the action settings within the rule, then you make your settings changes. The rule action name is always commerce_payment_enable_<name of your payment method>
$rule = rules_config_load('commerce_payment_<name of your payment method>');
foreach ($rule->actions() as $action) {
if (is_callable(array($action, 'getElementName')) && $action->getElementName() == 'commerce_payment_enable_<name of your payment method>') {
dpm('bh_market_settings: in action array');
if (is_array($action->settings['payment_method']) && !empty($action->settings['payment_method']['settings'])) {
$action->settings['payment_method']['settings']['txn_type']=COMMERCE_CREDIT_AUTH_ONLY;
}
}
}
$rule->save();
This example can be applied to anytime you are trying to change a rule outside of the UI. You can make changes to all aspects of the rule and then save it using $rule->save()