WC_QuickPay_API_Transaction

WC_QuickPay_API_Transaction class.

Defined (1)

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

/classes/api/woocommerce-quickpay-api-transaction.php  
  1. class WC_QuickPay_API_Transaction extends WC_QuickPay_API 
  2. /** 
  3. * get_current_type function. 
  4. *  
  5. * Returns the current payment type 
  6. * @access public 
  7. * @return void 
  8. */  
  9. public function get_current_type()  
  10. $last_operation = $this->get_last_operation(); 
  11.  
  12. if( ! is_object( $last_operation ) )  
  13. throw new QuickPay_API_Exception( "Malformed operation response", 0 );  
  14.  
  15. return $last_operation->type; 
  16.  
  17.  
  18. /** 
  19. * get_last_operation function. 
  20. *  
  21. * Returns the last successful transaction operation 
  22. * @access public 
  23. * @return void 
  24. * @throws QuickPay_API_Exception 
  25. */  
  26. public function get_last_operation()  
  27. if( ! is_object( $this->resource_data ) )  
  28. throw new QuickPay_API_Exception( 'No API payment resource data available.', 0 ); 
  29.  
  30. // Loop through all the operations and return only the operations that were successful (based on the qp_status_code and pending mode). 
  31. $successful_operations = array_filter($this->resource_data->operations, function( $operation ) { 
  32. return $operation->qp_status_code == 20000 || $operation->pending == TRUE; 
  33. } ); 
  34.  
  35. $last_operation = end( $successful_operations ); 
  36.  
  37. if( $last_operation->pending == TRUE ) { 
  38. $last_operation->type = __( 'Pending - check your QuickPay manager', 'woo-quickpay' );  
  39.  
  40. return $last_operation; 
  41.  
  42.  
  43. /** 
  44. * is_test function. 
  45. *  
  46. * Tests if a payment was made in test mode. 
  47. * @access public 
  48. * @return boolean 
  49. * @throws QuickPay_API_Exception 
  50. */  
  51. public function is_test()  
  52. if( ! is_object( $this->resource_data ) ) { 
  53. throw new QuickPay_API_Exception( 'No API payment resource data available.', 0 ); 
  54.  
  55. return $this->resource_data->test_mode; 
  56.  
  57. /** 
  58. * create function. 
  59. *  
  60. * Creates a new payment via the API 
  61. * @access public 
  62. * @param WC_QuickPay_Order $order 
  63. * @return object 
  64. * @throws QuickPay_API_Exception 
  65. */  
  66. public function create( WC_QuickPay_Order $order )  
  67. $base_params = array( 
  68. 'currency' => WC_QP()->get_gateway_currency( $order ),  
  69. 'order_post_id' => version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(),  
  70. ); 
  71.  
  72. $text_on_statement = WC_QP()->s('quickpay_text_on_statement'); 
  73. if (!empty($text_on_statement)) { 
  74. $base_params['text_on_statement'] = $text_on_statement; 
  75.  
  76. $order_params = $order->get_transaction_params(); 
  77.  
  78. $params = array_merge( $base_params, $order_params ); 
  79.  
  80. $payment = $this->post( '/', $params); 
  81.  
  82. return $payment; 
  83. }  
  84.  
  85.  
  86. /** 
  87. * create_link function. 
  88. *  
  89. * Creates or updates a payment link via the API 
  90. * @since 4.5.0  
  91. * @access public 
  92. * @param int $transaction_id 
  93. * @param WC_QuickPay_Order $order 
  94. * @return object 
  95. * @throws QuickPay_API_Exception 
  96. */  
  97. public function patch_link($transaction_id, WC_QuickPay_Order $order )  
  98. {  
  99. $cardtypelock = WC_QP()->s( 'quickpay_cardtypelock' ); 
  100.  
  101. $payment_method = strtolower(version_compare( WC_VERSION, '3.0', '<' ) ? $order->payment_method : $order->get_payment_method()); 
  102.  
  103. $base_params = array( 
  104. 'language' => WC_QP()->get_gateway_language(),  
  105. 'currency' => WC_QP()->get_gateway_currency( $order ),  
  106. 'callbackurl' => WC_QuickPay_Helper::get_callback_url(),  
  107. 'autocapture' => WC_QuickPay_Helper::option_is_enabled( $order->get_autocapture_setting() ),  
  108. 'autofee' => WC_QuickPay_Helper::option_is_enabled( WC_QP()->s( 'quickpay_autofee' ) ),  
  109. 'payment_methods' => apply_filters('woocommerce_quickpay_cardtypelock_' . $payment_method, $cardtypelock, $payment_method),  
  110. 'branding_id' => WC_QP()->s( 'quickpay_branding_id' ),  
  111. 'google_analytics_tracking_id' => WC_QP()->s( 'quickpay_google_analytics_tracking_id' ),  
  112. 'customer_email' => version_compare( WC_VERSION, '3.0', '<' ) ? $order->billing_email : $order->get_billing_email(),  
  113. ); 
  114.  
  115. $order_params = $order->get_transaction_link_params(); 
  116.  
  117. $merged_params = array_merge( $base_params, $order_params ); 
  118.  
  119. $params = apply_filters( 'woocommerce_quickpay_transaction_link_params', $merged_params, $order, $payment_method ); 
  120.  
  121. $payment_link = $this->put( sprintf( '%d/link', $transaction_id ), $params); 
  122.  
  123. return $payment_link; 
  124.  
  125.  
  126. /** 
  127. * get_cardtype function 
  128. *  
  129. * Returns the payment type / card type used on the transaction 
  130. * @since 4.5.0 
  131. * @return mixed 
  132. * @throws QuickPay_API_Exception 
  133. */ 
  134. public function get_brand() { 
  135. if( ! is_object( $this->resource_data ) ) 
  136. throw new QuickPay_API_Exception( 'No API payment resource data available.', 0 ); 
  137. return $this->resource_data->metadata->brand; 
  138.  
  139. /** 
  140. * get_balance function 
  141. * Returns the transaction balance 
  142. * @since 4.5.0 
  143. * @return mixed 
  144. * @throws QuickPay_API_Exception 
  145. */ 
  146. public function get_balance() { 
  147. if( ! is_object( $this->resource_data ) ) 
  148. throw new QuickPay_API_Exception( 'No API payment resource data available.', 0 ); 
  149. return ! empty($this->resource_data->balance) ? $this->resource_data->balance : NULL; 
  150.  
  151. /** 
  152. * get_formatted_balance function 
  153. * Returns a formatted transaction balance 
  154. * @since 4.5.0 
  155. * @return mixed 
  156. * @throws QuickPay_API_Exception 
  157. */  
  158. public function get_formatted_balance() { 
  159. return WC_QuickPay_Helper::price_normalize( $this->get_balance() ); 
  160.  
  161. /** 
  162. * get_currency function 
  163. * Returns a transaction currency 
  164. * @since 4.5.0 
  165. * @return mixed 
  166. * @throws QuickPay_API_Exception 
  167. */ 
  168. public function get_currency() { 
  169. if( ! is_object( $this->resource_data ) ) 
  170. throw new QuickPay_API_Exception( 'No API payment resource data available.', 0 ); 
  171. return $this->resource_data->currency; 
  172.  
  173. /** 
  174. * get_remaining_balance function 
  175. * Returns a remaining balance 
  176. * @since 4.5.0 
  177. * @return mixed 
  178. * @throws QuickPay_API_Exception 
  179. */  
  180. public function get_remaining_balance() { 
  181. $balance = $this->get_balance(); 
  182.  
  183. $authorized_operations = array_filter($this->resource_data->operations, function($operation) { 
  184. return 'authorize' === $operation->type; 
  185. }); 
  186.  
  187. if ( empty( $authorized_operations ) ) { 
  188. return; 
  189.  
  190. $operation = reset($authorized_operations); 
  191.  
  192. $amount = $operation->amount; 
  193.  
  194. $remaining = $amount; 
  195.  
  196. if ($balance > 0) { 
  197. $remaining = $amount - $balance; 
  198.  
  199. return $remaining; 
  200.  
  201. /** 
  202. * get_formatted_remaining_balance function 
  203. * Returns a formatted transaction balance 
  204. * @since 4.5.0 
  205. * @return mixed 
  206. * @throws QuickPay_API_Exception 
  207. */ 
  208. public function get_formatted_remaining_balance() { 
  209. return WC_QuickPay_Helper::price_normalize( $this->get_remaining_balance() ); 
  210.  
  211. /** 
  212. * Checks if either a specific operation or the last operation was successful. 
  213. * @param null $operation 
  214. * @return bool 
  215. * @since 4.5.0 
  216. * @throws QuickPay_API_Exception 
  217. */ 
  218. public function is_operation_approved( $operation = NULL ) { 
  219. if( ! is_object( $this->resource_data ) ) 
  220. throw new QuickPay_API_Exception( 'No API payment resource data available.', 0 ); 
  221.  
  222. if( $operation === NULL ) { 
  223. $operation = $this->get_last_operation(); 
  224.  
  225. return $this->resource_data->accepted && $operation->qp_status_code == 20000 && $operation->aq_status_code == 20000; 
  226.  
  227. /** 
  228. * get_metadata function 
  229. * Returns the metadata of a transaction 
  230. * @since 4.5.0 
  231. * @return mixed 
  232. * @throws QuickPay_API_Exception 
  233. */ 
  234. public function get_metadata() { 
  235. if( ! is_object( $this->resource_data ) ) 
  236. throw new QuickPay_API_Exception( 'No API payment resource data available.', 0 ); 
  237. return $this->resource_data->metadata; 
  238.  
  239. /** 
  240. * get_state function 
  241. * Returns the current transaction state 
  242. * @since 4.5.0 
  243. * @return mixed 
  244. * @throws QuickPay_API_Exception 
  245. */ 
  246. public function get_state() { 
  247. if( ! is_object( $this->resource_data ) ) 
  248. throw new QuickPay_API_Exception( 'No API payment resource data available.', 0 ); 
  249. return $this->resource_data->state;