function payment_commerce_payment_method_validate in Payment for Drupal Commerce 7
Same name and namespace in other branches
- 7.2 payment_commerce.rules.inc \payment_commerce_payment_method_validate()
Implements Rules plugin callback.
1 string reference to 'payment_commerce_payment_method_validate'
File
- ./
payment_commerce.rules.inc, line 30 - Rules integration.
Code
function payment_commerce_payment_method_validate($order, $foo, $RulesState, $RulesCondition, $operation) {
if ($operation == 'execute') {
$rule = $RulesCondition
->parentElement()
->parentElement();
foreach ($rule
->getIterator() as $child) {
// Check if this is a rule action to enable a Payment payment method.
if ($child instanceof RulesAction && strpos($child
->getElementName(), 'commerce_payment_enable_payment_commerce_') === 0) {
// Extract the PMID.
$commerce_payment_method_name = $child->settings['payment_method'];
$pmid = (int) str_replace('payment_commerce_', '', $commerce_payment_method_name);
// Create and validate the payment for this order.
$payment = payment_commerce_payment_create($order, $pmid);
try {
$payment->method
->validate($payment);
return TRUE;
} catch (PaymentValidationException $e) {
return FALSE;
}
}
}
}
}