| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Pronamic\WordPress\Pay\Gateways\IDealBasic; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Pronamic\WordPress\Pay\Gateways\IDeal\AbstractIntegration; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * Title: Integration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * Description: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * Copyright: 2005-2020 Pronamic | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * Company: Pronamic | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @author  Remco Tolsma | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @version 2.1.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @since   1.0.0 | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 16 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  | class Integration extends AbstractIntegration { | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  | 	 * Construct iDEAL Basic integration. | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  | 	 * | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  | 	 * @param array $args Arguments. | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 	public function __construct( $args = array() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 		$args = wp_parse_args( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 			$args, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 			array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 				'id'               => 'ideal-basic', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 				'name'             => 'iDEAL Basic', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 				'url'              => \__( 'https://www.ideal.nl/en/', 'pronamic_ideal' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 				'product_url'      => \__( 'https://www.ideal.nl/en/', 'pronamic_ideal' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 				'manual_url'       => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 				'dashboard_url'    => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 				'provider'         => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 				'aquirer_url'      => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 				'aquirer_test_url' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 				'deprecated'       => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 				'supports'         => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 					'webhook', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 					'webhook_log', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 				), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 			) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		parent::__construct( $args ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		// Acquirer URL. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 		$this->aquirer_url      = $args['aquirer_url']; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		$this->aquirer_test_url = $args['aquirer_test_url']; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		// Actions. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 		$function = array( __NAMESPACE__ . '\Listener', 'listen' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 		if ( ! has_action( 'wp_loaded', $function ) ) { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 54 |  |  | 			add_action( 'wp_loaded', $function ); | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 	public function get_settings_fields() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		$fields = parent::get_settings_fields(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 		// Hash Key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		$fields[] = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 			'section'  => 'general', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 			'filter'   => FILTER_SANITIZE_STRING, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 			'meta_key' => '_pronamic_gateway_ideal_hash_key', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 			'title'    => __( 'Hash Key', 'pronamic_ideal' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 			'type'     => 'text', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 			'classes'  => array( 'regular-text', 'code' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 			'tooltip'  => __( 'Hash key (also known as: key or secret key) as mentioned in the payment provider dashboard.', 'pronamic_ideal' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 			'methods'  => array( 'ideal-basic' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 		// XML Notification URL. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		$fields[] = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 			'section'  => 'feedback', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 			/* translators: Translate 'XML notification URL' the same as in the iDEAL Basic dashboard. */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 			'title'    => _x( 'XML Notification URL', 'iDEAL Basic dashboard', 'pronamic_ideal' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 			'type'     => 'text', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 			'classes'  => array( 'regular-text', 'code' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 			'value'    => add_query_arg( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 				array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 					'gateway'          => 'IDealBasic', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 					'xml_notification' => 'true', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 				), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 				site_url( '/' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 			), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 			'methods'  => array( 'ideal-basic' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 			'readonly' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 			'size'     => 200, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 			/* translators: Translate 'XML notification URL' the same as in the iDEAL Basic dashboard. */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 			'tooltip'  => _x( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 				'Copy the XML notification URL to the payment provider dashboard to receive automatic transaction status updates.', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 				'iDEAL Basic dashboard', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 				'pronamic_ideal' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 			), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 		// Return fields. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 99 |  |  | 		return $fields; | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 	public function get_config( $post_id ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 		$mode = get_post_meta( $post_id, '_pronamic_gateway_mode', true ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 		$config = new Config(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 		$config->url = $this->aquirer_url; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 		if ( 'test' === $mode && null !== $this->aquirer_test_url ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 			$config->url = $this->aquirer_test_url; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 		$config->merchant_id = get_post_meta( $post_id, '_pronamic_gateway_ideal_merchant_id', true ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 		$config->sub_id      = get_post_meta( $post_id, '_pronamic_gateway_ideal_sub_id', true ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 		$config->hash_key    = get_post_meta( $post_id, '_pronamic_gateway_ideal_hash_key', true ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 		$config->purchase_id = get_post_meta( $post_id, '_pronamic_gateway_ideal_purchase_id', true ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 118 |  |  | 		return $config; | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  | 	 * Get gateway. | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  | 	 * | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  | 	 * @param int $post_id Post ID. | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  | 	 * @return Gateway | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 	public function get_gateway( $post_id ) { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 128 |  |  | 		return new Gateway( $this->get_config( $post_id ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 130 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 131 |  |  |  |