Programmatically enabled a payment method in commerce

Last updated on 19/04/2018

A payment method is just a generated rule, so by enabling the respective rule, the Payment method is becoming enabled.

/**
 * Enable the "paypal_ec" Payment method method.
 */
function HOOK_update_7001() {
  $method_id = 'paypal_ec';
  if ($rules_config = rules_config_load('commerce_payment_' . $method_id)) {
    $rules_config->active = TRUE;
    $rules_config->save();
  }
}