/app_old/membershipincludes/gateways/gateway.paypalsolo.php

  1. <?php 
  2. /** 
  3. Addon Name: PayPal Single Payments Gateway 
  4. Author: Barry (Incsub) 
  5. Author URI: http://caffeinatedb.com 
  6. Gateway ID: paypalsolo 
  7. */ 
  8.  
  9. class paypalsolo extends M_Gateway { 
  10.  
  11. var $gateway = 'paypalsolo'; 
  12. var $title = 'PayPal Express - with Single Payments'; 
  13. var $issingle = true; 
  14.  
  15. function paypalsolo() { 
  16. parent::M_Gateway(); 
  17.  
  18. add_action('M_gateways_settings_' . $this->gateway, array(&$this, 'mysettings')); 
  19.  
  20. // If I want to override the transactions output - then I can use this action 
  21. //add_action('M_gateways_transactions_' . $this->gateway, array(&$this, 'mytransactions')); 
  22.  
  23. if($this->is_active()) { 
  24. // Subscription form gateway 
  25. add_action('membership_purchase_button', array(&$this, 'display_subscribe_button'), 1, 3); 
  26.  
  27. // Payment return 
  28. add_action('membership_handle_payment_return_' . $this->gateway, array(&$this, 'handle_paypal_return')); 
  29. add_filter( 'membership_subscription_form_subscription_process', array(&$this, 'signup_free_subscription'), 10, 2 ); 
  30.  
  31.  
  32. function mysettings() { 
  33.  
  34. global $M_options; 
  35.  
  36. ?> 
  37. <table class="form-table"> 
  38. <tbody> 
  39. <tr valign="top"> 
  40. <th scope="row"><?php _e('PayPal Email', 'membership') ?></th> 
  41. <td><input type="text" name="paypal_email" value="<?php esc_attr_e(get_option( $this->gateway . "_paypal_email" )); ?>" /> 
  42. <br /> 
  43. </td> 
  44. </tr> 
  45. <tr valign="top"> 
  46. <th scope="row"><?php _e('PayPal Site', 'membership') ?></th> 
  47. <td><select name="paypal_site"> 
  48. <?php 
  49. $paypal_site = get_option( $this->gateway . "_paypal_site" ); 
  50. $sel_locale = empty($paypal_site) ? 'US' : $paypal_site; 
  51. $locales = array( 
  52. 'AU' => __('Australia', 'membership'),  
  53. 'AT' => __('Austria', 'membership'),  
  54. 'BE' => __('Belgium', 'membership'),  
  55. 'CA' => __('Canada', 'membership'),  
  56. 'CN' => __('China', 'membership'),  
  57. 'FR' => __('France', 'membership'),  
  58. 'DE' => __('Germany', 'membership'),  
  59. 'HK' => __('Hong Kong', 'membership'),  
  60. 'IT' => __('Italy', 'membership'),  
  61. 'jp_JP' => __('Japan', 'membership'),  
  62. 'MX' => __('Mexico', 'membership'),  
  63. 'NL' => __('Netherlands', 'membership'),  
  64. 'NZ' => __('New Zealand', 'membership'),  
  65. 'PL' => __('Poland', 'membership'),  
  66. 'SG' => __('Singapore', 'membership'),  
  67. 'ES' => __('Spain', 'membership'),  
  68. 'SE' => __('Sweden', 'membership'),  
  69. 'CH' => __('Switzerland', 'membership'),  
  70. 'GB' => __('United Kingdom', 'membership'),  
  71. 'US' => __('United States', 'membership') 
  72. ); 
  73.  
  74. foreach ($locales as $key => $value) { 
  75. echo '<option value="' . esc_attr($key) . '"'; 
  76. if($key == $sel_locale) echo 'selected="selected"'; 
  77. echo '>' . esc_html($value) . '</option>' . "\n"; 
  78. ?> 
  79. </select> 
  80. <br /> 
  81. <?php //_e('Format: 00.00 - Ex: 1.25', 'supporter') ?></td> 
  82. </tr> 
  83. <tr valign="top"> 
  84. <th scope="row"><?php _e('Paypal Currency', 'membership') ?></th> 
  85. <td><?php 
  86. if(empty($M_options['paymentcurrency'])) { 
  87. $M_options['paymentcurrency'] = 'USD'; 
  88. echo esc_html($M_options['paymentcurrency']); ?></td> 
  89. </tr> 
  90. <tr valign="top"> 
  91. <th scope="row"><?php _e('PayPal Mode', 'membership') ?></th> 
  92. <td><select name="paypal_status"> 
  93. <option value="live" <?php if (get_option( $this->gateway . "_paypal_status" ) == 'live') echo 'selected="selected"'; ?>><?php _e('Live Site', 'membership') ?></option> 
  94. <option value="test" <?php if (get_option( $this->gateway . "_paypal_status" ) == 'test') echo 'selected="selected"'; ?>><?php _e('Test Mode (Sandbox)', 'membership') ?></option> 
  95. </select> 
  96. <br /> 
  97. </td> 
  98. </tr> 
  99. <tr valign="top"> 
  100. <th scope="row"><?php _e('Subscription button', 'membership') ?></th> 
  101. <?php 
  102. $button = get_option( $this->gateway . "_paypal_button", 'https://www.paypal.com/en_US/i/btn/btn_subscribe_LG.gif' ); 
  103. ?> 
  104. <td><input type="text" name="paypal_button" value="<?php esc_attr_e($button); ?>" style='width: 40em;' /> 
  105. <br /> 
  106. </td> 
  107. </tr> 
  108. <tr valign="top"> 
  109. <th scope="row"><?php _e('Renew button', 'membership') ?></th> 
  110. <?php 
  111. $button = get_option( $this->gateway . "_paypal_renew_button", 'http://www.paypal.com/en_US/i/btn/x-click-but23.gif' ); 
  112. ?> 
  113. <td><input type="text" name="_paypal_renew_button" value="<?php esc_attr_e($button); ?>" style='width: 40em;' /> 
  114. <br /> 
  115. </td> 
  116. </tr> 
  117. <tr valign="top"> 
  118. <th scope="row"><?php _e('Upgrade button', 'membership') ?></th> 
  119. <?php 
  120. $button = get_option( $this->gateway . "_paypal_upgrade_button", 'https://www.paypal.com/en_US/i/btn/btn_subscribe_LG.gif' ); 
  121. ?> 
  122. <td><input type="text" name="_paypal_upgrade_button" value="<?php esc_attr_e($button); ?>" style='width: 40em;' /> 
  123. <br /> 
  124. </td> 
  125. </tr> 
  126. <tr valign="top"> 
  127. <th scope="row"><?php _e('Cancel button', 'membership') ?></th> 
  128. <?php 
  129. $button = get_option( $this->gateway . "_paypal_cancel_button", 'https://www.paypal.com/en_US/i/btn/btn_unsubscribe_LG.gif' ); 
  130. ?> 
  131. <td><input type="text" name="_paypal_cancel_button" value="<?php esc_attr_e($button); ?>" style='width: 40em;' /> 
  132. <br /> 
  133. </td> 
  134. </tr> 
  135.  
  136. </tbody> 
  137. </table> 
  138. <?php 
  139.  
  140. function build_custom($user_id, $sub_id, $amount, $sublevel = 0, $fromsub = 0) { 
  141.  
  142. global $M_options; 
  143.  
  144. $custom = ''; 
  145.  
  146. //fake:user:sub:key 
  147.  
  148. $custom = time() . ':' . $user_id . ':' . $sub_id . ':'; 
  149. $key = md5('MEMBERSHIP' . apply_filters('membership_amount_' . $M_options['paymentcurrency'], $amount)); 
  150.  
  151. $custom .= $key; 
  152. $custom .= ":" . $sublevel . ":" . $fromsub; 
  153.  
  154. return $custom; 
  155.  
  156.  
  157. function single_button($pricing, $subscription, $user_id, $sublevel = 0, $fromsub = 0) { 
  158.  
  159. global $M_options; 
  160.  
  161. if(empty($M_options['paymentcurrency'])) { 
  162. $M_options['paymentcurrency'] = 'USD'; 
  163.  
  164. $form = ''; 
  165.  
  166. if (get_option( $this->gateway . "_paypal_status" ) == 'live') { 
  167. $form .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">'; 
  168. } else { 
  169. $form .= '<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">'; 
  170. $form .= '<input type="hidden" name="charset" value="utf-8">'; 
  171. $form .= '<input type="hidden" name="business" value="' . esc_attr(get_option( $this->gateway . "_paypal_email" )) . '">'; 
  172. $form .= '<input type="hidden" name="cmd" value="_xclick">'; 
  173. $form .= '<input type="hidden" name="item_number" value="' . $subscription->sub_id() . '">'; 
  174. $form .= '<input type="hidden" name="item_name" value="' . $subscription->sub_name() . '">'; 
  175. $form .= '<input type="hidden" name="amount" value="' . apply_filters('membership_amount_' . $M_options['paymentcurrency'], number_format($pricing[$sublevel -1]['amount'], 2, '.' , '')) . '">'; 
  176. $form .= '<input type="hidden" name="currency_code" value="' . $M_options['paymentcurrency'] .'">'; 
  177.  
  178. $form .= '<input type="hidden" name="return" value="' . apply_filters( 'membership_return_url_' . $this->gateway, M_get_returnurl_permalink()) . '">'; 
  179. $form .= '<input type="hidden" name="cancel_return" value="' . apply_filters( 'membership_cancel_url_' . $this->gateway, M_get_subscription_permalink()) . '">'; 
  180.  
  181. $form .= '<input type="hidden" name="custom" value="' . $this->build_custom($user_id, $subscription->id, number_format($pricing[$sublevel -1]['amount'], 2, '.' , ''), $sublevel, $fromsub) .'">'; 
  182.  
  183. $form .= '<input type="hidden" name="lc" value="' . esc_attr(get_option( $this->gateway . "_paypal_site" )) . '">'; 
  184. $form .= '<input type="hidden" name="notify_url" value="' . apply_filters( 'membership_notify_url_' . $this->gateway, trailingslashit(get_option('home')) . 'paymentreturn/' . esc_attr($this->gateway)) . '">'; 
  185.  
  186. if($sublevel == 1) { 
  187. $button = get_option( $this->gateway . "_paypal_button", 'https://www.paypal.com/en_US/i/btn/btn_subscribe_LG.gif' ); 
  188. } else { 
  189. $button = get_option( $this->gateway . "_paypal_button", 'http://www.paypal.com/en_US/i/btn/x-click-but23.gif' ); 
  190.  
  191. $form .= '<input type="image" name="submit" border="0" src="' . $button . '" alt="PayPal - The safer, easier way to pay online">'; 
  192. $form .= '<img alt="" border="0" width="1" height="1" src="https://www.paypal.com/en_US/i/scr/pixel.gif" >'; 
  193. $form .= '</form>'; 
  194.  
  195. return $form; 
  196.  
  197.  
  198. function signup_free_subscription($content, $error) { 
  199.  
  200. if(!isset($_POST['action']) || $_POST['action'] != 'validatepage2') { 
  201. return $content; 
  202.  
  203. if(isset($_POST['custom'])) { 
  204. list($timestamp, $user_id, $sub_id, $key) = explode(':', $_POST['custom']); 
  205.  
  206. // create_subscription 
  207. $member = new M_Membership($user_id); 
  208. if($member) { 
  209. $member->create_subscription($sub_id, $this->gateway); 
  210.  
  211. do_action('membership_payment_subscr_signup', $user_id, $sub_id); 
  212.  
  213. $content .= '<div id="reg-form">'; // because we can't have an enclosing form for this part 
  214.  
  215. $content .= '<div class="formleft">'; 
  216.  
  217. $message = get_option( $this->gateway . "_completed_message", $this->defaultmessage ); 
  218. $content .= stripslashes($message); 
  219.  
  220. $content .= '</div>'; 
  221.  
  222. $content .= "</div>"; 
  223.  
  224. $content = apply_filters('membership_subscriptionform_signedup', $content, $user_id, $sub_id); 
  225.  
  226. return $content; 
  227.  
  228.  
  229. function single_free_button($pricing, $subscription, $user_id, $sublevel = 0) { 
  230.  
  231. global $M_options; 
  232.  
  233. if(empty($M_options['paymentcurrency'])) { 
  234. $M_options['paymentcurrency'] = 'USD'; 
  235.  
  236. $form = ''; 
  237.  
  238. $form .= '<form action="' . M_get_returnurl_permalink() . '" method="post">'; 
  239. $form .= '<input type="hidden" name="custom" value="' . $this->build_custom($user_id, $subscription->id, '0', $sublevel) .'">'; 
  240.  
  241. if($sublevel == 1) { 
  242. $form .= '<input type="hidden" name="action" value="subscriptionsignup" />'; 
  243. $form .= wp_nonce_field('free-sub_' . $subscription->sub_id(), "_wpnonce", true, false); 
  244. $form .= "<input type='hidden' name='gateway' value='" . $this->gateway . "' />"; 
  245. $button = get_option( $this->gateway . "_payment_button", 'https://www.paypal.com/en_US/i/btn/btn_subscribe_LG.gif' ); 
  246. } else { 
  247. $form .= wp_nonce_field('renew-sub_' . $subscription->sub_id(), "_wpnonce", true, false); 
  248. $form .= "<input type='hidden' name='action' value='subscriptionsignup' />"; 
  249. $form .= "<input type='hidden' name='gateway' value='" . $this->gateway . "' />"; 
  250. $form .= "<input type='hidden' name='subscription' value='" . $subscription->sub_id() . "' />"; 
  251. $form .= "<input type='hidden' name='user' value='" . $user_id . "' />"; 
  252. $form .= "<input type='hidden' name='level' value='" . $sublevel . "' />"; 
  253. $button = get_option( $this->gateway . "_payment_button", 'http://www.paypal.com/en_US/i/btn/x-click-but23.gif' ); 
  254.  
  255. $form .= '<input type="image" name="submit" border="0" src="' . $button . '" alt="PayPal - The safer, easier way to pay online">'; 
  256. $form .= '</form>'; 
  257.  
  258. return $form; 
  259.  
  260.  
  261. function build_subscribe_button($subscription, $pricing, $user_id, $sublevel = 1, $fromsub = 0) { 
  262.  
  263. if(!empty($pricing)) { 
  264. // check to make sure there is a price in the subscription 
  265. // we don't want to display free ones for a payment system 
  266.  
  267. if( isset($pricing[$sublevel - 1]) ) { 
  268. if( empty($pricing[$sublevel - 1]) || $pricing[$sublevel - 1]['amount'] == 0 ) { 
  269. // It's a free level 
  270. return $this->single_free_button($pricing, $subscription, $user_id, $sublevel); 
  271. } else { 
  272. // It's a paid level 
  273. return $this->single_button($pricing, $subscription, $user_id, $sublevel, $fromsub); 
  274.  
  275.  
  276.  
  277. function display_upgrade_from_free_button($subscription, $pricing, $user_id, $fromsub_id = false) { 
  278. if($pricing[0]['amount'] < 1) { 
  279. // a free first level 
  280. $this->display_upgrade_button($subscription, $pricing, $user_id, $fromsub_id); 
  281. } else { 
  282. echo $this->build_subscribe_button($subscription, $pricing, $user_id, $fromsub_id); 
  283.  
  284.  
  285. function display_upgrade_button($subscription, $pricing, $user_id, $fromsub_id = false) { 
  286.  
  287. echo '<form class="upgradebutton" action="' . M_get_subscription_permalink() . '" method="post">'; 
  288. wp_nonce_field('upgrade-sub_' . $subscription->sub_id()); 
  289. echo "<input type='hidden' name='action' value='upgradesolo' />"; 
  290. echo "<input type='hidden' name='gateway' value='" . $this->gateway . "' />"; 
  291. echo "<input type='hidden' name='subscription' value='" . $subscription->sub_id() . "' />"; 
  292. echo "<input type='hidden' name='user' value='" . $user_id . "' />"; 
  293. echo "<input type='hidden' name='fromsub_id' value='" . $fromsub_id . "' />"; 
  294. echo "<input type='submit' name='submit' value=' " . __('Upgrade', 'membership') . " ' class='button blue' />"; 
  295. echo "</form>"; 
  296.  
  297. function display_cancel_button($subscription, $pricing, $user_id) { 
  298.  
  299. echo '<form class="unsubbutton" action="' . M_get_subscription_permalink() . '" method="post">'; 
  300. wp_nonce_field('cancel-sub_' . $subscription->sub_id()); 
  301. echo "<input type='hidden' name='action' value='unsubscribe' />"; 
  302. echo "<input type='hidden' name='gateway' value='" . $this->gateway . "' />"; 
  303. echo "<input type='hidden' name='subscription' value='" . $subscription->sub_id() . "' />"; 
  304. echo "<input type='hidden' name='user' value='" . $user_id . "' />"; 
  305. echo "<input type='submit' name='submit' value=' " . __('Unsubscribe', 'membership') . " ' class='button blue' />"; 
  306. echo "</form>"; 
  307.  
  308. function display_subscribe_button($subscription, $pricing, $user_id, $sublevel = 1) { 
  309. echo $this->build_subscribe_button($subscription, $pricing, $user_id, $sublevel); 
  310.  
  311. function update() { 
  312.  
  313. if(isset($_POST['paypal_email'])) { 
  314. update_option( $this->gateway . "_paypal_email", $_POST[ 'paypal_email' ] ); 
  315. update_option( $this->gateway . "_paypal_site", $_POST[ 'paypal_site' ] ); 
  316. update_option( $this->gateway . "_currency", (isset($_POST[ 'currency' ])) ? $_POST[ 'currency' ] : '' ); 
  317. update_option( $this->gateway . "_paypal_status", $_POST[ 'paypal_status' ] ); 
  318. update_option( $this->gateway . "_paypal_button", $_POST[ 'paypal_button' ] ); 
  319. update_option( $this->gateway . "_paypal_upgrade_button", $_POST[ '_paypal_upgrade_button' ] ); 
  320. update_option( $this->gateway . "_paypal_cancel_button", $_POST[ '_paypal_cancel_button' ] ); 
  321. update_option( $this->gateway . "_paypal_renew_button", $_POST[ '_paypal_renew_button' ] ); 
  322. update_option( $this->gateway . "_completed_message", $_POST[ 'completed_message' ] ); 
  323.  
  324. // default action is to return true 
  325. return true; 
  326.  
  327.  
  328. // IPN stuff 
  329. function handle_paypal_return() { 
  330. // PayPal IPN handling code 
  331.  
  332. if ((isset($_POST['payment_status']) || isset($_POST['txn_type'])) && isset($_POST['custom'])) { 
  333.  
  334. if (get_option( $this->gateway . "_paypal_status" ) == 'live') { 
  335. $domain = 'https://www.paypal.com'; 
  336. } else { 
  337. $domain = 'https://www.sandbox.paypal.com'; 
  338.  
  339. $req = 'cmd=_notify-validate'; 
  340. if (!isset($_POST)) $_POST = $HTTP_POST_VARS; 
  341. foreach ($_POST as $k => $v) { 
  342. if (get_magic_quotes_gpc()) $v = stripslashes($v); 
  343. $req .= '&' . $k . '=' . $v; 
  344.  
  345. $header = 'POST /cgi-bin/webscr HTTP/1.0' . "\r\n" 
  346. . 'Content-Type: application/x-www-form-urlencoded' . "\r\n" 
  347. . 'Content-Length: ' . strlen($req) . "\r\n" 
  348. . "\r\n"; 
  349.  
  350. @set_time_limit(60); 
  351. if ($conn = @fsockopen($domain, 80, $errno, $errstr, 30)) { 
  352. fputs($conn, $header . $req); 
  353. socket_set_timeout($conn, 30); 
  354.  
  355. $response = ''; 
  356. $close_connection = false; 
  357. while (true) { 
  358. if (feof($conn) || $close_connection) { 
  359. fclose($conn); 
  360. break; 
  361.  
  362. $st = @fgets($conn, 4096); 
  363. if ($st === false) { 
  364. $close_connection = true; 
  365. continue; 
  366.  
  367. $response .= $st; 
  368.  
  369. $error = ''; 
  370. $lines = explode("\n", str_replace("\r\n", "\n", $response)); 
  371. // looking for: HTTP/1.1 200 OK 
  372. if (count($lines) == 0) $error = 'Response Error: Header not found'; 
  373. else if (substr($lines[0], -7) != ' 200 OK') $error = 'Response Error: Unexpected HTTP response'; 
  374. else { 
  375. // remove HTTP header 
  376. while (count($lines) > 0 && trim($lines[0]) != '') array_shift($lines); 
  377.  
  378. // first line will be empty, second line will have the result 
  379. if (count($lines) < 2) $error = 'Response Error: No content found in transaction response'; 
  380. else if (strtoupper(trim($lines[1])) != 'VERIFIED') $error = 'Response Error: Unexpected transaction response'; 
  381.  
  382. if ($error != '') { 
  383. echo $error; 
  384. exit; 
  385.  
  386. // handle cases that the system must ignore 
  387. //if ($_POST['payment_status'] == 'In-Progress' || $_POST['payment_status'] == 'Partially-Refunded') exit; 
  388. $new_status = false; 
  389. // process PayPal response 
  390. switch ($_POST['payment_status']) { 
  391. case 'Partially-Refunded': 
  392. break; 
  393.  
  394. case 'In-Progress': 
  395. break; 
  396.  
  397. case 'Completed': 
  398. case 'Processed': 
  399. // case: successful payment 
  400. $amount = $_POST['mc_gross']; 
  401. $currency = $_POST['mc_currency']; 
  402. list($timestamp, $user_id, $sub_id, $key, $sublevel, $fromsub) = explode(':', $_POST['custom']); 
  403.  
  404. $newkey = md5('MEMBERSHIP' . $amount); 
  405. if($key != $newkey) { 
  406. $member = new M_Membership($user_id); 
  407. if($member) { 
  408. if(defined('MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION') && MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION == true ) { 
  409. $member->deactivate(); 
  410. } else { 
  411. if( !$this->duplicate_transaction( $user_id, $sub_id, $amount, $currency, $timestamp, trim($_POST['txn_id']), $_POST['payment_status'], '' ) ) { 
  412. $this->record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, trim($_POST['txn_id']), $_POST['payment_status'], ''); 
  413.  
  414. if($sublevel == '1') { 
  415. // This is the first level of a subscription so we need to create one if it doesn't already exist 
  416. $member = new M_Membership($user_id); 
  417. if($member) { 
  418. $member->create_subscription($sub_id, $this->gateway); 
  419. do_action('membership_payment_subscr_signup', $user_id, $sub_id); 
  420. } else { 
  421. $member = new M_Membership($user_id); 
  422. if($member) { 
  423. // Mark the payment so that we can move through ok 
  424. $member->record_active_payment( $sub_id, $sublevel, $timestamp ); 
  425.  
  426. // remove any current subs for upgrades 
  427. if(!empty($fromsub) && $fromsub != 0) { 
  428. $member->drop_subscription( $fromsub ); 
  429.  
  430. // Added for affiliate system link 
  431. do_action('membership_payment_processed', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']); 
  432. break; 
  433.  
  434. case 'Reversed': 
  435. // case: charge back 
  436. $note = __('Last transaction has been reversed. Reason: Payment has been reversed (charge back)', 'membership'); 
  437. $amount = $_POST['mc_gross']; 
  438. $currency = $_POST['mc_currency']; 
  439. list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']); 
  440.  
  441. $this->record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $_POST['txn_id'], $_POST['payment_status'], $note); 
  442.  
  443. $member = new M_Membership($user_id); 
  444. if($member) { 
  445. $member->expire_subscription($sub_id); 
  446. if(defined('MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION') && MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION == true ) { 
  447. $member->deactivate(); 
  448.  
  449. do_action('membership_payment_reversed', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']); 
  450. break; 
  451.  
  452. case 'Refunded': 
  453. // case: refund 
  454. $note = __('Last transaction has been reversed. Reason: Payment has been refunded', 'membership'); 
  455. $amount = $_POST['mc_gross']; 
  456. $currency = $_POST['mc_currency']; 
  457. list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']); 
  458.  
  459. $this->record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $_POST['txn_id'], $_POST['payment_status'], $note); 
  460.  
  461. $member = new M_Membership($user_id); 
  462. if($member) { 
  463. $member->expire_subscription($sub_id); 
  464.  
  465. do_action('membership_payment_refunded', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']); 
  466. break; 
  467.  
  468. case 'Denied': 
  469. // case: denied 
  470. $note = __('Last transaction has been reversed. Reason: Payment Denied', 'membership'); 
  471. $amount = $_POST['mc_gross']; 
  472. $currency = $_POST['mc_currency']; 
  473. list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']); 
  474.  
  475. $this->record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $_POST['txn_id'], $_POST['payment_status'], $note); 
  476.  
  477. $member = new M_Membership($user_id); 
  478. if($member) { 
  479. $member->expire_subscription($sub_id); 
  480. if(defined('MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION') && MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION == true ) { 
  481. $member->deactivate(); 
  482.  
  483. do_action('membership_payment_denied', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']); 
  484. break; 
  485.  
  486. case 'Pending': 
  487. // case: payment is pending 
  488. $pending_str = array( 
  489. 'address' => __('Customer did not include a confirmed shipping address', 'membership'),  
  490. 'authorization' => __('Funds not captured yet', 'membership'),  
  491. 'echeck' => __('eCheck that has not cleared yet', 'membership'),  
  492. 'intl' => __('Payment waiting for aproval by service provider', 'membership'),  
  493. 'multi-currency' => __('Payment waiting for service provider to handle multi-currency process', 'membership'),  
  494. 'unilateral' => __('Customer did not register or confirm his/her email yet', 'membership'),  
  495. 'upgrade' => __('Waiting for service provider to upgrade the PayPal account', 'membership'),  
  496. 'verify' => __('Waiting for service provider to verify his/her PayPal account', 'membership'),  
  497. '*' => '' 
  498. ); 
  499. $reason = @$_POST['pending_reason']; 
  500. $note = 'Last transaction is pending. Reason: ' . (isset($pending_str[$reason]) ? $pending_str[$reason] : $pending_str['*']); 
  501. $amount = $_POST['mc_gross']; 
  502. $currency = $_POST['mc_currency']; 
  503. list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']); 
  504.  
  505. $this->record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $_POST['txn_id'], $_POST['payment_status'], $note); 
  506.  
  507. do_action('membership_payment_pending', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']); 
  508. break; 
  509.  
  510. default: 
  511. // case: various error cases 
  512.  
  513. //check for subscription details 
  514. switch ($_POST['txn_type']) { 
  515.  
  516. case 'new_case': 
  517. // a dispute 
  518. if($_POST['case_type'] == 'dispute') { 
  519. list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']); 
  520. // immediately suspend the account 
  521. $member = new M_Membership($user_id); 
  522. if($member) { 
  523. $member->deactivate(); 
  524.  
  525. do_action('membership_payment_new_case', $user_id, $sub_id, $_POST['case_type']); 
  526. break; 
  527.  
  528. } else { 
  529. // Did not find expected POST variables. Possible access attempt from a non PayPal site. 
  530. header('Status: 404 Not Found'); 
  531. echo 'Error: Missing POST variables. Identification is not possible.'; 
  532. exit; 
  533.  
  534.  
  535. M_register_gateway('paypalsolo', 'paypalsolo'); 
  536.  
  537. ?> 
.