test_gateway.module

Tracking 5.x-1.x branch
  1. drupal
    1. 5 contributions/ubercart/payment/uc_payment/test_gateway.module
    2. 6 contributions/ubercart/payment/uc_credit/test_gateway.module
    3. 7 contributions/ubercart/payment/uc_credit/tests/test_gateway.module

A test module used as an example for a payment gateway.

Development sponsored by the Ubercart project. http://www.ubercart.org

Functions & methods

NameDescription
test_gateway_charge
test_gateway_payment_gateway

File

View source
  1. <?php
  2. /**
  3. * @file
  4. * A test module used as an example for a payment gateway.
  5. *
  6. * Development sponsored by the Ubercart project. http://www.ubercart.org
  7. */
  8. /*******************************************************************************
  9. * Hook Functions (Ubercart)
  10. ******************************************************************************/
  11. function test_gateway_payment_gateway() {
  12. $gateways[] = array(
  13. 'id' => 'test_gateway',
  14. 'title' => t('Test Gateway'),
  15. 'description' => t('Process credit card payments through the Test Gateway.'),
  16. 'credit' => 'test_gateway_charge',
  17. );
  18. return $gateways;
  19. }
  20. /*******************************************************************************
  21. * Module and Helper Functions
  22. ******************************************************************************/
  23. function test_gateway_charge($order_id, $amount, $data) {
  24. global $user;
  25. $order = uc_order_load($order_id);
  26. // Use 0000000000000000 to test a failed payment, anything else for a good one.
  27. if ($order->payment_details['cc_number'] == '0000000000000000') {
  28. $success = FALSE;
  29. }
  30. else {
  31. $success = TRUE;
  32. }
  33. // Uncomment this lines to see the order object. The information for the
  34. // payment is in the $order->payment_details array.
  35. // drupal_set_message('<pre>'. print_r($order->payment_details, true) .'</pre>');
  36. if ($success) {
  37. $message = t('Credit card charged: !amount', array('!amount' => uc_currency_format($amount)));
  38. uc_order_comment_save($order_id, $user->uid, $message, 'admin');
  39. }
  40. else {
  41. $message = t('Credit card charge failed.');
  42. uc_order_comment_save($order_id, $user->uid, $message, 'admin');
  43. }
  44. $result = array(
  45. 'success' => $success,
  46. 'comment' => t('Card charged, resolution code: 0022548315'),
  47. 'message' => $success ? t('Credit card payment processed successfully.') : t('Credit card charge failed.'),
  48. 'uid' => $user->uid,
  49. // 'data' => $data,
  50. );
  51. return $result;
  52. }