uc_paypal.install 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the uc_paypal module.
  5. */
  6. /**
  7. * Implements hook_requirements().
  8. */
  9. function uc_paypal_requirements($phase) {
  10. $requirements = array();
  11. $t = get_t();
  12. $has_curl = function_exists('curl_init');
  13. // PayPal WPP requires cURL.
  14. if (variable_get('uc_pg_paypal_wpp_enabled', TRUE)) {
  15. $requirements['uc_paypal_curl'] = array(
  16. 'title' => $t('cURL'),
  17. 'value' => $has_curl ? $t('Enabled') : $t('Not found'),
  18. );
  19. if (!$has_curl) {
  20. $requirements['uc_paypal_curl']['severity'] = REQUIREMENT_ERROR;
  21. $requirements['uc_paypal_curl']['description'] = $t("PayPal WPP requires the PHP <a href='!curl_url'>cURL</a> library.", array('!curl_url' => 'http://php.net/manual/en/curl.setup.php'));
  22. }
  23. }
  24. return $requirements;
  25. }
  26. /**
  27. * Implements hook_schema().
  28. */
  29. function uc_paypal_schema() {
  30. $schema = array();
  31. $schema['uc_payment_paypal_ipn'] = array(
  32. 'description' => 'Logs PayPal Instant Payment Notifications.',
  33. 'fields' => array(
  34. 'order_id' => array(
  35. 'description' => 'The order ID.',
  36. 'type' => 'int',
  37. 'unsigned' => TRUE,
  38. 'not null' => TRUE,
  39. 'default' => 0,
  40. ),
  41. 'txn_id' => array(
  42. 'description' => 'The transaction ID from PayPal.',
  43. 'type' => 'varchar',
  44. 'length' => 255,
  45. 'not null' => TRUE,
  46. 'default' => '',
  47. ),
  48. 'txn_type' => array(
  49. 'description' => 'The transaction type from PayPal.',
  50. 'type' => 'varchar',
  51. 'length' => 255,
  52. 'not null' => TRUE,
  53. 'default' => '',
  54. ),
  55. 'mc_gross' => array(
  56. 'description' => 'The payment amount from PayPal.',
  57. 'type' => 'varchar',
  58. 'length' => 255,
  59. 'not null' => TRUE,
  60. 'default' => '',
  61. ),
  62. 'status' => array(
  63. 'description' => 'The IPN status from PayPal.',
  64. 'type' => 'varchar',
  65. 'length' => 255,
  66. 'not null' => TRUE,
  67. 'default' => '',
  68. ),
  69. 'receiver_email' => array(
  70. 'description' => 'The e-mail address of the PayPal account.',
  71. 'type' => 'varchar',
  72. 'length' => 255,
  73. 'not null' => TRUE,
  74. 'default' => '',
  75. ),
  76. 'payer_email' => array(
  77. 'description' => 'The e-mail address of the buyer.',
  78. 'type' => 'varchar',
  79. 'length' => 255,
  80. 'not null' => TRUE,
  81. 'default' => '',
  82. ),
  83. 'received' => array(
  84. 'description' => 'The IPN receipt timestamp.',
  85. 'type' => 'int',
  86. 'unsigned' => TRUE,
  87. 'not null' => TRUE,
  88. 'default' => 0,
  89. ),
  90. ),
  91. 'indexes' => array(
  92. 'order_id' => array('order_id'),
  93. ),
  94. 'foreign keys' => array(
  95. 'uc_orders' => array(
  96. 'table' => 'uc_orders',
  97. 'columns' => array('order_id' => 'order_id'),
  98. ),
  99. ),
  100. );
  101. return $schema;
  102. }
  103. /**
  104. * Implements hook_install().
  105. */
  106. function uc_paypal_install() {
  107. $t = get_t();
  108. db_merge('uc_order_statuses')
  109. ->key(array('order_status_id' => 'paypal_pending'))
  110. ->insertFields(array(
  111. 'order_status_id' => 'paypal_pending',
  112. 'title' => $t('PayPal pending'),
  113. 'state' => 'post_checkout',
  114. 'weight' => 7,
  115. 'locked' => 1,
  116. ))
  117. ->updateFields(array(
  118. 'state' => 'post_checkout',
  119. 'locked' => 1,
  120. ))
  121. ->execute();
  122. }
  123. /**
  124. * Implements hook_uninstall().
  125. */
  126. function uc_paypal_uninstall() {
  127. db_update('uc_order_statuses')
  128. ->fields(array(
  129. 'locked' => 0,
  130. ))
  131. ->condition('order_status_id', 'paypal_pending')
  132. ->execute();
  133. db_delete('variable')
  134. ->condition('name', 'uc_paypal_%', 'LIKE')
  135. ->execute();
  136. }
  137. /**
  138. * Implements hook_update_last_removed().
  139. */
  140. function uc_paypal_update_last_removed() {
  141. // 7.x-3.0-beta2 and earlier were installed with schema version 0,
  142. // which causes update.php to fail.
  143. return drupal_get_installed_schema_version('uc_paypal') == 0 ? 0 : 6000;
  144. }
  145. /*
  146. * Removed completely unnecessary update 7000.
  147. */
  148. /**
  149. * Fix incorrect order status configuration.
  150. */
  151. function uc_paypal_update_7001() {
  152. db_delete('uc_order_statuses')
  153. ->condition('order_status_id', '')
  154. ->execute();
  155. db_merge('uc_order_statuses')
  156. ->key(array('order_status_id' => 'paypal_pending'))
  157. ->insertFields(array(
  158. 'order_status_id' => 'paypal_pending',
  159. 'title' => t('PayPal pending'),
  160. 'state' => 'payment_received',
  161. 'weight' => 7,
  162. 'locked' => 1,
  163. ))
  164. ->updateFields(array(
  165. 'state' => 'payment_received',
  166. 'locked' => 1,
  167. ))
  168. ->execute();
  169. }
  170. /**
  171. * Fix incorrect order state configuration.
  172. */
  173. function uc_paypal_update_7300() {
  174. db_update('uc_order_statuses')
  175. ->fields(array(
  176. 'state' => 'post_checkout',
  177. ))
  178. ->condition('order_status_id', 'paypal_pending')
  179. ->execute();
  180. }
  181. /**
  182. * Remove unused variable.
  183. */
  184. function uc_paypal_update_7301() {
  185. variable_del('uc_paypal_wps_checkout_button');
  186. }