WCML_Exchange_Rate_Service

The WooCommerce Multilingual WCML Exchange Rate Service class.

Defined (1)

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

/inc/abstracts/class-wcml-exchange-rate-service.php  
  1. abstract class WCML_Exchange_Rate_Service{ 
  2.  
  3. private $id; 
  4. private $name; 
  5. private $url; 
  6. private $api_url; 
  7.  
  8. private $settings = array(); 
  9.  
  10. protected $api_key = ''; 
  11.  
  12. const REQUIRES_KEY = false; 
  13.  
  14. public function __construct( $id, $name, $api_url, $url = '' ) { 
  15.  
  16. $this->id = $id; 
  17. $this->name = $name; 
  18. $this->api_url = $api_url; 
  19. $this->url = $url; 
  20.  
  21. $this->settings = get_option('wcml_exchange_rate_service_' . $this->id, array() ); 
  22.  
  23. if( $this->is_key_required() ) { 
  24. $this->api_key = $this->get_setting( 'api-key' ); 
  25.  
  26.  
  27. public function get_name() { 
  28. return $this->name; 
  29.  
  30. public function get_url() { 
  31. return $this->url; 
  32.  
  33. /** 
  34. * @param $from 
  35. * @param $to 
  36. * @return mixed 
  37. */ 
  38. public abstract function get_rates( $from, $to ); 
  39.  
  40. /** 
  41. * @return array 
  42. */ 
  43. public function get_settings() { 
  44. return $this->settings; 
  45.  
  46. /** 
  47. */ 
  48. private function save_settings() { 
  49. update_option('wcml_exchange_rate_service_' . $this->id, $this->settings); 
  50.  
  51. /** 
  52. * @param $key string 
  53. * @return mixed|null 
  54. */ 
  55. public function get_setting( $key ) { 
  56. return isset( $this->settings[$key] ) ? $this->settings[$key] : null; 
  57.  
  58. /** 
  59. * @param $key string 
  60. * @param $value mixed 
  61. */ 
  62. public function save_setting( $key, $value ) { 
  63. $this->settings[$key] = $value; 
  64. $this->save_settings(); 
  65.  
  66. /** 
  67. * @return bool 
  68. */ 
  69. public function is_key_required() { 
  70. return self::REQUIRES_KEY; 
  71.  
  72. /** 
  73. * @param $error_message string 
  74. */ 
  75. public function save_last_error( $error_message ) { 
  76. $this->save_setting( 'last_error',  
  77. array( 
  78. 'text' => $error_message,  
  79. 'time' => date_i18n( 'F j, Y g:i a', current_time( 'timestamp' ) ) 
  80. ); 
  81.  
  82. /** 
  83. */ 
  84. public function clear_last_error() { 
  85. $this->save_setting( 'last_error', false ); 
  86.  
  87. /** 
  88. * @return mixed 
  89. */ 
  90. public function get_last_error() { 
  91. return isset( $this->settings['last_error'] ) ? $this->settings['last_error'] : false; 
  92.  
  93.