| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Config factory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @author    Pronamic <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @copyright 2005-2018 Pronamic | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @license   GPL-3.0-or-later | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @package   Pronamic\WordPress\Pay\Gateways\OmniKassa2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Pronamic\WordPress\Pay\Core\GatewayConfigFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * Config factory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @author  Remco Tolsma | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @version 2.0.2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @since   1.0.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | class ConfigFactory extends GatewayConfigFactory { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 	 * Get configuration by post ID. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 	 * @param string $post_id Post ID. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	 * @return Config | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 28 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  | 	public function get_config( $post_id ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  | 		$config = new Config(); | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  | 		$config->post_id                  = $post_id; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  | 		$config->mode                     = $this->get_meta( $post_id, 'mode' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  | 		$config->refresh_token            = $this->get_meta( $post_id, 'omnikassa_2_refresh_token' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  | 		$config->signing_key              = $this->get_meta( $post_id, 'omnikassa_2_signing_key' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  | 		$config->access_token             = $this->get_meta( $post_id, 'omnikassa_2_access_token' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  | 		$config->access_token_valid_until = $this->get_meta( $post_id, 'omnikassa_2_access_token_valid_until' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  | 		$config->order_id                 = $this->get_meta( $post_id, 'omnikassa_2_order_id' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  | 		return $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	 * Get meta value. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	 * @param string|int $post_id Post ID. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	 * @param string     $key     Shortened meta key. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 	private function get_meta( $post_id, $key ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 		if ( empty( $post_id ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 			return ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		$post_id = intval( $post_id ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		$meta_key = sprintf( '_pronamic_gateway_%s', $key ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		// Get post meta. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 		$meta_value = get_post_meta( $post_id, $meta_key, true ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 		if ( false === $meta_value ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 			$meta_value = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		return $meta_value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 69 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |  |