PMProGateway

The Paid Memberships Pro PMProGateway class.

Defined (1)

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

/classes/gateways/class.pmprogateway.php  
  1. class PMProGateway 
  2. function __construct($gateway = NULL) 
  3. $this->gateway = $gateway; 
  4. return $this->gateway; 
  5. }  
  6.  
  7. function process(&$order) 
  8. //check for initial payment 
  9. if(floatval($order->InitialPayment) == 0) 
  10. //auth first, then process 
  11. if($this->authorize($order)) 
  12. {  
  13. $this->void($order);  
  14. if(!pmpro_isLevelTrial($order->membership_level)) 
  15. //subscription will start today with a 1 period trial 
  16. $order->ProfileStartDate = date_i18n("Y-m-d") . "T0:0:0"; 
  17. $order->TrialBillingPeriod = $order->BillingPeriod; 
  18. $order->TrialBillingFrequency = $order->BillingFrequency;  
  19. $order->TrialBillingCycles = 1; 
  20. $order->TrialAmount = 0; 
  21.  
  22. //add a billing cycle to make up for the trial, if applicable 
  23. if(!empty($order->TotalBillingCycles)) 
  24. $order->TotalBillingCycles++; 
  25. elseif($order->InitialPayment == 0 && $order->TrialAmount == 0) 
  26. //it has a trial, but the amount is the same as the initial payment, so we can squeeze it in there 
  27. $order->ProfileStartDate = date_i18n("Y-m-d") . "T0:0:0";  
  28. $order->TrialBillingCycles++; 
  29.  
  30. //add a billing cycle to make up for the trial, if applicable 
  31. if($order->TotalBillingCycles) 
  32. $order->TotalBillingCycles++; 
  33. else 
  34. //add a period to the start date to account for the initial payment 
  35. $order->ProfileStartDate = date_i18n("Y-m-d", strtotime("+ " . $order->BillingFrequency . " " . $order->BillingPeriod, current_time("timestamp"))) . "T0:0:0"; 
  36.  
  37. $order->ProfileStartDate = apply_filters("pmpro_profile_start_date", $order->ProfileStartDate, $order); 
  38. return $this->subscribe($order); 
  39. else 
  40. if(empty($order->error)) 
  41. $order->error = __("Unknown error: Authorization failed.", 'paid-memberships-pro' ); 
  42. return false; 
  43. else 
  44. //charge first payment 
  45. if($this->charge($order)) 
  46. {  
  47. //set up recurring billing  
  48. if(pmpro_isLevelRecurring($order->membership_level)) 
  49. {  
  50. if(!pmpro_isLevelTrial($order->membership_level)) 
  51. //subscription will start today with a 1 period trial 
  52. $order->ProfileStartDate = date_i18n("Y-m-d") . "T0:0:0"; 
  53. $order->TrialBillingPeriod = $order->BillingPeriod; 
  54. $order->TrialBillingFrequency = $order->BillingFrequency;  
  55. $order->TrialBillingCycles = 1; 
  56. $order->TrialAmount = 0; 
  57.  
  58. //add a billing cycle to make up for the trial, if applicable 
  59. if(!empty($order->TotalBillingCycles)) 
  60. $order->TotalBillingCycles++; 
  61. elseif($order->InitialPayment == 0 && $order->TrialAmount == 0) 
  62. //it has a trial, but the amount is the same as the initial payment, so we can squeeze it in there 
  63. $order->ProfileStartDate = date_i18n("Y-m-d") . "T0:0:0";  
  64. $order->TrialBillingCycles++; 
  65.  
  66. //add a billing cycle to make up for the trial, if applicable 
  67. if(!empty($order->TotalBillingCycles)) 
  68. $order->TotalBillingCycles++; 
  69. else 
  70. //add a period to the start date to account for the initial payment 
  71. $order->ProfileStartDate = date_i18n("Y-m-d", strtotime("+ " . $this->BillingFrequency . " " . $this->BillingPeriod, current_time("timestamp"))) . "T0:0:0"; 
  72.  
  73. $order->ProfileStartDate = apply_filters("pmpro_profile_start_date", $order->ProfileStartDate, $order); 
  74. if($this->subscribe($order)) 
  75. return true; 
  76. else 
  77. if($this->void($order)) 
  78. if(!$order->error) 
  79. $order->error = __("Unknown error: Payment failed.", 'paid-memberships-pro' ); 
  80. else 
  81. if(!$order->error) 
  82. $order->error = __("Unknown error: Payment failed.", 'paid-memberships-pro' ); 
  83.  
  84. $order->error .= " " . __("A partial payment was made that we could not void. Please contact the site owner immediately to correct this.", 'paid-memberships-pro' ); 
  85.  
  86. return false;  
  87. else 
  88. //only a one time charge 
  89. $order->status = "success"; //saved on checkout page  
  90. return true; 
  91. else 
  92. if(empty($order->error)) 
  93. $order->error = __("Unknown error: Payment failed.", 'paid-memberships-pro' ); 
  94.  
  95. return false; 
  96. }  
  97. }  
  98.  
  99. function authorize(&$order) 
  100. //create a code for the order 
  101. if(empty($order->code)) 
  102. $order->code = $order->getRandomCode(); 
  103.  
  104. //simulate a successful authorization 
  105. $order->payment_transaction_id = "TEST" . $order->code; 
  106. $order->updateStatus("authorized");  
  107. return true;  
  108.  
  109. function void(&$order) 
  110. //need a transaction id 
  111. if(empty($order->payment_transaction_id)) 
  112. return false; 
  113.  
  114. //simulate a successful void 
  115. $order->payment_transaction_id = "TEST" . $order->code; 
  116. $order->updateStatus("voided");  
  117. return true; 
  118. }  
  119.  
  120. function charge(&$order) 
  121. //create a code for the order 
  122. if(empty($order->code)) 
  123. $order->code = $order->getRandomCode(); 
  124.  
  125. //simulate a successful charge 
  126. $order->payment_transaction_id = "TEST" . $order->code; 
  127. $order->updateStatus("success");  
  128. return true;  
  129.  
  130. function subscribe(&$order) 
  131. //create a code for the order 
  132. if(empty($order->code)) 
  133. $order->code = $order->getRandomCode(); 
  134.  
  135. //filter order before subscription. use with care. 
  136. $order = apply_filters("pmpro_subscribe_order", $order, $this); 
  137.  
  138. //simulate a successful subscription processing 
  139. $order->status = "success";  
  140. $order->subscription_transaction_id = "TEST" . $order->code;  
  141. return true; 
  142. }  
  143.  
  144. function update(&$order) 
  145. //simulate a successful billing update 
  146. return true; 
  147.  
  148. function cancel(&$order) 
  149. //require a subscription id 
  150. if(empty($order->subscription_transaction_id)) 
  151. return false; 
  152.  
  153. //simulate a successful cancel  
  154. $order->updateStatus("cancelled");  
  155. return true; 
  156. }  
  157.  
  158. function getSubscriptionStatus(&$order) 
  159. //require a subscription id 
  160. if(empty($order->subscription_transaction_id)) 
  161. return false; 
  162.  
  163. //this looks different for each gateway, but generally an array of some sort 
  164. return array(); 
  165.  
  166. function getTransactionStatus(&$order) 
  167. {  
  168. //this looks different for each gateway, but generally an array of some sort 
  169. return array();