paypalsolo

Addon Name: PayPal Single Payments Gateway Author: Barry (Incsub) Author URI: http://caffeinatedb.com Gateway ID: paypalsolo.

Defined (1)

The class is defined in the following location(s).

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