WC_QuickPay_Helper

WC_QuickPay_Helper class.

Defined (1)

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

/classes/woocommerce-quickpay-helper.php  
  1. class WC_QuickPay_Helper { 
  2.  
  3.  
  4. /** 
  5. * price_normalize function. 
  6. * Returns the price with decimals. 1010 returns as 10.10. 
  7. * @access public static 
  8. * @return float 
  9. */ 
  10. public static function price_normalize( $price ) { 
  11. return number_format( $price / 100, 2, wc_get_price_decimal_separator(), '' ); 
  12.  
  13. /** 
  14. * @param $price 
  15. * @return string 
  16. */ 
  17. public static function price_multiplied_to_float( $price ) { 
  18. return number_format( $price / 100, 2, '.', '' ); 
  19.  
  20. /** 
  21. * Multiplies a custom formatted price based on the WooCommerce decimal- and thousand separators 
  22. * @param $price 
  23. */ 
  24. public static function price_custom_to_multiplied( $price ) { 
  25. $decimal_separator = get_option( 'woocommerce_price_decimal_sep' ); 
  26. $thousand_separator = get_option( 'woocommerce_price_thousand_sep' ); 
  27.  
  28. $price = str_replace( $thousand_separator, '', $price ); 
  29. $price = str_replace( $decimal_separator, '.', $price ); 
  30.  
  31. return self::price_multiply( $price ); 
  32.  
  33. /** 
  34. * price_multiply function. 
  35. * Returns the price with no decimals. 10.10 returns as 1010. 
  36. * @access public static 
  37. * @return integer 
  38. */ 
  39. public static function price_multiply( $price ) { 
  40. return number_format( $price * 100, 0, '', '' ); 
  41.  
  42. /** 
  43. * enqueue_javascript_backend function. 
  44. * @access public static 
  45. * @return string 
  46. */ 
  47. public static function enqueue_javascript_backend() { 
  48. wp_enqueue_script( 'quickpay-backend', plugins_url( '/assets/javascript/backend.js', dirname( __FILE__ ) ), array( 'jquery' ) ); 
  49. wp_localize_script( 'quickpay-backend', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); 
  50.  
  51.  
  52. /** 
  53. * enqueue_stylesheet function. 
  54. * @access public static 
  55. * @return string 
  56. */ 
  57. public static function enqueue_stylesheet() { 
  58. wp_enqueue_style( 'style', plugins_url( '/assets/stylesheets/woocommerce-quickpay.css', dirname( __FILE__ ) ) ); 
  59.  
  60.  
  61. /** 
  62. * load_i18n function. 
  63. * @access public static 
  64. * @return void 
  65. */ 
  66. public static function load_i18n() { 
  67. load_plugin_textdomain( 'woo-quickpay', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' ); 
  68.  
  69.  
  70. /** 
  71. * option_is_enabled function. 
  72. * Checks if a setting options is enabled by checking on yes/no data. 
  73. * @access public static 
  74. * @return int 
  75. */ 
  76. public static function option_is_enabled( $value ) { 
  77. return ( $value == 'yes' ) ? 1 : 0; 
  78.  
  79.  
  80. /** 
  81. * get_callback_url function 
  82. * Returns the order's main callback url 
  83. * @access public 
  84. * @return string 
  85. */ 
  86. public static function get_callback_url( $post_id = NULL ) { 
  87. $args = array( 'wc-api' => 'WC_QuickPay'); 
  88.  
  89. if( $post_id !== NULL ) { 
  90. $args['order_post_id'] = $post_id; 
  91.  
  92. $args = apply_filters('woocommerce_quickpay_callback_args', $args, $post_id); 
  93.  
  94. return add_query_arg( $args , site_url( '/' ) ); 
  95.  
  96.  
  97. /** 
  98. * is_url function 
  99. * Checks if a string is a URL 
  100. * @access public 
  101. * @return string 
  102. */ 
  103. public static function is_url( $url ) { 
  104. return ! filter_var( $url, FILTER_VALIDATE_URL ) === false; 
  105.  
  106. /** 
  107. * @since 4.5.0 
  108. * @param $payment_type 
  109. * @return null 
  110. */ 
  111. public static function get_payment_type_logo( $payment_type ) { 
  112. $logos = array( 
  113. "american-express" => "americanexpress.png",  
  114. "dankort" => "dankort.png",  
  115. "diners" => "diners.png",  
  116. "edankort" => "edankort.png",  
  117. "fbg1886" => "forbrugsforeningen.png",  
  118. "jcb" => "jcb.png",  
  119. "maestro" => "maestro.png",  
  120. "mastercard" => "mastercard.png",  
  121. "mastercard-debet" => "mastercard.png",  
  122. "mobilepay" => "mobilepay.png",  
  123. "visa" => "visa.png",  
  124. "visa-electron" => "visaelectron.png",  
  125. "paypal" => "paypal.png",  
  126. "sofort" => "sofort.png",  
  127. "viabill" => "viabill.png",  
  128. "klarna" => "klarna.png",  
  129. ); 
  130.  
  131. if ( array_key_exists( trim( $payment_type ), $logos ) ) { 
  132. return WC_QP()->plugin_url( 'assets/images/cards/' . $logos[ $payment_type ] ); 
  133.  
  134. return null; 
  135.  
  136. /** 
  137. * Checks if WooCommerce Pre-Orders is active 
  138. */ 
  139. public static function has_preorder_plugin() { 
  140. return class_exists( 'WC_Pre_Orders' ); 
  141.  
  142. /** 
  143. * @param $value 
  144. * @param null $default 
  145. * @return null 
  146. */ 
  147. public static function value( $value, $default = null ) { 
  148. if ( empty( $value ) ) { 
  149. return $default; 
  150.  
  151. return $value; 
  152.  
  153. /** 
  154. * Prevents qTranslate to make browser redirects resulting in missing callback data. 
  155. * @param $url_lang 
  156. * @param $url_orig 
  157. * @param $url_info 
  158. * @return bool 
  159. */ 
  160. public static function qtranslate_prevent_redirect( $url_lang, $url_orig, $url_info ) { 
  161. // Prevent only on wc-api for this specific gateway 
  162. if (isset( $url_info['query'] ) && stripos( $url_info['query'], 'wc-api=wc_quickpay' ) !== FALSE ) { 
  163. return false; 
  164. return $url_lang; 
  165.  
  166. /** 
  167. * @param $bypass 
  168. * @return bool 
  169. */ 
  170. public static function spamshield_bypass_security_check( $bypass ) { 
  171. return isset($_GET['wc-api']) && strtolower($_GET['wc-api']) === 'wc_quickpay';