Changeset 3262812
- Timestamp:
- 03/27/2025 12:25:09 PM (12 months ago)
- Location:
- run-my-accounts-for-woocommerce
- Files:
-
- 27 added
- 2 deleted
- 11 edited
-
tags/1.8.0 (added)
-
tags/1.8.0/LICENSE (added)
-
tags/1.8.0/README.md (added)
-
tags/1.8.0/assets (added)
-
tags/1.8.0/assets/css (added)
-
tags/1.8.0/assets/css/select2.min.css (added)
-
tags/1.8.0/assets/js (added)
-
tags/1.8.0/assets/js/admin.js (added)
-
tags/1.8.0/assets/js/select2.min.js (added)
-
tags/1.8.0/classes (added)
-
tags/1.8.0/classes/class-RMA_WC_API.php (added)
-
tags/1.8.0/classes/class-RMA_WC_Backend.php (added)
-
tags/1.8.0/classes/class-RMA_WC_Backend_Abstract.php (added)
-
tags/1.8.0/classes/class-RMA_WC_Collective_Invoicing.php (added)
-
tags/1.8.0/classes/class-RMA_WC_Frontend.php (added)
-
tags/1.8.0/classes/class-RMA_WC_Payment.php (added)
-
tags/1.8.0/classes/class-RMA_WC_Rental_And_Booking.php (added)
-
tags/1.8.0/classes/class-RMA_WC_Settings_Page.php (added)
-
tags/1.8.0/index.php (added)
-
tags/1.8.0/readme.txt (added)
-
tags/1.8.0/rma-wc-main.php (added)
-
tags/1.8.0/rma-wc.php (added)
-
tags/1.8.0/templates (added)
-
tags/1.8.0/templates/email (added)
-
tags/1.8.0/templates/email/error-email-template.php (added)
-
tags/1.8.0/uninstall.php (added)
-
trunk/classes/class-RMA_Settings_Page.php (deleted)
-
trunk/classes/class-RMA_WC_API.php (modified) (13 diffs)
-
trunk/classes/class-RMA_WC_Backend.php (modified) (1 diff)
-
trunk/classes/class-RMA_WC_Backend_Abstract.php (modified) (18 diffs)
-
trunk/classes/class-RMA_WC_Collective_Invoicing.php (modified) (7 diffs)
-
trunk/classes/class-RMA_WC_Frontend.php (modified) (9 diffs)
-
trunk/classes/class-RMA_WC_Payment.php (modified) (5 diffs)
-
trunk/classes/class-RMA_WC_Rental_And_Booking.php (modified) (1 diff)
-
trunk/classes/class-RMA_WC_Settings_Page.php (modified) (1 diff)
-
trunk/languages (deleted)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/rma-wc-main.php (added)
-
trunk/rma-wc.php (modified) (2 diffs)
-
trunk/templates/email/error-email-template.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
run-my-accounts-for-woocommerce/trunk/classes/class-RMA_WC_API.php
r2873238 r3262812 11 11 public function __construct() { 12 12 13 // define constants only if they are not defined yet14 // for this we check for two common constants which definitely needs to be defined15 if ( !defined( 'RMA_MANDANT' ) || !defined( 'RMA_INVOICE_PREFIX' ) )16 self::define_constants();17 18 } 19 20 /**21 * define default constants22 */13 // define constants only if they are not defined yet 14 // for this we check for two common constants which definitely needs to be defined 15 if ( !defined( 'RMA_MANDANT' ) || !defined( 'RMA_INVOICE_PREFIX' ) ) 16 self::define_constants(); 17 18 } 19 20 /** 21 * define default constants 22 */ 23 23 private function define_constants() { 24 24 25 // read rma settings26 $settings = get_option('wc_rma_settings');27 28 // check if operation mode is set and is live29 if( isset( $settings['rma-mode'] ) && 'live' == $settings['rma-mode'] ) {30 31 // define constants with live values32 if( !defined( 'RMA_MANDANT' ) ) DEFINE( 'RMA_MANDANT', ( $settings[ 'rma-live-client' ] ?? '') );33 if( !defined( 'RMA_APIKEY' ) ) DEFINE( 'RMA_APIKEY', ( $settings[ 'rma-live-apikey' ] ?? '') );34 if( !defined( 'RMA_CALLERSANDBOX' ) ) DEFINE( 'RMA_CALLERSANDBOX', FALSE );35 36 }37 else {38 39 // set default operation mode to test40 if( !defined( 'RMA_MANDANT' ) ) DEFINE( 'RMA_MANDANT', ( $settings[ 'rma-test-client' ] ?? '') );41 if( !defined( 'RMA_APIKEY' ) ) DEFINE( 'RMA_APIKEY', ( $settings[ 'rma-test-apikey' ] ?? '') );42 if( !defined( 'RMA_CALLERSANDBOX' ) ) DEFINE( 'RMA_CALLERSANDBOX', TRUE );43 44 }45 46 DEFINE( 'RMA_GLOBAL_PAYMENT_PERIOD', ( $settings[ 'rma-payment-period' ] ?? '0') ); // default value 0 days47 DEFINE( 'RMA_INVOICE_PREFIX', ( $settings[ 'rma-invoice-prefix' ] ?? '') );48 DEFINE( 'RMA_INVOICE_DIGITS', ( isset( $settings['rma-digits'] ) ? $settings[ 'rma-invoice-description' ] : '' ) );49 50 // if rma-loglevel ist not set, LOGLEVEL is set to error by default51 if( isset( $settings['rma-loglevel'] ) ) {52 if( 'error' == $settings['rma-loglevel'] || empty( $settings['rma-loglevel'] ) ) {53 if( !defined( 'LOGLEVEL' ) ) DEFINE( 'LOGLEVEL' , 'error' );54 }55 elseif ( $settings['rma-loglevel'] == 'complete' ) {56 if( !defined( 'LOGLEVEL' ) ) DEFINE( 'LOGLEVEL' , 'complete' );57 }58 } else {59 if( !defined( 'LOGLEVEL' ) ) DEFINE( 'LOGLEVEL' , 'error' );60 }61 62 // if rma-log-send-email ist not set, SENDLOGEMAIL is set to false by default63 if( isset ( $settings['rma-log-send-email'] ) &&64 'yes' == $settings['rma-log-send-email'] ) {65 if( !defined( 'SENDLOGEMAIL' ) ) DEFINE( 'SENDLOGEMAIL' , true );66 67 // who will get email on error68 if( !defined( 'LOGEMAIL' ) ) DEFINE( 'LOGEMAIL', ( !empty( $settings['rma-log-email'] ) ? $settings['rma-log-email'] : get_option( 'admin_email' ) ) );69 70 } else {71 if( !defined( 'SENDLOGEMAIL' ) ) DEFINE( 'SENDLOGEMAIL' , false );72 }73 74 }25 // read rma settings 26 $settings = get_option('wc_rma_settings'); 27 28 // check if operation mode is set and is live 29 if( isset( $settings['rma-mode'] ) && 'live' == $settings['rma-mode'] ) { 30 31 // define constants with live values 32 if( !defined( 'RMA_MANDANT' ) ) DEFINE( 'RMA_MANDANT', ( $settings[ 'rma-live-client' ] ?? '') ); 33 if( !defined( 'RMA_APIKEY' ) ) DEFINE( 'RMA_APIKEY', ( $settings[ 'rma-live-apikey' ] ?? '') ); 34 if( !defined( 'RMA_CALLERSANDBOX' ) ) DEFINE( 'RMA_CALLERSANDBOX', FALSE ); 35 36 } 37 else { 38 39 // set default operation mode to test 40 if( !defined( 'RMA_MANDANT' ) ) DEFINE( 'RMA_MANDANT', ( $settings[ 'rma-test-client' ] ?? '') ); 41 if( !defined( 'RMA_APIKEY' ) ) DEFINE( 'RMA_APIKEY', ( $settings[ 'rma-test-apikey' ] ?? '') ); 42 if( !defined( 'RMA_CALLERSANDBOX' ) ) DEFINE( 'RMA_CALLERSANDBOX', TRUE ); 43 44 } 45 46 DEFINE( 'RMA_GLOBAL_PAYMENT_PERIOD', ( $settings[ 'rma-payment-period' ] ?? '0') ); // default value 0 days 47 DEFINE( 'RMA_INVOICE_PREFIX', ( $settings[ 'rma-invoice-prefix' ] ?? '') ); 48 DEFINE( 'RMA_INVOICE_DIGITS', ( isset( $settings['rma-digits'] ) ? $settings[ 'rma-invoice-description' ] : '' ) ); 49 50 // if rma-loglevel ist not set, LOGLEVEL is set to error by default 51 if( isset( $settings['rma-loglevel'] ) ) { 52 if( 'error' == $settings['rma-loglevel'] || empty( $settings['rma-loglevel'] ) ) { 53 if( !defined( 'LOGLEVEL' ) ) DEFINE( 'LOGLEVEL' , 'error' ); 54 } 55 elseif ( $settings['rma-loglevel'] == 'complete' ) { 56 if( !defined( 'LOGLEVEL' ) ) DEFINE( 'LOGLEVEL' , 'complete' ); 57 } 58 } else { 59 if( !defined( 'LOGLEVEL' ) ) DEFINE( 'LOGLEVEL' , 'error' ); 60 } 61 62 // if rma-log-send-email ist not set, SENDLOGEMAIL is set to false by default 63 if( isset ( $settings['rma-log-send-email'] ) && 64 'yes' == $settings['rma-log-send-email'] ) { 65 if( !defined( 'SENDLOGEMAIL' ) ) DEFINE( 'SENDLOGEMAIL' , true ); 66 67 // who will get email on error 68 if( !defined( 'LOGEMAIL' ) ) DEFINE( 'LOGEMAIL', ( !empty( $settings['rma-log-email'] ) ? $settings['rma-log-email'] : get_option( 'admin_email' ) ) ); 69 70 } else { 71 if( !defined( 'SENDLOGEMAIL' ) ) DEFINE( 'SENDLOGEMAIL' , false ); 72 } 73 74 } 75 75 76 76 /** 77 77 * Set Caller URL live oder sandbox 78 *78 * 79 79 * @return string 80 80 */ 81 81 public static function get_caller_url(): string 82 {82 { 83 83 // Set caller URL 84 84 if( RMA_CALLERSANDBOX ) { // Caller URL for sandbox 85 $url = 'https://service.int.runmyaccounts.com/api/latest/clients/'; // End with / !86 //$url = ' https://service-swint.runmyaccounts.com/api/latest/clients/'; // End with / !85 $url = 'https://service.int.runmyaccounts.com/api/latest/clients/'; // End with / ! 86 //$url = ' https://service-swint.runmyaccounts.com/api/latest/clients/'; // End with / ! 87 87 } 88 88 else { // Caller URL set for Live page … … 95 95 /** 96 96 * Read customer list from RMA 97 *97 * 98 98 * @return mixed 99 99 */ 100 100 public function get_customers() { 101 101 102 if( !RMA_MANDANT || !RMA_APIKEY ) {103 104 $log_values = array(105 'status' => 'error',106 'section_id' => '',107 'section' => esc_html_x('Get Customer', 'Log Section', 'rma-wc'),108 'mode' => self::rma_mode(),109 'message' => esc_html__('Missing API data', 'rma-wc') );110 111 self::write_log($log_values);112 113 return false;114 115 }102 if( !RMA_MANDANT || !RMA_APIKEY ) { 103 104 $log_values = array( 105 'status' => 'error', 106 'section_id' => '', 107 'section' => esc_html_x('Get Customer', 'Log Section', 'run-my-accounts-for-woocommerce'), 108 'mode' => self::rma_mode(), 109 'message' => esc_html__('Missing API data', 'run-my-accounts-for-woocommerce') ); 110 111 self::write_log($log_values); 112 113 return false; 114 115 } 116 116 117 117 $url = self::get_caller_url() . RMA_MANDANT . '/customers?api_key=' . RMA_APIKEY; 118 $response = wp_remote_get( $url );119 120 // Check response code118 $response = wp_remote_get( $url ); 119 120 // Check response code 121 121 if ( 200 <> wp_remote_retrieve_response_code( $response ) ){ 122 122 123 $message = esc_html__( 'Response Code', 'rma-wc') . ' '. wp_remote_retrieve_response_code( $response );124 $message .= ' '. wp_remote_retrieve_response_message( $response );125 126 127 if ( is_wp_error( $response ) ) {128 129 $error_string = $response->get_error_message();130 echo '<div id="message" class="error"><p>' . $error_string. '</p></div>';131 132 return false;133 134 }135 136 $response = (array) $response['http_response'];137 138 foreach ( $response as $object ) {139 $message .= ' ' . $object->url;140 break;141 }142 143 $log_values = array(144 'status' => 'error',145 'section_id' => '',146 'section' => esc_html_x('Get Customer', 'Log Section', 'rma-wc'),147 'mode' => self::rma_mode(),148 'message' => $message );149 150 self::write_log($log_values);151 152 return false;123 $message = esc_html__( 'Response Code', 'run-my-accounts-for-woocommerce') . ' '. wp_remote_retrieve_response_code( $response ); 124 $message .= ' '. wp_remote_retrieve_response_message( $response ); 125 126 127 if ( is_wp_error( $response ) ) { 128 129 $error_string = sanitize_text_field( $response->get_error_message() ); 130 echo '<div id="message" class="error"><p>' . esc_html( $error_string ) . '</p></div>'; 131 132 return false; 133 134 } 135 136 $response = (array) $response['http_response']; 137 138 foreach ( $response as $object ) { 139 $message .= ' ' . $object->url; 140 break; 141 } 142 143 $log_values = array( 144 'status' => 'error', 145 'section_id' => '', 146 'section' => esc_html_x('Get Customer', 'Log Section', 'run-my-accounts-for-woocommerce'), 147 'mode' => self::rma_mode(), 148 'message' => $message ); 149 150 self::write_log($log_values); 151 152 return false; 153 153 154 154 } 155 155 else { 156 156 157 libxml_use_internal_errors( true );158 159 $body = wp_remote_retrieve_body( $response );160 $xml = simplexml_load_string( $body );157 libxml_use_internal_errors( true ); 158 159 $body = wp_remote_retrieve_body( $response ); 160 $xml = simplexml_load_string( $body ); 161 161 162 162 if ( !$xml ) { 163 163 // ToDO: Add this information to error log 164 164 foreach( libxml_get_errors() as $error ) { 165 echo "\t", $error->message;165 echo "\t", esc_html( $error->message ); 166 166 } 167 167 … … 177 177 178 178 foreach ($value as $key => $customer ) { 179 $number = $customer['customernumber'];180 181 if ( is_array( $customer['name'] ) ) {182 183 if ( is_array( $customer['firstname'] ) ||184 is_array( $customer['lastname'] )) {185 $name = '';186 }187 else {188 $name = $customer['firstname'] . ' ' . $customer['lastname'];189 }190 191 }192 else {193 $name = $customer['name'];194 }195 196 $customers[ $number ] = $name . ' ( ' . $number . ' )';179 $number = $customer['customernumber']; 180 181 if ( is_array( $customer['name'] ) ) { 182 183 if ( is_array( $customer['firstname'] ) || 184 is_array( $customer['lastname'] )) { 185 $name = ''; 186 } 187 else { 188 $name = $customer['firstname'] . ' ' . $customer['lastname']; 189 } 190 191 } 192 else { 193 $name = $customer['name']; 194 } 195 196 $customers[ $number ] = $name . ' ( ' . $number . ' )'; 197 197 } 198 198 … … 204 204 } 205 205 206 /**207 * Read parts list from RMA208 *209 * @return mixed210 *211 * @since 1.5.0212 */213 public function get_parts() {214 215 if( !RMA_MANDANT || !RMA_APIKEY ) {216 217 $log_values = array(218 'status' => 'error',219 'section_id' => '',220 'section' => esc_html_x('Get Parts', 'Log Section', 'rma-wc'),221 'mode' => self::rma_mode(),222 'message' => esc_html__('Missing API data', 'rma-wc') );223 224 self::write_log($log_values);225 226 return false;227 228 }229 230 $url = self::get_caller_url() . RMA_MANDANT . '/parts?api_key=' . RMA_APIKEY;231 232 $response = wp_remote_get( $url );233 234 // Check response code235 if ( 200 <> wp_remote_retrieve_response_code( $response ) ){236 237 $message = esc_html__( 'Response Code', 'rma-wc') . ' '. wp_remote_retrieve_response_code( $response );238 $message .= ' '. wp_remote_retrieve_response_message( $response );239 240 $response = (array) $response[ 'http_response' ];241 242 foreach ( $response as $object ) {243 $message .= ' ' . $object->url;244 break;245 }246 247 $log_values = array(248 'status' => 'error',249 'section_id' => '',250 'section' => esc_html_x('Get Parts', 'Log Section', 'rma-wc'),251 'mode' => self::rma_mode(),252 'message' => $message );253 254 self::write_log($log_values);255 256 return false;257 258 }259 else {260 261 libxml_use_internal_errors( true );262 263 $body = wp_remote_retrieve_body( $response );264 $xml = simplexml_load_string( $body );265 266 if ( !$xml ) {267 // ToDO: Add this information to error log268 foreach( libxml_get_errors() as $error ) {269 echo "\t", $error->message;270 }271 272 return false;273 274 }275 else {276 // Parse response277 $array = json_decode( json_encode( (array)$xml ), TRUE);278 279 $sku_list = array();280 281 foreach ( $array['part'] as $part ) {282 283 $sku_list[ $part['partnumber'] ] = $part['partnumber'];284 285 }286 287 return ( !empty( $sku_list ) ? $sku_list : false );288 }289 }290 }291 292 /**293 * Collect data for invoice294 *295 * @param $order_id296 *297 * @return array298 * @throws DOMException299 */206 /** 207 * Read parts list from RMA 208 * 209 * @return mixed 210 * 211 * @since 1.5.0 212 */ 213 public function get_parts() { 214 215 if( !RMA_MANDANT || !RMA_APIKEY ) { 216 217 $log_values = array( 218 'status' => 'error', 219 'section_id' => '', 220 'section' => esc_html_x('Get Parts', 'Log Section', 'run-my-accounts-for-woocommerce'), 221 'mode' => self::rma_mode(), 222 'message' => esc_html__('Missing API data', 'run-my-accounts-for-woocommerce') ); 223 224 self::write_log($log_values); 225 226 return false; 227 228 } 229 230 $url = self::get_caller_url() . RMA_MANDANT . '/parts?api_key=' . RMA_APIKEY; 231 232 $response = wp_remote_get( $url ); 233 234 // Check response code 235 if ( 200 <> wp_remote_retrieve_response_code( $response ) ){ 236 237 $message = esc_html__( 'Response Code', 'run-my-accounts-for-woocommerce') . ' '. wp_remote_retrieve_response_code( $response ); 238 $message .= ' '. wp_remote_retrieve_response_message( $response ); 239 240 $response = (array) $response[ 'http_response' ]; 241 242 foreach ( $response as $object ) { 243 $message .= ' ' . $object->url; 244 break; 245 } 246 247 $log_values = array( 248 'status' => 'error', 249 'section_id' => '', 250 'section' => esc_html_x('Get Parts', 'Log Section', 'run-my-accounts-for-woocommerce'), 251 'mode' => self::rma_mode(), 252 'message' => $message ); 253 254 self::write_log($log_values); 255 256 return false; 257 258 } 259 else { 260 261 libxml_use_internal_errors( true ); 262 263 $body = wp_remote_retrieve_body( $response ); 264 $xml = simplexml_load_string( $body ); 265 266 if ( !$xml ) { 267 // ToDO: Add this information to error log 268 foreach( libxml_get_errors() as $error ) { 269 echo "\t", esc_html( $error->message ); 270 } 271 272 return false; 273 274 } 275 else { 276 // Parse response 277 $array = json_decode( json_encode( (array)$xml ), TRUE); 278 279 $sku_list = array(); 280 281 foreach ( $array['part'] as $part ) { 282 283 $sku_list[ $part['partnumber'] ] = $part['partnumber']; 284 285 } 286 287 return ( !empty( $sku_list ) ? $sku_list : false ); 288 } 289 } 290 } 291 292 /** 293 * Collect data for invoice 294 * 295 * @param $order_id 296 * 297 * @return array 298 * @throws DOMException 299 */ 300 300 private function get_invoice_values( $order_id ): array 301 {301 { 302 302 303 303 $order_details = self::get_wc_order_details( $order_id ); 304 304 305 // add products to order306 $order_details_products = self::get_order_details_products( $order_id );307 308 // add shipping costs to order309 $order_details_products = self::get_order_details_shipping_costs( $order_id, $order_details_products );310 311 $invoice_id = RMA_INVOICE_PREFIX . str_pad( $order_id, max(intval(RMA_INVOICE_DIGITS) - strlen(RMA_INVOICE_PREFIX ), 0 ), '0', STR_PAD_LEFT );312 313 return self::get_invoice_data( $order_details, $order_details_products, $invoice_id, $order_id );314 315 } 316 317 public static function get_invoice_data( $order_details, $order_details_products, $invoice_id, $order_id, $description = '' ): array {318 319 $settings = get_option( 'wc_rma_settings' );320 $fallback_sku = $settings[ 'rma-product-fallback_id' ];321 322 if ( !empty( $fallback_sku ) )323 $rma_part_numbers = (new RMA_WC_API)->get_parts();324 325 if( empty( $description ) ) {326 327 $description = str_replace('[orderdate]', $order_details[ 'orderdate' ], $settings[ 'rma-invoice-description' ] ?? '' );328 329 }330 331 $data = array(332 'invoice' => array(333 'invnumber' => $invoice_id,334 'ordnumber' => $order_id,335 'status' => 'OPEN',336 'currency' => $order_details[ 'currency' ],337 'ar_accno' => $order_details[ 'ar_accno' ],338 'transdate' =>date(DateTimeInterface::RFC3339, time() ),339 'duedate' => $order_details[ 'duedate' ], //date( DateTime::RFC3339, time() ),340 'description' => $description,341 'notes' => '',342 'intnotes' => $order_details[ 'notes' ],343 'taxincluded' => $order_details[ 'taxincluded' ],344 'dcn' => '',345 'customernumber' => $order_details[ 'customernumber' ],346 'payment_accno' => $order_details[ 'payment_accno' ]347 ),348 'part' => array()349 );350 351 // Add parts352 if ( count( $order_details_products ) > 0 ) :353 354 foreach ( $order_details_products as $part_number => $part ) :355 356 // check if fallback sku exist and part number does not exist in list of RMA part numbers357 if( !empty( $fallback_sku ) &&358 !array_key_exists( $part_number, $rma_part_numbers ) )359 $part_number = $fallback_sku;360 361 $data['part'][] = apply_filters( 'rma_invoice_part', array (362 'partnumber' => $part_number,363 'description' => $part[ 'name' ],364 'unit' => '',365 'quantity' => $part[ 'quantity' ],366 'sellprice' => $part[ 'price' ],367 'discount' => '0.0',368 'itemnote' => '',369 'price_update' => '',370 ), $part[ 'item_id' ] ?? null );371 endforeach;372 373 endif;374 375 return $data;376 377 }378 379 /**380 * Prepare data of a customer by user id for sending to Run my Accounts381 *382 * @param $user_id383 *384 * @return array385 * @throws Exception386 */305 // add products to order 306 $order_details_products = self::get_order_details_products( $order_id ); 307 308 // add shipping costs to order 309 $order_details_products = self::get_order_details_shipping_costs( $order_id, $order_details_products ); 310 311 $invoice_id = RMA_INVOICE_PREFIX . str_pad( $order_id, max(intval(RMA_INVOICE_DIGITS) - strlen(RMA_INVOICE_PREFIX ), 0 ), '0', STR_PAD_LEFT ); 312 313 return self::get_invoice_data( $order_details, $order_details_products, $invoice_id, $order_id ); 314 315 } 316 317 public static function get_invoice_data( $order_details, $order_details_products, $invoice_id, $order_id, $description = '' ): array { 318 319 $settings = get_option( 'wc_rma_settings' ); 320 $fallback_sku = $settings[ 'rma-product-fallback_id' ]; 321 322 if ( !empty( $fallback_sku ) ) 323 $rma_part_numbers = (new RMA_WC_API)->get_parts(); 324 325 if( empty( $description ) ) { 326 327 $description = str_replace('[orderdate]', $order_details[ 'orderdate' ], $settings[ 'rma-invoice-description' ] ?? '' ); 328 329 } 330 331 $data = array( 332 'invoice' => array( 333 'invnumber' => $invoice_id, 334 'ordnumber' => $order_id, 335 'status' => 'OPEN', 336 'currency' => $order_details[ 'currency' ], 337 'ar_accno' => $order_details[ 'ar_accno' ], 338 'transdate' => gmdate(DateTimeInterface::RFC3339, time() ), 339 'duedate' => $order_details[ 'duedate' ], //gmdate( DateTime::RFC3339, time() ), 340 'description' => $description, 341 'notes' => '', 342 'intnotes' => $order_details[ 'notes' ], 343 'taxincluded' => $order_details[ 'taxincluded' ], 344 'dcn' => '', 345 'customernumber' => $order_details[ 'customernumber' ], 346 'payment_accno' => $order_details[ 'payment_accno' ] 347 ), 348 'part' => array() 349 ); 350 351 // Add parts 352 if ( count( $order_details_products ) > 0 ) : 353 354 foreach ( $order_details_products as $part_number => $part ) : 355 356 // check if fallback sku exist and part number does not exist in list of RMA part numbers 357 if( !empty( $fallback_sku ) && 358 !array_key_exists( $part_number, $rma_part_numbers ) ) 359 $part_number = $fallback_sku; 360 361 $data['part'][] = apply_filters( 'rma_invoice_part', array ( 362 'partnumber' => $part_number, 363 'description' => $part[ 'name' ], 364 'unit' => '', 365 'quantity' => $part[ 'quantity' ], 366 'sellprice' => $part[ 'price' ], 367 'discount' => '0.0', 368 'itemnote' => '', 369 'price_update' => '', 370 ), $part[ 'item_id' ] ?? null ); 371 endforeach; 372 373 endif; 374 375 return $data; 376 377 } 378 379 /** 380 * Prepare data of a customer by user id for sending to Run my Accounts 381 * 382 * @param $user_id 383 * 384 * @return array 385 * @throws Exception 386 */ 387 387 private function get_customer_values_by_user_id( $user_id ) :array { 388 388 389 $settings = get_option( 'wc_rma_settings' );390 $customer_prefix = isset( $settings[ 'rma-customer-prefix' ] ) ? $settings[ 'rma-customer-prefix' ] : '';391 392 $customer = new WC_Customer( $user_id );393 394 $is_company = !empty( $customer->get_billing_company() ) ? true : false;395 $billing_account = get_user_meta( $user_id, 'rma_billing_account', true );396 397 return array(389 $settings = get_option( 'wc_rma_settings' ); 390 $customer_prefix = isset( $settings[ 'rma-customer-prefix' ] ) ? $settings[ 'rma-customer-prefix' ] : ''; 391 392 $customer = new WC_Customer( $user_id ); 393 394 $is_company = !empty( $customer->get_billing_company() ) ? true : false; 395 $billing_account = get_user_meta( $user_id, 'rma_billing_account', true ); 396 397 return array( 398 398 'customernumber' => $customer_prefix . $user_id, 399 399 'name' => ( $is_company ? $customer->get_billing_company() : $customer->get_billing_first_name() . ' ' . $customer->get_billing_last_name() ), 400 'created' => date('Y-m-d') . 'T00:00:00+01:00',401 'salutation' => ( 1 == get_user_meta( $user_id, 'billing_title', true ) ? __('Mr.', 'r ma-wc') : __('Ms.', 'rma-wc') ),400 'created' => gmdate('Y-m-d') . 'T00:00:00+01:00', 401 'salutation' => ( 1 == get_user_meta( $user_id, 'billing_title', true ) ? __('Mr.', 'run-my-accounts-for-woocommerce') : __('Ms.', 'run-my-accounts-for-woocommerce') ), 402 402 'firstname' => $customer->get_billing_first_name(), 403 403 'lastname' => $customer->get_billing_last_name(), … … 417 417 'remittancevoucher' => 'false', 418 418 'arap_accno' => !empty ( $billing_account ) ? $billing_account : '', // Default accounts receivable account number - 1100 419 'payment_accno' => '', // Default payment account number 1020419 'payment_accno' => '', // Default payment account number 1020 420 420 'notes' => '', 421 421 'terms' => '0', … … 426 426 } 427 427 428 /**429 * Prepare data of a customer by order id for sending to Run my Accounts430 *431 * @param $order_id432 *433 * @return array434 * @throws Exception435 */436 private function get_customer_values_by_order_id( $order_id ) : array {437 438 $settings = get_option( 'wc_rma_settings' );439 $customer_prefix = isset( $settings[ 'rma-guest-customer-prefix' ] ) ? $settings[ 'rma-guest-customer-prefix' ] : '';440 unset( $settings );441 442 $order = new WC_Order( $order_id );443 444 $is_company = !empty( $order->get_billing_company() );445 446 return array(447 'customernumber' => $customer_prefix . $order_id,448 'name' => ( $is_company ? $order->get_billing_company() : $order->get_billing_first_name() . ' ' . $order->get_billing_last_name() ),449 'created' =>date('Y-m-d') . 'T00:00:00+01:00',450 'salutation' => ( 1 == get_post_meta( $order_id, '_billing_title', true ) ? __('Mr.', 'rma-wc') : __('Ms.', 'rma-wc') ),451 'firstname' => $order->get_billing_first_name(),452 'lastname' => $order->get_billing_last_name(),453 'address1' => $order->get_billing_address_1(),454 'address2' => $order->get_billing_address_2(),455 'zipcode' => $order->get_billing_postcode(),456 'city' => $order->get_billing_city(),457 'state' => $order->get_billing_state(),458 'country' => WC()->countries->countries[ $order->get_billing_country() ],459 'phone' => $order->get_billing_phone(),460 'fax' => '',461 'mobile' => '',462 'email' => $order->get_billing_email(),463 'cc' => '',464 'bcc' => '',465 'language_code' => '',466 'remittancevoucher' => 'false',467 'arap_accno' => '', // Default accounts receivable account number - 1100468 'payment_accno' => '', // Default payment account number 1020469 'notes' => '',470 'terms' => '0',471 'typeofcontact' => ( $is_company ? 'company' : 'person' ),472 'gender' => ( 1 == $order->get_meta( '_billing_title' ) ? 'M' : 'F' ),473 474 );475 476 }477 478 /**479 * get WooCommerce order details480 *481 * @param $order_id482 *483 * @return array484 * @throws DOMException485 */428 /** 429 * Prepare data of a customer by order id for sending to Run my Accounts 430 * 431 * @param $order_id 432 * 433 * @return array 434 * @throws Exception 435 */ 436 private function get_customer_values_by_order_id( $order_id ) : array { 437 438 $settings = get_option( 'wc_rma_settings' ); 439 $customer_prefix = isset( $settings[ 'rma-guest-customer-prefix' ] ) ? $settings[ 'rma-guest-customer-prefix' ] : ''; 440 unset( $settings ); 441 442 $order = new WC_Order( $order_id ); 443 444 $is_company = !empty( $order->get_billing_company() ); 445 446 return array( 447 'customernumber' => $customer_prefix . $order_id, 448 'name' => ( $is_company ? $order->get_billing_company() : $order->get_billing_first_name() . ' ' . $order->get_billing_last_name() ), 449 'created' => gmdate('Y-m-d') . 'T00:00:00+01:00', 450 'salutation' => ( 1 == $order->get_meta( '_billing_title', true ) ? __('Mr.', 'run-my-accounts-for-woocommerce') : __('Ms.', 'run-my-accounts-for-woocommerce') ), 451 'firstname' => $order->get_billing_first_name(), 452 'lastname' => $order->get_billing_last_name(), 453 'address1' => $order->get_billing_address_1(), 454 'address2' => $order->get_billing_address_2(), 455 'zipcode' => $order->get_billing_postcode(), 456 'city' => $order->get_billing_city(), 457 'state' => $order->get_billing_state(), 458 'country' => WC()->countries->countries[ $order->get_billing_country() ], 459 'phone' => $order->get_billing_phone(), 460 'fax' => '', 461 'mobile' => '', 462 'email' => $order->get_billing_email(), 463 'cc' => '', 464 'bcc' => '', 465 'language_code' => '', 466 'remittancevoucher' => 'false', 467 'arap_accno' => '', // Default accounts receivable account number - 1100 468 'payment_accno' => '', // Default payment account number 1020 469 'notes' => '', 470 'terms' => '0', 471 'typeofcontact' => ( $is_company ? 'company' : 'person' ), 472 'gender' => ( 1 == $order->get_meta( '_billing_title' ) ? 'M' : 'F' ), 473 474 ); 475 476 } 477 478 /** 479 * get WooCommerce order details 480 * 481 * @param $order_id 482 * 483 * @return array 484 * @throws DOMException 485 */ 486 486 public static function get_wc_order_details( $order_id ): array { 487 487 488 $order = wc_get_order( $order_id );488 $order = wc_get_order( $order_id ); 489 489 $option_accounting = get_option( 'wc_rma_settings_accounting' ); 490 $order_payment_method = $order->get_payment_method();491 492 // if order is done without user account493 if ( 0 == get_post_meta( $order_id,'_customer_user', true ) ) {494 495 $settings = get_option('wc_rma_settings');496 497 if ( 1 == $settings[ 'rma-create-guest-customer' ] ) {498 499 $rma_customer_id = (new RMA_WC_API)->create_rma_customer('order', $order_id );500 501 if ( false == $rma_customer_id ) {502 503 $log_values = array(504 'status' => 'error',505 'section_id' => $order_id,506 'section' => esc_html_x( 'Customer', 'Log Section', 'rma-wc'),507 'mode' => self::rma_mode(),508 'message' => __( 'Could not create RMA customer dedicated guest account', 'rma-wc' )509 );510 511 (new RMA_WC_API)->write_log($log_values);512 513 }514 515 }516 else {517 518 // customer id is equal to predefined catch all guest account519 $rma_customer_id = $settings['rma-guest-catch-all'];520 521 }522 523 }524 // ...or with user account525 else {526 527 $rma_customer_id = get_user_meta( $order->get_customer_id(), 'rma_customer', true );528 529 }530 531 // Set order header490 $order_payment_method = $order->get_payment_method(); 491 492 // if order is done without user account 493 if ( 0 == $order->get_meta( '_customer_user', true ) ) { 494 495 $settings = get_option('wc_rma_settings'); 496 497 if ( 1 == $settings[ 'rma-create-guest-customer' ] ) { 498 499 $rma_customer_id = (new RMA_WC_API)->create_rma_customer('order', $order_id ); 500 501 if ( false == $rma_customer_id ) { 502 503 $log_values = array( 504 'status' => 'error', 505 'section_id' => $order_id, 506 'section' => esc_html_x( 'Customer', 'Log Section', 'run-my-accounts-for-woocommerce'), 507 'mode' => self::rma_mode(), 508 'message' => __( 'Could not create RMA customer dedicated guest account', 'run-my-accounts-for-woocommerce' ) 509 ); 510 511 (new RMA_WC_API)->write_log($log_values); 512 513 } 514 515 } 516 else { 517 518 // customer id is equal to predefined catch all guest account 519 $rma_customer_id = $settings['rma-guest-catch-all']; 520 521 } 522 523 } 524 // ...or with user account 525 else { 526 527 $rma_customer_id = get_user_meta( $order->get_customer_id(), 'rma_customer', true ); 528 529 } 530 531 // Set order header 532 532 $order_details[ 'currency' ] = $order->get_currency(); 533 533 $order_details[ 'orderdate' ] = wc_format_datetime( $order->get_date_created(),'d.m.Y' ); 534 534 $order_details[ 'taxincluded' ] = $order->get_prices_include_tax() ? 'true' : 'false'; 535 535 $order_details[ 'customernumber' ] = $rma_customer_id; 536 $order_details[ 'ar_accno' ] = isset( $option_accounting[ $order_payment_method ] ) && !empty( $option_accounting[ $order_payment_method ] ) ? $option_accounting[ $order_payment_method ] : '';537 $order_details[ 'payment_accno' ] = isset( $option_accounting[ $order_payment_method . '_payment_account' ] ) && !empty( $option_accounting[ $order_payment_method . '_payment_account' ] ) ? $option_accounting[ $order_payment_method . '_payment_account' ] : '' ;538 539 // Calculate due date536 $order_details[ 'ar_accno' ] = isset( $option_accounting[ $order_payment_method ] ) && !empty( $option_accounting[ $order_payment_method ] ) ? $option_accounting[ $order_payment_method ] : ''; 537 $order_details[ 'payment_accno' ] = isset( $option_accounting[ $order_payment_method . '_payment_account' ] ) && !empty( $option_accounting[ $order_payment_method . '_payment_account' ] ) ? $option_accounting[ $order_payment_method . '_payment_account' ] : '' ; 538 539 // Calculate due date 540 540 $user_payment_period = get_user_meta( $order->get_customer_id(), 'rma_payment_period', true ); 541 541 // Set payment period - if user payment period not exist set to global period 542 542 $payment_period = $user_payment_period ? $user_payment_period : RMA_GLOBAL_PAYMENT_PERIOD; 543 543 // Calculate duedate (now + payment period) 544 $order_details[ 'duedate' ] = date( DateTime::RFC3339, time() + ( $payment_period*60*60*24 ) );545 546 // add shipping address if needed547 $order_details[ 'notes' ] = '';548 if( $order->needs_shipping_address() ) {549 550 // first converts a break tag to a newline – no matter what kind of HTML is being processed.551 $order_details[ 'notes' ] = preg_replace('/<br(\s+)?\/?>/i', "\n", $order->get_formatted_shipping_address());552 553 }544 $order_details[ 'duedate' ] = gmdate( DateTime::RFC3339, time() + ( $payment_period*60*60*24 ) ); 545 546 // add shipping address if needed 547 $order_details[ 'notes' ] = ''; 548 if( $order->needs_shipping_address() ) { 549 550 // first converts a break tag to a newline – no matter what kind of HTML is being processed. 551 $order_details[ 'notes' ] = preg_replace('/<br(\s+)?\/?>/i', "\n", $order->get_formatted_shipping_address()); 552 553 } 554 554 555 555 return $order_details; … … 557 557 } 558 558 559 /**560 * Collect products as order details561 *562 * @param int $order_id563 * @param array $order_details_products564 *565 * @return array566 *567 * @since 1.7.0568 */569 public static function get_order_details_products( int $order_id, array $order_details_products = array() ): array570 {571 572 $order = wc_get_order( $order_id );573 574 // add line items575 foreach ( $order->get_items() as $item_id => $item ) {576 $product = $item->get_product();577 578 // make sure the product is still available in WooCommerce579 if( is_object( $product ) ) {580 581 $order_details_products[ $product->get_sku() ] = array(582 'name' => $item->get_name(),583 'quantity' => $item->get_quantity(),584 'price' => wc_format_decimal( $product->get_price(), 2 ),585 'item_id' => $item_id586 );587 588 }589 590 }591 592 return $order_details_products;593 594 }595 596 /**597 * Add shipping costs as product, if necessary598 *599 * @param int $order_id600 * @param array $order_details_products601 *602 * @return array603 *604 * @since 1.7.0605 */606 public static function get_order_details_shipping_costs( int $order_id, array $order_details_products): array607 {608 609 $settings = get_option( 'wc_rma_settings' );610 $order = wc_get_order( $order_id );611 612 // Add Shipping costs613 // @since 1.6.0614 $order_shipping_total_net = (float) $order->get_shipping_total();615 $order_shipping_tax = (float) $order->get_shipping_tax();616 $shipping_costs_product_id = $settings['rma-shipping-id'] ?? '';617 618 // Calculate shipping costs w/ or wo/ tax619 if( $order->get_prices_include_tax() ) {620 $order_shipping_total = $order_shipping_total_net + $order_shipping_tax;621 }622 else {623 $order_shipping_total = $order_shipping_total_net;624 }625 626 // do we have shipping costs and a product id on file?627 if( 0 < $order_shipping_total && !empty( $shipping_costs_product_id ) ) {628 629 // we get shipping text from settings page otherwise we take shipping method630 $shipping_text = ( isset( $settings['rma-shipping-text'] ) && !empty( $settings['rma-shipping-text'] ) ? $settings['rma-shipping-text'] : $order->get_shipping_method() );631 632 $order_details_products[ $shipping_costs_product_id ] = array(633 'name' => $shipping_text,634 'quantity' => 1,635 'price' => $order_shipping_total636 );637 638 }639 // do we have shipping costs but no product id on file?640 elseif ( 0 < $order_shipping_total && empty( $shipping_costs_product_id ) ) {641 642 $log_values = array(643 'status' => 'error',644 'section_id' => $order->get_id(),645 'section' => esc_html_x( 'Invoice', 'Log Section', 'rma-wc'),646 'mode' => (new RMA_WC_API)->rma_mode(),647 'message' => __( 'Could not add shipping costs to invoice because of missing shipping costs product sku', 'rma-wc' )648 );649 650 (new RMA_WC_API)->write_log($log_values);651 652 }653 654 return $order_details_products;655 656 }657 658 /**659 * Create invoice in Run my Accounts660 *661 * @param string $order_id662 *663 * @return bool664 *665 * @throws DOMException666 */559 /** 560 * Collect products as order details 561 * 562 * @param int $order_id 563 * @param array $order_details_products 564 * 565 * @return array 566 * 567 * @since 1.7.0 568 */ 569 public static function get_order_details_products( int $order_id, array $order_details_products = array() ): array 570 { 571 572 $order = wc_get_order( $order_id ); 573 574 // add line items 575 foreach ( $order->get_items() as $item_id => $item ) { 576 $product = $item->get_product(); 577 578 // make sure the product is still available in WooCommerce 579 if( is_object( $product ) ) { 580 581 $order_details_products[ $product->get_sku() ] = array( 582 'name' => $item->get_name(), 583 'quantity' => $item->get_quantity(), 584 'price' => wc_format_decimal( $product->get_price(), 2 ), 585 'item_id' => $item_id 586 ); 587 588 } 589 590 } 591 592 return $order_details_products; 593 594 } 595 596 /** 597 * Add shipping costs as product, if necessary 598 * 599 * @param int $order_id 600 * @param array $order_details_products 601 * 602 * @return array 603 * 604 * @since 1.7.0 605 */ 606 public static function get_order_details_shipping_costs( int $order_id, array $order_details_products): array 607 { 608 609 $settings = get_option( 'wc_rma_settings' ); 610 $order = wc_get_order( $order_id ); 611 612 // Add Shipping costs 613 // @since 1.6.0 614 $order_shipping_total_net = (float) $order->get_shipping_total(); 615 $order_shipping_tax = (float) $order->get_shipping_tax(); 616 $shipping_costs_product_id = $settings['rma-shipping-id'] ?? ''; 617 618 // Calculate shipping costs w/ or wo/ tax 619 if( $order->get_prices_include_tax() ) { 620 $order_shipping_total = $order_shipping_total_net + $order_shipping_tax; 621 } 622 else { 623 $order_shipping_total = $order_shipping_total_net; 624 } 625 626 // do we have shipping costs and a product id on file? 627 if( 0 < $order_shipping_total && !empty( $shipping_costs_product_id ) ) { 628 629 // we get shipping text from settings page otherwise we take shipping method 630 $shipping_text = ( isset( $settings['rma-shipping-text'] ) && !empty( $settings['rma-shipping-text'] ) ? $settings['rma-shipping-text'] : $order->get_shipping_method() ); 631 632 $order_details_products[ $shipping_costs_product_id ] = array( 633 'name' => $shipping_text, 634 'quantity' => 1, 635 'price' => $order_shipping_total 636 ); 637 638 } 639 // do we have shipping costs but no product id on file? 640 elseif ( 0 < $order_shipping_total && empty( $shipping_costs_product_id ) ) { 641 642 $log_values = array( 643 'status' => 'error', 644 'section_id' => $order->get_id(), 645 'section' => esc_html_x( 'Invoice', 'Log Section', 'run-my-accounts-for-woocommerce'), 646 'mode' => (new RMA_WC_API)->rma_mode(), 647 'message' => __( 'Could not add shipping costs to invoice because of missing shipping costs product sku', 'run-my-accounts-for-woocommerce' ) 648 ); 649 650 (new RMA_WC_API)->write_log($log_values); 651 652 } 653 654 return $order_details_products; 655 656 } 657 658 /** 659 * Create invoice in Run my Accounts 660 * 661 * @param string $order_id 662 * 663 * @return bool 664 * 665 * @throws DOMException 666 */ 667 667 public function create_invoice( string $order_id='' ): bool { 668 668 669 $is_active = self::is_activated( '$order_id ' . $order_id );669 $is_active = self::is_activated( '$order_id ' . $order_id ); 670 670 671 671 // Continue only if an order_id is available and plugin function is activated … … 674 674 $data = self::get_invoice_values( $order_id ); 675 675 676 return self::create_xml_content( $data, array( $order_id ) ); 677 678 } 679 680 /** 681 * Creates XML and send to Run My Accounts 682 * 683 * @param array $data data of the complete invoice 684 * @param array $order_ids an array of all affected orders for which we create the invoice 685 * @param bool $collective_invoice true if we create an collective invoice 686 * 687 * @return bool true if the invoice creation was successful otherwise false 688 * @throws DOMException 689 */ 690 public static function create_xml_content( array $data, array $order_ids, bool $collective_invoice = false ): bool { 691 692 $url = self::get_caller_url() . RMA_MANDANT . '/invoices?api_key=' . RMA_APIKEY; 693 694 //create the xml document 695 $xml = new DOMDocument('1.0', 'UTF-8'); 696 697 // create root element invoice and child 698 $root = $xml->appendChild( $xml->createElement("invoice") ); 699 foreach( $data[ 'invoice' ] as $key => $value ) { 700 if ( ! empty( $key ) ) 701 $root->appendChild( $xml->createElement( $key, $value ) ); 702 } 703 704 $tab_invoice = $root->appendChild($xml->createElement('parts')); 705 706 // create child elements part 707 foreach( $data[ 'part' ] as $part ){ 708 if( !empty( $part ) ){ 709 $tab_part = $tab_invoice->appendChild($xml->createElement('part')); 710 711 foreach( $part as $key=>$value ){ 712 $tab_part->appendChild($xml->createElement($key, $value)); 713 } 714 } 715 } 716 717 // make the output pretty 718 $xml->formatOutput = true; 719 720 // create xml content 721 $xml_str = $xml->saveXML() . "\n"; 722 723 // send xml content to RMA 724 $response = self::send_xml_content( $xml_str, $url ); 725 726 // $response empty == no errors 727 if ( 200 == self::first_key_of_array( $response ) || 728 204 == self::first_key_of_array( $response )) { 729 730 $status = 'invoiced'; 731 $invoice_type = $collective_invoice ? esc_html_x( 'Collective invoice', 'Order Note', 'rma-wc') : esc_html_x( 'Invoice', 'Order Note', 'rma-wc') ; 732 733 $invoice_number = $data[ 'invoice' ][ 'invnumber' ]; 734 $message = sprintf( esc_html_x( '%s %s created', 'Log', 'rma-wc'), $collective_invoice, $invoice_number); 735 736 // add order note to each order 737 foreach ( $order_ids as $order_id ) { 738 739 $order = wc_get_order( $order_id ); 740 $note = sprintf( esc_html_x( '%s %s created in Run my Accounts', 'Order Note', 'rma-wc'), $invoice_type, $invoice_number); 741 $order->add_order_note( $note ); 742 743 update_post_meta( $order_id, '_rma_invoice', $invoice_number ); 744 745 unset( $order ); 746 747 } 748 749 $return = true; 750 751 } 752 else { 753 754 $status = 'error'; 755 $message = '[' . self::first_key_of_array( $response ) . '] ' . reset( $response ); // get value of first key = return message 756 757 $return = false; 758 759 } 760 761 if ( ( 'error' == LOGLEVEL && 'error' == $status ) || 'complete' == LOGLEVEL ) { 762 763 $log_values = array( 764 'status' => $status, 765 'section_id' => $order_id, 766 'section' => esc_html_x('Invoice', 'Log Section', 'rma-wc'), 767 'mode' => self::rma_mode(), 768 'message' => $message ); 769 770 (new RMA_WC_API)->write_log($log_values); 771 772 // send email on error 773 if ( 'error' == $status && SENDLOGEMAIL ) (new RMA_WC_API)->send_log_email($log_values); 774 775 } 776 777 return $return; 778 779 } 780 781 /** 782 * Create customer in Run my Accounts 783 * 784 * @param string $type 785 * @param string $id 786 * @param string $action new|update 787 * 788 * @return bool|string 789 * 790 * @throws DOMException 791 */ 676 return self::create_xml_content( $data, array( $order_id ) ); 677 678 } 679 680 /** 681 * Creates XML and send to Run My Accounts 682 * 683 * @param array $data data of the complete invoice 684 * @param array $order_ids an array of all affected orders for which we create the invoice 685 * @param bool $collective_invoice true if we create an collective invoice 686 * 687 * @return bool true if the invoice creation was successful otherwise false 688 * @throws DOMException 689 */ 690 public static function create_xml_content( array $data, array $order_ids, bool $collective_invoice = false ): bool { 691 692 $url = self::get_caller_url() . RMA_MANDANT . '/invoices?api_key=' . RMA_APIKEY; 693 694 //create the xml document 695 $xml = new DOMDocument('1.0', 'UTF-8'); 696 697 // create root element invoice and child 698 $root = $xml->appendChild( $xml->createElement("invoice") ); 699 foreach( $data[ 'invoice' ] as $key => $value ) { 700 if ( ! empty( $key ) ) 701 $root->appendChild( $xml->createElement( $key, $value ) ); 702 } 703 704 $tab_invoice = $root->appendChild($xml->createElement('parts')); 705 706 // create child elements part 707 foreach( $data[ 'part' ] as $part ){ 708 if( !empty( $part ) ){ 709 $tab_part = $tab_invoice->appendChild($xml->createElement('part')); 710 711 foreach( $part as $key=>$value ){ 712 $tab_part->appendChild($xml->createElement($key, $value)); 713 } 714 } 715 } 716 717 // make the output pretty 718 $xml->formatOutput = true; 719 720 // create xml content 721 $xml_str = $xml->saveXML() . "\n"; 722 723 // send xml content to RMA 724 $response = self::send_xml_content( $xml_str, $url ); 725 726 // $response empty == no errors 727 if ( 200 == self::first_key_of_array( $response ) || 728 204 == self::first_key_of_array( $response )) { 729 730 $status = 'invoiced'; 731 $invoice_type = $collective_invoice ? esc_html_x( 'Collective invoice', 'Order Note', 'run-my-accounts-for-woocommerce') : esc_html_x( 'Invoice', 'Order Note', 'run-my-accounts-for-woocommerce') ; 732 733 $invoice_number = $data[ 'invoice' ][ 'invnumber' ]; 734 $message = sprintf( esc_html_x( '%1$s %2$s created', 'Log', 'run-my-accounts-for-woocommerce'), $collective_invoice, $invoice_number); 735 736 // add order note to each order 737 foreach ( $order_ids as $order_id ) { 738 739 $order = wc_get_order( $order_id ); 740 $note = sprintf( esc_html_x( '%1$s %2$s created in Run my Accounts', 'Order Note', 'run-my-accounts-for-woocommerce'), $invoice_type, $invoice_number); 741 $order->add_order_note( $note ); 742 $order->update_meta_data( '_rma_invoice', $invoice_number ); 743 744 $order->save(); 745 746 unset( $order ); 747 748 } 749 750 $return = true; 751 752 } 753 else { 754 755 $status = 'error'; 756 $message = '[' . self::first_key_of_array( $response ) . '] ' . reset( $response ); // get value of first key = return message 757 758 $return = false; 759 760 } 761 762 if ( ( 'error' == LOGLEVEL && 'error' == $status ) || 'complete' == LOGLEVEL ) { 763 764 $log_values = array( 765 'status' => $status, 766 'section_id' => $order_id, 767 'section' => esc_html_x('Invoice', 'Log Section', 'run-my-accounts-for-woocommerce'), 768 'mode' => self::rma_mode(), 769 'message' => $message ); 770 771 (new RMA_WC_API)->write_log($log_values); 772 773 // send email on error 774 if ( 'error' == $status && SENDLOGEMAIL ) (new RMA_WC_API)->send_log_email($log_values); 775 776 } 777 778 return $return; 779 780 } 781 782 /** 783 * Create customer in Run my Accounts 784 * 785 * @param string $type 786 * @param string $id 787 * @param string $action new|update 788 * 789 * @return bool|string 790 * 791 * @throws DOMException 792 */ 792 793 public function create_rma_customer( $type, $id='', $action = 'new') { 793 794 794 if( !$id || !$type)795 return false;796 797 // exit if plugin is not activated795 if( !$id || !$type) 796 return false; 797 798 // exit if plugin is not activated 798 799 if ( !self::is_activated('$user_id ' . $id ) ) 799 return false;800 return false; 800 801 801 802 // exit if a customer should not be created automatically 802 if ( !self::do_create_customer() )803 return false;804 805 // exit if user is already linked to a RMA customer account806 if ( 'user' == $type &&807 'new' == $action &&808 get_user_meta( $id, 'rma_customer', true ) )809 return false;810 811 $method = 'get_customer_values_by_' . $type . '_id';812 $data = self::$method( $id );803 if ( !self::do_create_customer() ) 804 return false; 805 806 // exit if user is already linked to a RMA customer account 807 if ( 'user' == $type && 808 'new' == $action && 809 get_user_meta( $id, 'rma_customer', true ) ) 810 return false; 811 812 $method = 'get_customer_values_by_' . $type . '_id'; 813 $data = self::$method( $id ); 813 814 814 815 // build REST api url for Run my Accounts … … 836 837 } 837 838 838 //create xml content839 $xml_str = $xml_doc->saveXML() . "\n";840 841 // send xml content to RMA with curl842 $response = self::send_xml_content( $xml_str, $caller_url_customer );843 844 // $response empty == no errors845 if ( 200 == self::first_key_of_array( $response ) ||846 204 == self::first_key_of_array( $response )) {847 848 // add RMA customer number to user_meta849 $status = 'created';850 $message = sprintf( esc_html_x( 'Customer %s created', 'Log', 'rma-wc'), $data['customernumber']);851 852 if ( 'user' == $type )853 update_user_meta( $id, 'rma_customer', $data[ 'customernumber' ] );854 855 }856 else {857 858 $status = 'error';859 $message = '[' . self::first_key_of_array( $response ) . '] ' . reset( $response ); // get value of first key = return message860 861 }862 863 if ( ( 'error' == LOGLEVEL && 'error' == $status ) || 'complete' == LOGLEVEL ) {864 865 $log_values = array(866 'status' => $status,867 'section_id' => $id,868 'section' => sprintf( esc_html_x('Customer by %s id', 'Log Section', 'rma-wc'), $type),869 'mode' => self::rma_mode(),870 'message' => $message );871 872 self::write_log($log_values);873 874 }839 //create xml content 840 $xml_str = $xml_doc->saveXML() . "\n"; 841 842 // send xml content to RMA with curl 843 $response = self::send_xml_content( $xml_str, $caller_url_customer ); 844 845 // $response empty == no errors 846 if ( 200 == self::first_key_of_array( $response ) || 847 204 == self::first_key_of_array( $response )) { 848 849 // add RMA customer number to user_meta 850 $status = 'created'; 851 $message = sprintf( esc_html_x( 'Customer %s created', 'Log', 'run-my-accounts-for-woocommerce'), $data['customernumber']); 852 853 if ( 'user' == $type ) 854 update_user_meta( $id, 'rma_customer', $data[ 'customernumber' ] ); 855 856 } 857 else { 858 859 $status = 'error'; 860 $message = '[' . self::first_key_of_array( $response ) . '] ' . reset( $response ); // get value of first key = return message 861 862 } 863 864 if ( ( 'error' == LOGLEVEL && 'error' == $status ) || 'complete' == LOGLEVEL ) { 865 866 $log_values = array( 867 'status' => $status, 868 'section_id' => $id, 869 'section' => sprintf( esc_html_x('Customer by %s id', 'Log Section', 'run-my-accounts-for-woocommerce'), $type), 870 'mode' => self::rma_mode(), 871 'message' => $message ); 872 873 self::write_log($log_values); 874 875 } 875 876 876 877 return 'error' == $status ? 'false' : $data[ 'customernumber' ]; 877 878 } 878 879 879 /**880 * Return first key of an array881 * can be replaced by array_key_first() when min. PHP is 7.3882 *883 * @param $array884 *885 * @return string886 *887 * @since 1.5.2888 */889 // ToDo: replace this function as soon as min. PHP is 7.3 or above880 /** 881 * Return first key of an array 882 * can be replaced by array_key_first() when min. PHP is 7.3 883 * 884 * @param $array 885 * 886 * @return string 887 * 888 * @since 1.5.2 889 */ 890 // ToDo: replace this function as soon as min. PHP is 7.3 or above 890 891 public static function first_key_of_array( $array ): string 891 {892 893 // set point of the array894 reset( $array );895 896 // return the key897 return key( $array );898 899 }900 901 /**902 * Send xml content to RMA with curl903 *904 * @param $xml string905 * @param $url string906 *907 * @return array908 */892 { 893 894 // set point of the array 895 reset( $array ); 896 897 // return the key 898 return key( $array ); 899 900 } 901 902 /** 903 * Send xml content to RMA with curl 904 * 905 * @param $xml string 906 * @param $url string 907 * 908 * @return array 909 */ 909 910 public static function send_xml_content( string $xml, string $url ): array { 910 911 911 $response = wp_safe_remote_post(912 $url,913 array(914 'headers' => array(915 'Content-Type' => 'application/xml'916 ),917 'body' => $xml918 )919 );920 921 $response_code = wp_remote_retrieve_response_code( $response );922 $response_body = wp_remote_retrieve_body( $response );923 924 return array( $response_code => $response_body );925 926 }912 $response = wp_safe_remote_post( 913 $url, 914 array( 915 'headers' => array( 916 'Content-Type' => 'application/xml' 917 ), 918 'body' => $xml 919 ) 920 ); 921 922 $response_code = wp_remote_retrieve_response_code( $response ); 923 $response_body = wp_remote_retrieve_body( $response ); 924 925 return array( $response_code => $response_body ); 926 927 } 927 928 928 929 /** … … 943 944 'status' => 'deactivated', 944 945 'section_id' => $section_id, 945 'section' => esc_html_x( 'Activation', 'Log Section', 'rma-wc' ),946 'section' => esc_html_x( 'Activation', 'Log Section', 'run-my-accounts-for-woocommerce' ), 946 947 'mode' => self::rma_mode(), 947 'message' => esc_html_x( 'Plugin was not activated', 'Log', 'r ma-wc' ) );948 'message' => esc_html_x( 'Plugin was not activated', 'Log', 'run-my-accounts-for-woocommerce' ) ); 948 949 949 950 self::write_log($log_values); … … 955 956 } 956 957 957 /**958 * Check if the customer should be created in Run my Accounts959 *960 * @return string961 */962 private function do_create_customer(): string {963 964 $settings = get_option( 'wc_rma_settings' );965 return isset( $settings[ 'rma-create-customer' ] ) ? $settings[ 'rma-create-customer' ] : '';966 967 }968 969 /**970 * @return string971 */972 public static function rma_mode(): string973 {974 return RMA_CALLERSANDBOX ? 'Test' : 'Live' ;975 }958 /** 959 * Check if the customer should be created in Run my Accounts 960 * 961 * @return string 962 */ 963 private function do_create_customer(): string { 964 965 $settings = get_option( 'wc_rma_settings' ); 966 return isset( $settings[ 'rma-create-customer' ] ) ? $settings[ 'rma-create-customer' ] : ''; 967 968 } 969 970 /** 971 * @return string 972 */ 973 public static function rma_mode(): string 974 { 975 return RMA_CALLERSANDBOX ? 'Test' : 'Live' ; 976 } 976 977 977 978 /** … … 983 984 */ 984 985 public function write_log( &$values ): bool { 985 global $wpdb; 986 987 $table_name = $wpdb->prefix . RMA_WC_LOG_TABLE; 988 989 $wpdb->insert( $table_name, 990 array( 991 'time' => current_time( 'mysql' ), 992 'status' => $values['status'], 993 'section_id' => $values['section_id'], 994 'section' => $values['section'], 995 'mode' => $values['mode'], 996 'message' => $values['message'] 997 ) 986 987 If( ! function_exists( 'wc_get_logger' ) || empty( $values ) ) { 988 return false; 989 } 990 991 // create the message 992 $message = sprintf( esc_html__( 'Section %1$s: status %2$s message "%3$s".', 'run-my-accounts-for-woocommerce'), 993 $values['section'], 994 $values['status'], 995 $values['message'] 998 996 ); 999 997 1000 // send email on error 1001 if ( 'error' == $values['status'] && SENDLOGEMAIL ) $this->send_log_email($values); 1002 1003 return true; 998 // array with additional log information 999 $args = array( 1000 'source' => 'Run My Accounts', 1001 'section' => $values['section'], 1002 'ID' => $values['section_id'], 1003 'mode' => $values['mode'] 1004 1005 ); 1006 1007 switch( $values['status'] ) { 1008 /* 1009 * wc_get_logger()->emergency( '' ); system is unusable 1010 * wc_get_logger()->alert( '' ); action must be taken immediately 1011 * wc_get_logger()->critical( '' ); critical conditions 1012 * wc_get_logger()->error( '' ); error conditions 1013 * wc_get_logger()->warning( '' ); warning conditions 1014 * wc_get_logger()->notice( '' ); normal but significant condition 1015 * wc_get_logger()->info( '' ); informational messages 1016 * wc_get_logger()->debug( '' ); debug-level messages 1017 */ 1018 case 'error': 1019 wc_get_logger()->error( $message, $args ); 1020 1021 // send email on error 1022 if ( SENDLOGEMAIL ) $this->send_log_email($values); 1023 1024 break; 1025 1026 case 'failed': 1027 wc_get_logger()->warning( $message, $args ); 1028 break; 1029 default: 1030 wc_get_logger()->info( $message, $args ); 1031 break; 1032 } 1033 1034 return true; 1004 1035 } 1005 1036 … … 1013 1044 public function send_log_email( &$values ): bool { 1014 1045 1015 ob_start();1016 include( plugin_dir_path( __FILE__ ) . '../templates/email/error-email-template.php');1017 $email_content = ob_get_contents();1018 ob_end_clean();1019 1020 $headers = array('Content-Type: text/html; charset=UTF-8');1021 if ( !wp_mail( LOGEMAIL, esc_html_x('An error occurred while connecting with Run my Accounts API', 'email', 'rma-wc'), $email_content, $headers) ) {1022 1023 $log_values = array(1024 'status' => 'failed',1025 'section_id' => LOGEMAIL,1026 'section' => esc_html_x( 'Email', 'Log Section', 'rma-wc' ),1027 'mode' => self::rma_mode(),1028 'message' => esc_html_x( 'Failed to send email.' , 'Log', 'rma-wc') );1029 1030 self::write_log($log_values);1031 1032 } elseif ( 'complete' == LOGLEVEL) {1033 1034 $log_values = array(1035 'status' => 'send',1036 'section_id' => LOGEMAIL,1037 'section' => esc_html_x( 'Email', 'Log Section', 'rma-wc' ),1038 'mode' => self::rma_mode(),1039 'message' => esc_html_x( 'Email sent successfully.' , 'Log', 'rma-wc') );1040 1041 self::write_log($log_values);1042 1043 }1046 ob_start(); 1047 include( plugin_dir_path( __FILE__ ) . '../templates/email/error-email-template.php'); 1048 $email_content = ob_get_contents(); 1049 ob_end_clean(); 1050 1051 $headers = array('Content-Type: text/html; charset=UTF-8'); 1052 if ( !wp_mail( LOGEMAIL, esc_html_x('An error occurred while connecting with Run my Accounts API', 'email', 'run-my-accounts-for-woocommerce'), $email_content, $headers) ) { 1053 1054 $log_values = array( 1055 'status' => 'failed', 1056 'section_id' => LOGEMAIL, 1057 'section' => esc_html_x( 'Email', 'Log Section', 'run-my-accounts-for-woocommerce' ), 1058 'mode' => self::rma_mode(), 1059 'message' => esc_html_x( 'Failed to send email.' , 'Log', 'run-my-accounts-for-woocommerce') ); 1060 1061 self::write_log($log_values); 1062 1063 } elseif ( 'complete' == LOGLEVEL) { 1064 1065 $log_values = array( 1066 'status' => 'send', 1067 'section_id' => LOGEMAIL, 1068 'section' => esc_html_x( 'Email', 'Log Section', 'run-my-accounts-for-woocommerce' ), 1069 'mode' => self::rma_mode(), 1070 'message' => esc_html_x( 'Email sent successfully.' , 'Log', 'run-my-accounts-for-woocommerce') ); 1071 1072 self::write_log($log_values); 1073 1074 } 1044 1075 1045 1076 return true; -
run-my-accounts-for-woocommerce/trunk/classes/class-RMA_WC_Backend.php
r2707913 r3262812 71 71 public function plugins_loaded() { 72 72 73 $this->create();74 73 $this->update(); 75 74 } -
run-my-accounts-for-woocommerce/trunk/classes/class-RMA_WC_Backend_Abstract.php
r2873238 r3262812 17 17 18 18 const VERSION = '1.7.1'; 19 const DB_VERSION = '1.1.0';20 21 private static function _table_log() {22 global $wpdb;23 return $wpdb->prefix . RMA_WC_LOG_TABLE;24 }25 26 public function create() {27 28 /**29 * Create Custom Table30 * https://codex.wordpress.org/Creating_Tables_with_Plugins31 */32 33 global $wpdb;34 35 if ($wpdb->get_var("SHOW TABLES LIKE '".self::_table_log()."'") != self::_table_log()) {36 37 $charset_collate = $wpdb->get_charset_collate();38 39 $sql = 'CREATE TABLE ' . self::_table_log() . ' (40 id mediumint(9) NOT NULL AUTO_INCREMENT,41 time datetime DEFAULT "0000-00-00 00:00:00" NOT NULL,42 status text NOT NULL,43 section text NOT NULL,44 section_id text NOT NULL,45 mode text NOT NULL,46 message text NOT NULL,47 UNIQUE KEY id (id) ) ' . $charset_collate . ';';48 49 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');50 51 dbDelta($sql);52 53 }54 55 }56 19 57 20 /** … … 60 23 */ 61 24 public function update() { 62 /**63 * get_option() WP Since: 1.0.064 * https://codex.wordpress.org/Function_Reference/get_option65 */66 if ( self::DB_VERSION > get_option( 'wc_rma_db_version' ) ) { // update option if value is different67 68 // database update if necessary69 /**70 * update_option() WP Since: 1.0.071 * https://codex.wordpress.org/Function_Reference/update_option72 */73 update_option("wc_rma_db_version", self::DB_VERSION);74 75 }76 25 77 26 if ( self::VERSION > get_option( 'wc_rma_version' ) ) { // update option if value is different … … 90 39 91 40 // drop table 92 $wpdb->query('DROP TABLE IF EXISTS ' . self::_table_log() . ';'); 41 $table_name = $wpdb->prefix . 'rma_wc_log'; 42 $wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $table_name ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.SchemaChange 93 43 94 44 // delete all options … … 107 57 */ 108 58 add_option('wc_rma_version', self::VERSION); 109 add_option('wc_rma_db_version', self::DB_VERSION); 59 110 60 } 111 61 … … 126 76 127 77 // add invoice column to order page 128 add_filter( 'manage_edit-shop_order_columns', array( $this, 'add_column_to_order_table' ) ); 129 add_action( 'manage_shop_order_posts_custom_column', array( $this, 'add_value_to_order_table_row' ) ); 130 131 // add bulk action to order page 78 add_filter( 'manage_edit-shop_order_columns', array( $this, 'add_column_to_order_table' ) ); // compatibility without HPOS 79 add_action( 'manage_shop_order_posts_custom_column', array( $this, 'add_value_to_order_table_row' ) ); // compatibility without HPOS 80 81 add_filter( 'manage_woocommerce_page_wc-orders_columns', array( $this, 'add_column_to_order_table' ) ); // with HPOS 82 add_action( 'manage_woocommerce_page_wc-orders_custom_column', array( $this, 'add_value_to_order_table_row_hpos' ), 10, 2 ); // with HPOS 83 84 // add bulk action to order page 132 85 add_filter( 'bulk_actions-edit-shop_order', array( $this, 'create_invoice_bulk_actions_edit_product'), 20, 1 ); 133 86 add_filter( 'handle_bulk_actions-edit-shop_order', array( $this, 'create_invoice_handle_bulk_action_edit_shop_order'), 10, 3 ); … … 158 111 */ 159 112 public function create_invoice_bulk_actions_edit_product( $actions ) { 160 $actions['rma_create_invoice'] = __( 'Create Invoice', 'r ma-wc' );113 $actions['rma_create_invoice'] = __( 'Create Invoice', 'run-my-accounts-for-woocommerce' ); 161 114 return $actions; 162 115 } … … 192 145 foreach ( $post_ids as $post_id ) { 193 146 194 $invoice_number = get_post_meta( $post_id, '_rma_invoice' ); 147 $order = wc_get_order( $post_id ); 148 $invoice_number = $order->get_meta( '_rma_invoice', true ); 195 149 196 150 // order has already an invoice … … 245 199 'Created %s invoices', 246 200 $success_count, 247 'r ma-wc'201 'run-my-accounts-for-woocommerce' 248 202 ) . '</p></div>', number_format_i18n( $success_count ) ); 249 203 … … 263 217 264 218 // bail if the order has been paid for or invoice was already created 265 if ( $theorder->is_paid() || !empty( get_post_meta( $theorder->get_id(),'_rma_invoice', true ) ) ){219 if ( $theorder->is_paid() || !empty( $theorder->get_meta( '_rma_invoice', true ) ) ){ 266 220 return $actions; 267 221 } 268 222 269 $actions['create_rma_invoice'] = __( 'Create invoice in Run my Accounts', 'r ma-wc' );223 $actions['create_rma_invoice'] = __( 'Create invoice in Run my Accounts', 'run-my-accounts-for-woocommerce' ); 270 224 return $actions; 271 225 … … 293 247 * @return array 294 248 */ 295 public function add_column_to_order_table( $columns ) { 296 297 $columns = RMA_WC_Frontend::array_insert( $columns, 'order_total', 'rma_invoice', __( 'Invoice #', 'rma-wc')); 298 299 return $columns; 300 } 301 249 public function add_column_to_order_table( $columns ): array { 250 251 return RMA_WC_Frontend::array_insert($columns, 'order_total', 'rma_invoice', __('Invoice #', 'run-my-accounts-for-woocommerce')); 252 253 } 302 254 public function add_value_to_order_table_row( $column ) { 303 255 … … 306 258 switch ( $column ) { 307 259 case 'rma_invoice' : 308 echo get_post_meta( $post->ID, '_rma_invoice', true ); 260 261 $order = wc_get_order( $post->ID ); 262 echo $order->get_meta( '_rma_invoice', true ); 263 309 264 default: 310 265 } … … 312 267 313 268 } 269 270 /** 271 * Add value to admin order table for HPOS 272 * 273 * @param $column 274 * @param $wc_order_obj 275 * 276 * @return void 277 */ 278 public function add_value_to_order_table_row_hpos( $column, $wc_order_obj ) { 279 280 switch ( $column ) { 281 case 'rma_invoice' : 282 283 echo $wc_order_obj->get_meta( '_rma_invoice', true ); 284 285 default: 286 } 287 288 289 } 314 290 315 291 /** … … 366 342 if ( ! defined( 'WC_GERMANIZED_VERSION' ) ) { 367 343 $fields['billing']['fields']['billing_title'] = array( 368 'label' => __('Title', 'r ma-wc'),344 'label' => __('Title', 'run-my-accounts-for-woocommerce'), 369 345 'type' => 'select', 370 346 'options' => apply_filters( 'woocommerce_rma_title_options', 371 347 array( 372 1 => __('Mr.', 'r ma-wc'),373 2 => __('Ms.', 'r ma-wc')348 1 => __('Mr.', 'run-my-accounts-for-woocommerce'), 349 2 => __('Ms.', 'run-my-accounts-for-woocommerce') 374 350 ) 375 351 ) … … 377 353 } 378 354 379 $fields[ 'rma' ][ 'title' ] = __( 'Settings Run my Accounts', 'r ma-wc' );355 $fields[ 'rma' ][ 'title' ] = __( 'Settings Run my Accounts', 'run-my-accounts-for-woocommerce' ); 380 356 381 357 $RMA_WC_API = new RMA_WC_API(); … … 385 361 386 362 $fields[ 'rma' ][ 'fields' ][ 'rma_customer' ] = array( 387 'label' => __( 'Customer', 'r ma-wc' ),363 'label' => __( 'Customer', 'run-my-accounts-for-woocommerce' ), 388 364 'type' => 'select', 389 'options' => array('' => __( 'Error while connecting to RMA. Please check your settings.', 'r ma-wc' )),390 'description' => __( 'Select the corresponding RMA customer for this account.', 'r ma-wc' )365 'options' => array('' => __( 'Error while connecting to RMA. Please check your settings.', 'run-my-accounts-for-woocommerce' )), 366 'description' => __( 'Select the corresponding RMA customer for this account.', 'run-my-accounts-for-woocommerce' ) 391 367 ); 392 368 … … 394 370 } 395 371 396 $options = array('' => __( 'Select customer...', 'r ma-wc' )) + $options;372 $options = array('' => __( 'Select customer...', 'run-my-accounts-for-woocommerce' )) + $options; 397 373 398 374 $fields[ 'rma' ][ 'fields' ][ 'rma_customer' ] = array( 399 'label' => __( 'Customer', 'r ma-wc' ),375 'label' => __( 'Customer', 'run-my-accounts-for-woocommerce' ), 400 376 'type' => 'select', 401 377 'options' => $options, 402 'description' => __( 'Select the corresponding RMA customer for this account.', 'r ma-wc' )378 'description' => __( 'Select the corresponding RMA customer for this account.', 'run-my-accounts-for-woocommerce' ) 403 379 ); 404 380 … … 406 382 407 383 $fields[ 'rma' ][ 'fields' ][ 'rma_billing_account' ] = array( 408 'label' => __( 'Receivables Account', 'r ma-wc' ),384 'label' => __( 'Receivables Account', 'run-my-accounts-for-woocommerce' ), 409 385 'type' => 'input', 410 'description' => __( 'The receivables account has to be available in RMA. Leave it blank to use default value 1100.', 'r ma-wc' )386 'description' => __( 'The receivables account has to be available in RMA. Leave it blank to use default value 1100.', 'run-my-accounts-for-woocommerce' ) 411 387 ); 412 388 413 389 $fields[ 'rma' ][ 'fields' ][ 'rma_payment_period' ] = array( 414 'label' => __( 'Payment Period', 'r ma-wc' ),390 'label' => __( 'Payment Period', 'run-my-accounts-for-woocommerce' ), 415 391 'type' => 'input', 416 'description' => __( 'How many days has this customer to pay your invoice?', 'r ma-wc' )392 'description' => __( 'How many days has this customer to pay your invoice?', 'run-my-accounts-for-woocommerce' ) 417 393 ); 418 394 … … 424 400 * 425 401 * @param $user_id int the ID of the current user. 402 * 426 403 * @return bool Meta ID if the key didn't exist, true on successful update, false on failure. 427 404 */ 428 public function usermeta_form_field_update( $user_id ){405 public function usermeta_form_field_update( int $user_id ): bool { 429 406 // check that the current user have the capability to edit the $user_id 430 407 if (!current_user_can('edit_user', $user_id)) -
run-my-accounts-for-woocommerce/trunk/classes/class-RMA_WC_Collective_Invoicing.php
r2707913 r3262812 41 41 if( !empty( $dates ) ) { 42 42 43 $this->settings[ 'collective_invoice_next_date_ts' ] = strtotime( date('Y-m-d', $dates[ 'next_date_ts' ] ) );43 $this->settings[ 'collective_invoice_next_date_ts' ] = strtotime(gmdate('Y-m-d', $dates[ 'next_date_ts' ] ) ); 44 44 update_option( 'wc_rma_settings_collective_invoice', $this->settings ); 45 45 … … 81 81 82 82 // if weekday is today and the next cron run is today 83 if( date('N', strtotime( 'now' ) ) == $weekday_number &&83 if( gmdate('N', strtotime( 'now' ) ) == $weekday_number && 84 84 $next_time[ 'next_time_ts_utc' ] == $possible_today_cron_ts_utc ) { 85 85 … … 161 161 return array( 162 162 'next_time_ts_utc' => $next_ts_utc, 163 'time_utc' => date( get_option( 'time_format' ) . ':s', $next_ts_utc ),164 'time' => get_date_from_gmt( date( get_option( 'time_format' ), $next_ts_utc ), get_option( 'time_format' ) )163 'time_utc' => gmdate( get_option( 'time_format' ) . ':s', $next_ts_utc ), 164 'time' => get_date_from_gmt( gmdate( get_option( 'time_format' ), $next_ts_utc ), get_option( 'time_format' ) ) 165 165 ); 166 166 … … 197 197 } 198 198 199 $orders_no_invoice = get_posts( array( 200 'numberposts' => -1, 201 'post_type' => 'shop_order', 202 'post_status' => 'wc-completed', 203 'meta_query' => array( 204 'relation' => 'AND', 205 array( 206 'key' => '_rma_invoice', 207 'compare' => 'NOT EXISTS', 208 ), 209 ) 210 ) 211 ); 199 $orders_no_invoice = wc_get_orders( 200 array( 201 'type' => 'shop_order', 202 'limit' => -1, 203 'status' => array( 204 'wc-completed' 205 ), 206 array( 207 'meta_query' => array( 208 'relation' => 'AND', 209 array( 210 'key' => '_rma_invoice', 211 'compare' => 'NOT EXISTS', 212 ), 213 ) 214 ) 215 ) 216 ); 212 217 213 218 $cumulated_orders_by_customer_id = array(); … … 257 262 258 263 // get the timestamp with the current date, but without time 259 $current_date = strtotime( date('Y-m-d', time() ) );264 $current_date = strtotime(gmdate('Y-m-d', time() ) ); 260 265 261 266 // if we do not have to create collective invoices today … … 348 353 349 354 $headers = array('Content-Type: text/html; charset=UTF-8'); 350 $email_content = sprintf( esc_html_x('The following collective invoices were sent: %s', 'email', 'r ma-wc'), implode(', ', $created_invoices ) );351 wp_mail( LOGEMAIL, esc_html_x( 'Collective invoices were sent', 'email', 'r ma-wc' ), $email_content, $headers);355 $email_content = sprintf( esc_html_x('The following collective invoices were sent: %s', 'email', 'run-my-accounts-for-woocommerce'), implode(', ', $created_invoices ) ); 356 wp_mail( LOGEMAIL, esc_html_x( 'Collective invoices were sent', 'email', 'run-my-accounts-for-woocommerce' ), $email_content, $headers); 352 357 353 358 } … … 361 366 if( !empty( $dates ) ) { 362 367 363 $this->settings[ 'collective_invoice_next_date_ts' ] = strtotime( date('Y-m-d', $dates[ 'next_date_ts' ] ) );368 $this->settings[ 'collective_invoice_next_date_ts' ] = strtotime(gmdate('Y-m-d', $dates[ 'next_date_ts' ] ) ); 364 369 update_option( 'wc_rma_settings_collective_invoice', $this->settings ); 365 370 -
run-my-accounts-for-woocommerce/trunk/classes/class-RMA_WC_Frontend.php
r2707913 r3262812 106 106 107 107 $fields['billing_title'] = array( 108 'label' => esc_html__('Title', 'r ma-wc'),108 'label' => esc_html__('Title', 'run-my-accounts-for-woocommerce'), 109 109 'type' => 'select', 110 110 'class' => array ( 'form-row-wide', 'address-field' ), … … 112 112 'woocommerce_rma_title_options', 113 113 array( 114 1 => __('Mr.', 'r ma-wc'),115 2 => __('Ms.', 'r ma-wc')114 1 => __('Mr.', 'run-my-accounts-for-woocommerce'), 115 2 => __('Ms.', 'run-my-accounts-for-woocommerce') 116 116 ) 117 117 ), … … 133 133 134 134 if ( ! empty( $_POST['billing_title'] ) ) { 135 update_post_meta( $order_id, '_billing_title', sanitize_text_field( $_POST['billing_title'] ) ); 135 136 $order = wc_get_order( $order_id ); 137 $order->update_meta_data( '_billing_title', sanitize_text_field( $_POST['billing_title'] ) ); 138 $order->save(); 139 136 140 } 137 141 … … 147 151 public function add_column_to_user_table( $column ): array { 148 152 149 $column = self::array_insert( $column, 'email', 'rma_customer_id', __( 'RMA Customer # ', 'r ma-wc') );153 $column = self::array_insert( $column, 'email', 'rma_customer_id', __( 'RMA Customer # ', 'run-my-accounts-for-woocommerce') ); 150 154 151 155 return $column; … … 197 201 public function plugins_loaded() { 198 202 199 self::load_textdomain();200 201 203 // Display the admin notification 202 204 add_action( 'admin_notices', array( $this, 'admin_notices' ) ) ; 203 }204 205 /**206 * Load Textdomains207 */208 public function load_textdomain() {209 210 /**211 * load_textdomain() WP Since: 1.0.0212 * https://codex.wordpress.org/Function_Reference/load_textdomain213 */214 load_textdomain( 'rma-wc', WP_LANG_DIR . "/plugins/rma-wc/rma-wc-$this->locale.mo" );215 216 /**217 * load_plugin_textdomain() WP Since: 1.0.0218 * https://codex.wordpress.org/Function_Reference/load_plugin_textdomain219 */220 load_plugin_textdomain( 'rma-wc', false, plugin_basename( RMA_WC_PFAD . 'languages/' ) );221 222 205 } 223 206 … … 234 217 $html = '<div class="notice notice-error">'; 235 218 $html .= '<p>'; 236 $html .= '<b>'.esc_html__( 'Run my Accounts for WooCommerce', 'r ma-wc' ).' </b>';237 $html .= esc_html__( 'You are using a wrong PHP version. You need to install PHP 7.2 or higher.', 'r ma-wc' );219 $html .= '<b>'.esc_html__( 'Run my Accounts for WooCommerce', 'run-my-accounts-for-woocommerce' ).' </b>'; 220 $html .= esc_html__( 'You are using a wrong PHP version. You need to install PHP 7.2 or higher.', 'run-my-accounts-for-woocommerce' ); 238 221 $html .= ' '; 239 $html .= sprintf( esc_html__( 'The current PHP version is %s.', 'r ma-wc' ), PHP_VERSION);222 $html .= sprintf( esc_html__( 'The current PHP version is %s.', 'run-my-accounts-for-woocommerce' ), PHP_VERSION); 240 223 $html .= '</p>'; 241 224 $html .= '</div>'; … … 249 232 $html = '<div class="notice notice-warning">'; 250 233 $html .= '<p>'; 251 $html .= '<b>'.esc_html__( 'Warning', 'r ma-wc' ).' </b>';252 $html .= esc_html__('Please enter your Production Client and Production API Key before using Run my Accounts for WooCommerce in production mode.', 'r ma-wc' );234 $html .= '<b>'.esc_html__( 'Warning', 'run-my-accounts-for-woocommerce' ).' </b>'; 235 $html .= esc_html__('Please enter your Production Client and Production API Key before using Run my Accounts for WooCommerce in production mode.', 'run-my-accounts-for-woocommerce' ); 253 236 $html .= '</p>'; 254 237 $html .= '</div>'; … … 261 244 262 245 $html = '<div class="update-nag">'; 263 $html .= esc_html__( 'WooCommerce Run my Accounts is not activated. No invoice will be created.', 'r ma-wc' );246 $html .= esc_html__( 'WooCommerce Run my Accounts is not activated. No invoice will be created.', 'run-my-accounts-for-woocommerce' ); 264 247 $html .= '</div>'; 265 248 … … 324 307 public function create_invoice_on_status_change( $order_id, $old_status, $new_status ) { 325 308 326 $invoice_number = get_post_meta( $order_id, '_rma_invoice', true ); 309 $order = wc_get_order( $order_id ); 310 $invoice_number = $order->get_meta( '_rma_invoice', true ); 327 311 328 312 if( !empty( $invoice_number ) || 'completed' != $new_status || !class_exists('RMA_WC_API') ) -
run-my-accounts-for-woocommerce/trunk/classes/class-RMA_WC_Payment.php
r2707913 r3262812 81 81 82 82 // get the Run My Accounts invoice number 83 $this->invoice = get_post_meta( $this->order_id, '_rma_invoice', true ); 83 $order = wc_get_order( $this->order_id ); 84 $this->invoice = $order->get_meta('_rma_invoice', true ); 84 85 85 86 $data = self::get_payment_details(); … … 111 112 $status = 'paid'; 112 113 113 $message = sprintf( esc_html_x( 'Payment % s %s booked on account %s', 'Order Note', 'rma-wc'), $data['payment']['amount_paid'], $data['payment']['currency'], $data['payment']['payment_accno'] );114 $message = sprintf( esc_html_x( 'Payment %1$s %2$s booked on account %3$s', 'Order Note', 'run-my-accounts-for-woocommerce'), $data['payment']['amount_paid'], $data['payment']['currency'], $data['payment']['payment_accno'] ); 114 115 115 116 // add order note … … 130 131 131 132 $log_values = array( 132 'status' => $status,133 'status' => $status, 133 134 'section_id' => $this->order_id, 134 'section' => esc_html_x('Payment', 'Log Section', 'rma-wc'),135 'mode' => (new RMA_WC_API)->rma_mode(),136 'message' => $message );135 'section' => esc_html_x('Payment', 'Log Section', 'run-my-accounts-for-woocommerce'), 136 'mode' => (new RMA_WC_API)->rma_mode(), 137 'message' => $message ); 137 138 138 139 (new RMA_WC_API)->write_log($log_values); … … 158 159 if ( isset( $this->settings[ $name ] ) && 1 == $this->settings[ $name ] ) { 159 160 160 $message = esc_html_x( 'Payment not booked in Run my Accounts. Payment method is excluded for payment booking.', 'Order Note', 'r ma-wc');161 $message = esc_html_x( 'Payment not booked in Run my Accounts. Payment method is excluded for payment booking.', 'Order Note', 'run-my-accounts-for-woocommerce'); 161 162 // add order note 162 163 $order->add_order_note( $message ); … … 189 190 'id' => $this->order_id, 190 191 'invnumber' => $this->invoice, 191 'datepaid' => date(DATE_RFC3339), //$order->get_date_paid() ,//date( DateTime::RFC3339, time() ),192 'datepaid' => gmdate(DATE_RFC3339), //$order->get_date_paid() ,//gmdate( DateTime::RFC3339, time() ), 192 193 'amount_paid' => $order->get_total(), 193 194 'source' => 'Shop-Payment', -
run-my-accounts-for-woocommerce/trunk/classes/class-RMA_WC_Rental_And_Booking.php
r2707913 r3262812 105 105 // build multiline description 106 106 $part[ 'description' ] = $part[ 'description' ] . "\n" . 107 sprintf( __( 'Pickup Location: %s', 'r ma-wc' ), $pickup_location ) . "\n" .108 sprintf( __( 'Pickup Date/Time: %s', 'r ma-wc' ), $pickup_date ) . "\n" .109 sprintf( __( 'Return Date/Time: %s', 'r ma-wc' ), $return_date ) . "\n" .110 sprintf( __( 'Total Days: % s (%s)', 'rma-wc' ), $days, $total_days );107 sprintf( __( 'Pickup Location: %s', 'run-my-accounts-for-woocommerce' ), $pickup_location ) . "\n" . 108 sprintf( __( 'Pickup Date/Time: %s', 'run-my-accounts-for-woocommerce' ), $pickup_date ) . "\n" . 109 sprintf( __( 'Return Date/Time: %s', 'run-my-accounts-for-woocommerce' ), $return_date ) . "\n" . 110 sprintf( __( 'Total Days: %1$s (%2$s)', 'run-my-accounts-for-woocommerce' ), $days, $total_days ); 111 111 112 112 // return modified array -
run-my-accounts-for-woocommerce/trunk/classes/class-RMA_WC_Settings_Page.php
r2707913 r3262812 14 14 if ( !class_exists('RMA_WC_Settings_Page') ) { 15 15 16 class RMA_WC_Settings_Page { 17 18 private $admin_url; 19 private $option_group_general; 20 private $option_group_accounting; 21 private $option_group_collective_invoice; 22 private $options_general; 23 private $options_accounting; 24 private $options_collective_invoice; 25 private $option_page_general; 26 private $option_page_accounting; 27 private $option_page_collective_invoice; 28 private $option_page_log; 29 private $rma_log_count; 30 31 public function __construct() { 32 33 $this->admin_url = 'admin.php?page=rma-wc'; 34 $this->option_group_general = 'wc_rma_settings'; 35 $this->option_group_accounting = 'wc_rma_settings_accounting'; 36 $this->option_group_collective_invoice = 'wc_rma_settings_collective_invoice'; 37 $this->option_page_general = 'settings-general'; 38 $this->option_page_accounting = 'settings-accounting'; 39 $this->option_page_collective_invoice = 'settings-collective-invoice'; 40 $this->option_page_log = 'settings-log'; 41 42 $this->options_general = get_option( $this->option_group_general ); 43 $this->options_accounting = get_option( $this->option_group_accounting ); 44 $this->options_collective_invoice = get_option( $this->option_group_collective_invoice ); 45 46 add_action( 'wp_ajax_rma_log_table', array( $this, 'ajax_handle_database_log_table') ); 47 48 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue' ) ); 49 50 add_action( 'admin_menu', array( $this, 'add_plugin_page' ) ); 51 } 52 53 public function admin_enqueue( $hook ) { 54 55 if( 'woocommerce_page_rma-wc' != $hook ) 56 return; 57 58 // enqueue script and style for autocomplete on admin page 59 wp_enqueue_script( 'select2', plugins_url( '../assets/js/select2.min.js', __FILE__ ), array('jquery'), '4.0.13', 'true' ); 60 wp_register_style( 'select2', plugins_url( '../assets/css/select2.min.css', __FILE__ ), false, '4.0.13' ); 61 wp_enqueue_style( 'select2' ); 62 63 wp_enqueue_script( 'rma-admin-script', plugins_url( '../assets/js/admin.js', __FILE__ ), array('jquery'), get_option( 'wc_rma_version' ), 'true' ); 64 65 } 66 67 public function add_plugin_page(){ 68 // This page will be under "WooCommerce" 69 add_submenu_page('woocommerce', // $parent_slug 70 'Run my Accounts - Settings', // $page_title 71 __('Run my Accounts', 'rma-wc'), // $menu_title 72 'manage_options', // $capability 73 'rma-wc', // $menu_slug 74 array($this, 'create_admin_page') // $function 75 ); 76 77 add_action( 'admin_init', array( $this, 'options_init') ); 78 79 } 80 81 public function create_admin_page() { 82 83 $active_page = sanitize_text_field( ( isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'general' ) ); // set default tab ?> 16 class RMA_WC_Settings_Page { 17 18 private $admin_url; 19 private $option_group_general; 20 private $option_group_accounting; 21 private $option_group_collective_invoice; 22 private $options_general; 23 private $options_accounting; 24 private $options_collective_invoice; 25 private $option_page_general; 26 private $option_page_accounting; 27 private $option_page_collective_invoice; 28 private $option_page_log; 29 private $rma_log_count; 30 31 public function __construct() { 32 33 $this->admin_url = 'admin.php?page=rma-wc'; 34 $this->option_group_general = 'wc_rma_settings'; 35 $this->option_group_accounting = 'wc_rma_settings_accounting'; 36 $this->option_group_collective_invoice = 'wc_rma_settings_collective_invoice'; 37 $this->option_page_general = 'settings-general'; 38 $this->option_page_accounting = 'settings-accounting'; 39 $this->option_page_collective_invoice = 'settings-collective-invoice'; 40 $this->option_page_log = 'settings-log'; 41 42 $this->options_general = get_option( $this->option_group_general ); 43 $this->options_accounting = get_option( $this->option_group_accounting ); 44 $this->options_collective_invoice = get_option( $this->option_group_collective_invoice ); 45 46 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue' ) ); 47 48 add_action( 'admin_menu', array( $this, 'add_plugin_page' ) ); 49 } 50 51 public function admin_enqueue( $hook ) { 52 53 if( 'woocommerce_page_rma-wc' != $hook ) 54 return; 55 56 // enqueue script and style for autocomplete on admin page 57 wp_enqueue_script( 'select2', plugins_url( '../assets/js/select2.min.js', __FILE__ ), array('jquery'), '4.0.13', 'true' ); 58 wp_register_style( 'select2', plugins_url( '../assets/css/select2.min.css', __FILE__ ), false, '4.0.13' ); 59 wp_enqueue_style( 'select2' ); 60 61 wp_enqueue_script( 'rma-admin-script', plugins_url( '../assets/js/admin.js', __FILE__ ), array('jquery'), get_option( 'wc_rma_version' ), 'true' ); 62 63 } 64 65 public function add_plugin_page(){ 66 // This page will be under "WooCommerce" 67 add_submenu_page('woocommerce', // $parent_slug 68 esc_html__('Run my Accounts - Settings', 'run-my-accounts-for-woocommerce'), // $page_title 69 'Run my Accounts', // $menu_title 70 'manage_options', // $capability 71 'rma-wc', // $menu_slug 72 array($this, 'create_admin_page') // $function 73 ); 74 75 add_action( 'admin_init', array( $this, 'options_init') ); 76 77 } 78 79 public function create_admin_page() { 80 81 $active_page = sanitize_text_field( ( isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'general' ) ); // set default tab ?> 84 82 85 83 <div class="wrap"> 86 <h1><?php _e('Run my Accounts - Settings', 'rma-wc'); ?></h1>87 <?php settings_errors(); ?>84 <h1><?php esc_html_e('Run my Accounts - Settings', 'run-my-accounts-for-woocommerce'); ?></h1> 85 <?php settings_errors(); ?> 88 86 <h2 class="nav-tab-wrapper"> 89 <a href="<?php echo admin_url( $this->admin_url ); ?>" class="nav-tab<?php echo ( 'general' == $active_page ? ' nav-tab-active' : '' ); ?>"><?php esc_html_e('General', 'r ma-wc'); ?></a>90 <a href="<?php echo esc_url( add_query_arg( array( 'tab' => 'accounting' ), admin_url( $this->admin_url ) ) ); ?>" class="nav-tab<?php echo ( 'accounting' == $active_page ? ' nav-tab-active' : '' ); ?>"><?php esc_html_e('Accounting', 'r ma-wc'); ?></a>91 <a href="<?php echo esc_url( add_query_arg( array( 'tab' => 'collective' ), admin_url( $this->admin_url ) ) ); ?>" class="nav-tab<?php echo ( 'collective' == $active_page ? ' nav-tab-active' : '' ); ?>"><?php esc_html_e('Collective Invoice', 'r ma-wc'); ?></a>92 <a href="<?php echo esc_url( add_query_arg( array( 'tab' => 'log' ), admin_url( $this->admin_url ) ) ); ?>" class="nav-tab<?php echo ( 'log' == $active_page ? ' nav-tab-active' : '' ); ?>"><?php esc_html_e('Log', 'r ma-wc'); ?></a>87 <a href="<?php echo admin_url( $this->admin_url ); ?>" class="nav-tab<?php echo ( 'general' == $active_page ? ' nav-tab-active' : '' ); ?>"><?php esc_html_e('General', 'run-my-accounts-for-woocommerce'); ?></a> 88 <a href="<?php echo esc_url( add_query_arg( array( 'tab' => 'accounting' ), admin_url( $this->admin_url ) ) ); ?>" class="nav-tab<?php echo ( 'accounting' == $active_page ? ' nav-tab-active' : '' ); ?>"><?php esc_html_e('Accounting', 'run-my-accounts-for-woocommerce'); ?></a> 89 <a href="<?php echo esc_url( add_query_arg( array( 'tab' => 'collective' ), admin_url( $this->admin_url ) ) ); ?>" class="nav-tab<?php echo ( 'collective' == $active_page ? ' nav-tab-active' : '' ); ?>"><?php esc_html_e('Collective Invoice', 'run-my-accounts-for-woocommerce'); ?></a> 90 <a href="<?php echo esc_url( add_query_arg( array( 'tab' => 'log' ), admin_url( $this->admin_url ) ) ); ?>" class="nav-tab<?php echo ( 'log' == $active_page ? ' nav-tab-active' : '' ); ?>"><?php esc_html_e('Log', 'run-my-accounts-for-woocommerce'); ?></a> 93 91 </h2> 94 92 95 93 <form method="post" action="options.php"><?php // settings_fields( $this->option_group_general ); 96 switch ( $active_page ) { 97 case 'accounting': 98 settings_fields( $this->option_group_accounting ); 99 do_settings_sections( $this->option_page_accounting ); 100 submit_button(); 101 break; 102 case 'log': 103 do_settings_sections( $this->option_page_log ); 104 $this->flush_log_button(); 105 break; 106 case 'collective': 107 settings_fields( $this->option_group_collective_invoice ); 108 do_settings_sections( $this->option_page_collective_invoice ); 109 submit_button(); 110 break; 111 112 default: 113 settings_fields( $this->option_group_general ); 114 do_settings_sections( $this->option_page_general ); 115 submit_button(); 116 break; 117 } ?> 94 switch ( $active_page ) { 95 case 'accounting': 96 settings_fields( $this->option_group_accounting ); 97 do_settings_sections( $this->option_page_accounting ); 98 submit_button(); 99 break; 100 case 'log': 101 do_settings_sections( $this->option_page_log ); 102 break; 103 case 'collective': 104 settings_fields( $this->option_group_collective_invoice ); 105 do_settings_sections( $this->option_page_collective_invoice ); 106 submit_button(); 107 break; 108 109 default: 110 settings_fields( $this->option_group_general ); 111 do_settings_sections( $this->option_page_general ); 112 submit_button(); 113 break; 114 } ?> 118 115 </form> 119 116 </div> <?php 120 117 121 } 122 123 /** 124 * Initialize Options on Settings Page 125 */ 126 public function options_init() { 127 register_setting( 128 $this->option_group_general, // Option group 129 $this->option_group_general, // Option name 130 array( $this, 'sanitize' ) // Sanitize 131 ); 132 133 $this->options_general_api(); 134 135 $this->options_general_customer(); 136 137 $this->options_general_billing(); 138 139 $this->options_general_payment(); 140 141 $this->options_general_product(); 142 143 $this->options_general_shipping(); 144 145 $this->options_general_log(); 146 147 $this->options_general_misc(); 148 149 register_setting( 150 $this->option_group_accounting, // Option group 151 $this->option_group_accounting, // Option name 152 array( $this, 'sanitize' ) // Sanitize 153 ); 154 155 $this->options_accounting_gateways(); 156 157 $this->options_payment_gateways(); 158 159 register_setting( 160 $this->option_group_collective_invoice, // Option group 161 $this->option_group_collective_invoice, // Option name 162 array( $this, 'sanitize' ) // Sanitize 163 ); 164 165 $this->options_collective_invoice(); 166 167 $this->log(); 168 169 } 170 171 /** 172 * Page General, Section API 173 */ 174 public function options_general_api() { 175 $section = 'general_settings_api'; 176 177 add_settings_section( 178 $section, // ID 179 esc_html__('API', 'rma-wc'), 180 '', // Callback 181 $this->option_page_general // Page 182 ); 183 184 $id = 'rma-active'; 185 add_settings_field( 186 $id, 187 esc_html__('Activate Function', 'rma-wc'), 188 array( $this, 'option_input_checkbox_cb'), // general callback for checkbox 189 $this->option_page_general, 190 $section, 191 array( 192 'option_group' => $this->option_group_general, 193 'id' => $id, 194 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 195 'description' => esc_html__('Do not activate the plugin before you have set up all data.', 'rma-wc' ) 196 ) 197 ); 198 199 $id = 'rma-mode'; 200 add_settings_field( 201 $id, 202 esc_html__('Operation Mode', 'rma-wc'), 203 array( $this, 'rma_mode_cb'), // individual callback 204 $this->option_page_general, 205 $section, 206 array( 'option_group' => $this->option_group_general, 207 'id' => $id 208 ) 209 ); 210 211 $id = 'rma-live-client'; 212 add_settings_field( 213 $id, 214 esc_html__('Production Client', 'rma-wc'), 215 array( $this, 'option_input_text_cb'), // general call back for input text 216 $this->option_page_general, 217 $section, 218 array( 219 'option_group' => $this->option_group_general, 220 'id' => $id, 221 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '' 222 ) 223 ); 224 225 $id = 'rma-live-apikey'; 226 add_settings_field( 227 $id, 228 esc_html__('Production API key', 'rma-wc'), 229 array( $this, 'option_input_text_cb'), 230 $this->option_page_general, 231 $section, 232 array( 233 'option_group' => $this->option_group_general, 234 'id' => $id, 235 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '' 236 ) 237 ); 238 239 $id = 'rma-test-client'; 240 add_settings_field( 241 $id, 242 esc_html__('Sandbox Client', 'rma-wc'), 243 array( $this, 'option_input_text_cb'), // general call back for input text 244 $this->option_page_general, 245 $section, 246 array( 247 'option_group' => $this->option_group_general, 248 'id' => $id, 249 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '' 250 ) 251 ); 252 253 $id = 'rma-test-apikey'; 254 add_settings_field( 255 $id, 256 esc_html__('Sandbox API key', 'rma-wc'), 257 array( $this, 'option_input_text_cb'), 258 $this->option_page_general, 259 $section, 260 array( 261 'option_group' => $this->option_group_general, 262 'id' => $id, 263 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '' 264 ) 265 ); 266 } 267 268 /** 269 * Page General, Section Billing 270 */ 271 public function options_general_billing() { 272 273 $section = 'general_settings_billing'; 274 275 add_settings_section( 276 $section, // ID 277 esc_html__('Billing', 'rma-wc'), 278 '', // Callback 279 $this->option_page_general // Page 280 ); 281 282 $id = 'rma-invoice-trigger'; 283 add_settings_field( 284 $id, 285 esc_html__('Trigger', 'rma-wc'), 286 array( $this, 'option_select_cb'), 287 $this->option_page_general, 288 $section, 289 array( 290 'option_group' => $this->option_group_general, 291 'id' => $id, 292 'options' => $this->options_general, 293 'select_options' => array( 294 'immediately' => esc_html__('Immediately after ordering','rma-wc'), 295 'completed' => esc_html__('On order status completed','rma-wc'), 296 'collective' => esc_html__('Collective invoice','rma-wc'), 297 ), 298 'class' => 'invoice-trigger', 299 'description' => esc_html__('When should customers and invoices be created in Run My Accounts?', 'rma-wc' ), 300 301 ) 302 ); 303 304 $id = 'rma-payment-period'; 305 add_settings_field( 306 $id, 307 esc_html__('Payment Period in days', 'rma-wc'), 308 array( $this, 'option_input_text_cb'), 309 $this->option_page_general, 310 $section, 311 array( 312 'option_group' => $this->option_group_general, 313 'id' => $id, 314 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 315 'description' => esc_html__('Please set the general payment period. You can set a individual value, for a customer, in the user profile.', 'rma-wc' ) 316 ) 317 ); 318 319 $id = 'rma-invoice-prefix'; 320 add_settings_field( 321 $id, 322 esc_html__('Invoice Prefix', 'rma-wc'), 323 array( $this, 'option_input_text_cb'), 324 $this->option_page_general, 325 $section, 326 array( 327 'option_group' => $this->option_group_general, 328 'id' => 'rma-invoice-prefix', 329 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 330 'description' => esc_html__('Prefix followed by order number will be the invoice number in Run my Accounts.', 'rma-wc' ) 331 ) 332 ); 333 334 $id = 'rma-digits'; 335 add_settings_field( 336 $id, 337 esc_html__('Number of digits', 'rma-wc'), 338 array( $this, 'option_input_text_cb'), 339 $this->option_page_general, 340 $section, 341 array( 342 'option_group' => $this->option_group_general, 343 'id' => $id, 344 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 345 'description' => esc_html__('Set the maximum number of digits for the invoice number (including prefix).', 'rma-wc' ) 346 ) 347 ); 348 349 $id = 'rma-invoice-description'; 350 add_settings_field( 351 $id, 352 esc_html__('Invoice Description', 'rma-wc'), 353 array( $this, 'option_input_text_cb'), 354 $this->option_page_general, 355 $section, 356 array( 357 'option_group' => $this->option_group_general, 358 'id' => $id, 359 'value' => $this->options_general[$id] ?? '', 360 'description' => esc_html__('Description of the invoice in Run My Accounts. Possible variable: [orderdate]', 'rma-wc' ) 361 ) 362 ); 363 364 $id = 'rma-collective-invoice-description'; 365 add_settings_field( 366 $id, 367 esc_html__('Collective Invoice Description', 'rma-wc'), 368 array( $this, 'option_input_text_cb'), 369 $this->option_page_general, 370 $section, 371 array( 372 'option_group' => $this->option_group_general, 373 'id' => $id, 374 'value' => $this->options_general[$id] ?? '', 375 'description' => esc_html__('Description of the collective invoice in Run My Accounts. Possible variable: [period]', 'rma-wc' ) 376 ) 377 ); 378 379 } 380 381 /** 382 * Page General, Section Payment 383 */ 384 public function options_general_payment() { 385 386 $section = 'general_settings_payment'; 387 388 add_settings_section( 389 $section, // ID 390 esc_html__('Payment', 'rma-wc'), 391 '', // Callback 392 $this->option_page_general // Page 393 ); 394 395 $id = 'rma-payment-trigger'; 396 add_settings_field( 397 $id, 398 esc_html__('Trigger', 'rma-wc'), 399 array( $this, 'option_select_cb'), 400 $this->option_page_general, 401 $section, 402 array( 403 'option_group' => $this->option_group_general, 404 'id' => $id, 405 'options' => $this->options_general, 406 'select_options' => array( 407 '' => esc_html__('Booking manually','rma-wc'), 408 'immediately' => esc_html__('Immediately after ordering','rma-wc'), 409 'completed' => esc_html__('On order status completed','rma-wc'), 410 ), 411 'class' => 'payment-trigger', 412 'description' => esc_html__('When should the payment be booked in Run My Accounts', 'rma-wc' ), 413 414 ) 415 ); 416 417 $id = 'rma-payment-trigger-exclude'; 418 add_settings_field( 419 $id, 420 esc_html__('Excluded Payment Options', 'rma-wc'), 421 array( $this, 'option_select_cb'), 422 $this->option_page_general, 423 $section, 424 array( 425 'option_group' => $this->option_group_general, 426 'id' => $id, 427 'options' => $this->options_general, 428 'select_options' => array( 429 'no' => esc_html__('no','rma-wc'), 430 'yes' => esc_html__('yes','rma-wc'), 431 ), 432 'class' => 'payment-trigger-exclude', 433 'description' => esc_html__('Would you like to exclude payment options from the payment booking?', 'rma-wc' ), 434 ) 435 ); 436 437 $id = 'rma-payment-trigger-exclude-values'; 438 add_settings_field( 439 $id, 440 '', 441 array( $this, 'option_input_multiple_payment_gateway_checkbox_cb'), 442 $this->option_page_general, 443 $section, 444 array( 445 'option_group' => $this->option_group_general, 446 'id' => $id, 447 'value' => $this->options_general[$id] ?? '', 448 'description' => esc_html__('Please select the payment options you want to exclude?', 'rma-wc' ), 449 ) 450 ); 451 452 } 453 454 /** 455 * Page General, Section Customer 456 */ 457 public function options_general_customer() { 458 459 $section = 'general_settings_customer'; 460 461 add_settings_section( 462 $section, // ID 463 esc_html__('Customer', 'rma-wc'), 464 '', // Callback 465 $this->option_page_general // Page 466 ); 467 468 $id = 'rma-create-customer'; 469 add_settings_field( 470 $id, 471 esc_html__('Create New Customer', 'rma-wc'), 472 array( $this, 'option_input_checkbox_cb'), 473 $this->option_page_general, 474 $section, 475 array( 476 'option_group' => $this->option_group_general, 477 'id' => $id, 478 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 479 'description' => esc_html__('Tick this if you want to create a customer as soon as a new user is created in WooCommerce (recommended if customer can register by itself).', 'rma-wc' ) 480 ) 481 ); 482 483 $id = 'rma-customer-prefix'; 484 add_settings_field( 485 $id, 486 esc_html__('Customer Number Prefix', 'rma-wc'), 487 array( $this, 'option_input_text_cb'), 488 $this->option_page_general, 489 $section, 490 array( 491 'option_group' => $this->option_group_general, 492 'id' => $id, 493 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 494 'description' => esc_html__('Prefix followed by user id will be the customer number in Run my Accounts.', 'rma-wc' ) 495 ) 496 ); 497 498 $id = 'rma-create-guest-customer'; 499 add_settings_field( 500 $id, 501 esc_html__('Create Account for Guests', 'rma-wc'), 502 array( $this, 'option_input_checkbox_cb'), 503 $this->option_page_general, 504 $section, 505 array( 506 'option_group' => $this->option_group_general, 507 'id' => $id, 508 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 509 'description' => esc_html__('Tick this if you want to create unique customer account in Run my Accounts for guest orders. Otherwise the guest orders will be booked on a pre-defined catch-all customer account.', 'rma-wc' ) 510 ) 511 ); 512 513 $id = 'rma-guest-customer-prefix'; 514 add_settings_field( 515 $id, 516 esc_html__('Guest Customer Number Prefix', 'rma-wc'), 517 array( $this, 'option_input_text_cb'), 518 $this->option_page_general, 519 $section, 520 array( 521 'option_group' => $this->option_group_general, 522 'id' => $id, 523 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 524 'description' => esc_html__('Prefix followed by order id will be the customer number in Run my Accounts.', 'rma-wc' ) 525 ) 526 ); 527 528 $id = 'rma-guest-catch-all'; 529 add_settings_field( 530 $id, 531 esc_html__('Catch-All Account', 'rma-wc'), 532 array( $this, 'rma_customer_accounts_cb'), // individual callback 533 $this->option_page_general, 534 $section, 535 array( 'option_group' => $this->option_group_general, 536 'id' => $id 537 ) 538 ); 539 540 } 541 542 /** 543 * Page General, Section Product 544 */ 545 public function options_general_product() { 546 547 $section = 'general_settings_product'; 548 549 add_settings_section( 550 $section, // ID 551 esc_html__('Product', 'rma-wc'), 552 '', // Callback 553 $this->option_page_general // Page 554 ); 555 556 $id = 'rma-product-fallback_id'; 557 add_settings_field( 558 $id, 559 esc_html__('Fallback product sku', 'rma-wc'), 560 array( $this, 'rma_parts_cb'), // individual callback 561 $this->option_page_general, 562 $section, 563 array( 564 'option_group' => $this->option_group_general, 565 'id' => $id, 566 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 567 'description' => esc_html__('This is a fallback sku in Run My Accounts which will be used to create an invoice if the WooCommerce sku of a product is not available in Run My Accounts. Leave it empty if you do not want to use it. In this case the invoice cannot be created if the sku is not available in Run My Accounts.', 'rma-wc' ) 568 ) 569 ); 570 571 } 572 573 /** 574 * Page General, Section Shipping 575 */ 576 public function options_general_shipping() { 577 578 $section = 'general_settings_shipping'; 579 580 add_settings_section( 581 $section, // ID 582 esc_html__('Shipping', 'rma-wc'), 583 '', // Callback 584 $this->option_page_general // Page 585 ); 586 587 $id = 'rma-shipping-id'; 588 add_settings_field( 589 $id, 590 esc_html__('SKU', 'rma-wc'), 591 array( $this, 'rma_parts_cb'), // individual callback 592 $this->option_page_general, 593 $section, 594 array( 595 'option_group' => $this->option_group_general, 596 'id' => $id, 597 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 598 'description' => esc_html__('To book the shipping costs, you have to select a dedicated product in Run my Accounts. The shipping costs will be booked on this product id.', 'rma-wc' ) 599 ) 600 ); 601 602 $id = 'rma-shipping-text'; 603 add_settings_field( 604 $id, 605 esc_html__('Description', 'rma-wc'), 606 array( $this, 'option_input_text_cb'), 607 $this->option_page_general, 608 $section, 609 array( 610 'option_group' => $this->option_group_general, 611 'id' => $id, 612 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 613 'description' => esc_html__('Optionally, the text on the invoice for shipping. Usually it is the text from the shipping method chosen by the customer.', 'rma-wc' ) 614 ) 615 ); 616 617 618 } 619 620 /** 621 * Page General, Section Misc 622 */ 623 public function options_general_log() { 624 625 $section = 'general_settings_log'; 626 627 add_settings_section( 628 $section, // ID 629 esc_html__('Error Log', 'rma-wc'), 630 '', // Callback 631 $this->option_page_general // Page 632 ); 633 634 $id = 'rma-loglevel'; 635 add_settings_field( 636 $id, 637 esc_html__('Log Level', 'rma-wc'), 638 array( $this, 'option_select_cb'), 639 $this->option_page_general, 640 $section, 641 array( 642 'option_group' => $this->option_group_general, 643 'id' => $id, 644 'options' => $this->options_general, 645 'select_options' => array( 646 'error' => esc_html__('error','rma-wc'), 647 'complete' => esc_html__('complete','rma-wc'), 648 ) 649 ) 650 ); 651 652 $id = 'rma-log-send-email'; 653 add_settings_field( 654 $id, 655 esc_html__('Send email', 'rma-wc'), 656 array( $this, 'option_select_cb'), 657 $this->option_page_general, 658 $section, 659 array( 660 'option_group' => $this->option_group_general, 661 'id' => $id, 662 'options' => $this->options_general, 663 'select_options' => array( 664 'no' => esc_html__('no','rma-wc'), 665 'yes' => esc_html__('yes','rma-wc'), 666 ), 667 'description' => esc_html__('Receive emails on errors and general notifications.', 'rma-wc' ) 668 669 ) 670 ); 671 672 $id = 'rma-log-email'; 673 add_settings_field( 674 $id, 675 esc_html__('email', 'rma-wc'), 676 array( $this, 'option_input_text_cb'), 677 $this->option_page_general, 678 $section, 679 array( 680 'option_group' => $this->option_group_general, 681 'id' => $id, 682 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : get_option( 'admin_email' ), 683 'description' => esc_html__( 'Get an email to this recipient. Administrators email address is used by default.', 'rma-wc' ) 684 ) 685 ); 686 687 688 } 689 690 /** 691 * Page General, Section Misc 692 */ 693 public function options_general_misc() { 694 695 $section = 'general_settings_misc'; 696 697 add_settings_section( 698 $section, // ID 699 esc_html__('Misc', 'rma-wc'), 700 '', // Callback 701 $this->option_page_general // Page 702 ); 703 704 $id = 'rma-delete-settings'; 705 add_settings_field( 706 $id, 707 esc_html__('Delete Settings', 'rma-wc'), 708 array( $this, 'option_select_cb'), 709 $this->option_page_general, 710 $section, 711 array( 712 'option_group' => $this->option_group_general, 713 'id' => $id, 714 'options' => $this->options_general, 715 'select_options' => array( 716 'no' => esc_html__('no','rma-wc'), 717 'yes' => esc_html__('yes','rma-wc'), 718 ), 719 'description' => esc_html__('Remove all plugin data when using the "Delete" link on the plugins screen', 'rma-wc' ), 720 721 ) 722 ); 723 724 } 725 726 public function options_accounting_gateways() { 727 728 $section = 'accounting_settings_payment'; 729 730 add_settings_section( 731 $section, // ID 732 esc_html__('Receivables Account', 'rma-wc'), // Title 733 array( $this, 'section_info_accounting' ), // Callback 734 $this->option_page_accounting // Page 735 ); 736 737 // add settings fields for all payment gateways 738 $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); 739 740 foreach ( $available_gateways as $gateway_key => $values ) { 741 742 add_settings_field( 743 $gateway_key, 744 $values->title, 745 array( $this, 'option_input_text_cb'), 746 $this->option_page_accounting, 747 $section, 748 array( 749 'option_group' => $this->option_group_accounting, 750 'id' => $gateway_key, 751 'value' => isset( $this->options_accounting[ $gateway_key ] ) ? $this->options_accounting[ $gateway_key ] : '' 752 ) 753 ); 754 755 } 756 757 } 758 759 public function options_payment_gateways() { 760 761 $section = 'accounting_settings_payment_account'; 762 763 add_settings_section( 764 $section, // ID 765 esc_html__('Payment Account', 'rma-wc'), // Title 766 array( $this, 'section_info_payment' ), // Callback 767 $this->option_page_accounting // Page 768 ); 769 770 // add settings fields for all payment gateways 771 $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); 772 773 foreach ( $available_gateways as $gateway_key => $values ) { 774 775 $field_id = $gateway_key . '_payment_account'; 776 777 add_settings_field( 778 $field_id, 779 $values->title, 780 array( $this, 'option_input_text_cb'), 781 $this->option_page_accounting, 782 $section, 783 array( 784 'option_group' => $this->option_group_accounting, 785 'id' => $field_id, 786 'value' => isset( $this->options_accounting[ $field_id ] ) ? $this->options_accounting[ $field_id ] : '', 787 'placeholder' => '1020' 788 ) 789 ); 790 791 } 792 793 } 794 795 public function options_collective_invoice() { 796 797 $section = 'collective_invoice_settings'; 798 add_settings_section( 799 $section, // ID 800 esc_html__( 'Collective Invoice', 'rma-wc'), // Title 801 array( $this, 'section_info_collective_invoice' ), // Callback 802 $this->option_page_collective_invoice // Page 803 ); 804 805 if( empty( $this->options_collective_invoice[ 'collective_invoice_next_date_ts' ] ) ) { 806 $text = __('The next invoice date cannot be calculated. Please set all options first.'); 807 } 808 else { 809 $text = date_i18n( get_option('date_format') , $this->options_collective_invoice[ 'collective_invoice_next_date_ts' ] ); 810 } 811 $id = 'collective_invoice_next_text'; 812 add_settings_field( 813 $id, 814 esc_html__('Next Invoice Date', 'rma-wc'), 815 array( $this, 'plain_text_cb'), 816 $this->option_page_collective_invoice, 817 $section, 818 array( 819 'text' => $text, 820 'class' => 'next-invoice-date' 821 ) 822 ); 823 824 $id = 'collective_invoice_period'; 825 add_settings_field( 826 $id, 827 esc_html__('Invoice Period', 'rma-wc'), 828 array( $this, 'option_select_cb'), 829 $this->option_page_collective_invoice, 830 $section, 831 array( 832 'option_group' => $this->option_group_collective_invoice, 833 'id' => $id, 834 'options' => $this->options_collective_invoice, 835 'select_options' => array( 836 'week' => esc_html__( 'Once a week','rma-wc'), 837 'second_week' => esc_html__( 'Every second week','rma-wc'), 838 'month' => esc_html__( 'Every month (first weekday of the month)','rma-wc'), 839 ), 840 'description' => esc_html__('For what period of time should collective invoices be created?', 'rma-wc' ), 841 'class' => 'collective-invoice__period' 842 ) 843 ); 844 845 $id = 'collective_invoice_weekday'; 846 add_settings_field( 847 $id, 848 esc_html__('Weekday', 'rma-wc'), 849 array( $this, 'option_input_multiple_radio_cb'), 850 $this->option_page_collective_invoice, 851 $section, 852 array( 853 'option_group' => $this->option_group_collective_invoice, 854 'id' => $id, 855 'value' => $this->options_collective_invoice[$id] ?? '', 856 'description' => esc_html__('Please select the days of the week on which a collective invoice should be created.', 'rma-wc' ), 857 'values' => array( 858 'monday' => esc_html__( 'Monday', 'rma-wc' ), 859 'tuesday' => esc_html__( 'Tuesday', 'rma-wc' ), 860 'wednesday' => esc_html__( 'Wednesday', 'rma-wc' ), 861 'thursday' => esc_html__( 'Thursday', 'rma-wc' ), 862 'friday' => esc_html__( 'Friday', 'rma-wc' ), 863 'saturday' => esc_html__( 'Saturday', 'rma-wc' ), 864 'sunday' => esc_html__( 'Sunday', 'rma-wc' ), 865 ), 866 'line_break' => false, 867 'class' => 'collective-invoice__weekday' 868 ) 869 ); 870 871 $id = 'collective_invoice_span'; 872 add_settings_field( 873 $id, 874 esc_html__('Invoice Span', 'rma-wc'), 875 array( $this, 'option_select_cb'), 876 $this->option_page_collective_invoice, 877 $section, 878 array( 879 'option_group' => $this->option_group_collective_invoice, 880 'id' => $id, 881 'options' => $this->options_collective_invoice, 882 'select_options' => array( 883 'all' => esc_html__( 'All unbilled invoices','rma-wc'), 884 'per_week' => esc_html__( 'Day of creation and a week before','rma-wc'), 885 'per_month' => esc_html__( 'Day of creation and a month before','rma-wc'), 886 ), 887 'description' => esc_html__('For what period of time should collective invoices be created?', 'rma-wc' ), 888 889 ) 890 ); 891 892 } 893 894 public function section_info_accounting() { 895 esc_html_e('You can specify a dedicated receivable account for each active payment gateway.', 'rma-wc'); 896 } 897 898 public function section_info_collective_invoice() { 899 esc_html_e('Set up the handling of the collective invoices', 'rma-wc'); 900 } 901 902 public function section_info_payment() { 903 esc_html_e('You can specify a dedicated payment account for each active payment gateway.', 'rma-wc'); 904 } 905 906 /** 907 * Page Error Log, Section Log 908 */ 909 public function log() { 910 911 $section = 'log'; 912 913 add_settings_section( 914 $section, // ID 915 esc_html__('Error Log', 'rma-wc'), 916 array( $this, 'section_info_log' ), // Callback 917 $this->option_page_log // Page 918 ); 919 920 $id = 'rma-error-log'; 921 add_settings_field( 922 $id, 923 '', 924 array( $this, 'output_log'), // general callback for checkbox 925 $this->option_page_log, 926 $section 927 ); 928 929 } 930 931 public function section_info_log() { 932 esc_html_e('This page shows you the error logs.', 'rma-wc'); 933 } 934 935 /** 936 * General Input Field Checkbox 937 * 938 * @param array $args 939 */ 940 public function option_input_checkbox_cb( $args ){ 941 942 $option_group = ( isset( $args['option_group'] ) ) ? $args['option_group'] : ''; 943 $id = ( isset( $args['id'] ) ) ? $args['id'] : ''; 944 $checked = ( isset( $args['value'] ) && !empty( $args['value'] ) ) ? 'checked' : ''; 945 $description = ( isset( $args['description'] ) ) ? $args['description'] : ''; 946 947 printf( 948 '<input type="checkbox" id="%1$s" name="%3$s[%1$s]" value="1" %2$s />', 949 $id, $checked, $option_group 950 ); 951 952 if ( !empty( $description) ) 953 echo '<p class="description">' . $description . '</p>'; 954 955 } 956 957 /** 958 * General Input with Multiple Checkboxes 959 * 960 * @param array $args 961 * 962 * @since 1.7.0 963 */ 964 public function option_input_multiple_checkbox_cb( $args ){ 965 966 $legend = ( isset( $args['legend'] ) ) ? $args['legend'] : ''; 967 $option_group = ( isset( $args['option_group'] ) ) ? $args['option_group'] : ''; 968 $id = ( isset( $args['id'] ) ) ? $args['id'] : ''; 969 $options = ( isset( $args['options'] ) ) ? $args['options'] : ''; 970 $description = ( isset( $args['description'] ) ) ? $args['description'] : ''; 971 $values = ( isset( $args['values'] ) ) ? $args['values'] : ''; 972 $line_break = ( isset( $args['line_break'] ) ) ? $args['line_break'] : true; 973 974 if( 0 == count( $values ) ) 975 return; 976 977 echo '<fieldset id="' . $id . '"> '; 978 if( $legend ) { 979 printf( '<legend>%1$s</legend>', $legend ); 980 } 981 982 foreach ( $values as $key => $title ) { 983 984 $checked = isset( $options[ $id . '-'. $key ] ) && 1 == $options[ $id . '-'. $key ] ? 'checked' : ''; 985 $br = isset( $line_break ) && true === $line_break ? '<br>' : ' '; 986 987 printf( 988 '<input type="checkbox" id="%5$s" name="%3$s[%1$s-%5$s]" value="1" %2$s /><label for="%5$s">%4$s</label>%6$s', 989 $id, $checked, $option_group, $title, $key, $br 990 ); 991 992 } 993 994 echo '</fieldset>'; 995 996 if ( !empty( $description) ) 997 echo '<p class="description">' . $description . '</p>'; 998 999 } 1000 1001 /** 1002 * General Input with Multiple Checkboxes 1003 * 1004 * @param array $args 1005 * 1006 * @since 1.7.0 1007 */ 1008 public function option_input_multiple_radio_cb( $args ){ 1009 1010 $legend = ( isset( $args['legend'] ) ) ? $args['legend'] : ''; 1011 $option_group = ( isset( $args['option_group'] ) ) ? $args['option_group'] : ''; 1012 $id = ( isset( $args['id'] ) ) ? $args['id'] : ''; 1013 $value = ( isset( $args['value'] ) ) ? $args['value'] : ''; 1014 $description = ( isset( $args['description'] ) ) ? $args['description'] : ''; 1015 $values = ( isset( $args['values'] ) ) ? $args['values'] : ''; 1016 $line_break = ( isset( $args['line_break'] ) ) ? $args['line_break'] : true; 1017 1018 if( 0 == count( $values ) ) 1019 return; 1020 1021 if( $legend ) { 1022 printf( '<legend>%1$s</legend>', $legend ); 1023 } 1024 1025 foreach ( $values as $key => $title ) { 1026 1027 $checked = $value == $key ? 'checked' : ''; 1028 $br = isset( $line_break ) && true === $line_break ? '<br>' : ' '; 1029 1030 printf( 1031 '<input type="radio" id="%5$s" name="%3$s[%1$s]" value="%5$s" %2$s /><label for="%5$s">%4$s</label>%6$s', 1032 $id, $checked, $option_group, $title, $key, $br 1033 ); 1034 1035 } 1036 1037 if ( !empty( $description) ) 1038 echo '<p class="description">' . $description . '</p>'; 1039 1040 } 1041 1042 /** 1043 * Input Field with Multiple Checkboxes for Payment Gateways 1044 * 1045 * @param array $args 1046 */ 1047 public function option_input_multiple_payment_gateway_checkbox_cb( $args ){ 1048 1049 // add settings fields for all payment gateways 1050 $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); 1051 1052 if( 0 == count( $available_gateways ) ) 1053 return; 1054 1055 $legend = ( isset( $args['legend'] ) ) ? $args['legend'] : ''; 1056 $option_group = ( isset( $args['option_group'] ) ) ? $args['option_group'] : ''; 1057 $id = ( isset( $args['id'] ) ) ? $args['id'] : ''; 1058 $description = ( isset( $args['description'] ) ) ? $args['description'] : ''; 1059 1060 $s = get_option('wc_rma_settings'); 1061 1062 echo '<fieldset id="' . $id . '"> '; 1063 if( $legend ) { 1064 printf( '<legend>%1$s</legend>', $legend ); 1065 } 1066 1067 foreach ( $available_gateways as $gateway_key => $values ) { 1068 1069 $checked = ( isset( $this->options_general[ $id . '-'. $gateway_key ] ) && 1 == $this->options_general[ $id . '-'. $gateway_key ] ) ? 'checked' : ''; 1070 1071 printf( 1072 '<input type="checkbox" id="%5$s" name="%3$s[%1$s-%5$s]" value="1" %2$s /> %4$s<br />', 1073 $id, $checked, $option_group, $values->title, $gateway_key 1074 ); 1075 1076 } 1077 1078 echo '</fieldset>'; 1079 1080 if ( !empty( $description) ) 1081 echo '<p class="description">' . $description . '</p>'; 1082 1083 } 1084 1085 /** 1086 * General Input Field Text 1087 * 1088 * @param array $args 1089 */ 1090 public function option_input_text_cb( $args ) { 1091 1092 $option_group = ( isset( $args['option_group'] ) ) ? $args['option_group'] : ''; 1093 $id = ( isset( $args['id'] ) ) ? $args['id'] : ''; 1094 $value = ( isset( $args['value'] ) ) ? $args['value'] : ''; 1095 $placeholder = ( isset( $args['placeholder'] ) ) ? $args['placeholder'] : ''; 1096 $description = ( isset( $args['description'] ) ) ? $args['description'] : ''; 1097 1098 printf( 1099 '<input type="text" id="%1$s" name="%3$s[%1$s]" value="%2$s" placeholder="%4$s" />', 1100 $id, $value, $option_group, $placeholder 1101 ); 1102 1103 if ( !empty( $description) ) 1104 echo '<p class="description">' . $description . '</p>'; 1105 } 1106 1107 /** 1108 * General Select 1109 * 1110 * @param array $args 1111 */ 1112 public function option_select_cb( $args ) { 1113 $option_group = (isset($args['option_group'])) ? $args['option_group'] : ''; 1114 $id = (isset($args['id'])) ? $args['id'] : ''; 1115 $options = (isset($args['options'])) ? $args['options'] : ''; 1116 $select_options = (isset($args['select_options'])) ? $args['select_options'] : array(); 1117 $description = (isset($args['description'])) ? $args['description'] : ''; 1118 $class = (isset($args['class'])) ? $args['class'] : ''; 1119 1120 echo '<select name="' . $option_group . '[' . $id . ']"' . ( !empty( $class) ? 'id="'. $id .'" class="' . $class . '"' : '' ) . '>'; 1121 1122 foreach ( $select_options as $value => $text ) { 1123 printf( 1124 '<option value="%1$s" %2$s />%3$s</option>', 1125 $value, 1126 ( isset( $options[ $id ] ) && $value == $options[ $id ] ) ? 'selected="selected"' : '', 1127 $text 1128 ); 1129 } 1130 1131 echo '</select>'; 1132 1133 if ( !empty( $description) ) 1134 echo '<p class="description">' . $description . '</p>'; 1135 1136 } 1137 1138 /** 1139 * @param array 1140 */ 1141 public function plain_text_cb( $args ) { 1142 $text = ( isset( $args[ 'text' ] ) ) ? $args[ 'text' ] : ''; 1143 $class = ( isset( $args[ 'class' ] ) ) ? $args[ 'class' ] : ''; 1144 1145 echo '<p class="' . $class . '">' . $text . '</p>'; 1146 } 1147 1148 /** 1149 * Individual pulldown 1150 * 1151 * @param array $args 1152 */ 1153 public function rma_mode_cb( $args ) { 1154 $option_group = ( isset( $args['option_group'] ) ) ? $args['option_group'] : ''; 1155 $id = ( isset( $args['id'] ) ) ? $args['id'] : ''; 1156 1157 $select_args = array( 1158 'option_group' => $option_group, 1159 'id' => $id, 1160 'options' => $this->options_general, 1161 'select_options' => array( 1162 'test' => esc_html__('Sandbox Test','rma-wc'), 1163 'live' => esc_html__('Production','rma-wc'), 1164 ) 1165 ); 1166 1167 // create select 1168 self::option_select_cb( $select_args ); 1169 1170 // output connection status 1171 $RMA_WC_API = new RMA_WC_API(); 1172 // Retrieve customers to check connection 1173 $options = $RMA_WC_API->get_customers(); 1174 unset( $RMA_WC_API ); 1175 1176 if ( ! $options ) 1177 echo ' <span style="color: red; font-weight: bold">' . __('No connection. Please check your settings.', 'rma-wc') . '</span>'; 1178 else 1179 echo ' <span style="color: green">' . __('Connection successful.', 'rma-wc') . '</span>'; 1180 1181 } 1182 1183 /** 1184 * Pull down with RMA customer list 1185 * 1186 * @param $args 1187 */ 1188 public function rma_customer_accounts_cb( $args ) { 1189 $option_group = ( isset( $args['option_group'] ) ) ? $args['option_group'] : ''; 1190 $id = ( isset( $args['id'] ) ) ? $args['id'] : ''; 1191 1192 $RMA_WC_API = new RMA_WC_API(); 1193 $options = $RMA_WC_API->get_customers(); 1194 1195 if ( !empty( $RMA_WC_API ) ) unset( $RMA_WC_API ); 1196 1197 if( !isset( $options ) || !$options ) { 1198 1199 $options = array('' => __( 'Error while connecting to RMA. Please check your settings.', 'rma-wc' ) ); 1200 1201 } 1202 else { 1203 1204 $options = array('' => __( 'Select...', 'rma-wc' ) ) + $options; 1205 1206 } 1207 1208 $select_args = array ( 1209 'option_group' => $option_group, 1210 'id' => $id, 1211 'options' => $this->options_general, 1212 'select_options' => $options, 1213 'class' => 'select2' 1214 ); 1215 1216 // create select 1217 self::option_select_cb( $select_args ); 1218 1219 } 1220 1221 /** 1222 * Pull down with RMA parts list 1223 * 1224 * @param $args 1225 * 1226 * @since 1.5.0 1227 */ 1228 public function rma_parts_cb( $args ) { 1229 $option_group = ( isset( $args['option_group'] ) ) ? $args['option_group'] : ''; 1230 $id = ( isset( $args['id'] ) ) ? $args['id'] : ''; 1231 $description = ( isset( $args['description'] ) ) ? $args['description'] : ''; 1232 1233 if ( !isset( $parts ) || empty( $parts ) ) { 1234 1235 $rma_api = new RMA_WC_API(); 1236 $parts = $rma_api->get_parts(); 1237 1238 if ( !empty( $RMA_WC_API ) ) unset( $RMA_WC_API ); 1239 1240 } 1241 1242 if( !isset( $parts ) || !$parts ) { 1243 1244 $options = array('' => __( 'Error while connecting to RMA. Please check your settings.', 'rma-wc' ) ); 1245 1246 } 1247 else { 1248 1249 $options = array('' => __( 'Select...', 'rma-wc' ) ) + $parts; 1250 1251 } 1252 1253 $select_args = array ( 1254 'option_group' => $option_group, 1255 'id' => $id, 1256 'options' => $this->options_general, 1257 'select_options' => $options, 1258 'description' => $description, 1259 'class' => 'select2' 1260 ); 1261 1262 // create select 1263 self::option_select_cb( $select_args ); 1264 1265 } 1266 1267 1268 /** 1269 * Output the error log from database 1270 */ 1271 public function output_log() { 1272 1273 $output = $this->get_log_from_database(); 1274 1275 echo '<style>[scope=row]{ display:none; }.form-table th { padding: 8px 10px; width: unset; font-weight: unset; }#textarea td {border: 1px solid #ddd; border-width: 0 1px 1px 0; }</style>'; 1276 1277 echo '<div id="textarea" contenteditable>'; 1278 echo $output; 1279 echo '</div>'; 1280 1281 } 1282 1283 /** 1284 * Sanitizes a string from user input 1285 * Checks for invalid UTF-8, Converts single < characters to entities, Strips all tags, Removes line breaks, tabs, and extra whitespace, Strips octets 1286 * 1287 * @param array $input 1288 * 1289 * @return array 1290 */ 1291 public function sanitize( $input ) { 1292 1293 $new_input = array(); 1294 1295 foreach ( $input as $key => $value ) { 1296 1297 $new_input[ $key ] = sanitize_text_field( $input[ $key ] ); 1298 1299 } 1300 1301 return $new_input; 1302 } 1303 1304 /** 1305 * Read log information from database 1306 * 1307 * @return string 1308 */ 1309 private function get_log_from_database() { 1310 1311 global $wpdb; 1312 1313 $table_name = $wpdb->prefix . RMA_WC_LOG_TABLE; 1314 1315 $results = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $table_name ORDER BY id DESC;", ARRAY_A ); 1316 1317 if ( 0 == count( $results ) ) { 1318 1319 $this->rma_log_count = 0; 1320 1321 return esc_html__('No error data was found.', 'rma-wc'); 1322 1323 } 1324 1325 $output = '<table class="widefat">'; 1326 1327 $table_header = true; 1328 1329 foreach ( $results as $result ) { 1330 1331 if ( $table_header ) { 1332 $output .= '<thead><tr>'; 1333 foreach ( array_keys( ( $result ) ) as $key ) { 1334 $output .= '<th>' . $key . '</th>'; 1335 } 1336 $output .= '</tr></thead>'; 1337 1338 $table_header = false; 1339 } 1340 1341 $output .= '<tr>'; 1342 foreach ( $result as $key => $value ) { 1343 1344 $value = str_replace('error','<span style="color: red;">error</span>',$value); 1345 $value = str_replace('failed','<span style="color: red;">failed</span>',$value); 1346 $value = str_replace('success','<span style="color: green;">success</span>',$value); 1347 $value = str_replace('paid','<span style="color: green;">paid</span>',$value); 1348 $value = str_replace('created','<span style="color: green;">created</span>',$value); 1349 $value = str_replace('invoiced','<span style="color: green;">invoiced</span>',$value); 1350 1351 $output .= '<td>' . $value . '</td>'; 1352 } 1353 $output .= '</tr>'; 1354 } 1355 1356 $output .= '</table>'; 1357 1358 return $output; 1359 1360 } 1361 1362 /** 1363 * Add flush table button below table 1364 */ 1365 private function flush_log_button() { 1366 1367 if ( 0 < $this->rma_log_count || !empty( $this->rma_log_count ) || !isset( $this->rma_log_count )) { 1368 echo sprintf( 1369 '<a href="#" id="flush-table" class="button-primary">%s</a> <span class="spinner">', 1370 esc_html__('Flush Table', 'rma-wc') 1371 ); 1372 } 1373 1374 } 1375 1376 /** 1377 * WP ajax request to flush error table 1378 */ 1379 public function ajax_handle_database_log_table() { 1380 global $wpdb; // this is how you get access to the database 1381 1382 $db_action = $_POST['db_action']; 1383 1384 switch ( $db_action ) { 1385 case 'flush': 1386 1387 $table_name = $wpdb->prefix . RMA_WC_LOG_TABLE; 1388 1389 $wpdb->query("TRUNCATE TABLE $table_name"); 1390 1391 if($wpdb->last_error !== '') { 1392 1393 esc_html_e( 'An error occurred while flushing the error log.', 'rma-wc'); 1394 1395 $wpdb->print_error(); 1396 1397 break; 1398 1399 } 1400 1401 $this->rma_log_count = 0; 1402 1403 break; 1404 default: 1405 break; 1406 } 1407 1408 wp_die(); // this is required to terminate immediately and return a proper response 1409 } 1410 1411 } 118 } 119 120 /** 121 * Initialize Options on Settings Page 122 */ 123 public function options_init() { 124 register_setting( 125 $this->option_group_general, // Option group 126 $this->option_group_general, // Option name 127 array( $this, 'sanitize' ) // Sanitize 128 ); 129 130 $this->options_general_api(); 131 132 $this->options_general_customer(); 133 134 $this->options_general_billing(); 135 136 $this->options_general_payment(); 137 138 $this->options_general_product(); 139 140 $this->options_general_shipping(); 141 142 $this->options_general_log(); 143 144 $this->options_general_misc(); 145 146 register_setting( 147 $this->option_group_accounting, // Option group 148 $this->option_group_accounting, // Option name 149 array( $this, 'sanitize' ) // Sanitize 150 ); 151 152 $this->options_accounting_gateways(); 153 154 $this->options_payment_gateways(); 155 156 register_setting( 157 $this->option_group_collective_invoice, // Option group 158 $this->option_group_collective_invoice, // Option name 159 array( $this, 'sanitize' ) // Sanitize 160 ); 161 162 $this->options_collective_invoice(); 163 164 $this->log(); 165 166 } 167 168 /** 169 * Page General, Section API 170 */ 171 public function options_general_api() { 172 $section = 'general_settings_api'; 173 174 add_settings_section( 175 $section, // ID 176 esc_html__('API', 'run-my-accounts-for-woocommerce'), 177 '', // Callback 178 $this->option_page_general // Page 179 ); 180 181 $id = 'rma-active'; 182 add_settings_field( 183 $id, 184 esc_html__('Activate Function', 'run-my-accounts-for-woocommerce'), 185 array( $this, 'option_input_checkbox_cb'), // general callback for checkbox 186 $this->option_page_general, 187 $section, 188 array( 189 'option_group' => $this->option_group_general, 190 'id' => $id, 191 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 192 'description' => esc_html__('Do not activate the plugin before you have set up all data.', 'run-my-accounts-for-woocommerce' ) 193 ) 194 ); 195 196 $id = 'rma-mode'; 197 add_settings_field( 198 $id, 199 esc_html__('Operation Mode', 'run-my-accounts-for-woocommerce'), 200 array( $this, 'rma_mode_cb'), // individual callback 201 $this->option_page_general, 202 $section, 203 array( 'option_group' => $this->option_group_general, 204 'id' => $id 205 ) 206 ); 207 208 $id = 'rma-live-client'; 209 add_settings_field( 210 $id, 211 esc_html__('Production Client', 'run-my-accounts-for-woocommerce'), 212 array( $this, 'option_input_text_cb'), // general call back for input text 213 $this->option_page_general, 214 $section, 215 array( 216 'option_group' => $this->option_group_general, 217 'id' => $id, 218 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '' 219 ) 220 ); 221 222 $id = 'rma-live-apikey'; 223 add_settings_field( 224 $id, 225 esc_html__('Production API key', 'run-my-accounts-for-woocommerce'), 226 array( $this, 'option_input_text_cb'), 227 $this->option_page_general, 228 $section, 229 array( 230 'option_group' => $this->option_group_general, 231 'id' => $id, 232 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '' 233 ) 234 ); 235 236 $id = 'rma-test-client'; 237 add_settings_field( 238 $id, 239 esc_html__('Sandbox Client', 'run-my-accounts-for-woocommerce'), 240 array( $this, 'option_input_text_cb'), // general call back for input text 241 $this->option_page_general, 242 $section, 243 array( 244 'option_group' => $this->option_group_general, 245 'id' => $id, 246 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '' 247 ) 248 ); 249 250 $id = 'rma-test-apikey'; 251 add_settings_field( 252 $id, 253 esc_html__('Sandbox API key', 'run-my-accounts-for-woocommerce'), 254 array( $this, 'option_input_text_cb'), 255 $this->option_page_general, 256 $section, 257 array( 258 'option_group' => $this->option_group_general, 259 'id' => $id, 260 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '' 261 ) 262 ); 263 } 264 265 /** 266 * Page General, Section Billing 267 */ 268 public function options_general_billing() { 269 270 $section = 'general_settings_billing'; 271 272 add_settings_section( 273 $section, // ID 274 esc_html__('Billing', 'run-my-accounts-for-woocommerce'), 275 '', // Callback 276 $this->option_page_general // Page 277 ); 278 279 $id = 'rma-invoice-trigger'; 280 add_settings_field( 281 $id, 282 esc_html__('Trigger', 'run-my-accounts-for-woocommerce'), 283 array( $this, 'option_select_cb'), 284 $this->option_page_general, 285 $section, 286 array( 287 'option_group' => $this->option_group_general, 288 'id' => $id, 289 'options' => $this->options_general, 290 'select_options' => array( 291 'immediately' => esc_html__('Immediately after ordering','run-my-accounts-for-woocommerce'), 292 'completed' => esc_html__('On order status completed','run-my-accounts-for-woocommerce'), 293 'collective' => esc_html__('Collective invoice','run-my-accounts-for-woocommerce'), 294 ), 295 'class' => 'invoice-trigger', 296 'description' => esc_html__('When should customers and invoices be created in Run My Accounts?', 'run-my-accounts-for-woocommerce' ), 297 298 ) 299 ); 300 301 $id = 'rma-payment-period'; 302 add_settings_field( 303 $id, 304 esc_html__('Payment Period in days', 'run-my-accounts-for-woocommerce'), 305 array( $this, 'option_input_text_cb'), 306 $this->option_page_general, 307 $section, 308 array( 309 'option_group' => $this->option_group_general, 310 'id' => $id, 311 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 312 'description' => esc_html__('Please set the general payment period. You can set a individual value, for a customer, in the user profile.', 'run-my-accounts-for-woocommerce' ) 313 ) 314 ); 315 316 $id = 'rma-invoice-prefix'; 317 add_settings_field( 318 $id, 319 esc_html__('Invoice Prefix', 'run-my-accounts-for-woocommerce'), 320 array( $this, 'option_input_text_cb'), 321 $this->option_page_general, 322 $section, 323 array( 324 'option_group' => $this->option_group_general, 325 'id' => 'rma-invoice-prefix', 326 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 327 'description' => esc_html__('Prefix followed by order number will be the invoice number in Run my Accounts.', 'run-my-accounts-for-woocommerce' ) 328 ) 329 ); 330 331 $id = 'rma-digits'; 332 add_settings_field( 333 $id, 334 esc_html__('Number of digits', 'run-my-accounts-for-woocommerce'), 335 array( $this, 'option_input_text_cb'), 336 $this->option_page_general, 337 $section, 338 array( 339 'option_group' => $this->option_group_general, 340 'id' => $id, 341 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 342 'description' => esc_html__('Set the maximum number of digits for the invoice number (including prefix).', 'run-my-accounts-for-woocommerce' ) 343 ) 344 ); 345 346 $id = 'rma-invoice-description'; 347 add_settings_field( 348 $id, 349 esc_html__('Invoice Description', 'run-my-accounts-for-woocommerce'), 350 array( $this, 'option_input_text_cb'), 351 $this->option_page_general, 352 $section, 353 array( 354 'option_group' => $this->option_group_general, 355 'id' => $id, 356 'value' => $this->options_general[$id] ?? '', 357 'description' => esc_html__('Description of the invoice in Run My Accounts. Possible variable: [orderdate]', 'run-my-accounts-for-woocommerce' ) 358 ) 359 ); 360 361 $id = 'rma-collective-invoice-description'; 362 add_settings_field( 363 $id, 364 esc_html__('Collective Invoice Description', 'run-my-accounts-for-woocommerce'), 365 array( $this, 'option_input_text_cb'), 366 $this->option_page_general, 367 $section, 368 array( 369 'option_group' => $this->option_group_general, 370 'id' => $id, 371 'value' => $this->options_general[$id] ?? '', 372 'description' => esc_html__('Description of the collective invoice in Run My Accounts. Possible variable: [period]', 'run-my-accounts-for-woocommerce' ) 373 ) 374 ); 375 376 } 377 378 /** 379 * Page General, Section Payment 380 */ 381 public function options_general_payment() { 382 383 $section = 'general_settings_payment'; 384 385 add_settings_section( 386 $section, // ID 387 esc_html__('Payment', 'run-my-accounts-for-woocommerce'), 388 '', // Callback 389 $this->option_page_general // Page 390 ); 391 392 $id = 'rma-payment-trigger'; 393 add_settings_field( 394 $id, 395 esc_html__('Trigger', 'run-my-accounts-for-woocommerce'), 396 array( $this, 'option_select_cb'), 397 $this->option_page_general, 398 $section, 399 array( 400 'option_group' => $this->option_group_general, 401 'id' => $id, 402 'options' => $this->options_general, 403 'select_options' => array( 404 '' => esc_html__('Booking manually','run-my-accounts-for-woocommerce'), 405 'immediately' => esc_html__('Immediately after ordering','run-my-accounts-for-woocommerce'), 406 'completed' => esc_html__('On order status completed','run-my-accounts-for-woocommerce'), 407 ), 408 'class' => 'payment-trigger', 409 'description' => esc_html__('When should the payment be booked in Run My Accounts', 'run-my-accounts-for-woocommerce' ), 410 411 ) 412 ); 413 414 $id = 'rma-payment-trigger-exclude'; 415 add_settings_field( 416 $id, 417 esc_html__('Excluded Payment Options', 'run-my-accounts-for-woocommerce'), 418 array( $this, 'option_select_cb'), 419 $this->option_page_general, 420 $section, 421 array( 422 'option_group' => $this->option_group_general, 423 'id' => $id, 424 'options' => $this->options_general, 425 'select_options' => array( 426 'no' => esc_html__('no','run-my-accounts-for-woocommerce'), 427 'yes' => esc_html__('yes','run-my-accounts-for-woocommerce'), 428 ), 429 'class' => 'payment-trigger-exclude', 430 'description' => esc_html__('Would you like to exclude payment options from the payment booking?', 'run-my-accounts-for-woocommerce' ), 431 ) 432 ); 433 434 $id = 'rma-payment-trigger-exclude-values'; 435 add_settings_field( 436 $id, 437 '', 438 array( $this, 'option_input_multiple_payment_gateway_checkbox_cb'), 439 $this->option_page_general, 440 $section, 441 array( 442 'option_group' => $this->option_group_general, 443 'id' => $id, 444 'value' => $this->options_general[$id] ?? '', 445 'description' => esc_html__('Please select the payment options you want to exclude.', 'run-my-accounts-for-woocommerce' ), 446 ) 447 ); 448 449 } 450 451 /** 452 * Page General, Section Customer 453 */ 454 public function options_general_customer() { 455 456 $section = 'general_settings_customer'; 457 458 add_settings_section( 459 $section, // ID 460 esc_html__('Customer', 'run-my-accounts-for-woocommerce'), 461 '', // Callback 462 $this->option_page_general // Page 463 ); 464 465 $id = 'rma-create-customer'; 466 add_settings_field( 467 $id, 468 esc_html__('Create New Customer', 'run-my-accounts-for-woocommerce'), 469 array( $this, 'option_input_checkbox_cb'), 470 $this->option_page_general, 471 $section, 472 array( 473 'option_group' => $this->option_group_general, 474 'id' => $id, 475 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 476 'description' => esc_html__('Tick this if you want to create a customer as soon as a new user is created in WooCommerce (recommended if customer can register by itself).', 'run-my-accounts-for-woocommerce' ) 477 ) 478 ); 479 480 $id = 'rma-customer-prefix'; 481 add_settings_field( 482 $id, 483 esc_html__('Customer Number Prefix', 'run-my-accounts-for-woocommerce'), 484 array( $this, 'option_input_text_cb'), 485 $this->option_page_general, 486 $section, 487 array( 488 'option_group' => $this->option_group_general, 489 'id' => $id, 490 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 491 'description' => esc_html__('Prefix followed by user id will be the customer number in Run my Accounts.', 'run-my-accounts-for-woocommerce' ) 492 ) 493 ); 494 495 $id = 'rma-create-guest-customer'; 496 add_settings_field( 497 $id, 498 esc_html__('Create Account for Guests', 'run-my-accounts-for-woocommerce'), 499 array( $this, 'option_input_checkbox_cb'), 500 $this->option_page_general, 501 $section, 502 array( 503 'option_group' => $this->option_group_general, 504 'id' => $id, 505 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 506 'description' => esc_html__('Tick this if you want to create unique customer account in Run my Accounts for guest orders. Otherwise the guest orders will be booked on a pre-defined catch-all customer account.', 'run-my-accounts-for-woocommerce' ) 507 ) 508 ); 509 510 $id = 'rma-guest-customer-prefix'; 511 add_settings_field( 512 $id, 513 esc_html__('Guest Customer Number Prefix', 'run-my-accounts-for-woocommerce'), 514 array( $this, 'option_input_text_cb'), 515 $this->option_page_general, 516 $section, 517 array( 518 'option_group' => $this->option_group_general, 519 'id' => $id, 520 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 521 'description' => esc_html__('Prefix followed by order id will be the customer number in Run my Accounts.', 'run-my-accounts-for-woocommerce' ) 522 ) 523 ); 524 525 $id = 'rma-guest-catch-all'; 526 add_settings_field( 527 $id, 528 esc_html__('Catch-All Account', 'run-my-accounts-for-woocommerce'), 529 array( $this, 'rma_customer_accounts_cb'), // individual callback 530 $this->option_page_general, 531 $section, 532 array( 'option_group' => $this->option_group_general, 533 'id' => $id 534 ) 535 ); 536 537 } 538 539 /** 540 * Page General, Section Product 541 */ 542 public function options_general_product() { 543 544 $section = 'general_settings_product'; 545 546 add_settings_section( 547 $section, // ID 548 esc_html__('Product', 'run-my-accounts-for-woocommerce'), 549 '', // Callback 550 $this->option_page_general // Page 551 ); 552 553 $id = 'rma-product-fallback_id'; 554 add_settings_field( 555 $id, 556 esc_html__('Fallback product sku', 'run-my-accounts-for-woocommerce'), 557 array( $this, 'rma_parts_cb'), // individual callback 558 $this->option_page_general, 559 $section, 560 array( 561 'option_group' => $this->option_group_general, 562 'id' => $id, 563 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 564 'description' => esc_html__('This is a fallback sku in Run My Accounts which will be used to create an invoice if the WooCommerce sku of a product is not available in Run My Accounts. Leave it empty if you do not want to use it. In this case the invoice cannot be created if the sku is not available in Run My Accounts.', 'run-my-accounts-for-woocommerce' ) 565 ) 566 ); 567 568 } 569 570 /** 571 * Page General, Section Shipping 572 */ 573 public function options_general_shipping() { 574 575 $section = 'general_settings_shipping'; 576 577 add_settings_section( 578 $section, // ID 579 esc_html__('Shipping', 'run-my-accounts-for-woocommerce'), 580 '', // Callback 581 $this->option_page_general // Page 582 ); 583 584 $id = 'rma-shipping-id'; 585 add_settings_field( 586 $id, 587 esc_html__('SKU', 'run-my-accounts-for-woocommerce'), 588 array( $this, 'rma_parts_cb'), // individual callback 589 $this->option_page_general, 590 $section, 591 array( 592 'option_group' => $this->option_group_general, 593 'id' => $id, 594 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 595 'description' => esc_html__('To book the shipping costs, you have to select a dedicated product in Run my Accounts. The shipping costs will be booked on this product id.', 'run-my-accounts-for-woocommerce' ) 596 ) 597 ); 598 599 $id = 'rma-shipping-text'; 600 add_settings_field( 601 $id, 602 esc_html__('Description', 'run-my-accounts-for-woocommerce'), 603 array( $this, 'option_input_text_cb'), 604 $this->option_page_general, 605 $section, 606 array( 607 'option_group' => $this->option_group_general, 608 'id' => $id, 609 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : '', 610 'description' => esc_html__('Optionally, the text on the invoice for shipping. Usually it is the text from the shipping method chosen by the customer.', 'run-my-accounts-for-woocommerce' ) 611 ) 612 ); 613 614 615 } 616 617 /** 618 * Page General, Section Misc 619 */ 620 public function options_general_log() { 621 622 $section = 'general_settings_log'; 623 624 add_settings_section( 625 $section, // ID 626 esc_html__('Error Log', 'run-my-accounts-for-woocommerce'), 627 '', // Callback 628 $this->option_page_general // Page 629 ); 630 631 $id = 'rma-loglevel'; 632 add_settings_field( 633 $id, 634 esc_html__('Log Level', 'run-my-accounts-for-woocommerce'), 635 array( $this, 'option_select_cb'), 636 $this->option_page_general, 637 $section, 638 array( 639 'option_group' => $this->option_group_general, 640 'id' => $id, 641 'options' => $this->options_general, 642 'select_options' => array( 643 'error' => esc_html__('error','run-my-accounts-for-woocommerce'), 644 'complete' => esc_html__('complete','run-my-accounts-for-woocommerce'), 645 ) 646 ) 647 ); 648 649 $id = 'rma-log-send-email'; 650 add_settings_field( 651 $id, 652 esc_html__('Send email', 'run-my-accounts-for-woocommerce'), 653 array( $this, 'option_select_cb'), 654 $this->option_page_general, 655 $section, 656 array( 657 'option_group' => $this->option_group_general, 658 'id' => $id, 659 'options' => $this->options_general, 660 'select_options' => array( 661 'no' => esc_html__('no','run-my-accounts-for-woocommerce'), 662 'yes' => esc_html__('yes','run-my-accounts-for-woocommerce'), 663 ), 664 'description' => esc_html__('Receive emails on errors and general notifications.', 'run-my-accounts-for-woocommerce' ) 665 666 ) 667 ); 668 669 $id = 'rma-log-email'; 670 add_settings_field( 671 $id, 672 esc_html__('email', 'run-my-accounts-for-woocommerce'), 673 array( $this, 'option_input_text_cb'), 674 $this->option_page_general, 675 $section, 676 array( 677 'option_group' => $this->option_group_general, 678 'id' => $id, 679 'value' => isset( $this->options_general[ $id ] ) ? $this->options_general[ $id ] : get_option( 'admin_email' ), 680 'description' => esc_html__( 'Get an email to this recipient. Administrators email address is used by default.', 'run-my-accounts-for-woocommerce' ) 681 ) 682 ); 683 684 685 } 686 687 /** 688 * Page General, Section Misc 689 */ 690 public function options_general_misc() { 691 692 $section = 'general_settings_misc'; 693 694 add_settings_section( 695 $section, // ID 696 esc_html__('Misc', 'run-my-accounts-for-woocommerce'), 697 '', // Callback 698 $this->option_page_general // Page 699 ); 700 701 $id = 'rma-delete-settings'; 702 add_settings_field( 703 $id, 704 esc_html__('Delete Settings', 'run-my-accounts-for-woocommerce'), 705 array( $this, 'option_select_cb'), 706 $this->option_page_general, 707 $section, 708 array( 709 'option_group' => $this->option_group_general, 710 'id' => $id, 711 'options' => $this->options_general, 712 'select_options' => array( 713 'no' => esc_html__('no','run-my-accounts-for-woocommerce'), 714 'yes' => esc_html__('yes','run-my-accounts-for-woocommerce'), 715 ), 716 'description' => esc_html__('Remove all plugin data when using the "Delete" link on the plugins screen', 'run-my-accounts-for-woocommerce' ), 717 718 ) 719 ); 720 721 } 722 723 public function options_accounting_gateways() { 724 725 $section = 'accounting_settings_payment'; 726 727 add_settings_section( 728 $section, // ID 729 esc_html__('Receivables Account', 'run-my-accounts-for-woocommerce'), // Title 730 array( $this, 'section_info_accounting' ), // Callback 731 $this->option_page_accounting // Page 732 ); 733 734 // add settings fields for all payment gateways 735 $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); 736 737 foreach ( $available_gateways as $gateway_key => $values ) { 738 739 add_settings_field( 740 $gateway_key, 741 $values->title, 742 array( $this, 'option_input_text_cb'), 743 $this->option_page_accounting, 744 $section, 745 array( 746 'option_group' => $this->option_group_accounting, 747 'id' => $gateway_key, 748 'value' => isset( $this->options_accounting[ $gateway_key ] ) ? $this->options_accounting[ $gateway_key ] : '' 749 ) 750 ); 751 752 } 753 754 } 755 756 public function options_payment_gateways() { 757 758 $section = 'accounting_settings_payment_account'; 759 760 add_settings_section( 761 $section, // ID 762 esc_html__('Payment Account', 'run-my-accounts-for-woocommerce'), // Title 763 array( $this, 'section_info_payment' ), // Callback 764 $this->option_page_accounting // Page 765 ); 766 767 // add settings fields for all payment gateways 768 $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); 769 770 foreach ( $available_gateways as $gateway_key => $values ) { 771 772 $field_id = $gateway_key . '_payment_account'; 773 774 add_settings_field( 775 $field_id, 776 $values->title, 777 array( $this, 'option_input_text_cb'), 778 $this->option_page_accounting, 779 $section, 780 array( 781 'option_group' => $this->option_group_accounting, 782 'id' => $field_id, 783 'value' => isset( $this->options_accounting[ $field_id ] ) ? $this->options_accounting[ $field_id ] : '', 784 'placeholder' => '1020' 785 ) 786 ); 787 788 } 789 790 } 791 792 public function options_collective_invoice() { 793 794 $section = 'collective_invoice_settings'; 795 add_settings_section( 796 $section, // ID 797 esc_html__( 'Collective Invoice', 'run-my-accounts-for-woocommerce' ), // Title 798 array( $this, 'section_info_collective_invoice' ), // Callback 799 $this->option_page_collective_invoice // Page 800 ); 801 802 if( empty( $this->options_collective_invoice[ 'collective_invoice_next_date_ts' ] ) ) { 803 $text = esc_html__( 'The next invoice date cannot be calculated. Please set all options first.', 'run-my-accounts-for-woocommerce' ); 804 } 805 else { 806 $text = date_i18n( get_option('date_format') , $this->options_collective_invoice[ 'collective_invoice_next_date_ts' ] ); 807 } 808 $id = 'collective_invoice_next_text'; 809 add_settings_field( 810 $id, 811 esc_html__('Next Invoice Date', 'run-my-accounts-for-woocommerce' ), 812 array( $this, 'plain_text_cb'), 813 $this->option_page_collective_invoice, 814 $section, 815 array( 816 'text' => $text, 817 'class' => 'next-invoice-date' 818 ) 819 ); 820 821 $id = 'collective_invoice_period'; 822 add_settings_field( 823 $id, 824 esc_html__('Invoice Period', 'run-my-accounts-for-woocommerce'), 825 array( $this, 'option_select_cb'), 826 $this->option_page_collective_invoice, 827 $section, 828 array( 829 'option_group' => $this->option_group_collective_invoice, 830 'id' => $id, 831 'options' => $this->options_collective_invoice, 832 'select_options' => array( 833 'week' => esc_html__( 'Once a week','run-my-accounts-for-woocommerce'), 834 'second_week' => esc_html__( 'Every second week','run-my-accounts-for-woocommerce'), 835 'month' => esc_html__( 'Every month (first weekday of the month)','run-my-accounts-for-woocommerce'), 836 ), 837 'description' => esc_html__('For what period of time should collective invoices be created?', 'run-my-accounts-for-woocommerce' ), 838 'class' => 'collective-invoice__period' 839 ) 840 ); 841 842 $id = 'collective_invoice_weekday'; 843 add_settings_field( 844 $id, 845 esc_html__('Weekday', 'run-my-accounts-for-woocommerce'), 846 array( $this, 'option_input_multiple_radio_cb'), 847 $this->option_page_collective_invoice, 848 $section, 849 array( 850 'option_group' => $this->option_group_collective_invoice, 851 'id' => $id, 852 'value' => $this->options_collective_invoice[$id] ?? '', 853 'description' => esc_html__('Please select the days of the week on which a collective invoice should be created.', 'run-my-accounts-for-woocommerce' ), 854 'values' => array( 855 'monday' => esc_html__( 'Monday', 'run-my-accounts-for-woocommerce' ), 856 'tuesday' => esc_html__( 'Tuesday', 'run-my-accounts-for-woocommerce' ), 857 'wednesday' => esc_html__( 'Wednesday', 'run-my-accounts-for-woocommerce' ), 858 'thursday' => esc_html__( 'Thursday', 'run-my-accounts-for-woocommerce' ), 859 'friday' => esc_html__( 'Friday', 'run-my-accounts-for-woocommerce' ), 860 'saturday' => esc_html__( 'Saturday', 'run-my-accounts-for-woocommerce' ), 861 'sunday' => esc_html__( 'Sunday', 'run-my-accounts-for-woocommerce' ), 862 ), 863 'line_break' => false, 864 'class' => 'collective-invoice__weekday' 865 ) 866 ); 867 868 $id = 'collective_invoice_span'; 869 add_settings_field( 870 $id, 871 esc_html__('Invoice Span', 'run-my-accounts-for-woocommerce'), 872 array( $this, 'option_select_cb'), 873 $this->option_page_collective_invoice, 874 $section, 875 array( 876 'option_group' => $this->option_group_collective_invoice, 877 'id' => $id, 878 'options' => $this->options_collective_invoice, 879 'select_options' => array( 880 'all' => esc_html__( 'All unbilled invoices','run-my-accounts-for-woocommerce'), 881 'per_week' => esc_html__( 'Day of creation and a week before','run-my-accounts-for-woocommerce'), 882 'per_month' => esc_html__( 'Day of creation and a month before','run-my-accounts-for-woocommerce'), 883 ), 884 'description' => esc_html__('For what period of time should collective invoices be created?', 'run-my-accounts-for-woocommerce' ), 885 886 ) 887 ); 888 889 } 890 891 public function section_info_accounting() { 892 esc_html_e('You can specify a dedicated receivable account for each active payment gateway.', 'run-my-accounts-for-woocommerce'); 893 } 894 895 public function section_info_collective_invoice() { 896 esc_html_e('Set up the handling of the collective invoices', 'run-my-accounts-for-woocommerce'); 897 } 898 899 public function section_info_payment() { 900 esc_html_e('You can specify a dedicated payment account for each active payment gateway.', 'run-my-accounts-for-woocommerce'); 901 } 902 903 /** 904 * Page Error Log, Section Log 905 */ 906 public function log() { 907 908 $section = 'log'; 909 910 add_settings_section( 911 $section, // ID 912 esc_html__('Error Log', 'run-my-accounts-for-woocommerce'), 913 array( $this, 'section_info_log' ), // Callback 914 $this->option_page_log // Page 915 ); 916 917 $id = 'rma-error-log'; 918 add_settings_field( 919 $id, 920 '', 921 array( $this, 'output_log'), // general callback for checkbox 922 $this->option_page_log, 923 $section 924 ); 925 926 } 927 928 public function section_info_log() { 929 echo sprintf( esc_html__('We have moved the logs to %s', 'run-my-accounts-for-woocommerce'), '<a href="https://plugins.trac.wordpress.org/wp-admin/admin.php?page=wc-status&tab=logs">' . esc_html__('WooCommerce Logs', 'run-my-accounts-for-woocommerce') . '</a>'); 930 } 931 932 /** 933 * General Input Field Checkbox 934 * 935 * @param array $args 936 */ 937 public function option_input_checkbox_cb( $args ){ 938 939 $option_group = ( isset( $args['option_group'] ) ) ? $args['option_group'] : ''; 940 $id = ( isset( $args['id'] ) ) ? $args['id'] : ''; 941 $checked = ( isset( $args['value'] ) && !empty( $args['value'] ) ) ? 'checked' : ''; 942 $description = ( isset( $args['description'] ) ) ? $args['description'] : ''; 943 944 printf( 945 '<input type="checkbox" id="%1$s" name="%3$s[%1$s]" value="1" %2$s />', 946 $id, $checked, $option_group 947 ); 948 949 if ( !empty( $description) ) 950 echo '<p class="description">' . $description . '</p>'; 951 952 } 953 954 /** 955 * General Input with Multiple Checkboxes 956 * 957 * @param array $args 958 * 959 * @since 1.7.0 960 */ 961 public function option_input_multiple_checkbox_cb( $args ){ 962 963 $legend = ( isset( $args['legend'] ) ) ? $args['legend'] : ''; 964 $option_group = ( isset( $args['option_group'] ) ) ? $args['option_group'] : ''; 965 $id = ( isset( $args['id'] ) ) ? $args['id'] : ''; 966 $options = ( isset( $args['options'] ) ) ? $args['options'] : ''; 967 $description = ( isset( $args['description'] ) ) ? $args['description'] : ''; 968 $values = ( isset( $args['values'] ) ) ? $args['values'] : ''; 969 $line_break = ( isset( $args['line_break'] ) ) ? $args['line_break'] : true; 970 971 if( 0 == count( $values ) ) 972 return; 973 974 echo '<fieldset id="' . $id . '"> '; 975 if( $legend ) { 976 printf( '<legend>%1$s</legend>', $legend ); 977 } 978 979 foreach ( $values as $key => $title ) { 980 981 $checked = isset( $options[ $id . '-'. $key ] ) && 1 == $options[ $id . '-'. $key ] ? 'checked' : ''; 982 $br = isset( $line_break ) && true === $line_break ? '<br>' : ' '; 983 984 printf( 985 '<input type="checkbox" id="%5$s" name="%3$s[%1$s-%5$s]" value="1" %2$s /><label for="%5$s">%4$s</label>%6$s', 986 $id, $checked, $option_group, $title, $key, $br 987 ); 988 989 } 990 991 echo '</fieldset>'; 992 993 if ( !empty( $description) ) 994 echo '<p class="description">' . $description . '</p>'; 995 996 } 997 998 /** 999 * General Input with Multiple Checkboxes 1000 * 1001 * @param array $args 1002 * 1003 * @since 1.7.0 1004 */ 1005 public function option_input_multiple_radio_cb( $args ){ 1006 1007 $legend = ( isset( $args['legend'] ) ) ? $args['legend'] : ''; 1008 $option_group = ( isset( $args['option_group'] ) ) ? $args['option_group'] : ''; 1009 $id = ( isset( $args['id'] ) ) ? $args['id'] : ''; 1010 $value = ( isset( $args['value'] ) ) ? $args['value'] : ''; 1011 $description = ( isset( $args['description'] ) ) ? $args['description'] : ''; 1012 $values = ( isset( $args['values'] ) ) ? $args['values'] : ''; 1013 $line_break = ( isset( $args['line_break'] ) ) ? $args['line_break'] : true; 1014 1015 if( 0 == count( $values ) ) 1016 return; 1017 1018 if( $legend ) { 1019 printf( '<legend>%1$s</legend>', $legend ); 1020 } 1021 1022 foreach ( $values as $key => $title ) { 1023 1024 $checked = $value == $key ? 'checked' : ''; 1025 $br = isset( $line_break ) && true === $line_break ? '<br>' : ' '; 1026 1027 printf( 1028 '<input type="radio" id="%5$s" name="%3$s[%1$s]" value="%5$s" %2$s /><label for="%5$s">%4$s</label>%6$s', 1029 $id, $checked, $option_group, $title, $key, $br 1030 ); 1031 1032 } 1033 1034 if ( !empty( $description) ) 1035 echo '<p class="description">' . $description . '</p>'; 1036 1037 } 1038 1039 /** 1040 * Input Field with Multiple Checkboxes for Payment Gateways 1041 * 1042 * @param array $args 1043 */ 1044 public function option_input_multiple_payment_gateway_checkbox_cb( $args ){ 1045 1046 // add settings fields for all payment gateways 1047 $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); 1048 1049 if( 0 == count( $available_gateways ) ) 1050 return; 1051 1052 $legend = ( isset( $args['legend'] ) ) ? $args['legend'] : ''; 1053 $option_group = ( isset( $args['option_group'] ) ) ? $args['option_group'] : ''; 1054 $id = ( isset( $args['id'] ) ) ? $args['id'] : ''; 1055 $description = ( isset( $args['description'] ) ) ? $args['description'] : ''; 1056 1057 $s = get_option('wc_rma_settings'); 1058 1059 echo '<fieldset id="' . $id . '"> '; 1060 if( $legend ) { 1061 printf( '<legend>%1$s</legend>', $legend ); 1062 } 1063 1064 foreach ( $available_gateways as $gateway_key => $values ) { 1065 1066 $checked = ( isset( $this->options_general[ $id . '-'. $gateway_key ] ) && 1 == $this->options_general[ $id . '-'. $gateway_key ] ) ? 'checked' : ''; 1067 1068 printf( 1069 '<input type="checkbox" id="%5$s" name="%3$s[%1$s-%5$s]" value="1" %2$s /> %4$s<br />', 1070 $id, $checked, $option_group, $values->title, $gateway_key 1071 ); 1072 1073 } 1074 1075 echo '</fieldset>'; 1076 1077 if ( !empty( $description) ) 1078 echo '<p class="description">' . $description . '</p>'; 1079 1080 } 1081 1082 /** 1083 * General Input Field Text 1084 * 1085 * @param array $args 1086 */ 1087 public function option_input_text_cb( $args ) { 1088 1089 $option_group = ( isset( $args['option_group'] ) ) ? $args['option_group'] : ''; 1090 $id = ( isset( $args['id'] ) ) ? $args['id'] : ''; 1091 $value = ( isset( $args['value'] ) ) ? $args['value'] : ''; 1092 $placeholder = ( isset( $args['placeholder'] ) ) ? $args['placeholder'] : ''; 1093 $description = ( isset( $args['description'] ) ) ? $args['description'] : ''; 1094 1095 printf( 1096 '<input type="text" id="%1$s" name="%3$s[%1$s]" value="%2$s" placeholder="%4$s" />', 1097 $id, $value, $option_group, $placeholder 1098 ); 1099 1100 if ( !empty( $description) ) 1101 echo '<p class="description">' . $description . '</p>'; 1102 } 1103 1104 /** 1105 * General Select 1106 * 1107 * @param array $args 1108 */ 1109 public function option_select_cb( $args ) { 1110 $option_group = (isset($args['option_group'])) ? $args['option_group'] : ''; 1111 $id = (isset($args['id'])) ? $args['id'] : ''; 1112 $options = (isset($args['options'])) ? $args['options'] : ''; 1113 $select_options = (isset($args['select_options'])) ? $args['select_options'] : array(); 1114 $description = (isset($args['description'])) ? $args['description'] : ''; 1115 $class = (isset($args['class'])) ? $args['class'] : ''; 1116 1117 echo '<select name="' . $option_group . '[' . $id . ']"' . ( !empty( $class) ? 'id="'. $id .'" class="' . $class . '"' : '' ) . '>'; 1118 1119 foreach ( $select_options as $value => $text ) { 1120 printf( 1121 '<option value="%1$s" %2$s />%3$s</option>', 1122 $value, 1123 ( isset( $options[ $id ] ) && $value == $options[ $id ] ) ? 'selected="selected"' : '', 1124 $text 1125 ); 1126 } 1127 1128 echo '</select>'; 1129 1130 if ( !empty( $description) ) 1131 echo '<p class="description">' . $description . '</p>'; 1132 1133 } 1134 1135 /** 1136 * @param array 1137 */ 1138 public function plain_text_cb( $args ) { 1139 $text = ( isset( $args[ 'text' ] ) ) ? $args[ 'text' ] : ''; 1140 $class = ( isset( $args[ 'class' ] ) ) ? $args[ 'class' ] : ''; 1141 1142 echo '<p class="' . $class . '">' . $text . '</p>'; 1143 } 1144 1145 /** 1146 * Individual pulldown 1147 * 1148 * @param array $args 1149 */ 1150 public function rma_mode_cb( $args ) { 1151 $option_group = ( isset( $args['option_group'] ) ) ? $args['option_group'] : ''; 1152 $id = ( isset( $args['id'] ) ) ? $args['id'] : ''; 1153 1154 $select_args = array( 1155 'option_group' => $option_group, 1156 'id' => $id, 1157 'options' => $this->options_general, 1158 'select_options' => array( 1159 'test' => esc_html__('Sandbox Test','run-my-accounts-for-woocommerce'), 1160 'live' => esc_html__('Production','run-my-accounts-for-woocommerce'), 1161 ) 1162 ); 1163 1164 // create select 1165 self::option_select_cb( $select_args ); 1166 1167 // output connection status 1168 $RMA_WC_API = new RMA_WC_API(); 1169 // Retrieve customers to check connection 1170 $options = $RMA_WC_API->get_customers(); 1171 unset( $RMA_WC_API ); 1172 1173 if ( ! $options ) 1174 echo ' <span style="color: red; font-weight: bold">' . __('No connection. Please check your settings.', 'run-my-accounts-for-woocommerce') . '</span>'; 1175 else 1176 echo ' <span style="color: green">' . __('Connection successful.', 'run-my-accounts-for-woocommerce') . '</span>'; 1177 1178 } 1179 1180 /** 1181 * Pull down with RMA customer list 1182 * 1183 * @param $args 1184 */ 1185 public function rma_customer_accounts_cb( $args ) { 1186 $option_group = ( isset( $args['option_group'] ) ) ? $args['option_group'] : ''; 1187 $id = ( isset( $args['id'] ) ) ? $args['id'] : ''; 1188 1189 $RMA_WC_API = new RMA_WC_API(); 1190 $options = $RMA_WC_API->get_customers(); 1191 1192 if ( !empty( $RMA_WC_API ) ) unset( $RMA_WC_API ); 1193 1194 if( !isset( $options ) || !$options ) { 1195 1196 $options = array('' => __( 'Error while connecting to RMA. Please check your settings.', 'run-my-accounts-for-woocommerce' ) ); 1197 1198 } 1199 else { 1200 1201 $options = array('' => __( 'Select...', 'run-my-accounts-for-woocommerce' ) ) + $options; 1202 1203 } 1204 1205 $select_args = array ( 1206 'option_group' => $option_group, 1207 'id' => $id, 1208 'options' => $this->options_general, 1209 'select_options' => $options, 1210 'class' => 'select2' 1211 ); 1212 1213 // create select 1214 self::option_select_cb( $select_args ); 1215 1216 } 1217 1218 /** 1219 * Pull down with RMA parts list 1220 * 1221 * @param $args 1222 * 1223 * @since 1.5.0 1224 */ 1225 public function rma_parts_cb( $args ) { 1226 $option_group = ( isset( $args['option_group'] ) ) ? $args['option_group'] : ''; 1227 $id = ( isset( $args['id'] ) ) ? $args['id'] : ''; 1228 $description = ( isset( $args['description'] ) ) ? $args['description'] : ''; 1229 1230 if ( !isset( $parts ) || empty( $parts ) ) { 1231 1232 $rma_api = new RMA_WC_API(); 1233 $parts = $rma_api->get_parts(); 1234 1235 if ( !empty( $RMA_WC_API ) ) unset( $RMA_WC_API ); 1236 1237 } 1238 1239 if( !isset( $parts ) || !$parts ) { 1240 1241 $options = array('' => __( 'Error while connecting to RMA. Please check your settings.', 'run-my-accounts-for-woocommerce' ) ); 1242 1243 } 1244 else { 1245 1246 $options = array('' => __( 'Select...', 'run-my-accounts-for-woocommerce' ) ) + $parts; 1247 1248 } 1249 1250 $select_args = array ( 1251 'option_group' => $option_group, 1252 'id' => $id, 1253 'options' => $this->options_general, 1254 'select_options' => $options, 1255 'description' => $description, 1256 'class' => 'select2' 1257 ); 1258 1259 // create select 1260 self::option_select_cb( $select_args ); 1261 1262 } 1263 1264 /** 1265 * Sanitizes a string from user input 1266 * Checks for invalid UTF-8, Converts single < characters to entities, Strips all tags, Removes line breaks, tabs, and extra whitespace, Strips octets 1267 * 1268 * @param array $input 1269 * 1270 * @return array 1271 */ 1272 public function sanitize( $input ) { 1273 1274 $new_input = array(); 1275 1276 foreach ( $input as $key => $value ) { 1277 1278 $new_input[ $key ] = sanitize_text_field( $input[ $key ] ); 1279 1280 } 1281 1282 return $new_input; 1283 } 1284 1285 } 1412 1286 1413 1287 } -
run-my-accounts-for-woocommerce/trunk/readme.txt
r3231536 r3262812 2 2 * Contributors: openstream 3 3 * Tags: Run my Accounts, WooCommerce, Billing 4 * Requires at least: 4.75 * Tested up to: 6. 76 * Stable tag: 1. 7.14 * Requires at least: 6.2 5 * Tested up to: 6.8 6 * Stable tag: 1.8.0 7 7 * Requires PHP: 7.2 8 * License: GPLv 39 * License URI: https://www.gnu.org/licenses/gpl- 3.0.html8 * License: GPLv2 9 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 11 This plug-in connects WooCommerce with Run my Accounts. … … 54 54 55 55 == Changelog == 56 = 1.8.0 = 57 * Added support for WooCommerce HPOS 58 * Added code improvements, escaping and sanitizing text 59 * Moved language handling to [GlotPress](https://translate.wordpress.org/projects/wp-plugins/run-my-accounts-for-woocommerce/) 60 * Bumped required WordPress version to 6.2 61 * Bumped required WooCommerce version to 8.2 62 56 63 = 1.7.1 = 57 64 * Fix - added handling cURL error on settings page 58 * Compatibility - tested up to WooCommerce 7.4 65 * Compatibility - tested up to WooCommerce 7.4 - 8.3 59 66 * Compatibility - tested up to WordPress 6.2 - 6.7 60 67 -
run-my-accounts-for-woocommerce/trunk/rma-wc.php
r2873238 r3262812 1 1 <?php 2 3 2 /** 4 3 * rma-wc.php … … 8 7 * @package RunmyAccountsforWooCommerce 9 8 * @author Sandro Lucifora 10 * @copyright 202 3Openstream Internet Solutions9 * @copyright 2025 Openstream Internet Solutions 11 10 * @license GPL-3.0-or-later 12 11 * 13 12 * Plugin Name: Run my Accounts for WooCommerce 14 * Version: 1. 7.113 * Version: 1.8.0 15 14 * Description: This plug-in connects WooCommerce to <a href="https://www.runmyaccounts.ch/">Run my Accounts</a>. Create customers and invoices as soon as you get an order in your WooCommerce shop. 16 * Requires at least: 4.715 * Requires at least: 6.2 17 16 * Requires PHP: 7.2 18 17 * Author: Openstream Internet Solutions 19 18 * Author URI: https://www.openstream.ch 20 * Text Domain: rma-wc 21 * Domain Path: /languages/ 22 * WC requires at least: 3.2 23 * WC tested up to: 7.4 19 * Text Domain: run-my-accounts-for-woocommerce 20 * WC requires at least: 8.2 21 * WC tested up to: 9.7 24 22 * License: GPL v2 or later 25 23 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 26 24 */ 27 25 28 if ( ! defined('ABSPATH' ) ) exit;26 if ( ! defined('ABSPATH' ) ) exit; 29 27 30 28 // Set full path 31 if (!defined('RMA_WC_PFAD')) { define('RMA_WC_PFAD', plugin_dir_path(__FILE__)); } 32 if (!defined('RMA_WC_LOG_TABLE')) { define('RMA_WC_LOG_TABLE', 'rma_wc_log'); } 29 if ( ! defined('RMA_WC_PFAD') ) { 30 define('RMA_WC_PFAD', trailingslashit( plugin_dir_path( __FILE__) ) ); 31 } 33 32 34 33 /** 35 * Class autoload for plugin classes which contains RMA in the class name34 * Declare WooCommerce HPOS compatibility 36 35 * 37 * @ param $class_name36 * @since 1.8.0 38 37 */ 39 function rma_wc_autoloader( $class_name ) 40 { 41 if ( false !== strpos( $class_name, 'RMA' ) ) { 42 require_once plugin_dir_path(__FILE__) . 'classes/class-' . $class_name . '.php'; 43 } 38 function rma_declare_hpos() : void{ 39 if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { 40 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); 41 } 44 42 } 43 add_action( 'before_woocommerce_init', 'rma_declare_hpos'); 45 44 46 spl_autoload_register('rma_wc_autoloader'); 45 /** 46 * Load the main file only if WooCommerce is full loaded 47 * 48 * @return void 49 */ 50 function rma_woocommerce_loaded_action(){ 47 51 48 // LOAD BACKEND //////////////////////////////////////////////////////////////// 49 50 if ( is_admin() ) { 51 52 // Instantiate backend class 53 $RMA_WC_BACKEND = new RMA_WC_Backend(); 54 55 register_activation_hook(__FILE__, array('RMA_WC_Backend', 'activate') ); 56 register_deactivation_hook(__FILE__, array('RMA_WC_Backend', 'deactivate') ); 57 58 $my_settings_page = new RMA_WC_Settings_Page(); 52 include_once RMA_WC_PFAD . '/rma-wc-main.php'; 59 53 60 54 } 61 62 /* 63 * Instantiate Frontend Class 64 */ 65 $RMA_WC_FRONTEND = new RMA_WC_Frontend(); 66 67 $t = new RMA_WC_Collective_Invoicing(); 68 69 /* 70 * Integration of WooCommerce Rental & Booking System if activated 71 * https://codecanyon.net/item/rnb-woocommerce-rental-booking-system/14835145 72 */ 73 $active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) ); 74 $required_plugins = ['woocommerce-rental-and-booking']; 75 if ( count( array_intersect( $required_plugins, $active_plugins ) ) !== count( $required_plugins ) ) { 76 77 $RMA_RnB = new RMA_WC_Rental_And_Booking(); 78 79 } 55 add_action( 'woocommerce_loaded', 'rma_woocommerce_loaded_action' ); -
run-my-accounts-for-woocommerce/trunk/templates/email/error-email-template.php
r2332202 r3262812 1 <p><?php echo esc_html_X('While connecting with Run my Accounts API the following error occurred:', 'error email body', 'r ma-wc') ?></p>1 <p><?php echo esc_html_X('While connecting with Run my Accounts API the following error occurred:', 'error email body', 'run-my-accounts-for-woocommerce') ?></p> 2 2 <table border="1"> 3 3 <tr> 4 <th><?php echo esc_html_x('Mode', 'error email body', 'r ma-wc') ?></th>5 <th><?php echo esc_html_x('Section', 'error email body', 'r ma-wc') ?></th>6 <th><?php echo esc_html_x('Section ID', 'error email body', 'r ma-wc') ?></th>7 <th><?php echo esc_html_x('Message', 'error email body', 'r ma-wc') ?></th>4 <th><?php echo esc_html_x('Mode', 'error email body', 'run-my-accounts-for-woocommerce') ?></th> 5 <th><?php echo esc_html_x('Section', 'error email body', 'run-my-accounts-for-woocommerce') ?></th> 6 <th><?php echo esc_html_x('Section ID', 'error email body', 'run-my-accounts-for-woocommerce') ?></th> 7 <th><?php echo esc_html_x('Message', 'error email body', 'run-my-accounts-for-woocommerce') ?></th> 8 8 </tr> 9 9 <tr> 10 <td><?php echo $values['mode']; ?></td>11 <td><?php echo $values['section']; ?></td>12 <td><?php echo $values['section_id']; ?></td>13 <td><?php echo $values['message']; ?></td>10 <td><?php sanitize_text_field( $values['mode'] ); ?></td> 11 <td><?php sanitize_text_field( $values['section'] ); ?></td> 12 <td><?php sanitize_text_field( $values['section_id'] ); ?></td> 13 <td><?php sanitize_text_field( $values['message'] ); ?></td> 14 14 </tr> 15 15 </table>
Note: See TracChangeset
for help on using the changeset viewer.