uc_recurring.api.php

Tracking 6.x-2.x branch
  1. drupal
    1. 6 contributions/uc_recurring/uc_recurring.api.php

Functions & methods

NameDescription
hook_recurring_accessSet the access permission on user operations.
hook_recurring_fee_user_savedAct on recurring user that has just been saved (inserted or updated).
hook_recurring_infoDefine the recurring payment method/gateway function callbacks.
hook_recurring_info_alterAlter the recurring method/ gateway info.
hook_recurring_product_deletedAct on recurring product deleted.
hook_recurring_renewal_completedAct on recurring renewal completed event.
hook_recurring_renewal_failedAct on recurring renewal failed event.
hook_recurring_renewal_pendingAct on recurring renewal event.
hook_recurring_user_deletedAct on recurring user deleted.

File

View source
  1. <?php
  2. /**
  3. * Define the recurring payment method/gateway function callbacks.
  4. *
  5. * This hook enables payment modules to register that they support
  6. * ubercart recurring fees and define the callbacks to trigger when
  7. * a recurring operation is required using the specific payment
  8. * method or gateway.
  9. *
  10. * @return
  11. * An array of recurring fee handler items, each fee handler has a key
  12. * corresponding to the unique payment method or gateway id. The item is
  13. * an associative array that may contain the following key-value pairs:
  14. *
  15. * - "name": Required. The untranslated title of the menu item.
  16. * - "payment method": Required. The type of payment method, this needs
  17. * to correspond to another recurring fee handler (e.g. credit).
  18. * - "fee handler": the unique id of the payment gateway or
  19. * another handler that should handle the recurring fee.
  20. * - "module": name of the module that implements this fee handler.
  21. * - "process callback": The function to call when setting up the recurring
  22. * fee.
  23. * - "renew callbak": Function to call when renewing the recurring fee.
  24. * - "cancel callback": Function to call when cancelling a recurring fee.
  25. * - "own handler": set to TRUE if this recurring handler will be responsible
  26. * for processing renewals and not uc_recurring. (Default: FALSE)
  27. * - "saved profile": if set to TRUE then this payment method will be
  28. * available to other charges.
  29. * - "menu": Array of menu items that provide the user operations.
  30. * uc_recurring does provide some common default operations for charge,
  31. * edit and cancel which can be reused by setting these to either:
  32. * - UC_RECURRING_MENU_DISABLED (default)
  33. * - UC_RECURRING_MENU_DEFAULT
  34. *
  35. * For a detailed usage example, see modules/uc_recurring.test_gateway.inc.
  36. *
  37. * ~~~~ We should put some developer docs online somewhere ~~~~
  38. * For comprehensive documentation on the ubercart recurring system, see
  39. * @link http:// drupal.org/node/<nid> http:// drupal.org/node/<nid> @endlink .
  40. */
  41. function hook_recurring_info() {
  42. $items = array();
  43. $items['test_gateway'] = array(
  44. 'name' => t('Test Gateway'),
  45. 'payment method' => 'credit',
  46. 'module' => 'uc_recurring',
  47. 'fee handler' => 'test_gateway',
  48. 'renew callback' => 'uc_recurring_test_gateway_renew',
  49. 'process callback' => 'uc_recurring_test_gateway_process',
  50. 'own handler' => FALSE,
  51. 'saved profile' => FALSE,
  52. 'menu' => array(
  53. 'charge' => UC_RECURRING_MENU_DEFAULT,
  54. 'edit' => array(
  55. 'title' => 'Edit',
  56. 'page arguments' => array('uc_recurring_admin_edit_form'),
  57. 'access callback' => 'user_access',
  58. 'access arguments' => array('administer recurring fees'),
  59. 'file' => 'uc_recurring.admin.inc',
  60. ),
  61. 'cancel' => array(
  62. 'title' => 'Cancel',
  63. 'page arguments' => array('uc_recurring_user_cancel_form'),
  64. 'file' => 'uc_recurring.pages.inc',
  65. ),
  66. ), // Use the default user operation defined in uc_recurring.
  67. );
  68. return $items;
  69. }
  70. /**
  71. * Alter the recurring method/ gateway info.
  72. *
  73. * @param $info
  74. * Array of the recurring fee handlers.
  75. */
  76. function hook_recurring_info_alter(&$info) {
  77. if (!empty($info['test_gateway'])) {
  78. // Change the permission on the test_gateway so only user with the
  79. // administer recurring fee permissions can cancel recurring fees.
  80. $info['test_gateway']['menu']['cancel'] = array(
  81. 'title' => 'Cancel',
  82. 'page arguments' => array('uc_recurring_user_cancel_form'),
  83. 'file' => 'uc_recurring.pages.inc',
  84. 'access callback' => 'user_access',
  85. 'access arguments' => array('administer recurring fees'),
  86. );
  87. }
  88. }
  89. /**
  90. * Act on recurring renewal event.
  91. *
  92. * @param $order
  93. * The order object.
  94. * @param $fee
  95. * The recurring Fee object.
  96. */
  97. function hook_recurring_renewal_pending(&$order, &$fee) {
  98. }
  99. /**
  100. * Act on recurring renewal completed event.
  101. *
  102. * @param $order
  103. * The order object.
  104. * @param $fee
  105. * The recurring Fee object.
  106. */
  107. function hook_recurring_renewal_completed(&$order, &$fee) {
  108. }
  109. /**
  110. * Act on recurring renewal failed event.
  111. *
  112. * @param $order
  113. * The order object.
  114. * @param $fee
  115. * The recurring fee object.
  116. */
  117. function hook_recurring_renewal_failed(&$order, &$fee) {
  118. }
  119. /**
  120. * Act on recurring product deleted.
  121. *
  122. * @param $pfid
  123. * The product fee ID.
  124. */
  125. function hook_recurring_product_deleted($pfid) {
  126. }
  127. /**
  128. * Act on recurring user deleted.
  129. *
  130. * @param $rfid
  131. * the recurring fee ID.
  132. */
  133. function hook_recurring_user_deleted($rfid) {
  134. }
  135. /**
  136. * Act on recurring user that has just been saved (inserted or updated).
  137. *
  138. * @param $fee
  139. * The recurring fee object.
  140. */
  141. function hook_recurring_fee_user_saved($fee) {
  142. }
  143. /**
  144. * Set the access permission on user operations.
  145. *
  146. * @param $fee
  147. * The recurring fee object.
  148. * @param $op
  149. * The operation being performed, e.g. cancel, edit, update.
  150. * @param $account
  151. * The account of the user.
  152. */
  153. function hook_recurring_access($fee, $op, $account) {
  154. // Deny access to the cancel operation for recurring fees that do not have
  155. // have an unlimited number of remaining intervals (e.g payment plan)
  156. if ($op == 'cancel' && $fee->remaining_intervals != UC_RECURRING_UNLIMITED_INTERVALS) {
  157. return UC_RECURRING_ACCESS_DENY;
  158. }
  159. return UC_RECURRING_ACCESS_IGNORE;
  160. }