function pay_form::form_submit in Pay 6
Same name and namespace in other branches
- 7 includes/handlers/pay_form.inc \pay_form::form_submit()
Overrides pay::form_submit
File
- includes/
handlers/ pay_form.inc, line 354 - The base class for payment activities. All payment form classes should extend this.
Class
- pay_form
- @file The base class for payment activities. All payment form classes should extend this.
Code
function form_submit($form, &$form_state) {
global $user;
parent::form_submit($form, $form_state);
$values = $this
->form_values($form_state);
if ($this
->user_register()) {
// Copy & overwrite form values so it looks like a user_registration form.
$register_state = $form_state;
$register_state['values'] = $values['register'];
// Execute all of the user_registration form's submit handlers.
$register = $form[$this
->handler()]['register'];
form_execute_handlers('submit', $register, $register_state);
// Copy any new $register_state values into $form_state.
$form_state = array_merge($register_state, $form_state);
// Did the new user get logged in? If not, we need to temporarily log her
// in so that the transaction/actions/etc are associated with the account.
if (!$user->uid && isset($form_state['user'])) {
$user_anonymous = $user;
$user = $form_state['user'];
}
}
// Add a new transaction for this form with status as default of 'pending'.
$transaction = $this
->set_transaction($values);
// Run payment activities for the 1 or more selected payment methods.
$selected = $values['pay_method']['selected'];
if (!is_array($selected)) {
$selected = array(
$selected => 1,
);
}
foreach ($selected as $pmid => $status) {
if (!$status) {
continue;
}
$method_values = $values['pay_method'][$pmid];
$method_values['pmid'] = $pmid;
$pay_method = pay_method_load($method_values);
$transaction
->save($method_values);
$activity = $transaction
->add_activity($pay_method);
$activity
->do_activity($pay_method->pay_form_action, $method_values);
// Add this activity to form_state for other modules to use.
$form_state['pay_activity'][] = $activity;
}
// Trigger a special hook if there's a goal amount and we have reached it.
if ($this
->total_goal() && $this
->total_paid() >= $this
->total_goal()) {
$this
->drupal_invoke('pay_form_goal', $form_state);
}
// Leave the user object the way we found it.
if (isset($user_anonymous)) {
$user = $user_anonymous;
}
unset($form_state['rebuild'], $form_state['storage']);
}