function uc_credit_terminal_form_submit in Ubercart 5
Same name and namespace in other branches
- 6.2 payment/uc_credit/uc_credit.admin.inc \uc_credit_terminal_form_submit()
- 7.3 payment/uc_credit/uc_credit.admin.inc \uc_credit_terminal_form_submit()
File
- payment/
uc_credit/ uc_credit.module, line 1434 - Defines the credit card payment method and hooks in payment gateways.
Code
function uc_credit_terminal_form_submit($form_id, $form_values) {
// Load the order.
$order = uc_order_load($form_values['order_id']);
// Get the data from the form and replace masked data from the order.
$cc_data = $form_values['cc_data'];
if (strpos($cc_data['cc_number'], t('(Last 4) ')) === 0) {
$cc_data['cc_number'] = $order->payment_details['cc_number'];
}
if ($cc_data['cc_cvv'] == str_repeat('-', strlen($cc_data['cc_cvv']))) {
$cc_data['cc_cvv'] = $order->payment_details['cc_cvv'];
}
// Cache the values for use during processing.
uc_credit_cache('save', $cc_data, FALSE);
// Build the data array passed on to the payment gateway.
$data = array();
switch ($form_values['op']) {
case t('Charge amount'):
$data['txn_type'] = UC_CREDIT_AUTH_CAPTURE;
break;
case t('Authorize amount only'):
$data['txn_type'] = UC_CREDIT_AUTH_ONLY;
break;
case t('Set a reference only'):
$data['txn_type'] = UC_CREDIT_REFERENCE_SET;
break;
case t('Credit amount to this card'):
$data['txn_type'] = UC_CREDIT_CREDIT;
break;
case t('Capture amount to this authorization'):
$data['txn_type'] = UC_CREDIT_PRIOR_AUTH_CAPTURE;
$data['auth_id'] = $form_values['select_auth'];
break;
case t('Void authorization'):
$data['txn_type'] = UC_CREDIT_VOID;
$data['auth_id'] = $form_values['select_auth'];
break;
case t('Charge amount to this reference'):
$data['txn_type'] = UC_CREDIT_REFERENCE_TXN;
$data['ref_id'] = $form_values['select_ref'];
break;
case t('Remove reference'):
$data['txn_type'] = UC_CREDIT_REFERENCE_REMOVE;
$data['ref_id'] = $form_values['select_ref'];
break;
case t('Credit amount to this reference'):
$data['txn_type'] = UC_CREDIT_REFERENCE_CREDIT;
$data['ref_id'] = $form_values['select_ref'];
}
$result = uc_payment_process('credit', $form_values['order_id'], $form_values['amount'], $data, TRUE, NULL, FALSE);
if ($result) {
$crypt = new uc_encryption_class();
// Load up the existing data array.
$data = db_result(db_query("SELECT data FROM {uc_orders} WHERE order_id = %d", $form_values['order_id']));
$data = unserialize($data);
$cache = uc_credit_cache('load');
if (variable_get('uc_credit_debug', FALSE) && !variable_get('uc_credit_checkout_process', TRUE)) {
$cc_data = $cache;
}
else {
$cc_data = array(
'cc_number' => substr($cache['cc_number'], -4),
);
}
// Stuff the serialized and encrypted CC details into the array.
$data['cc_data'] = $crypt
->encrypt(uc_credit_encryption_key(), serialize($cc_data));
uc_store_encryption_errors($crypt, 'uc_credit');
// Save it again.
db_query("UPDATE {uc_orders} SET data = '%s' WHERE order_id = %d", serialize($data), $form_values['order_id']);
drupal_set_message(t('The credit card was processed successfully. See the admin comments for more details.'));
}
else {
if (variable_get('uc_credit_debug', FALSE)) {
_save_cc_data_to_order(uc_credit_cache('load'), $form_values['order_id']);
}
drupal_set_message(t('There was an error processing the credit card. See the admin comments for details.'), 'error');
}
return 'admin/store/orders/' . $form_values['order_id'];
}