function test_gateway_charge in Ubercart 7.3
Same name and namespace in other branches
- 5 payment/uc_payment/test_gateway.module \test_gateway_charge()
- 6.2 payment/uc_credit/test_gateway.module \test_gateway_charge()
Callback function to perform the charge operation.
See also
test_gateway_uc_payment_gateway()
2 string references to 'test_gateway_charge'
- hook_uc_payment_gateway in payment/
uc_payment/ uc_payment.api.php - Registers credit card payment gateway callbacks.
- test_gateway_uc_payment_gateway in payment/
uc_credit/ tests/ test_gateway.module - Implements hook_uc_payment_gateway().
File
- payment/
uc_credit/ tests/ test_gateway.module, line 48 - A dummy payment gateway to use for testing or as an example.
Code
function test_gateway_charge($order_id, $amount, $data) {
global $user;
$order = uc_order_load($order_id);
// cc_exp_month and cc_exp_year are also validated by
// _uc_credit_valid_card_expiration() on the checkout form.
$month = $order->payment_details['cc_exp_month'];
$year = $order->payment_details['cc_exp_year'];
if ($year < 100) {
$year = $year + 2000;
}
// Card is expired at 0:00 on the first day of the next month.
$expiration_date = mktime(0, 0, 0, $month + 1, 1, $year);
// Conditions for failure are described in file documentation block above.
// All other transactions will succeed.
if ($order->payment_details['cc_number'] == '0000000000000000' || isset($order->payment_details['cc_cvv']) && $order->payment_details['cc_cvv'] == '000' || $expiration_date - REQUEST_TIME <= 0 || $amount == 12.34 || $order->billing_first_name == 'Fictitious' || $order->billing_phone == '8675309') {
$success = FALSE;
}
else {
$success = TRUE;
}
// Uncomment this line to see the order object. The information for the
// payment is in the $order->payment_details array.
// drupal_set_message('<pre>' . print_r($order->payment_details, TRUE) . '</pre>');
if ($success) {
$message = t('Credit card charged: !amount', array(
'!amount' => uc_currency_format($amount),
));
uc_order_comment_save($order_id, $user->uid, $message, 'admin');
}
else {
$message = t('Credit card charge failed.');
uc_order_comment_save($order_id, $user->uid, $message, 'admin');
}
$result = array(
'success' => $success,
'comment' => t('Card charged, resolution code: 0022548315'),
'message' => $success ? t('Credit card payment processed successfully.') : t('Credit card charge failed.'),
'uid' => $user->uid,
);
return $result;
}