function pay_method_gateway::pay_method_validate in Pay 6
Same name and namespace in other branches
- 7 includes/handlers/pay_method_gateway.inc \pay_method_gateway::pay_method_validate()
Overrides pay_method::pay_method_validate
File
- includes/
handlers/ pay_method_gateway.inc, line 496 - The base class for credit card payment activities.
Class
- pay_method_gateway
- @file The base class for credit card payment activities.
Code
function pay_method_validate($form, &$form_state, $element) {
parent::pay_method_validate($form, $form_state, $element);
if ($this->payment_type == 'cc') {
// Manually handle #required on fields required by this payment_type.
$required = array(
'first_name',
'last_name',
'mail',
'cc_number',
'cc_exp_month',
'cc_exp_year',
);
foreach ($required as $key) {
if (!count($this->{$key}) || is_string($this->{$key}) && strlen(trim($this->{$key})) == 0) {
form_error($element[$key], t('!name field is required.', array(
'!name' => $element[$key]['#title'],
)));
}
}
// Validate the card number and set the form value to our clean version.
if (!$this
->cc_number_validate()) {
form_error($element['cc_number'], $this->error_message);
}
form_set_value($element['cc_number'], $this->cc_number, $form_state);
// Validate the CCV2 code and set the form value to our clean version.
if (!$this
->cc_ccv2_validate()) {
form_error($element['cc_ccv2'], $this->error_message);
}
form_set_value($element['cc_ccv2'], $this->cc_ccv2, $form_state);
// Validate the expiration date.
if (!$this
->cc_expiration_validate()) {
form_error($element['cc_exp_month'], $this->error_message);
}
// Set the "payment_type" value to the specific card type.
form_set_value($element['payment_type'], $this->cc_type, $form_state);
// Validate the issue number field.
if (!$this
->cc_issue_number_validate()) {
form_set_error('cc_issue_number', $this->error_message);
}
}
}