WC_QuickPay_API_Payment

WC_QuickPay_API_Payment class.

Defined (1)

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

/classes/api/woocommerce-quickpay-api-payment.php  
  1. class WC_QuickPay_API_Payment extends WC_QuickPay_API_Transaction 
  2. /** 
  3. * __construct function. 
  4. * @access public 
  5. * @return void 
  6. */  
  7. public function __construct( $resource_data = NULL )  
  8. // Run the parent construct 
  9. parent::__construct(); 
  10.  
  11. // Set the resource data to an object passed in on object instantiation. 
  12. // Usually done when we want to perform actions on an object returned from  
  13. // the API sent to the plugin callback handler. 
  14. if( is_object( $resource_data ) )  
  15. $this->resource_data = $resource_data; 
  16.  
  17. // Append the main API url 
  18. $this->api_url = $this->api_url . 'payments/'; 
  19.  
  20.  
  21. /** 
  22. * create function. 
  23. *  
  24. * Creates a new payment via the API 
  25. * @access public 
  26. * @param WC_QuickPay_Order $order 
  27. * @return object 
  28. * @throws QuickPay_API_Exception 
  29. */  
  30. public function create( WC_QuickPay_Order $order )  
  31. return parent::create( $order ); 
  32. }  
  33.  
  34.  
  35. /** 
  36. * capture function. 
  37. *  
  38. * Sends a 'capture' request to the QuickPay API 
  39. * @access public 
  40. * @param int $transaction_id 
  41. * @param int $amount 
  42. * @return object 
  43. * @throws QuickPay_API_Exception 
  44. */  
  45. public function capture( $transaction_id, $order, $amount = NULL )  
  46. // Check if a custom amount ha been set 
  47. if( $amount === NULL )  
  48. // No custom amount set. Default to the order total 
  49. $amount = $order->get_total();  
  50.  
  51. return $this->post( sprintf( '%d/%s', $transaction_id, "capture" ), array( 'amount' => WC_QuickPay_Helper::price_multiply( $amount ) ) ); 
  52.  
  53.  
  54. /** 
  55. * cancel function. 
  56. *  
  57. * Sends a 'cancel' request to the QuickPay API 
  58. * @access public 
  59. * @param int $transaction_id 
  60. * @return void 
  61. * @throws QuickPay_API_Exception 
  62. */  
  63. public function cancel( $transaction_id )  
  64. $this->post( sprintf( '%d/%s', $transaction_id, "cancel" ) ); 
  65.  
  66.  
  67. /** 
  68. * refund function. 
  69. *  
  70. * Sends a 'refund' request to the QuickPay API 
  71. * @access public 
  72. * @param int $transaction_id 
  73. * @param int $amount 
  74. * @return void 
  75. * @throws QuickPay_API_Exception 
  76. */  
  77. public function refund( $transaction_id, $order, $amount = NULL )  
  78. // Check if a custom amount ha been set 
  79. if( $amount === NULL )  
  80. // No custom amount set. Default to the order total 
  81. $amount = $order->get_total(); 
  82.  
  83. $this->post( sprintf( '%d/%s', $transaction_id, "refund" ), array( 'amount' => WC_QuickPay_Helper::price_multiply( $amount ) ) ); 
  84.  
  85.  
  86. /** 
  87. * is_action_allowed function. 
  88. * Check if the action we are about to perform is allowed according to the current transaction state. 
  89. * @access public 
  90. * @return boolean 
  91. */ 
  92. public function is_action_allowed( $action )  
  93. $state = $this->get_current_type(); 
  94. $remaining_balance = $this->get_remaining_balance(); 
  95.  
  96. $allowed_states = array( 
  97. 'capture' => array( 'authorize', 'recurring' ),  
  98. 'cancel' => array( 'authorize' ),  
  99. 'refund' => array( 'capture', 'refund' ),  
  100. 'renew' => array( 'authorize' ),  
  101. 'splitcapture' => array( 'authorize', 'capture' ),  
  102. 'recurring' => array( 'subscribe' ),  
  103. 'standard_actions' => array( 'authorize', 'recurring' ) 
  104. ); 
  105.  
  106. // We wants to still allow captures if there is a remaining balance. 
  107. if ( 'capture' == $state && $remaining_balance > 0 ) { 
  108. return TRUE; 
  109.  
  110. return in_array( $state, $allowed_states[$action] );