uc_cybersource.install 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the uc_cybersource module.
  5. */
  6. /**
  7. * Implements hook_requirements().
  8. */
  9. function uc_cybersource_requirements($phase) {
  10. $t = get_t();
  11. $has_curl = function_exists('curl_init');
  12. $has_dom = class_exists('DOMDocument');
  13. $has_soap = class_exists('SoapClient');
  14. // Valid methods are 'soap' and 'post'. Defaults here to 'post' on install.
  15. $method = variable_get('uc_cybersource_method', 'post');
  16. // Using SOAP.
  17. if ($method == 'soap') {
  18. $requirements['uc_cybersource_soap_and_dom'] = array(
  19. 'title' => $t('SOAP and DOM'),
  20. 'value' => $has_soap && $has_dom ? $t('Enabled') : $t('Not found'),
  21. );
  22. if (!$has_soap || !$has_dom) {
  23. $requirements['uc_cybersource_soap_and_dom']['severity'] = REQUIREMENT_ERROR;
  24. $requirements['uc_cybersource_soap_and_dom']['description'] = $t("CyberSource's SOAP Toolkit API requires the PHP <a href='!soap_url'>SOAP</a> and <a href='!dom_url'>DOM</a> libraries.", array('!soap_url' => 'http://php.net/manual/en/soap.setup.php', '!dom_url' => 'http://php.net/manual/en/dom.setup.php'));
  25. }
  26. }
  27. // Using POST with cURL.
  28. elseif ($method == 'post') {
  29. $requirements['uc_cybersource_curl'] = array(
  30. 'title' => $t('cURL'),
  31. 'value' => $has_curl ? $t('Enabled') : $t('Not found'),
  32. );
  33. if (!$has_curl) {
  34. $requirements['uc_cybersource_curl']['severity'] = REQUIREMENT_ERROR;
  35. $requirements['uc_cybersource_curl']['description'] = $t("CyberSource's Silent Order POST requires the PHP <a href='!curl_url'>cURL</a> library.", array('!curl_url' => 'http://php.net/manual/en/curl.setup.php'));
  36. }
  37. }
  38. // We need HOP.php if we're using the post method and also the Hosted Order
  39. // page, which is a payment method rather than a gateway.
  40. if ($method != 'soap') {
  41. require_once('uc_cybersource.module');
  42. $has_cybersource_hop = uc_cybersource_hop_include();
  43. $requirements['uc_cybersource'] = array(
  44. 'title' => t('CyberSource HOP.php'),
  45. 'value' => $has_cybersource_hop ? $t('Enabled') : $t('Not found'),
  46. );
  47. if (!$has_cybersource_hop) {
  48. $requirements['uc_cybersource']['description'] = t('For instructions on how to generate this file, please refer to <a href="http://www.cybersource.com/support_center/implementation/downloads/hosted_order_page/">CyberSource\'s Hosted Order Pages Documentation</a>, specifically the "Downloading Security Scripts" in Chapter 2 of the <a href="http://apps.cybersource.com/library/documentation/sbc/HOP_UG/html/">HOP User\'s Guide</a>.');
  49. $severity = $phase == 'install' ? REQUIREMENT_INFO : REQUIREMENT_ERROR;
  50. $requirements['uc_cybersource']['severity'] = $severity;
  51. }
  52. else {
  53. $requirements['uc_cybersource']['severity'] = REQUIREMENT_OK;
  54. $requirements['uc_cybersource']['description'] = t('The HOP.php library is readable.');
  55. }
  56. }
  57. return $requirements;
  58. }
  59. /**
  60. * Implements hook_uninstall().
  61. */
  62. function uc_cybersource_uninstall() {
  63. // Delete related variables all at once.
  64. db_delete('variable')
  65. ->condition(db_or()
  66. ->condition('name', 'uc_cybersource_%', 'LIKE')
  67. ->condition('name', 'cs_ship_from_%', 'LIKE')
  68. )
  69. ->execute();
  70. }
  71. /**
  72. * Implements hook_schema().
  73. */
  74. function uc_cybersource_schema() {
  75. $schema['uc_payment_cybersource_hop_post'] = array(
  76. 'fields' => array(
  77. 'order_id' => array(
  78. 'description' => 'The order ID as provided by the store.',
  79. 'type' => 'int',
  80. 'unsigned' => TRUE,
  81. 'not null' => TRUE,
  82. 'default' => 0,
  83. ),
  84. 'request_id' => array(
  85. 'description' => 'Unique id assigned by CyberSource that identifies payment request.',
  86. 'type' => 'varchar',
  87. 'length' => 255,
  88. 'not null' => TRUE,
  89. 'default' => '',
  90. ),
  91. 'request_token' => array(
  92. 'description' => 'Verification token associated with the request ID.',
  93. 'type' => 'varchar',
  94. 'length' => 255,
  95. 'not null' => TRUE,
  96. 'default' => '',
  97. ),
  98. 'reconciliation_id' => array(
  99. 'description' => 'Reference number generated by CyberSource that you use to reconcile your CyberSource reports with your processor reports.',
  100. 'type' => 'varchar',
  101. 'length' => 255,
  102. 'not null' => TRUE,
  103. 'default' => '',
  104. ),
  105. 'gross' => array(
  106. 'description' => 'The approved payment amount from CyberSource.',
  107. 'type' => 'varchar',
  108. 'length' => 255,
  109. 'not null' => TRUE,
  110. 'default' => '',
  111. ),
  112. 'decision' => array(
  113. 'description' => 'CyberSource decision for payment request.',
  114. 'type' => 'varchar',
  115. 'length' => 255,
  116. 'not null' => TRUE,
  117. 'default' => '',
  118. ),
  119. 'reason_code' => array(
  120. 'description' => 'A code for decision.',
  121. 'type' => 'varchar',
  122. 'length' => 255,
  123. 'not null' => TRUE,
  124. 'default' => '',
  125. ),
  126. 'payer_email' => array(
  127. 'description' => 'The e-mail address of the buyer.',
  128. 'type' => 'varchar',
  129. 'length' => 255,
  130. 'not null' => TRUE,
  131. 'default' => '',
  132. ),
  133. 'received' => array(
  134. 'description' => 'The IPN receipt timestamp.',
  135. 'type' => 'int',
  136. 'unsigned' => TRUE,
  137. 'not null' => TRUE,
  138. 'default' => 0,
  139. ),
  140. ),
  141. );
  142. return $schema;
  143. }
  144. /**
  145. * Implements hook_update_last_removed().
  146. */
  147. function uc_cybersource_update_last_removed() {
  148. return 2;
  149. }