123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- /**
- * @file
- * A dummy payment gateway to use for testing or as an example.
- *
- * All payments using this test gateway will succeed, except when:
- * - Credit card number equals '0000000000000000'. (Note that ANY card number
- * that fails the Luhn algorithm check performed by uc_credit will not even be
- * submitted to this gateway).
- * - CVV equals '000'.
- * - Credit card is expired.
- * - Payment amount equals 12.34 in store currency units.
- * - Customer's billing first name equals 'Fictitious'.
- * - Customer's billing telephone number equals '8675309'.
- */
- /*******************************************************************************
- * Hook Functions (Ubercart)
- ******************************************************************************/
- /**
- * Implements hook_uc_payment_gateway().
- *
- * @see test_gateway.module
- * @see test_gateway_charge()
- */
- function test_gateway_uc_payment_gateway() {
- $gateways['test_gateway'] = array(
- 'title' => t('Test Gateway'),
- 'description' => t('Process credit card payments through the Test Gateway.'),
- 'credit' => 'test_gateway_charge',
- );
- return $gateways;
- }
- /*******************************************************************************
- * Module and Helper Functions
- ******************************************************************************/
- /**
- * Callback function to perform the charge operation.
- *
- * @see test_gateway.module
- * @see test_gateway_uc_payment_gateway()
- */
- 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,
- // 'data' => $data,
- );
- return $result;
- }
|