PMProGateway_check

The Paid Memberships Pro PMProGateway check class.

Defined (1)

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

/classes/gateways/class.pmprogateway_check.php  
  1. class PMProGateway_check extends PMProGateway 
  2. function __construct($gateway = NULL) 
  3. $this->gateway = $gateway; 
  4. return $this->gateway; 
  5. }  
  6.  
  7. /** 
  8. * Run on WP init 
  9. *  
  10. * @since 1.8 
  11. */ 
  12. static function init() 
  13. {  
  14. //make sure Pay by Check is a gateway option 
  15. add_filter('pmpro_gateways', array('PMProGateway_check', 'pmpro_gateways')); 
  16.  
  17. //add fields to payment settings 
  18. add_filter('pmpro_payment_options', array('PMProGateway_check', 'pmpro_payment_options')); 
  19. add_filter('pmpro_payment_option_fields', array('PMProGateway_check', 'pmpro_payment_option_fields'), 10, 2); 
  20. add_filter('pmpro_checkout_after_payment_information_fields', array('PMProGateway_check', 'pmpro_checkout_after_payment_information_fields')); 
  21.  
  22. //code to add at checkout 
  23. $gateway = pmpro_getGateway(); 
  24. if($gateway == "check") 
  25. add_filter('pmpro_include_billing_address_fields', '__return_false'); 
  26. add_filter('pmpro_include_payment_information_fields', '__return_false'); 
  27. add_filter('pmpro_required_billing_fields', array('PMProGateway_check', 'pmpro_required_billing_fields')); 
  28.  
  29. /** 
  30. * Make sure Check is in the gateways list 
  31. *  
  32. * @since 1.8 
  33. */ 
  34. static function pmpro_gateways($gateways) 
  35. if(empty($gateways['check'])) 
  36. $gateways['check'] = __('Pay by Check', 'paid-memberships-pro' ); 
  37.  
  38. return $gateways; 
  39.  
  40. /** 
  41. * Get a list of payment options that the Check gateway needs/supports. 
  42. *  
  43. * @since 1.8 
  44. */ 
  45. static function getGatewayOptions() 
  46. {  
  47. $options = array( 
  48. 'sslseal',  
  49. 'nuclear_HTTPS',  
  50. 'gateway_environment',  
  51. 'instructions',  
  52. 'currency',  
  53. 'use_ssl',  
  54. 'tax_state',  
  55. 'tax_rate' 
  56. ); 
  57.  
  58. return $options; 
  59.  
  60. /** 
  61. * Set payment options for payment settings page. 
  62. *  
  63. * @since 1.8 
  64. */ 
  65. static function pmpro_payment_options($options) 
  66. {  
  67. //get stripe options 
  68. $check_options = PMProGateway_check::getGatewayOptions(); 
  69.  
  70. //merge with others. 
  71. $options = array_merge($check_options, $options); 
  72.  
  73. return $options; 
  74.  
  75. /** 
  76. * Display fields for Check options. 
  77. *  
  78. * @since 1.8 
  79. */ 
  80. static function pmpro_payment_option_fields($values, $gateway) 
  81. ?> 
  82. <tr class="pmpro_settings_divider gateway gateway_check" <?php if($gateway != "check") { ?>style="display: none;"<?php } ?>> 
  83. <td colspan="2"> 
  84. <?php _e('Pay by Check Settings', 'paid-memberships-pro' ); ?> 
  85. </td> 
  86. </tr> 
  87. <tr class="gateway gateway_check" <?php if($gateway != "check") { ?>style="display: none;"<?php } ?>> 
  88. <th scope="row" valign="top"> 
  89. <label for="instructions"><?php _e('Instructions', 'paid-memberships-pro' );?></label>  
  90. </th> 
  91. <td> 
  92. <textarea id="instructions" name="instructions" rows="3" cols="80"><?php echo esc_textarea($values['instructions'])?></textarea> 
  93. <p><small><?php _e('Who to write the check out to. Where to mail it. Shown on checkout, confirmation, and invoice pages.', 'paid-memberships-pro' );?></small></p> 
  94. </td> 
  95. </tr>  
  96. <?php 
  97.  
  98. /** 
  99. * Remove required billing fields 
  100. *  
  101. * @since 1.8 
  102. */ 
  103. static function pmpro_required_billing_fields($fields) 
  104. unset($fields['bfirstname']); 
  105. unset($fields['blastname']); 
  106. unset($fields['baddress1']); 
  107. unset($fields['bcity']); 
  108. unset($fields['bstate']); 
  109. unset($fields['bzipcode']); 
  110. unset($fields['bphone']); 
  111. unset($fields['bemail']); 
  112. unset($fields['bcountry']); 
  113. unset($fields['CardType']); 
  114. unset($fields['AccountNumber']); 
  115. unset($fields['ExpirationMonth']); 
  116. unset($fields['ExpirationYear']); 
  117. unset($fields['CVV']); 
  118.  
  119. return $fields; 
  120.  
  121. /** 
  122. * Show instructions on checkout page 
  123. * Moved here from pages/checkout.php 
  124. * @since 1.8.9.3 
  125. */ 
  126. static function pmpro_checkout_after_payment_information_fields() { 
  127. global $gateway; 
  128. global $pmpro_level; 
  129.  
  130. if($gateway == "check" && !pmpro_isLevelFree($pmpro_level)) { 
  131. $instructions = pmpro_getOption("instructions"); 
  132. echo '<div class="pmpro_check_instructions">' . wpautop($instructions) . '</div>'; 
  133.  
  134.  
  135. /** 
  136. * Process checkout. 
  137. */ 
  138. function process(&$order) 
  139. //clean up a couple values 
  140. $order->payment_type = "Check"; 
  141. $order->CardType = ""; 
  142. $order->cardtype = ""; 
  143.  
  144. //check for initial payment 
  145. if(floatval($order->InitialPayment) == 0) 
  146. //auth first, then process 
  147. if($this->authorize($order)) 
  148. {  
  149. $this->void($order);  
  150. if(!pmpro_isLevelTrial($order->membership_level)) 
  151. //subscription will start today with a 1 period trial 
  152. $order->ProfileStartDate = date_i18n("Y-m-d") . "T0:0:0"; 
  153. $order->TrialBillingPeriod = $order->BillingPeriod; 
  154. $order->TrialBillingFrequency = $order->BillingFrequency;  
  155. $order->TrialBillingCycles = 1; 
  156. $order->TrialAmount = 0; 
  157.  
  158. //add a billing cycle to make up for the trial, if applicable 
  159. if(!empty($order->TotalBillingCycles)) 
  160. $order->TotalBillingCycles++; 
  161. elseif($order->InitialPayment == 0 && $order->TrialAmount == 0) 
  162. //it has a trial, but the amount is the same as the initial payment, so we can squeeze it in there 
  163. $order->ProfileStartDate = date_i18n("Y-m-d") . "T0:0:0";  
  164. $order->TrialBillingCycles++; 
  165.  
  166. //add a billing cycle to make up for the trial, if applicable 
  167. if($order->TotalBillingCycles) 
  168. $order->TotalBillingCycles++; 
  169. else 
  170. //add a period to the start date to account for the initial payment 
  171. $order->ProfileStartDate = date_i18n("Y-m-d", strtotime("+ " . $order->BillingFrequency . " " . $order->BillingPeriod, current_time("timestamp"))) . "T0:0:0"; 
  172.  
  173. $order->ProfileStartDate = apply_filters("pmpro_profile_start_date", $order->ProfileStartDate, $order); 
  174. return $this->subscribe($order); 
  175. else 
  176. if(empty($order->error)) 
  177. $order->error = __("Unknown error: Authorization failed.", 'paid-memberships-pro' ); 
  178. return false; 
  179. else 
  180. //charge first payment 
  181. if($this->charge($order)) 
  182. {  
  183. //set up recurring billing  
  184. if(pmpro_isLevelRecurring($order->membership_level)) 
  185. {  
  186. if(!pmpro_isLevelTrial($order->membership_level)) 
  187. //subscription will start today with a 1 period trial 
  188. $order->ProfileStartDate = date_i18n("Y-m-d") . "T0:0:0"; 
  189. $order->TrialBillingPeriod = $order->BillingPeriod; 
  190. $order->TrialBillingFrequency = $order->BillingFrequency;  
  191. $order->TrialBillingCycles = 1; 
  192. $order->TrialAmount = 0; 
  193.  
  194. //add a billing cycle to make up for the trial, if applicable 
  195. if(!empty($order->TotalBillingCycles)) 
  196. $order->TotalBillingCycles++; 
  197. elseif($order->InitialPayment == 0 && $order->TrialAmount == 0) 
  198. //it has a trial, but the amount is the same as the initial payment, so we can squeeze it in there 
  199. $order->ProfileStartDate = date_i18n("Y-m-d") . "T0:0:0";  
  200. $order->TrialBillingCycles++; 
  201.  
  202. //add a billing cycle to make up for the trial, if applicable 
  203. if(!empty($order->TotalBillingCycles)) 
  204. $order->TotalBillingCycles++; 
  205. else 
  206. //add a period to the start date to account for the initial payment 
  207. $order->ProfileStartDate = date_i18n("Y-m-d", strtotime("+ " . $this->BillingFrequency . " " . $this->BillingPeriod, current_time("timestamp"))) . "T0:0:0"; 
  208.  
  209. $order->ProfileStartDate = apply_filters("pmpro_profile_start_date", $order->ProfileStartDate, $order); 
  210. if($this->subscribe($order)) 
  211. $order->status = apply_filters("pmpro_check_status_after_checkout", "success"); //saved on checkout page  
  212. return true; 
  213. else 
  214. if($this->void($order)) 
  215. if(!$order->error) 
  216. $order->error = __("Unknown error: Payment failed.", 'paid-memberships-pro' ); 
  217. else 
  218. if(!$order->error) 
  219. $order->error = __("Unknown error: Payment failed.", 'paid-memberships-pro' ); 
  220.  
  221. $order->error .= " " . __("A partial payment was made that we could not void. Please contact the site owner immediately to correct this.", 'paid-memberships-pro' ); 
  222.  
  223. return false;  
  224. else 
  225. //only a one time charge 
  226. $order->status = apply_filters("pmpro_check_status_after_checkout", "success"); //saved on checkout page  
  227. return true; 
  228. else 
  229. if(empty($order->error)) 
  230. $order->error = __("Unknown error: Payment failed.", 'paid-memberships-pro' ); 
  231.  
  232. return false; 
  233. }  
  234. }  
  235.  
  236. function authorize(&$order) 
  237. //create a code for the order 
  238. if(empty($order->code)) 
  239. $order->code = $order->getRandomCode(); 
  240.  
  241. //simulate a successful authorization 
  242. $order->payment_transaction_id = "CHECK" . $order->code; 
  243. $order->updateStatus("authorized");  
  244. return true;  
  245.  
  246. function void(&$order) 
  247. //need a transaction id 
  248. if(empty($order->payment_transaction_id)) 
  249. return false; 
  250.  
  251. //simulate a successful void 
  252. $order->payment_transaction_id = "CHECK" . $order->code; 
  253. $order->updateStatus("voided");  
  254. return true; 
  255. }  
  256.  
  257. function charge(&$order) 
  258. //create a code for the order 
  259. if(empty($order->code)) 
  260. $order->code = $order->getRandomCode(); 
  261.  
  262. //simulate a successful charge 
  263. $order->payment_transaction_id = "CHECK" . $order->code; 
  264. $order->updateStatus("success");  
  265. return true;  
  266.  
  267. function subscribe(&$order) 
  268. //create a code for the order 
  269. if(empty($order->code)) 
  270. $order->code = $order->getRandomCode(); 
  271.  
  272. //filter order before subscription. use with care. 
  273. $order = apply_filters("pmpro_subscribe_order", $order, $this); 
  274.  
  275. //simulate a successful subscription processing 
  276. $order->status = "success";  
  277. $order->subscription_transaction_id = "CHECK" . $order->code;  
  278. return true; 
  279. }  
  280.  
  281. function update(&$order) 
  282. //simulate a successful billing update 
  283. return true; 
  284.  
  285. function cancel(&$order) 
  286. //require a subscription id 
  287. if(empty($order->subscription_transaction_id)) 
  288. return false; 
  289.  
  290. //simulate a successful cancel  
  291. $order->updateStatus("cancelled");  
  292. return true; 
  293. }