freesubscriptions

Addon Name: Free subscriptions gateway Author: Barry (Incsub) Author URI: http://caffeinatedb.com Gateway ID: freesubscriptions.

Defined (1)

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

/app_old/membershipincludes/gateways/gateway.freesubscriptions.php  
  1. class freesubscriptions extends M_Gateway { 
  2.  
  3. var $gateway = 'freesubscriptions'; 
  4. var $title = 'Free Subscriptions'; 
  5. var $issingle = true; 
  6.  
  7. var $defaultmessage = "<h2>Completed: Thank you for signing up</h2>\n<p>\nYour subscription to our site is now set up and you should be able to visit the members only content.\n</p>\n"; 
  8.  
  9. function freesubscriptions() { 
  10.  
  11. if(M_is_gateway_active('paypalsolo')) { 
  12. return; 
  13.  
  14. parent::M_Gateway(); 
  15.  
  16. add_action('M_gateways_settings_' . $this->gateway, array(&$this, 'mysettings')); 
  17.  
  18. // If I want to override the transactions output - then I can use this action 
  19. add_action('M_gateways_transactions_' . $this->gateway, array(&$this, 'mytransactions')); 
  20.  
  21. if($this->is_active()) { 
  22. // Subscription form gateway 
  23. add_action('membership_purchase_button', array(&$this, 'display_subscribe_button'), 1, 3); 
  24. add_filter( 'membership_subscription_form_subscription_process', array(&$this, 'signup_free_subscription'), 10, 2 ); 
  25.  
  26.  
  27.  
  28.  
  29. function mytransactions() { 
  30.  
  31. echo '<div class="tablenav">'; 
  32. echo '</div>'; 
  33.  
  34. echo "<p>" . __('No transactions data for the Free gateway', 'membership') . "</p>"; 
  35.  
  36. function mysettings() { 
  37.  
  38. ?> 
  39. <table class="form-table"> 
  40. <tbody> 
  41. <tr valign="top"> 
  42. <th scope="row"><?php _e('Subscription button', 'membership') ?></th> 
  43. <?php 
  44. $button = get_option( $this->gateway . "_payment_button", 'https://www.paypal.com/en_US/i/btn/btn_subscribe_LG.gif' ); 
  45. ?> 
  46. <td><input type="text" name="payment_button" value="<?php esc_attr_e($button); ?>" style='width: 40em;' /> 
  47. <br /> 
  48. </td> 
  49. </tr> 
  50.  
  51. </tbody> 
  52. </table> 
  53. <?php 
  54.  
  55. function build_custom($user_id, $sub_id, $amount) { 
  56.  
  57. $custom = ''; 
  58.  
  59. //fake:user:sub:key 
  60.  
  61. $custom = time() . ':' . $user_id . ':' . $sub_id . ':'; 
  62. $key = md5('MEMBERSHIP' . $amount); 
  63.  
  64. $custom .= $key; 
  65.  
  66. return $custom; 
  67.  
  68.  
  69. function not_yet_display_upgrade_button($subscription, $pricing, $user_id, $fromsub_id = false) { 
  70.  
  71. echo '<form class="upgradebutton" action="" method="post">'; 
  72. wp_nonce_field('upgrade-sub_' . $subscription->sub_id()); 
  73. echo "<input type='hidden' name='action' value='upgradefree' />"; 
  74. echo "<input type='hidden' name='gateway' value='" . $this->gateway . "' />"; 
  75. echo "<input type='hidden' name='subscription' value='" . $subscription->sub_id() . "' />"; 
  76. echo "<input type='hidden' name='user' value='" . $user_id . "' />"; 
  77. echo "<input type='hidden' name='fromsub_id' value='" . $fromsub_id . "' />"; 
  78. echo "<input type='submit' name='submit' value=' " . __('Upgrade', 'membership') . " ' />"; 
  79. echo "</form>"; 
  80.  
  81. function display_cancel_button($subscription, $pricing, $user_id) { 
  82.  
  83. echo '<form class="unsubbutton" action="" method="post">'; 
  84. wp_nonce_field('cancel-sub_' . $subscription->sub_id()); 
  85. echo "<input type='hidden' name='action' value='unsubscribe' />"; 
  86. echo "<input type='hidden' name='gateway' value='" . $this->gateway . "' />"; 
  87. echo "<input type='hidden' name='subscription' value='" . $subscription->sub_id() . "' />"; 
  88. echo "<input type='hidden' name='user' value='" . $user_id . "' />"; 
  89. echo "<input type='submit' name='submit' value=' " . __('Unsubscribe', 'membership') . " ' />"; 
  90. echo "</form>"; 
  91.  
  92. function signup_free_subscription($content, $error) { 
  93.  
  94. if(isset($_POST['custom'])) { 
  95. list($timestamp, $user_id, $sub_id, $key) = explode(':', $_POST['custom']); 
  96.  
  97. // create_subscription 
  98. $member = new M_Membership($user_id); 
  99. if($member) { 
  100. $member->create_subscription($sub_id, $this->gateway); 
  101.  
  102. do_action('membership_payment_subscr_signup', $user_id, $sub_id); 
  103.  
  104. $content .= '<div id="reg-form">'; // because we can't have an enclosing form for this part 
  105.  
  106. $content .= '<div class="formleft">'; 
  107.  
  108. $message = get_option( $this->gateway . "_completed_message", $this->defaultmessage ); 
  109. $content .= stripslashes($message); 
  110.  
  111. $content .= '</div>'; 
  112.  
  113. $content .= "</div>"; 
  114.  
  115. $content = apply_filters('membership_subscriptionform_signedup', $content, $user_id, $sub_id); 
  116.  
  117. return $content; 
  118.  
  119.  
  120. function single_free_button($pricing, $subscription, $user_id, $norepeat = false) { 
  121.  
  122. global $M_options; 
  123.  
  124. if(empty($M_options['paymentcurrency'])) { 
  125. $M_options['paymentcurrency'] = 'USD'; 
  126.  
  127. $form = ''; 
  128.  
  129. $form .= '<form action="' . M_get_returnurl_permalink() . '" method="post">'; 
  130. $form .= wp_nonce_field('free-sub_' . $subscription->sub_id(), "_wpnonce", true, false); 
  131. $form .= "<input type='hidden' name='gateway' value='" . $this->gateway . "' />"; 
  132. $form .= '<input type="hidden" name="action" value="subscriptionsignup" />'; 
  133. $form .= '<input type="hidden" name="custom" value="' . $this->build_custom($user_id, $subscription->id, '0') .'">'; 
  134.  
  135. $button = get_option( $this->gateway . "_payment_button", 'https://www.paypal.com/en_US/i/btn/btn_subscribe_LG.gif' ); 
  136.  
  137. $form .= '<input type="image" name="submit" border="0" src="' . $button . '" alt="PayPal - The safer, easier way to pay online">'; 
  138. $form .= '</form>'; 
  139.  
  140. return $form; 
  141.  
  142.  
  143. function build_subscribe_button($subscription, $pricing, $user_id) { 
  144.  
  145. if(!empty($pricing)) { 
  146.  
  147. $free = true; 
  148. foreach($pricing as $key => $price) { 
  149. if(!empty($price['amount']) && $price['amount'] > 0 ) { 
  150. $free = false; 
  151.  
  152. if($free) { 
  153. return $this->single_free_button($pricing, $subscription, $user_id, true); 
  154.  
  155.  
  156.  
  157. function display_subscribe_button($subscription, $pricing, $user_id) { 
  158.  
  159. echo $this->build_subscribe_button($subscription, $pricing, $user_id); 
  160.  
  161.  
  162. function display_upgrade_button($subscription, $pricing, $user_id, $fromsub_id = false) { 
  163.  
  164. echo '<form class="upgradebutton" action="' . M_get_subscription_permalink() . '" method="post">'; 
  165. wp_nonce_field('upgrade-sub_' . $subscription->sub_id()); 
  166. echo "<input type='hidden' name='action' value='upgradefromfree' />"; 
  167. echo "<input type='hidden' name='gateway' value='" . $this->gateway . "' />"; 
  168. echo "<input type='hidden' name='subscription' value='" . $subscription->sub_id() . "' />"; 
  169. echo "<input type='hidden' name='user' value='" . $user_id . "' />"; 
  170. echo "<input type='hidden' name='fromsub_id' value='" . $fromsub_id . "' />"; 
  171. echo "<input type='submit' name='submit' value=' " . __('Upgrade', 'membership') . " ' class='button blue' />"; 
  172. echo "</form>"; 
  173.  
  174. function display_upgrade_from_free_button($subscription, $pricing, $user_id, $fromsub_id = false) { 
  175. if($pricing[0]['amount'] < 1) { 
  176. // a free first level 
  177. $this->display_upgrade_button($subscription, $pricing, $user_id, $fromsub_id); 
  178. } else { 
  179. //do_action('membership_purchase_button', $subscription, $pricing, $user_id); 
  180. echo "<form class=''>"; 
  181. echo "<input type='submit' value=' " . __('Upgrades not available', 'membership') . " ' disabled='disabled' class='button blue' />"; 
  182. echo "</form>"; 
  183.  
  184.  
  185. function update() { 
  186.  
  187. if(isset($_POST['payment_button'])) { 
  188. update_option( $this->gateway . "_payment_button", $_POST[ 'payment_button' ] ); 
  189. update_option( $this->gateway . "_completed_message", $_POST[ 'completed_message' ] ); 
  190.  
  191. // default action is to return true 
  192. return true; 
  193.  
  194.  
  195. // IPN stuff 
  196. function handle_paypal_return() { 
  197. // PayPal IPN handling code 
  198.  
  199.