GFPaystationFeed

The Gravity Forms Paystation (3 party hosted) GFPaystationFeed class.

Defined (1)

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

/class.GFPaystationFeed.php  
  1. class GFPaystationFeed { 
  2.  
  3. public $ID; // unique ID for feed, same as post ID 
  4. public $FeedName; // name of feed, same as post_title 
  5. public $FormID; // ID of form in Gravity Forms 
  6. public $DelayPost; // boolean: create post only when payment is received 
  7. public $DelayNotify; // boolean: send admin notification only when payment is received 
  8. public $DelayAutorespond; // boolean: send user notification only when payment is received 
  9. public $IsEnabled; // boolean: is this feed enabled? 
  10.  
  11. // fields set in admin 
  12. public $UrlFail; // URL to redirect to on transaction failure 
  13. public $Opt; // optional timeout data, TO=yymmddHHmm 
  14.  
  15. // field mappings to GF form 
  16. public $MerchantReference; // merchant reference 
  17. public $CustomerDetails; // optional string of up to 255 chars. 
  18. public $OrderDetails; // optional string of up to 255 chars. 
  19. public $PaystationOverrideId; 
  20.  
  21. protected static $fieldMap = array ( 
  22. 'FormID' => '_gfpaystation_form',  
  23. 'UrlFail' => '_gfpaystation_url_fail',  
  24. 'MerchantReference' => '_gfpaystation_merchant_ref',  
  25. 'CustomerDetails' => '_gfpaystation_customer_details',  
  26. 'OrderDetails' => '_gfpaystation_order_details',  
  27. 'PaystationOverrideId' => '_gfpaystation_override_id',  
  28. 'Opt' => '_gfpaystation_opt',  
  29. 'DelayPost' => '_gfpaystation_delay_post',  
  30. 'DelayNotify' => '_gfpaystation_delay_notify',  
  31. 'DelayAutorespond' => '_gfpaystation_delay_autorespond',  
  32. ); 
  33.  
  34. // ==================================================================================================================================== 
  35. /** 
  36. * Constructor. 
  37. * @param integer $ID unique ID of feed, or NULL to create an empty object initialised to sensible defaults 
  38. */ 
  39. // ==================================================================================================================================== 
  40. public function __construct($ID = NULL) { 
  41. if (is_null($ID)) { 
  42. $this->ID = 0; 
  43. $this->IsEnabled = TRUE; 
  44. return; 
  45.  
  46. $post = get_post($ID); 
  47. if ($post) { 
  48. $this->loadFromPost($post); 
  49. else { 
  50. throw new GFPaystationException(__CLASS__ . ": can't load feed: $ID"); 
  51.  
  52. // ==================================================================================================================================== 
  53. /** 
  54. * load feed from WordPress post object 
  55. * @param WP_Post $post 
  56. */ 
  57. // ==================================================================================================================================== 
  58. public function loadFromPost($post) { 
  59. // sanity check -- is it a wine pages feed? 
  60. if ($post->post_type != GFPAYSTATION_TYPE_FEED) { 
  61. throw new GFPaystationException(__CLASS__ . ": post is not a Paystation feed: {$post->ID}"); 
  62.  
  63. $this->ID = $post->ID; 
  64. $this->FeedName = $post->post_title; 
  65. $this->IsEnabled = ($post->post_status == 'publish'); 
  66.  
  67. $meta = get_post_meta($post->ID); 
  68.  
  69. foreach (self::$fieldMap as $name => $metaname) { 
  70. $this->$name = self::metaValue($meta, $metaname); 
  71.  
  72. // ==================================================================================================================================== 
  73. /** 
  74. * get single value from meta array 
  75. * @param array $meta 
  76. * @param string $key 
  77. * @return mixed 
  78. */ 
  79. // ==================================================================================================================================== 
  80. protected static function metaValue($meta, $key) { 
  81. return (isset($meta[$key][0])) ? $meta[$key][0] : false; 
  82.  
  83. // ==================================================================================================================================== 
  84. /** 
  85. * get inverse map of GF fields to feed fields 
  86. * @return array 
  87. */ 
  88. // ==================================================================================================================================== 
  89. public function getGfFieldMap() { 
  90. $map = array(); 
  91.  
  92. foreach (array('MerchantReference', 'CustomerDetails', 'OrderDetails', 'PaystationOverrideId') as $feedName) { 
  93. if (!empty($this->$feedName)) { 
  94. $map[(string) $this->$feedName] = $feedName; 
  95.  
  96. return $map; 
  97.  
  98. // ==================================================================================================================================== 
  99. /** 
  100. * list all feeds 
  101. * @return array(WpWinePagesProduct) 
  102. */ 
  103. // ==================================================================================================================================== 
  104. public static function getList() { 
  105. $feeds = array(); 
  106.  
  107. $args = array ( 
  108. 'post_type' => GFPAYSTATION_TYPE_FEED,  
  109. 'orderby' => 'menu_order',  
  110. 'order' => 'ASC',  
  111. 'posts_per_page' => -1,  
  112. ); 
  113.  
  114. $posts = get_posts($args); 
  115.  
  116. if ($posts) { 
  117. try { 
  118. foreach ($posts as $post) { 
  119. $feed = new self(); 
  120. $feed->loadFromPost($post); 
  121. $feeds[] = $feed; 
  122. catch (GFPaystationException $e) { 
  123. $feeds = false; 
  124.  
  125. return $feeds; 
  126.  
  127. // ==================================================================================================================================== 
  128. /** 
  129. * get feed for GF form, by form ID 
  130. * @param int $formID 
  131. * @return self 
  132. */ 
  133. // ==================================================================================================================================== 
  134. public static function getFormFeed($formID) { 
  135. if (!$formID) { 
  136. throw new GFPaystationException(__METHOD__ . ": must give form ID"); 
  137.  
  138. $posts = get_posts(array ( 
  139. 'post_type' => GFPAYSTATION_TYPE_FEED,  
  140. 'orderby' => 'menu_order',  
  141. 'order' => 'ASC',  
  142. 'posts_per_page' => 1,  
  143. 'meta_key' => '_gfpaystation_form',  
  144. 'meta_value' => $formID,  
  145. )); 
  146.  
  147. if ($posts && count($posts) > 0) { 
  148. try { 
  149. $feed = new self(); 
  150. $feed->loadFromPost($posts[0]); 
  151. catch (GFPaystationException $e) { 
  152. $feed = false; 
  153. else { 
  154. $feed = false; 
  155.  
  156. return $feed;